Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MySwitchChannel : public ActorChannel<Hal,SwitchList1,SwitchList3,PEERS_PER_CHANNEL,SwList0,SwitchStateMachine> {
- class PinControl : public Alarm {
- private:
- uint8_t pin_long;
- uint8_t pin_short;
- bool first;
- public:
- PinControl () : Alarm(0), pin_long(0), pin_short(0), first(true) {}
- virtual ~PinControl () {}
- void initPins(uint8_t p_long,uint8_t p_short) {
- pin_long=p_long;
- pin_short=p_short;
- ArduinoPins::setOutput(pin_long);
- ArduinoPins::setOutput(pin_short);
- }
- void start() {
- ArduinoPins::setLow(pin_long);
- ArduinoPins::setLow(pin_short);
- sysclock.cancel(*this);
- first = true;
- set(millis2ticks(1000));
- ArduinoPins::setHigh(pin_long);
- sysclock.add(*this);
- }
- virtual void trigger (__attribute__ ((unused)) AlarmClock& clock) {
- if (first == true) {
- ArduinoPins::setLow(pin_long);
- ArduinoPins::setHigh(pin_short);
- set(millis2ticks(500));
- clock.add(*this);
- } else {
- ArduinoPins::setLow(pin_short);
- }
- first = false;
- }
- };
- PinControl pincontrol;
- protected:
- typedef ActorChannel<Hal,SwitchList1,SwitchList3,PEERS_PER_CHANNEL,SwList0,SwitchStateMachine> BaseChannel;
- public:
- MySwitchChannel () : BaseChannel() {}
- virtual ~MySwitchChannel() {}
- void init (uint8_t p_long,uint8_t p_short) {
- pincontrol.initPins(p_long, p_short);
- typename BaseChannel::List1 l1 = BaseChannel::getList1();
- this->set(l1.powerUpAction() == true ? 200 : 0, 0, 0xffff );
- this->changed(true);
- }
- uint8_t flags () const {
- return BaseChannel::flags();
- }
- virtual void switchState(__attribute__((unused)) uint8_t oldstate,uint8_t newstate,__attribute__((unused)) uint32_t delay) {
- if (( newstate == AS_CM_JT_ON ) || ( newstate == AS_CM_JT_OFF )) {
- pincontrol.start();
- }
- this->changed(true);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment