Skip to content

Commit

Permalink
merged from V1 - lazy config fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pa-pa committed Feb 23, 2017
1 parent cad234f commit 58d80e7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
6 changes: 5 additions & 1 deletion Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ class Device {
#endif
{
result = response.isAck();
// we got the fag to stay awake
if( response.isKeepAwake() ) {
activity().stayAwake(millis2ticks(500));
}
}
}
DPRINT(F("waitAck: ")); DHEX((uint8_t)result); DPRINTLN(F(""));
Expand Down Expand Up @@ -404,7 +408,7 @@ class Device {
do {
uint8_t num = radio().read(response);
if( num > 0 ) {
// response.dump();
DPRINT(F("-> ")); response.dump();
if( msg.count() == response.count() &&
msg.to() == response.from() ) {
return true;
Expand Down
6 changes: 5 additions & 1 deletion Message.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ class Message {
flag &= ~BIDI;
}

bool isKeepAwake () const {
return (flag & WKUP) == WKUP;
}

bool isWakeMeUp () const {
return (flag & WKMEUP) == WKMEUP;
}
Expand Down Expand Up @@ -510,7 +514,7 @@ class InfoActuatorStatusMsg : public Message {
public:
template <class ChannelType>
void init (uint8_t count,const ChannelType& ch,uint8_t rssi) {
Message::init(0x0e,count,0x10,BIDI,0x06,ch.number());
Message::init(0x0e,count,0x10,BIDI|WKMEUP,0x06,ch.number());
pload[0] = ch.status();
pload[1] = ch.flags();
pload[2] = rssi;
Expand Down
6 changes: 1 addition & 5 deletions MultiChannelDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ class MultiChannelDevice : public Device<HalType> {
uint8_t mcomm = msg.command();
uint8_t msubc = msg.subcommand();
if( mtype == AS_MESSAGE_CONFIG ) {
DeviceType::activity().stayAwake(seconds2ticks(2));
// PAIR_SERIAL
if( msubc == AS_CONFIG_PAIR_SERIAL && memcmp(msg.data(),DeviceType::getSerial(),10)==0 ) {
DeviceType::led().set(StatusLed::pairing);
Expand Down Expand Up @@ -233,7 +234,6 @@ class MultiChannelDevice : public Device<HalType> {
cfgList = findList(cfgChannel,pm.peer(),pm.list());
// TODO setup alarm to disable after 2000ms
DeviceType::sendAck(msg);
DeviceType::activity().stayAwake(seconds2ticks(2));
}
}
// CONFIG_END
Expand All @@ -249,7 +249,6 @@ class MultiChannelDevice : public Device<HalType> {
cfgChannel = 0xff;
// TODO cancel alarm
DeviceType::sendAck(msg);
DeviceType::activity().stayAwake(millis2ticks(500));
}
else if( msubc == AS_CONFIG_WRITE_INDEX ) {
const ConfigWriteIndexMsg& pm = msg.configWriteIndex();
Expand Down Expand Up @@ -404,9 +403,6 @@ class MultiChannelDevice : public Device<HalType> {
// we send only to peers if there is no config message pending
if( cfgChannel != 0xff ) {
DeviceType::sendPeerEvent(msg,ch);
if( msg.isWakeMeUp() == true ) {
DeviceType::activity().stayAwake(millis2ticks(500));
}
}
}
};
Expand Down
5 changes: 2 additions & 3 deletions examples/HM-SEC-MDIR/HM-SEC-MDIR.ino
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,12 @@ class MotionChannel : public Channel<Hal,MotionList1,EmptyList,List4,PEERS_PER_C

private:
MotionEventMsg msg;
uint8_t msgcnt;
uint8_t counter;
QuietMode quiet;
Cycle cycle;

public:
MotionChannel () : Channel(), Alarm(0), msgcnt(0), counter(0), quiet(*this), cycle(*this) {
MotionChannel () : Channel(), Alarm(0), counter(0), quiet(*this), cycle(*this) {
aclock.add(cycle);
pinMode(PIR_PIN,INPUT);
pirInterruptOn();
Expand Down Expand Up @@ -266,7 +265,7 @@ public:
if( hal.led.active() == false ) {
hal.led.ledOn( centis2ticks(getList1().ledOntime()) / 2);
}
msg.init(++msgcnt,number(),++counter,brightness(),getList1().minInterval());
msg.init(device().nextcount(),number(),++counter,brightness(),getList1().minInterval());
device().sendPeerEvent(msg,*this);
}
else if ( getList1().captureWithinInterval() == true ) {
Expand Down

0 comments on commit 58d80e7

Please sign in to comment.