diff --git a/ap_fw/main.c b/ap_fw/main.c index 573816c5..2d3453c6 100644 --- a/ap_fw/main.c +++ b/ap_fw/main.c @@ -60,6 +60,7 @@ struct AvailDataReq { uint8_t softVer; uint8_t hwType; uint8_t protoVer; + uint8_t buttonState; } __packed; #define DATATYPE_NOUPDATE 0 diff --git a/esp32_fw/include/commstructs.h b/esp32_fw/include/commstructs.h index b9b6a5d6..bf1f2a24 100644 --- a/esp32_fw/include/commstructs.h +++ b/esp32_fw/include/commstructs.h @@ -27,6 +27,7 @@ struct AvailDataReq { uint8_t softVer; uint8_t hwType; uint8_t protoVer; + uint8_t buttonState; } __packed; struct espAvailDataReq { diff --git a/esp32_fw/src/newproto.cpp b/esp32_fw/src/newproto.cpp index 44900621..a323b133 100644 --- a/esp32_fw/src/newproto.cpp +++ b/esp32_fw/src/newproto.cpp @@ -145,9 +145,7 @@ void processXferComplete(struct espXferComplete* xfc) { void processDataReq(struct espAvailDataReq* eadr) { char buffer[64]; uint8_t src[8]; - // *((uint64_t*)src) = swap64(*((uint64_t*)adr->)); - sprintf(buffer, "src[7], eadr->src[6], eadr->src[5], eadr->src[4], eadr->src[3], eadr->src[2], eadr->src[1], eadr->src[0]); - // sprintf(buffer, "softVer, adr->batteryMv); + sprintf(buffer, "src[7], eadr->src[6], eadr->src[5], eadr->src[4], eadr->src[3], eadr->src[2], eadr->src[1], eadr->src[0], eadr->adr.buttonState); wsString((String)buffer); Serial.print(buffer); } diff --git a/tag_fw/fw29.bin b/tag_fw/fw29.bin index d90d2501..60dda2ec 100644 Binary files a/tag_fw/fw29.bin and b/tag_fw/fw29.bin differ diff --git a/tag_fw/syncedproto.c b/tag_fw/syncedproto.c index 10a43b93..56e23fd1 100644 --- a/tag_fw/syncedproto.c +++ b/tag_fw/syncedproto.c @@ -68,6 +68,7 @@ struct AvailDataReq { uint8_t softVer; uint8_t hwType; uint8_t protoVer; + uint8_t buttonState; } __packed; #define DATATYPE_NOUPDATE 0 @@ -159,6 +160,9 @@ uint8_t __xdata seq = 0; #define DATA_REQ_MAX_ATTEMPTS 14 // How many attempts (at most) we should do to get something back from the AP #define POWER_SAVING_SMOOTHING 8 // How many samples we should use to smooth the data request interval #define MINIMUM_INTERVAL 45 // IMPORTANT: Minimum interval for check-in; this determines overal battery life! + +#define HAS_BUTTON // uncomment to enable reading a push button (connect between 'TEST' en 'GND' on the tag, along with a 100nF capacitor in parallel). + uint16_t __xdata dataReqAttemptArr[POWER_SAVING_SMOOTHING] = {0}; // Holds the amount of attempts required per data_req/check-in uint8_t __xdata dataReqAttemptArrayIndex = 0; uint8_t __xdata dataReqLastAttempt = 0; @@ -252,8 +256,24 @@ void initAfterWake() { void doSleep(uint32_t __xdata t) { if(t>1000)pr("s=%lu\n ", t / 1000); powerPortsDownForSleep(); + +#ifdef HAS_BUTTON + //Button setup on TEST pin 1.0 (input pullup) + P1FUNC &=~ (1 << 0); + P1DIR |= (1 << 0); + P1PULL |= (1 << 0); + P1LVLSEL |= (1 << 0); + P1INTEN = (1 << 0); + P1CHSTA &=~ (1 << 0); +#endif + // sleepy sleepForMsec(t); + +#ifdef HAS_BUTTON + P1INTEN = 0; +#endif + initAfterWake(); } uint16_t getNextSleep() { @@ -295,6 +315,11 @@ void sendAvailDataReq() { txframe->srcPan = 0x4447; // TODO: send some meaningful data availreq->softVer = 1; + if (P1CHSTA && (1 << 0)) { + availreq->buttonState = 1; + pr("button pressed\n"); + P1CHSTA &=~ (1 << 0); + } addCRC(availreq, sizeof(struct AvailDataReq)); commsTxNoCpy(outBuffer); } @@ -897,6 +922,9 @@ void mainProtocolLoop(void) { screenSleep(); eepromDeepPowerDown(); initRadio(); + + P1CHSTA &=~ (1 << 0); + // drawPartial(); // i2ctest(); // doSleep(10000);