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:
- 100:da71436aa52a
- Parent:
- 99:229435dd4cfb
- Child:
- 101:0c3f33f14f4f
diff -r 229435dd4cfb -r da71436aa52a main.cpp --- a/main.cpp Mon Jan 11 20:42:03 2016 +0000 +++ b/main.cpp Tue Jan 12 21:00:34 2016 +0000 @@ -9,7 +9,6 @@ #include "NCP5623BMUTBG.h" #include "CronoDot.h" #include "EEPROM.h" -#include "US_Menu.h" #include "BLEDevice.h" #include "Calibration.h" #include "UPAS_Service.h" @@ -25,7 +24,6 @@ uint8_t startAndEndTime[12] = {0,}; uint8_t logIntervalReadOut[1] = {0,}; -const static char DEVICE_NAME[] = "UPAS"; //Will hold the actual name of the whichever UPAS is being connected to static const uint16_t uuid16_list[] = {UPAS_Service::UPAS_SERVICE_UUID}; //Currently a custom 16-bit representation of 128-bit UUID BLEDevice ble; UPAS_Service *upasServicePtr; @@ -44,7 +42,6 @@ NCP5623BMUTBG RGB_LED(p22, p20); CronoDot RTC(p22, p20); EEPROM E2PROM(p22, p20); -US_Menu Menu; DigitalOut GPS_EN(p4,0); //pin 4 is used to enable and disable the GPS, in order to recive serial communications Calibration calibrations(1); //Default serial/calibration if there are no values for the selected option @@ -135,14 +132,15 @@ E2PROM.write(0x00001,writeData,15); }else if(Handler->charHandle == upasServicePtr->runReadyCharacteristic.getValueAttribute().getHandle()){ + uint8_t runData = writeData[0]; + E2PROM.write(0x00033,writeData,1); - //if(runData == 10){ - RunReady = 10; - - //}else{ - // RunReady = 2; - //} + if(runData == 0x0A){ + RunReady = 10; + }else{ + RunReady = 12; + } }else if(Handler->charHandle == upasServicePtr->logIntevalCharacteristic.getValueAttribute().getHandle()){ /* Trigger demo mode*/ @@ -277,12 +275,12 @@ uint8_t subjectLabelOriginal[8] = {0,}; uint8_t dataLogOriginal[1] = {0,}; uint8_t flowRateOriginal[4] = {0,}; - //uint8_t blowerOff[1] = {0,}; + uint8_t presetRunModeCheck[1] = {0,}; E2PROM.read(0x00015, sampleTimePassValues, 12); E2PROM.read(0x00001, subjectLabelOriginal,8); E2PROM.read(0x00014,dataLogOriginal,1); E2PROM.read(0x00010,flowRateOriginal,4); - //const static uint8_t NEW_DEVICE_NAME[] = subjectLabelOriginal; + E2PROM.read(0x00033,presetRunModeCheck,1); ble.init(); ble.onDisconnection(disconnectionCallback); ble.onDataWritten(WrittenHandler); //add writeCharCallback (custom function) to whenever data is being written to device @@ -292,7 +290,7 @@ /* setup advertising Following lines do the follow: 1:Declare the device as Bluetooth Smart(Low-Energy) - 2.Advertise the UPAS service that will send and receive the 57-bits of settable values in the UPAS EEPROM + 2.Advertise the UPAS service that will send and receive the 113+ bits of settable values in the UPAS EEPROM 3.Advertise the name that will be associated with the UPAS 4.Allow the UPAS to advertise unrestricted (this might change) */ @@ -307,57 +305,105 @@ //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 - calibrations.initialize(serial_num); - RGB_LED.set_led(3,0,2); - blower=1; - RunReady=0; - } - if(RunReady==2 && blower ==1){ //Code used to see if one-click run is done. - blower=0; - RunReady=0; - } - - if(RunReady==10){ //Check to see if app is done with configurations - //blower = 1; + if(presetRunModeCheck[0] != 0x0C){ + while (1) { + ble.waitForEvent(); + + if(RunReady==10){ //Check to see if app is done with configurations + ble.stopAdvertising(); + break; + } - ble.stopAdvertising(); - break; - } + if(RunReady==12){ //If 24 hour mode has been set, then shut down the UPAS for automatic start later. + pbKill = 0; + } + } + }else{ + RunReady = 12; } + //If 24 hour mode was set by app, make sure to clear it for future use + presetRunModeCheck[0] = 0x01; + E2PROM.write(0x00033,presetRunModeCheck,1); + E2PROM.read(0x00015, startAndEndTime, 12); //Grab start and end times from EEPROM while(!RTC.compare(startAndEndTime[0], startAndEndTime[1], startAndEndTime[2], startAndEndTime[3], startAndEndTime[4], startAndEndTime[5])) { // this while waits for the start time by looping until the start time wait(0.5); RTC.get_time(); + } + //MARK: editting 24 hour mode code here + if(RunReady == 12) { + RTC.get_time(); + startAndEndTime[6] = RTC.seconds; + startAndEndTime[7] = RTC.minutes; + startAndEndTime[8] = RTC.hour; + if(RTC.month == 1 | RTC.month == 3 | RTC.month == 5 | RTC.month == 7 | RTC.month == 8 | RTC.month == 10) { + if(RTC.date == 31) { + startAndEndTime[9] = 1; + startAndEndTime[10] = RTC.month +1; + startAndEndTime[11] = RTC.year; + } else { + startAndEndTime[9] = RTC.date+1; + startAndEndTime[10] = RTC.month; + startAndEndTime[11] = RTC.year; + } + } else if(RTC.month == 4 | RTC.month == 6 | RTC.month == 9 | RTC.month == 11) { + if(RTC.date == 30) { + startAndEndTime[9] = 1; + startAndEndTime[10] = RTC.month +1; + startAndEndTime[11] = RTC.year; + } else { + startAndEndTime[9] = RTC.date+1; + startAndEndTime[10] = RTC.month; + startAndEndTime[11] = RTC.year; + } + } else if(RTC.month == 2) { + if(RTC.year == 16 | RTC.year == 20 | RTC.year == 24| RTC.year == 28) { + if(RTC.date == 29) { + startAndEndTime[9] = 1; + startAndEndTime[10] = RTC.month +1; + startAndEndTime[11] = RTC.year; + } else { + startAndEndTime[9] = RTC.date+1; + startAndEndTime[10] = RTC.month; + startAndEndTime[11] = RTC.year; + } + } else { + if(RTC.date == 28) { + startAndEndTime[9] = 1; + startAndEndTime[10] = RTC.month +1; + startAndEndTime[11] = RTC.year; + } else { + startAndEndTime[9] = RTC.date+1; + startAndEndTime[10] = RTC.month; + startAndEndTime[11] = RTC.year; + } + } + } else if(RTC.month == 12) { + if(RTC.date == 31) { + startAndEndTime[9] = 1; + startAndEndTime[10] = 1; + startAndEndTime[11] = RTC.year+1; + } else { + startAndEndTime[9] = RTC.date+1; + startAndEndTime[10] = RTC.month; + startAndEndTime[11] = RTC.year; + } } + } + //MARK: end of 24 hour mode code + RGB_LED.set_led(0,1,0); calibrations.initialize(serial_num); blower=1; E2PROM.read(0x00014,logIntervalReadOut,1); logInerval = logIntervalReadOut[0]; - - // while(!RTC.compare(startAndEndTime[6], startAndEndTime[7], startAndEndTime[8], startAndEndTime[9], startAndEndTime[10], startAndEndTime[11])) { //Waits for end time -// wait(0.5); -// RTC.get_time(); -// -// } - //pbKill = 0; // this is were we shut everything down - - - + pc.printf("You're done, you can now disconect the USB cable.\r\n"); RunReady = 0; - // Menu.save_menu(E2PROM, logInerval, refreshtime, volflowSet, device_name, dutyUp, dutyDown, home_lat, home_lon, work_lat, work_lon, RunReady, serial_num); //Save all data to the EEPROM - - //RGB_LED.set_led(1,1,0); - - calibrations.initialize(serial_num);