Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
trilu2000 committed May 30, 2014
1 parent d75e514 commit 570fa89
Show file tree
Hide file tree
Showing 18 changed files with 836 additions and 518 deletions.
549 changes: 339 additions & 210 deletions AskSinMain.cpp

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions AskSinMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "utility/StatusLed.h"
#include "utility/Battery.h"
#include "utility/Fastdelegate.h"
#include <util/delay.h>


//- some structures for device definition in Register.h -------------------------------------------------------------------
Expand All @@ -55,6 +56,7 @@ struct s_defaultRegsTbl { // struct for storing some defaults
//- -----------------------------------------------------------------------------------------------------------------------

//- interrupt handling
static volatile uint8_t int0_flag;
static volatile uint8_t wd_flag;
extern volatile unsigned long timer0_millis; // make millis timer available for correcting after deep sleep

Expand Down Expand Up @@ -107,7 +109,6 @@ class HM {
#define recv_payLoad (recv.data + 10) // payload for receive queue

struct s_devParm {
uint8_t HMID[3]; // own HMID
uint8_t maxRetr; // max send retries
uint16_t timeOut; // timeout for ACK sending
const uint8_t *p; // pointer to PROGMEM serial number, etc
Expand Down Expand Up @@ -141,9 +142,10 @@ class HM {
StatusLed statusLed; // declaration of status led
Battery battery;

char hmId[3]; // own HMID

//- homematic public protocol functions
void init(void); // Ok, initialize the HomeMatic module
void recvInterrupt(void); // Ok, interrupt handler for receive interrupt
void poll(void); // OK, main task to manage TX and RX messages
void send_out(void); // OK, send function

Expand All @@ -165,7 +167,9 @@ class HM {
void sendInfoActuatorStatus(uint8_t cnl, uint8_t status, uint8_t flag); // , send status function
void sendACKStatus(uint8_t cnl, uint8_t status, uint8_t douolo); // , send ACK with status
void sendPeerREMOTE(uint8_t button, uint8_t longPress, uint8_t lowBat); // (0x40) send REMOTE event to all peers
void sendPeerWEATHER(uint8_t cnl, uint16_t temp, uint8_t hum, uint16_t pres); // (0x70) send WEATHER event
// void sendPeerWEATHER(uint8_t cnl, uint16_t temp, uint8_t hum, uint16_t pres, uint32_t lux); // (0x70) send WEATHER event
// debugging
void sendPeerWEATHER(uint8_t cnl, uint16_t temp, uint8_t hum, uint16_t pres, uint32_t lux);
void sendPeerRAW(uint8_t cnl, uint8_t type, uint8_t *data, uint8_t len); // send event to all peers listed in the peers database by channel, type specifies the type of the message, data and len delivers the content of the event
void send_ACK(void); // , ACK sending function
void send_NACK(void); // , NACK sending function
Expand Down Expand Up @@ -208,6 +212,7 @@ class HM {
#define recv_toMst bitRead(recv.data[2],1) // message to master, true if 0x02 was set

//- hm communication functions
void cc1101Recv_poll(void);
void recv_poll(void); // handles the received string
void send_poll(void); // handles the send queue
void send_conf_poll(void); // handles information requests
Expand Down Expand Up @@ -291,10 +296,10 @@ extern HM hm;
//- interrupt handling for interface communication module to AskSin library
struct s_intGDO0 {
uint8_t nbr;
HM *ptr;
};

void isrGDO0(void);

ISR( WDT_vect );

#endif
#endif
70 changes: 37 additions & 33 deletions Buttons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const uint8_t peerEven[] = {0};
const uint8_t peerSingle[] = {0};

//- user code here --------------------------------------------------------------------------------------------------------
void MyClassName::config(uint8_t Pin, void tCallBack(uint8_t, uint8_t)) {
void Buttons::config(uint8_t Pin, void tCallBack(uint8_t, uint8_t)) {

// settings while setup
pinMode(Pin, INPUT_PULLUP); // setting the pin to input mode
Expand All @@ -25,7 +25,7 @@ void MyClassName::config(uint8_t Pin, void tCallBack(uint8_t, uint8_t)) {
dblLo = 0; // counter for a double low
rptLo = 0; // counter for repeated low

registerInt(Pin,s_dlgt(this,&MyClassName::interrupt)); // setting the interrupt and port mask
registerInt(Pin,s_dlgt(this,&Buttons::interrupt)); // setting the interrupt and port mask

if (regCnl) list1 = (s_regChanL1*)ptrMainList; // assign the pointer to our class struct
else {
Expand All @@ -34,13 +34,13 @@ void MyClassName::config(uint8_t Pin, void tCallBack(uint8_t, uint8_t)) {
}
configCngEvent(); // call the config change event for setting up the timing variables
}
void MyClassName::interrupt(uint8_t c) {
cStat = c; // getting the pin status
cTime = millis() + 10; // debounce timer
cFlag = 1; // jump in poll routine next time
void Buttons::interrupt(uint8_t c) {
cStat = c; // getting the pin status
cTime = millis() + 10; // debounce timer
cFlag = 1; // jump in poll routine next time
}

void MyClassName::buttonAction(uint8_t bEvent) {
void Buttons::buttonAction(uint8_t bEvent) {
// possible events of this function:
// 0 - short key press
// 1 - double short key press
Expand Down Expand Up @@ -79,7 +79,7 @@ void MyClassName::buttonAction(uint8_t bEvent) {
}

//- mandatory functions for every new module to communicate within HM protocol stack --------------------------------------
void MyClassName::configCngEvent(void) {
void Buttons::configCngEvent(void) {
// it's only for information purpose while something in the channel config was changed (List0/1 or List3/4)

if (regCnl == 0) { // we are in config button mode
Expand All @@ -89,17 +89,19 @@ void MyClassName::configCngEvent(void) {
toLoDbl = 5000; // maximum time between a double key press

} else { // we are in normal button mode
uint8_t pressTime = list1->dblPress;
toShDbl = pressTime * 100; // minimum time to be recognized as a short key press

toShDbl = list1->dblPress*100; // minimum time to be recognized as a short key press
lngKeyTme = 300 + (list1->longPress * 100); // time key should be pressed to be recognized as a long key press
uint8_t longPress = list1->longPress;
lngKeyTme = 300 + (longPress * 100); // time key should be pressed to be recognized as a long key press
toLoDbl = 1000; // maximum time between a double key press
}

#ifdef DM_DBG
Serial << F("config change; cnl: ") << regCnl << F(", longPress: ") << list1->longPress << F(", sign: ") << list1->sign << F(", dblPress: ") << list1->dblPress << '\n';
#endif
}
void MyClassName::pairSetEvent(uint8_t *data, uint8_t len) {
void Buttons::pairSetEvent(uint8_t *data, uint8_t len) {
// we received a message from master to set a new value, typical you will find three bytes in data
// 1st byte = value; 2nd byte = ramp time; 3rd byte = duration time;
// after setting the new value we have to send an enhanced ACK (<- 0E E7 80 02 1F B7 4A 63 19 63 01 01 C8 00 54)
Expand All @@ -112,15 +114,15 @@ void MyClassName::pairSetEvent(uint8_t *data, uint8_t len) {

hm->sendACKStatus(regCnl,modStat,0);
}
void MyClassName::pairStatusReq(void) {
void Buttons::pairStatusReq(void) {
// we received a status request, appropriate answer is an InfoActuatorStatus message
#ifdef DM_DBG
Serial << F("pairStatusReq\n");
#endif

hm->sendInfoActuatorStatus(regCnl, modStat, 0);
}
void MyClassName::peerMsgEvent(uint8_t type, uint8_t *data, uint8_t len) {
void Buttons::peerMsgEvent(uint8_t type, uint8_t *data, uint8_t len) {
// we received a peer event, in type you will find the marker if it was a switch(3E), remote(40) or sensor(41) event
// appropriate answer is an ACK
#ifdef DM_DBG
Expand All @@ -130,7 +132,9 @@ void MyClassName::peerMsgEvent(uint8_t type, uint8_t *data, uint8_t len) {
hm->send_ACK();
}

void MyClassName::poll(void) {
void Buttons::poll(void) {
unsigned long mils = millis();

// possible events of this function:
// 0 - short key press
// 1 - double short key press
Expand All @@ -143,33 +147,33 @@ void MyClassName::poll(void) {
// 255 - key press, for stay awake issues

if (cFlag == 0) return; // no need for do any thing
if (cTime > millis()) return; // for debouncing and timeout issues
if (cTime > mils) return; // for debouncing and timeout issues


// Serial.print("cFlag"); Serial.print(cFlag); Serial.print(", cTime:"); Serial.print(cTime);
// Serial.print(", cStat:"); Serial.print(cStat); Serial.print(", lStat:"); Serial.print(lStat);
// Serial.print(", dblLo:"); Serial.print(dblLo); Serial.print(", lngKeyTme:"); Serial.print(kTime);
// Serial.print(", millis():"); Serial.println(millis());
// Serial.print(", mils:"); Serial.println(mils);


// Serial << "cFlag: " << cFlag << ", cTime: " << cTime << ", cStat: " << cStat << ", lStat: " << lStat << ", dblLo: " << dblLo << ", lngKeyTme: " << lngKeyTme << ", kTime: " << kTime << ", millis(): " << millis() << '\n';
// Serial << "cFlag: " << cFlag << ", cTime: " << cTime << ", cStat: " << cStat << ", lStat: " << lStat << ", dblLo: " << dblLo << ", lngKeyTme: " << lngKeyTme << ", kTime: " << kTime << ", mils: " << mils << '\n';

if ((cStat == 1) && (lStat == 1)) { // timeout
// only timeouts should happen here

if ((dblLo) && (kTime + toLoDbl <= millis())) { // timeout for double long reached
if ((dblLo) && (kTime + toLoDbl <= mils)) { // timeout for double long reached
dblLo = 0; // no need for check against
//Serial.println("dbl lo to");
buttonAction(6); // raise timeout for double long
}
if ((dblSh) && (kTime + toShDbl <= millis())) { // timeout for double short reached
if ((dblSh) && (kTime + toShDbl <= mils)) { // timeout for double short reached
dblSh = 0; // no need for check against
//Serial.println("dbl sh to");
}

if ((dblLo == 0) && (dblSh == 0)) cFlag = 0; // no need for checking again
if (dblLo) cTime = millis() + toLoDbl; // set the next check time
if (dblSh) cTime = millis() + toShDbl; // set the next check time
if (dblLo) cTime = mils + toLoDbl; // set the next check time
if (dblSh) cTime = mils + toShDbl; // set the next check time

} else if ((cStat == 1) && (lStat == 0)) { // key release
// coming from a short or long key press, end of long key press by checking against rptLo
Expand All @@ -184,22 +188,22 @@ void MyClassName::poll(void) {
//Serial.println("dbl sh");
buttonAction(1); // double short key press

} else if (kTime + lngKeyTme > millis()) { // short key press
} else if (kTime + lngKeyTme > mils) { // short key press
dblSh = 1; // next time it could be a double short
//Serial.println("sh");
if (!toShDbl) buttonAction(0); // short key press
}

if ((dblSh) && (toShDbl)) cTime = millis() + toShDbl; // set the next check time
if (dblLo) cTime = millis() + toLoDbl; // set the next check time
kTime = millis(); // set variable to measure against
if ((dblSh) && (toShDbl)) cTime = mils + toShDbl; // set the next check time
if (dblLo) cTime = mils + toLoDbl; // set the next check time
kTime = mils; // set variable to measure against
lStat = cStat; // remember last key state
cFlag = 1; // next check needed

} else if ((cStat == 0) && (lStat == 1)) {
// key is pressed just now, set timeout
kTime = millis(); // store timer
cTime = millis() + lngKeyTme; // set next timeout
kTime = mils; // store timer
cTime = mils + lngKeyTme; // set next timeout
lStat = cStat; // remember last key state
cFlag = 1; // next check needed
buttonAction(255);
Expand All @@ -209,7 +213,7 @@ void MyClassName::poll(void) {
// if it is a long key press, check against dblLo for detecting a double long key press
if (rptLo) { // repeated long detect
dblLo = 0; // could not be a double any more
cTime = millis() + 300; //lngKeyTme; // set next timeout
cTime = mils + 300; //lngKeyTme; // set next timeout
//Serial.println("rpt lo");
buttonAction(3); // repeated long key press

Expand All @@ -223,7 +227,7 @@ void MyClassName::poll(void) {
} else { // first long detect
dblLo = 1; // next time it could be a double
rptLo = 1; // or a repeated long
cTime = millis() + lngKeyTme; // set next timeout
cTime = mils + lngKeyTme; // set next timeout
//Serial.println("lo");
buttonAction(2); // long key press

Expand All @@ -232,12 +236,12 @@ void MyClassName::poll(void) {
}

//- pre defined, no reason to touch ---------------------------------------------------------------------------------------
void MyClassName::regInHM(uint8_t cnl, HM *instPtr) {
void Buttons::regInHM(uint8_t cnl, HM *instPtr) {
hm = instPtr; // set pointer to the HM module
hm->regCnlModule(cnl,s_mod_dlgt(this,&MyClassName::hmEventCol),(uint16_t*)&ptrMainList,(uint16_t*)&ptrPeerList);
hm->regCnlModule(cnl,s_mod_dlgt(this,&Buttons::hmEventCol),(uint16_t*)&ptrMainList,(uint16_t*)&ptrPeerList);
regCnl = cnl; // stores the channel we are responsible fore
}
void MyClassName::hmEventCol(uint8_t by3, uint8_t by10, uint8_t by11, uint8_t *data, uint8_t len) {
void Buttons::hmEventCol(uint8_t by3, uint8_t by10, uint8_t by11, uint8_t *data, uint8_t len) {
if (by3 == 0x00) poll();
else if ((by3 == 0x01) && (by11 == 0x06)) configCngEvent();
else if ((by3 == 0x11) && (by10 == 0x02)) pairSetEvent(data, len);
Expand All @@ -246,7 +250,7 @@ void MyClassName::hmEventCol(uint8_t by3, uint8_t by10, uint8_t by11, uint8_t *d
else if (by3 >= 0x3E) peerMsgEvent(by3, data, len);
else return;
}
void MyClassName::peerAddEvent(uint8_t *data, uint8_t len) {
void Buttons::peerAddEvent(uint8_t *data, uint8_t len) {
// we received an peer add event, which means, there was a peer added in this respective channel
// 1st byte and 2nd byte shows the peer channel, 3rd and 4th byte gives the peer index
// no need for sending an answer, but we could set default data to the respective list3/4
Expand Down
5 changes: 2 additions & 3 deletions Buttons.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
#include "utility/Fastdelegate.h"
#include "utility/PinChangeIntHandler.h"

#define MyClassName Buttons // module name as macro to overcome the problem of renaming functions all the time
//#define DM_DBG // debug message flag
//#define DM_DBG // debug message flag


class MyClassName {
class Buttons {
//- user code here ------------------------------------------------------------------------------------------------------
public://----------------------------------------------------------------------------------------------------------------
void config(uint8_t Pin, void tCallBack(uint8_t, uint8_t));
Expand Down
18 changes: 9 additions & 9 deletions Dummy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@


//- mandatory functions for every new module to communicate within HM protocol stack --------------------------------------
void MyClassName::configCngEvent(void) {
void Dummy::configCngEvent(void) {
// it's only for information purpose while something in the channel config was changed (List0/1 or List3/4)
#ifdef DM_DBG
Serial << F("configCngEvent\n");
#endif
}
void MyClassName::pairSetEvent(uint8_t *data, uint8_t len) {
void Dummy::pairSetEvent(uint8_t *data, uint8_t len) {
// we received a message from master to set a new value, typical you will find three bytes in data
// 1st byte = value; 2nd byte = ramp time; 3rd byte = duration time;
// after setting the new value we have to send an enhanced ACK (<- 0E E7 80 02 1F B7 4A 63 19 63 01 01 C8 00 54)
Expand All @@ -28,15 +28,15 @@ void MyClassName::pairSetEvent(uint8_t *data, uint8_t len) {

hm->sendACKStatus(regCnl,modStat,0);
}
void MyClassName::pairStatusReq(void) {
void Dummy::pairStatusReq(void) {
// we received a status request, appropriate answer is an InfoActuatorStatus message
#ifdef DM_DBG
Serial << F("pairStatusReq\n");
#endif

hm->sendInfoActuatorStatus(regCnl, modStat, 0);
}
void MyClassName::peerMsgEvent(uint8_t type, uint8_t *data, uint8_t len) {
void Dummy::peerMsgEvent(uint8_t type, uint8_t *data, uint8_t len) {
// we received a peer event, in type you will find the marker if it was a switch(3E), remote(40) or sensor(41) event
// appropriate answer is an ACK
#ifdef DM_DBG
Expand All @@ -46,17 +46,17 @@ void MyClassName::peerMsgEvent(uint8_t type, uint8_t *data, uint8_t len) {
hm->send_ACK();
}

void MyClassName::poll(void) {
void Dummy::poll(void) {
// just polling, as the function name said
}

//- predefined, no reason to touch ----------------------------------------------------------------------------------------
void MyClassName::regInHM(uint8_t cnl, HM *instPtr) {
void Dummy::regInHM(uint8_t cnl, HM *instPtr) {
hm = instPtr; // set pointer to the HM module
hm->regCnlModule(cnl,s_mod_dlgt(this,&MyClassName::hmEventCol),(uint16_t*)&ptrMainList,(uint16_t*)&ptrPeerList);
hm->regCnlModule(cnl,s_mod_dlgt(this,&Dummy::hmEventCol),(uint16_t*)&ptrMainList,(uint16_t*)&ptrPeerList);
regCnl = cnl; // stores the channel we are responsible fore
}
void MyClassName::hmEventCol(uint8_t by3, uint8_t by10, uint8_t by11, uint8_t *data, uint8_t len) {
void Dummy::hmEventCol(uint8_t by3, uint8_t by10, uint8_t by11, uint8_t *data, uint8_t len) {
if (by3 == 0x00) poll();
else if ((by3 == 0x01) && (by11 == 0x06)) configCngEvent();
else if ((by3 == 0x11) && (by10 == 0x02)) pairSetEvent(data, len);
Expand All @@ -65,7 +65,7 @@ void MyClassName::hmEventCol(uint8_t by3, uint8_t by10, uint8_t by11, uint8_t *d
else if (by3 >= 0x3E) peerMsgEvent(by3, data, len);
else return;
}
void MyClassName::peerAddEvent(uint8_t *data, uint8_t len) {
void Dummy::peerAddEvent(uint8_t *data, uint8_t len) {
// we received an peer add event, which means, there was a peer added in this respective channel
// 1st byte and 2nd byte shows the peer channel, 3rd and 4th byte gives the peer index
// no need for sending an answer, but we could set default data to the respective list3/4
Expand Down
3 changes: 1 addition & 2 deletions Dummy.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
#include "utility/Serial.h"
#include "utility/Fastdelegate.h"

#define MyClassName Dummy // module name as macro to overcome the problem of renaming functions all the time
#define DM_DBG // debug message flag

const uint8_t peerOdd[] = {}; // default settings for list3 or list4
const uint8_t peerEven[] = {};
const uint8_t peerSingle[] = {};

class MyClassName {
class Dummy {
//- user code here ------------------------------------------------------------------------------------------------------
public://----------------------------------------------------------------------------------------------------------------
protected://-------------------------------------------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 570fa89

Please sign in to comment.