atm_digital startup state
us292231 opened this issue · comments
I really like your framework -- well done.
With that said, I'm still having a difficult time getting started. I want to control an alarm on a couple of doors. One is a simple switch with timer and the other has switches for open and closed with timers.
Here is my first question: with the atm_digital, how do you setup/determine initial state? When I start in the grounded/closed state all works well. However, when I start in the pull-up/open state the machine doesn't go into the open state. I have tried several ways, but nothing seems to be obvious. I am trying to use a single atm_digital object that initially moves from None to Idle, but doesn't move to the waitl or vlow state. I have tried using an external atm_digital and attaching that to my state machine as well as having the switch inside of my state machine.
Here is the begin method that seems to work the best so far:
PassageDoor& PassageDoor::begin(unsigned long doorSwitch) {
// clang-format off
const static state_t state_table[] PROGMEM = {
/* ON_ENTER ON_LOOP ON_EXIT EVT_OPENTIMEOUT EVT_OPENED EVT_CLOSED ELSE /
/ CLOSED / ENT_CLOSED, -1, EXT_CLOSED, -1, OPEN, -1, -1,
/ OPEN / -1, -1, -1, OPENTIMEOUT, -1, CLOSED, -1,
/ OPENTIMEOUT */ ENT_OPENTIMEOUT, -1, -1, -1, -1, CLOSED, OPEN,
};
// clang-format on
sw = doorSwitch;
pdswitch.begin(sw, 500, true, true)
.trace(Serial)
.onChange(LOW, *this, EVT_OPENED)
.onChange(HIGH, *this, EVT_CLOSED);
;
Machine::begin( state_table, ELSE );
next = pdswitch.state() ? OPEN : CLOSED; // Set initial state based on switch position
timer.begin(5000,1)
.onFinish(*this, EVT_OPENTIMEOUT);
return *this;
}
Second question: Once a state has been reached I want to send a mqtt message. Should I put that code in the state machine's event method or have a callback out to the code that manages the mqtt connection? What is the intended use of the and parameters on the push method?
Any suggestions on how to structure this would be appreciated.
Thank you,
Jim
Back... After looking at (studying) the atm_digital state machine I modified my state machine and added another 'idle' state and assumed that the door was open. After making this change my default state is correct on boot and the timeouts work.
Thanks again for the fine library, it really helps.
Jim