Code supports writing to the SD card as well as working with the Volckens group smartphone apps for the mbed HRM1017
Dependencies: ADS1115 BLE_API BME280 Calibration CronoDot EEPROM LSM303 MCP40D17 NCP5623BMUTBG SDFileSystem SI1145 STC3100 mbed nRF51822
Fork of UPAS_BLE_and_USB by
Diff: main.cpp
- Revision:
- 96:03106adb45c9
- Parent:
- 95:0ae0ffddc544
- Child:
- 97:c596f8ed4562
--- a/main.cpp Fri Dec 11 00:11:09 2015 +0000 +++ b/main.cpp Thu Dec 17 01:05:31 2015 +0000 @@ -143,10 +143,14 @@ RunReady = 2; } - }else if(Handler->charHandle == upasServicePtr->runModeCharacteristic.getValueAttribute().getHandle()){ + }else if(Handler->charHandle == upasServicePtr->logIntevalCharacteristic.getValueAttribute().getHandle()){ /* Trigger demo mode*/ - RGB_LED.set_led(3,1,0); - E2PROM.write(0x00036,writeData,1); + //RGB_LED.set_led(3,1,0); + E2PROM.write(0x00014,writeData,1); + + }else if(Handler->charHandle == upasServicePtr->flowRateCharacteristic.getValueAttribute().getHandle()){ + //RGB_LED.set_led(3,1,0); + E2PROM.write(0x00010,writeData,4); } } @@ -233,33 +237,47 @@ FILE *fp = fopen(filename, "a"); fprintf(fp, "%02d,%02d,%02d,%02d,%02d,%02d,%1.3f,%1.3f,%2.2f,%4.2f,%2.1f,%1.3f,%1.3f,%5.1f,%1.1f,%1.1f,%1.1f,%1.1f,%d,%d,%d,%d,%d,%d,%d,%d,%d,%1.3f,%1.3f,%f\r\n",RTC.year, RTC.month,RTC.date,RTC.hour,RTC.minutes,RTC.seconds,omronVolt,massflow,temp,press,rh,atmoRho,volflow,sampledVol,accel_x,accel_y,accel_z,accel_comp,uv,omronReading, vInReading, vBlowerReading, omronDiff,gasG.getAmps(), gasG.getVolts(), gasG.getCharge(),digital_pot_set, deltaMflow, deltaVflow, compass); fclose(fp); - //wait_ms(5); } - +/*EEPROM ADDRESSING: + 0:Status bit-Unused + 1-15:Device Name + 16-19:Flow Rate + 20: Data Log Interval + 21-26: Start Time: ssmmHHddMMyy + 27-32: Stop Time: ssmmHHddMMyy + 33: Duty Up + 34: Duty Down + 35-38: Home Latitude + 39-42: Home Longitude + 43-46: Work Latitude + 47-50: Work Longitude + 51: Runready: Currently useless, should be 0 + 52-53: Device Calibration + 54: Consider RunReady + 55-56: Menu Options + 57+ Nothing*/ int main() { - uint8_t temp_crr; RGB_LED.set_led(1,1,1); // Setup and Initialization //---------------------------------------------------------------------------------------------// - // Menu.read_menu(E2PROM, logInerval,refreshtime, volflowSet, device_name, dutyUp, dutyDown, home_lat, home_lon, work_lat, work_lon, RunReady, serial_num); //Read all data from the EEPROM here -// if(Menu.crr == 255) { -// Menu.factory_reset(E2PROM, logInerval,refreshtime, volflowSet, device_name, dutyUp, dutyDown, home_lat, home_lon, work_lat, work_lon, RunReady, serial_num); -// } //**************//BLE initialization//**************// RTC.get_time(); uint8_t rtcPassValues[6] = {RTC.seconds, RTC.minutes,RTC.hour,RTC.date,RTC.month,RTC.year}; uint8_t sampleTimePassValues[12] = {0,}; uint8_t subjectLabelOriginal[15] = {0,}; + uint8_t dataLogOriginal[1] = {0,}; + uint8_t flowRateOriginal[4] = {0,}; E2PROM.read(0x00015, sampleTimePassValues, 12); E2PROM.read(0x00001, subjectLabelOriginal,15); - + E2PROM.read(0x00014,dataLogOriginal,1); + E2PROM.read(0x00010,flowRateOriginal,4); ble.init(); ble.onDisconnection(disconnectionCallback); ble.onDataWritten(WrittenHandler); //add writeCharCallback (custom function) to whenever data is being written to device - UPAS_Service upasService(ble, false,rtcPassValues,sampleTimePassValues,subjectLabelOriginal); //Create a GattService that is defined in UPAS_Service.h + UPAS_Service upasService(ble, false,rtcPassValues,sampleTimePassValues,subjectLabelOriginal,dataLogOriginal,flowRateOriginal); //Create a GattService that is defined in UPAS_Service.h upasServicePtr = &upasService; //Create a pointer to the service (Allows advertisement without specifically adding the service /* setup advertising @@ -277,6 +295,9 @@ ble.startAdvertising(); //**************//BLE initialization//**************// + + //Logic Loop waiting for responses from the BLE iPhone App. + //Will not break loop without response from the app while (1) { ble.waitForEvent(); if(RunReady==2 && blower ==0){ //Code used to see if one-click run should begin @@ -332,7 +353,7 @@ calibrations.initialize(serial_num); - stop.attach(&check_stop, 60); // check if we should shut down every 9 seconds, starting 60s after the start. + stop.attach(&check_stop, 30); // check if we should shut down every 9 seconds, starting 60s after the start. if(volflowSet<=1.0) { gainFlow = 100;