Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
Typedefs | Functions | Variables
lampda::logic::behavior Namespace Reference

Main system behavior handle. More...

Typedefs

using BehaviorStates = enum class behavior_t { START_LOGIC, PRE_CHARGER_OPERATION, CHARGER_OPERATIONS, PRE_OUTPUT_LIGHT, OUTPUT_LIGHT, POST_OUTPUT_LIGHT, SHUTDOWN, ERROR, }
 

Functions

bool did_woke_up_from_power ()
 
bool is_system_should_be_powered ()
 
void set_power_on ()
 set system state to "output on"
 
void set_power_off ()
 set system state to "output off". Can be ignored
 
void go_to_external_battery_mode ()
 Try to switch to external battery mode.
 
bool is_in_start_logic_state ()
 return true if the system is in start mode
 
bool is_in_output_state ()
 return true if the system is in output mode
 
bool is_in_charge_state ()
 return true if the system is in charge mode
 
bool can_system_allowed_to_be_powered ()
 true if system can work at all (charger or output mode)
 
bool is_charger_powered ()
 
bool read_parameters ()
 Load the parameters from the filesystem.
 
void setup_clean_sleep_flag ()
 
void write_parameters (const bool shouldSaveUserParameters=true, const bool shouldSaveSystemParameters=true)
 
bool is_user_code_running ()
 
void true_power_off ()
 
void set_error_state_message (const std::string &errorMsg)
 
std::string get_error_state_message ()
 return the error message associated with the error state
 
void go_to_error_state (const std::string &errorMsg)
 
void state_machine_behavior ()
 Handle the behavior states.
 
void set_woke_up_from_vbus (const bool wokeUp)
 call once at program start, before the first main loop runs The system was powered from a vbus powered event, not a user action
 
void loop ()
 
std::string get_state ()
 

Variables

static constexpr uint32_t cleanSleepKey = utils::hash("cleanSleep")
 
static constexpr uint32_t brightnessKey = utils::hash("brightness")
 
static constexpr uint32_t indicatorLevelKey = utils::hash("indLvl")
 
static constexpr uint32_t isLockoutModeKey = utils::hash("lckMode")
 
static constexpr uint32_t buttonPinKey = utils::hash("bttPin")
 
static constexpr uint32_t bluetoothAutoKey = utils::hash("ble")
 
static constexpr uint32_t SYSTEM_TURN_ON_ALLOW_TURN_OFF_DELAY = 500
 
static constexpr uint32_t PRE_CHARGE_STATE_TIMEOUT_ms = 1000
 
static constexpr uint32_t PRE_OUTPUT_STATE_TIMEOUT_ms = 1000
 
static constexpr uint32_t maxBluetoothAutoActivations = 3
 bluetooth will power up automatically this number of next boots if user used it
 
static uint32_t wakeUpTime = 0
 
static uint32_t preOutputLightCalled = 0
 
static bool wokeUpFromVbus_s = false
 
static bool isTargetPoweredOn_s = false
 
static std::string errorStateRaisedStr = ""
 
static uint32_t preChargeCalled = 0
 
static uint32_t lastOutputLightValidTime = 0
 
static uint32_t bluetoothAutoActivationLeftCount = 0
 keep track of the number of auto bluetooth activation left
 
const char * BehaviorStatesStr []
 
utils::StateMachine< BehaviorStates > mainMachine (BehaviorStates::START_LOGIC)
 

Detailed Description

Main system behavior handle.

Function Documentation

◆ is_user_code_running()

bool lampda::logic::behavior::is_user_code_running ( )
Returns
true if the user code is runing

◆ read_parameters()

bool lampda::logic::behavior::read_parameters ( )

Load the parameters from the filesystem.

Returns
True is the parameters where loaded

◆ true_power_off()

void lampda::logic::behavior::true_power_off ( )

This turns off the system FOR REAL and enable the interrupt pin for power on DO NOT USE THIS IF YOU ARE NOT SURE, great potential for system brick/lock

Variable Documentation

◆ BehaviorStatesStr

const char* lampda::logic::behavior::BehaviorStatesStr[]
Initial value:
= {
"START_LOGIC",
"PRE_CHARGER_OPERATION",
"CHARGER_OPERATIONS",
"PRE_OUTPUT_LIGHT",
"OUTPUT_LIGHT",
"POST_OUTPUT_LIGHT",
"SHUTDOWN",
"ERROR",
}