Skip to content

Commit

Permalink
more rework
Browse files Browse the repository at this point in the history
  • Loading branch information
pa-pa committed Apr 11, 2017
1 parent 9ece611 commit f838b0a
Show file tree
Hide file tree
Showing 21 changed files with 434 additions and 490 deletions.
8 changes: 5 additions & 3 deletions Activity.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace as {

#ifdef ARDUINO_ARCH_AVR

template <bool ENABLETIMER2=false>
class Idle {
public:

Expand All @@ -32,12 +33,13 @@ class Idle {

template <class Hal>
static void powerSave (__attribute__((unused)) Hal& hal) {
LowPower.idle(SLEEP_FOREVER,ADC_OFF,TIMER2_OFF,TIMER1_ON,TIMER0_OFF,SPI_ON,USART0_ON,TWI_OFF);
LowPower.idle(SLEEP_FOREVER,ADC_OFF,ENABLETIMER2==false?TIMER2_OFF:TIMER2_ON,TIMER1_ON,TIMER0_OFF,SPI_ON,USART0_ON,TWI_OFF);
}

};

class Sleep : public Idle {
template <bool ENABLETIMER2=false>
class Sleep : public Idle<ENABLETIMER2> {
public:
static uint32_t doSleep (uint32_t ticks) {
uint32_t offset = 0;
Expand Down Expand Up @@ -73,7 +75,7 @@ class Sleep : public Idle {
}
else{
aclock.enable();
Idle::powerSave(hal);
Idle<>::powerSave(hal);
}
}
else {
Expand Down
55 changes: 55 additions & 0 deletions Button.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,61 @@ class StateButton: public Alarm {
// define standard button switches to GND
typedef StateButton<HIGH,LOW,INPUT_PULLUP> Button;

template <class DEVTYPE,uint8_t OFFSTATE=HIGH,uint8_t ONSTATE=LOW,WiringPinMode MODE=INPUT_PULLUP>
class ConfigButton : public StateButton<HIGH,LOW,INPUT_PULLUP> {
DEVTYPE& device;
public:
typedef StateButton<HIGH,LOW,INPUT_PULLUP> ButtonType;

ConfigButton (DEVTYPE& dev,uint8_t longpresstime=3) : device(dev) {
setLongPressTime(seconds2ticks(longpresstime));
}
virtual void state (uint8_t s) {
uint8_t old = ButtonType::state();
ButtonType::state(s);
if( s == ButtonType::released ) {
device.startPairing();
}
else if( s == ButtonType::longpressed ) {
if( old == ButtonType::longpressed ) {
device.reset(); // long pressed again - reset
}
else {
device.led().set(LedStates::key_long);
}
}
}
};

template <class DEVTYPE,uint8_t OFFSTATE=HIGH,uint8_t ONSTATE=LOW,WiringPinMode MODE=INPUT_PULLUP>
class ConfigToggleButton : public StateButton<HIGH,LOW,INPUT_PULLUP> {
DEVTYPE& device;
public:
typedef StateButton<HIGH,LOW,INPUT_PULLUP> ButtonType;

ConfigToggleButton (DEVTYPE& dev,uint8_t longpresstime=3) : device(dev) {
setLongPressTime(seconds2ticks(longpresstime));
}
virtual void state (uint8_t s) {
uint8_t old = ButtonType::state();
ButtonType::state(s);
if( s == ButtonType::released ) {
device.channel(1).toggleState();
}
else if( s == ButtonType::longreleased ) {
device.startPairing();
}
else if( s == ButtonType::longpressed ) {
if( old == ButtonType::longpressed ) {
device.reset(); // long pressed again - reset
}
else {
device.led().set(LedStates::key_long);
}
}
}
};

}

#endif
2 changes: 2 additions & 0 deletions Channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ class Channel {
return false;
}

void patchStatus (__attribute__((unused)) Message& msg) {}

void configChanged () {}

protected:
Expand Down
6 changes: 6 additions & 0 deletions Debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
inline void DDEC(uint16_t b) { }
inline void DDECLN(uint16_t b) { }

#define DINIT(baudrate,msg)

#else

#ifdef ARDUINO
Expand Down Expand Up @@ -67,6 +69,10 @@
Serial.print(b,DEC);
}

#define DINIT(baudrate,msg) \
Serial.begin(baudrate); \
DPRINTLN(msg);

#else

#include <iostream>
Expand Down
13 changes: 9 additions & 4 deletions Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ class Device {
msg.setRpten(); // has to be set always
bool result = false;
uint8_t maxsend = 6;
led().set(StatusLed::send);
led().set(LedStates::send);
while( result == false && maxsend > 0 ) {
DPRINT(F("<- "));
msg.dump();
Expand Down Expand Up @@ -254,8 +254,8 @@ class Device {
DPRINT(F("waitAck: ")); DHEX((uint8_t)result); DPRINTLN(F(""));
}
}
if( result == true ) led().set(StatusLed::ack);
else led().set(StatusLed::nack);
if( result == true ) led().set(LedStates::ack);
else led().set(LedStates::nack);
return result;
}

Expand All @@ -280,6 +280,7 @@ class Device {
template <class ChannelType>
void sendAck (Message& msg,ChannelType& ch) {
msg.ackStatus().init(ch,radio().rssi());
ch.patchStatus(msg);
kstore.addAuth(msg);
send(msg,msg.from());
ch.changed(false);
Expand All @@ -304,9 +305,13 @@ class Device {
}

template <class ChannelType>
void sendInfoActuatorStatus (const HMID& to,uint8_t count,ChannelType& ch) {
void sendInfoActuatorStatus (const HMID& to,uint8_t count,ChannelType& ch,bool ack=true) {
InfoActuatorStatusMsg& pm = msg.infoActuatorStatus();
pm.init(count,ch,radio().rssi());
if( ack == false ) {
pm.clearAck();
}
ch.patchStatus(msg);
send(msg,to);
ch.changed(false);
}
Expand Down
Loading

0 comments on commit f838b0a

Please sign in to comment.