Generalized-Core-Counter 3.20
Particle-based generalized core counter firmware
Loading...
Searching...
No Matches
StateMachine.h
Go to the documentation of this file.
1#pragma once
2
3#include "Particle.h"
4#include "AB1805_RK.h"
5
6// Core device state machine states
16
17// Global state variables (defined in Generalized-Core-Counter.cpp)
18extern State state;
19extern State oldState;
20extern char stateNames[7][16];
21
22// Sleep configuration and RTC/watchdog (defined in Generalized-Core-Counter.cpp)
23extern SystemSleepConfiguration config;
24extern AB1805 ab1805;
25
26// System health / flags shared across modules
27extern int outOfMemory;
28extern volatile bool userSwitchDetected;
29extern volatile bool sensorDetect;
30extern bool dataInFlight;
31
32// Connection / power management timing shared between the
33// state machine core and state handlers.
34extern const unsigned long stayAwakeLong;
35extern const unsigned long resetWait;
36extern const unsigned long maxOnlineWorkMs;
37extern const unsigned long maxConnectAttemptMs;
38extern const int wakeBoundary;
39extern unsigned long connectedStartMs;
40extern bool lastLowPowerMode;
41extern bool firstConnectionObserved;
44
45// Helper functions used by multiple state handlers
49
50// Shared software timer for BLUE_LED visibility on count events
51extern Timer countSignalTimer;
52
53// Application-level helpers implemented in Generalized-Core-Counter.cpp
54void dailyCleanup();
55void publishData();
const int wakeBoundary
const unsigned long resetWait
bool firstConnectionObserved
bool firstConnectionQueueDrainedLogged
volatile bool userSwitchDetected
volatile bool sensorDetect
unsigned long connectedStartMs
SystemSleepConfiguration config
char stateNames[7][16]
bool hibernateDisabledForSession
const unsigned long maxConnectAttemptMs
const unsigned long stayAwakeLong
void dailyCleanup()
Cleanup function that is run at the beginning of the day.
int secondsUntilNextOpen()
bool lastLowPowerMode
State
Definition StateMachine.h:7
@ SLEEPING_STATE
@ CONNECTING_STATE
@ FIRMWARE_UPDATE_STATE
@ REPORTING_STATE
@ ERROR_STATE
Definition StateMachine.h:9
@ INITIALIZATION_STATE
Definition StateMachine.h:8
@ IDLE_STATE
void publishData()
Publish sensor data to Ubidots webhook and device-data ledger.
AB1805 ab1805
Timer countSignalTimer
bool isWithinOpenHours()
const unsigned long maxOnlineWorkMs
void publishStateTransition()