This is used for sending Data to receiving mDot
Dependencies: libmDot-dev-mbed5-deprecated ISL29011
Fork of mdot-examples by
Diff: send_main.cpp
- Revision:
- 27:5db200a4d496
- Parent:
- 26:15df8f054d11
- Child:
- 28:29702434319d
--- a/send_main.cpp Sun Apr 01 21:21:29 2018 +0000 +++ b/send_main.cpp Sun Apr 01 21:32:06 2018 +0000 @@ -7,6 +7,7 @@ #include <iostream> #include <string.h> #include <mbed.h> +#include "mDot.h" #include "dot_util.h" #include "RadioEvent.h" #include "itoa.h" @@ -482,6 +483,7 @@ uint16_t YData; uint16_t ZData; + uint16_t XDataInterrupt[BUFFER_SIZE]; uint16_t YDataInterrupt[BUFFER_SIZE]; uint16_t ZDataInterrupt[BUFFER_SIZE]; @@ -558,6 +560,8 @@ Zlsb = ZData & 0xff; // Split the lower 8bits here Zmsb = ZData >> 8; // Split the higher 8bits here + + /* * Taking temperature data */ @@ -786,7 +790,7 @@ ADT7410Initialize(); ADXL372Initialize(); - Periodic.attach(&takePeriodicReadingTicker,5); + //Periodic.attach(&takePeriodicReadingTicker,5); while(1){ // Create a vector of uint8_t elements to be sent later @@ -794,53 +798,21 @@ std::vector<uint8_t> tx_data; - if(periodicReadingTrigger) - { - takePeriodicReading(tx_data); - } + + takePeriodicReading(tx_data); + if(takeAccelerometer || takeTemperature){ pc.printf("INTERRUPTEDDDDDDDD: "); if(takeTemperature) pc.printf("Temperature triggered!!!!!!!!!!!!\n\r"); else if(takeAccelerometer) pc.printf("AccelerometerTriggered!!!!!!!!!!!!!\n\r"); - for(int i = 0; i < BUFFER_SIZE; ++i){ - /* - * Taking accelerometer data - */ - regAddress = 0x08; // This is the register address for XData - accelValues = accelerometerI2CRead(regAddress); - Xmsb = *(accelValues + 0); - Xlsb = *(accelValues + 1); - Ymsb = *(accelValues + 2); - Ylsb = *(accelValues + 3); - Zmsb = *(accelValues + 4); - Zlsb = *(accelValues + 5); - - XDataInterrupt[i] = (Xmsb << 8 | Xlsb) >> 4; // Combine two bytes into short int, remove last 4 flag bits - YDataInterrupt[i] = (Ymsb << 8 | Ylsb) >> 4; - ZDataInterrupt[i] = (Zmsb << 8 | Zlsb) >> 4; - - XDataInterrupt[i] = twosComplementConversion(XDataInterrupt[i]); - YDataInterrupt[i] = twosComplementConversion(YDataInterrupt[i]); - ZDataInterrupt[i] = twosComplementConversion(ZDataInterrupt[i]); - - /* - * Taking temperature data - */ - regAddress = 0x00; - rawTempValues = ADT7410Read(regAddress); - temperatureBuffer[i] = ((*(rawTempValues + 0) << 8) | *(rawTempValues + 1)) >> 3; // Combine the two bytes into - // a short int variable(16 bits), remove last 3 bits - } + + takePeriodicReading(tx_data); - for(int i = 0; i < BUFFER_SIZE; ++i){ - pc.printf("Accelerometer::: "); - pc.printf("X: 0x%x | Y: 0x%x | Z: 0x%x\n\r", XDataInterrupt[i], YDataInterrupt[i], ZDataInterrupt[i]); - pc.printf("Temperature::: "); - pc.printf("Celsius: 0x%x\n\r", temperatureBuffer[i]); - } - //wait(0.2); + + + takeAccelerometer = false; // Flip back to no trigger takeTemperature = false; // Flip back to no trigger @@ -848,8 +820,13 @@ + // Go to sleep for 5 seconds and wake up after 5 seconds or wakeup from interrupt - //wait(1); + if(dot->sleep(5,mDot::RTC_ALARM_OR_INTERRUPT, false) == mDot::MDOT_OK) + { + pc.printf("Sleep well\n\r"); + } + } return 0;