voidsleepNow() {step.on_sleep(false); // reset state machine.the_twelite.sleep(10000); // 10sec}
ソースコード
以下にSM_SIMPLEのソースコードを示します。
// very simple class to control state used in loop().template <typenameSTATE>classSM_SIMPLE {uint32_t _u32_flag_value; // optional data when flag is set.uint32_t _ms_start; // system time when start waiting.uint32_t _ms_timeout; // timeout duration STATE _step; // current state STATE _step_prev; // previous statebool_t _b_flag; // flag control.public: // initvoidsetup() { memset(this,0,sizeof(SM_SIMPLE)); } // call befoer sleeping (save state machine status)voidon_sleep(bool b_save_state =false) { STATE save = _step;setup();if(b_save_state) _step = _step_prev = save; } // state controlvoidnext(STATE next) { _step = next; } // set next stateSTATEstate() { return _step; } // state numberboolb_more_loop() { // if state is changed during the loop, set trueif (_step != _step_prev) { _step_prev = _step; returntrue; }elsereturnfalse; } // timeout controlvoidset_timeout(uint32_t timeout) { _ms_start =millis(); _ms_timeout = timeout; }boolis_timeout() { return (millis() - _ms_start) >= _ms_timeout; } // flag controlvoidclear_flag() { _b_flag =false; _u32_flag_value =0; }voidset_flag(uint32_t u32_flag_value =0) { _b_flag =true; _u32_flag_value = u32_flag_value; }uint32_tget_flag_value() { return _u32_flag_value; }boolis_flag_ready() { return _b_flag; }};