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
main.cpp@78:a465de6cc47e, 2015-09-11 (annotated)
- Committer:
- joshuasmth04
- Date:
- Fri Sep 11 19:47:06 2015 +0000
- Revision:
- 78:a465de6cc47e
- Parent:
- 77:24fbeb2bfe05
- Child:
- 79:ed555e9081d0
Minor modifications to accommodate the UBM's new admen menu and it's arguments.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
caseyquinn | 0:14d46ef4b6cb | 1 | #include "mbed.h" |
caseyquinn | 0:14d46ef4b6cb | 2 | #include "SDFileSystem.h" |
caseyquinn | 0:14d46ef4b6cb | 3 | #include "Adafruit_ADS1015.h" |
caseyquinn | 1:37babeb68ab9 | 4 | #include "MCP40D17.h" |
caseyquinn | 7:a24d7156bc02 | 5 | #include "STC3100.h" |
caseyquinn | 10:f9cb61b29340 | 6 | #include "LSM303.h" |
caseyquinn | 12:8c00a7f5d483 | 7 | #include "BME280.h" |
caseyquinn | 14:ad550174db8b | 8 | #include "SI1145.h" |
joshuasmth04 | 40:ef7e1dcb3780 | 9 | #include "NCP5623BMUTBG.h" |
joshuasmth04 | 41:1fb3e0ac6f87 | 10 | #include "CronoDot.h" |
caseyquinn | 56:c4d6bdd7c3fb | 11 | #include "EEPROM.h" |
joshuasmth04 | 72:0b36575ab00d | 12 | #include "US_Menu.h" |
joshuasmth04 | 77:24fbeb2bfe05 | 13 | #include "BLEDevice.h" |
joshuasmth04 | 71:78edbceff4fc | 14 | #include "BLE_Menu.h" |
joshuasmth04 | 77:24fbeb2bfe05 | 15 | #include "Calibration.h" |
joshuasmth04 | 71:78edbceff4fc | 16 | |
joshuasmth04 | 71:78edbceff4fc | 17 | #define BLE_UUID_TXRX_SERVICE 0x0000 /**< The UUID of the Nordic UART Service. */ |
joshuasmth04 | 71:78edbceff4fc | 18 | #define BLE_UUID_TX_CHARACTERISTIC 0x0002 /**< The UUID of the TX Characteristic. */ |
joshuasmth04 | 71:78edbceff4fc | 19 | #define BLE_UUIDS_RX_CHARACTERISTIC 0x0003 /**< The UUID of the RX Characteristic. */ |
caseyquinn | 1:37babeb68ab9 | 20 | |
caseyquinn | 1:37babeb68ab9 | 21 | #define SERIAL_BAUD_RATE 9600 |
joshuasmth04 | 41:1fb3e0ac6f87 | 22 | #define SCL 20 |
caseyquinn | 7:a24d7156bc02 | 23 | #define SDA 22 |
caseyquinn | 57:0b554f7aa9a3 | 24 | //#define Crono 0xD0 //D0 for the chronoDot |
caseyquinn | 0:14d46ef4b6cb | 25 | |
joshuasmth04 | 71:78edbceff4fc | 26 | uint8_t txPayload[TXRX_BUF_LEN] = {0,}; |
joshuasmth04 | 71:78edbceff4fc | 27 | uint8_t rxPayload[TXRX_BUF_LEN] = {0,}; |
joshuasmth04 | 71:78edbceff4fc | 28 | |
joshuasmth04 | 71:78edbceff4fc | 29 | static const uint8_t uart_base_uuid[] = {0x71, 0x3D, 0, 0, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E}; |
joshuasmth04 | 71:78edbceff4fc | 30 | static const uint8_t uart_tx_uuid[] = {0x71, 0x3D, 0, 3, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E}; |
joshuasmth04 | 71:78edbceff4fc | 31 | static const uint8_t uart_rx_uuid[] = {0x71, 0x3D, 0, 2, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E}; |
joshuasmth04 | 71:78edbceff4fc | 32 | static const uint8_t uart_base_uuid_rev[] = {0x1E, 0x94, 0x8D, 0xF1, 0x48, 0x31, 0x94, 0xBA, 0x75, 0x4C, 0x3E, 0x50, 0, 0, 0x3D, 0x71}; |
joshuasmth04 | 71:78edbceff4fc | 33 | |
joshuasmth04 | 71:78edbceff4fc | 34 | GattCharacteristic txCharacteristic (uart_tx_uuid, txPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE); |
joshuasmth04 | 71:78edbceff4fc | 35 | GattCharacteristic rxCharacteristic (uart_rx_uuid, rxPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY); |
joshuasmth04 | 71:78edbceff4fc | 36 | GattCharacteristic *uartChars[] = {&txCharacteristic, &rxCharacteristic}; |
joshuasmth04 | 71:78edbceff4fc | 37 | GattService uartService(uart_base_uuid, uartChars, sizeof(uartChars) / sizeof(GattCharacteristic *)); |
joshuasmth04 | 71:78edbceff4fc | 38 | |
joshuasmth04 | 71:78edbceff4fc | 39 | BLEDevice ble; |
joshuasmth04 | 71:78edbceff4fc | 40 | BLE_Menu bleMenu(ble, txPayload, rxPayload, uart_base_uuid_rev, uart_base_uuid, uartService); |
joshuasmth04 | 71:78edbceff4fc | 41 | |
joshuasmth04 | 72:0b36575ab00d | 42 | I2C i2c(p22, p20); |
joshuasmth04 | 72:0b36575ab00d | 43 | Adafruit_ADS1115 ads(&i2c); |
joshuasmth04 | 72:0b36575ab00d | 44 | MCP40D17 DigPot(&i2c); |
joshuasmth04 | 72:0b36575ab00d | 45 | BME280 bmesensor(p22, p20); |
joshuasmth04 | 72:0b36575ab00d | 46 | STC3100 gasG(p22, p20); |
joshuasmth04 | 72:0b36575ab00d | 47 | Serial pc(USBTX, USBRX); |
joshuasmth04 | 72:0b36575ab00d | 48 | DigitalOut blower(p29, 0); |
joshuasmth04 | 72:0b36575ab00d | 49 | DigitalOut pbKill(p18, 1); |
joshuasmth04 | 72:0b36575ab00d | 50 | LSM303 movementsensor(p22, p20); |
joshuasmth04 | 72:0b36575ab00d | 51 | SI1145 lightsensor(p22, p20); |
joshuasmth04 | 72:0b36575ab00d | 52 | NCP5623BMUTBG RGB_LED(p22, p20); |
joshuasmth04 | 72:0b36575ab00d | 53 | CronoDot RTC(p22, p20); |
joshuasmth04 | 72:0b36575ab00d | 54 | EEPROM E2PROM(p22, p20); |
joshuasmth04 | 72:0b36575ab00d | 55 | US_Menu Menu; |
joshuasmth04 | 77:24fbeb2bfe05 | 56 | DigitalOut GPS_EN(p4,0); //pin 4 is used to enable and disable the GPS, in order to recive serial communications |
joshuasmth04 | 77:24fbeb2bfe05 | 57 | Calibration calibrations(1); //Default serial/calibration if there are no values for the selected option |
caseyquinn | 57:0b554f7aa9a3 | 58 | |
caseyquinn | 57:0b554f7aa9a3 | 59 | Timeout stop; //This is the stop call back object |
joshuasmth04 | 77:24fbeb2bfe05 | 60 | Timeout logg; //This is the logging call back object |
caseyquinn | 67:300418575137 | 61 | |
joshuasmth04 | 77:24fbeb2bfe05 | 62 | uint16_t serial_num = 1; // Default serial/calibration number |
joshuasmth04 | 77:24fbeb2bfe05 | 63 | int RunReady =0; |
caseyquinn | 70:81f04e69e08a | 64 | |
caseyquinn | 70:81f04e69e08a | 65 | |
caseyquinn | 20:ad9883973d86 | 66 | float press; |
caseyquinn | 20:ad9883973d86 | 67 | float temp; |
caseyquinn | 20:ad9883973d86 | 68 | float rh; |
caseyquinn | 4:69bd7e8a994c | 69 | |
caseyquinn | 20:ad9883973d86 | 70 | int uv; |
caseyquinn | 20:ad9883973d86 | 71 | int vis; |
caseyquinn | 20:ad9883973d86 | 72 | int ir; |
caseyquinn | 8:204c21adf693 | 73 | |
caseyquinn | 67:300418575137 | 74 | float compass; |
caseyquinn | 10:f9cb61b29340 | 75 | float accel_x; |
caseyquinn | 10:f9cb61b29340 | 76 | float accel_y; |
caseyquinn | 10:f9cb61b29340 | 77 | float accel_z; |
lionberg | 52:80480b2fafba | 78 | float accel_comp; |
caseyquinn | 10:f9cb61b29340 | 79 | float mag_x; |
caseyquinn | 10:f9cb61b29340 | 80 | float mag_y; |
caseyquinn | 10:f9cb61b29340 | 81 | float mag_z; |
caseyquinn | 10:f9cb61b29340 | 82 | |
caseyquinn | 0:14d46ef4b6cb | 83 | int vInReading; |
caseyquinn | 0:14d46ef4b6cb | 84 | int vBlowerReading; |
caseyquinn | 0:14d46ef4b6cb | 85 | int omronDiff; |
lionberg | 52:80480b2fafba | 86 | float omronVolt; //V |
caseyquinn | 20:ad9883973d86 | 87 | int omronReading; |
lionberg | 52:80480b2fafba | 88 | float atmoRho; //g/L |
caseyquinn | 49:19e828650618 | 89 | |
caseyquinn | 20:ad9883973d86 | 90 | float massflow; //g/min |
caseyquinn | 20:ad9883973d86 | 91 | float volflow; //L/min |
caseyquinn | 67:300418575137 | 92 | float volflowSet = 1.0; //L/min |
caseyquinn | 57:0b554f7aa9a3 | 93 | int logInerval = 10; |
caseyquinn | 57:0b554f7aa9a3 | 94 | double secondsD = 0; |
joshuasmth04 | 41:1fb3e0ac6f87 | 95 | float massflowSet; |
caseyquinn | 42:fc2f2b9f07ae | 96 | float deltaVflow = 0.0; |
caseyquinn | 42:fc2f2b9f07ae | 97 | float deltaMflow = 0.0; |
caseyquinn | 47:3146e8c949a9 | 98 | float gainFlow; |
lionberg | 52:80480b2fafba | 99 | float sampledVol; //L, total sampled volume |
caseyquinn | 20:ad9883973d86 | 100 | |
caseyquinn | 55:f24d70f519cd | 101 | int digital_pot_setpoint; //min = 0x7F, max = 0x00 |
caseyquinn | 55:f24d70f519cd | 102 | int digital_pot_set; |
caseyquinn | 55:f24d70f519cd | 103 | int digital_pot_change; |
caseyquinn | 55:f24d70f519cd | 104 | int digitalpotMax = 127; |
caseyquinn | 55:f24d70f519cd | 105 | int digitalpotMin = 2; |
caseyquinn | 55:f24d70f519cd | 106 | |
joshuasmth04 | 59:a9b21b3d9afc | 107 | int dutyUp; |
joshuasmth04 | 59:a9b21b3d9afc | 108 | int dutyDown; |
caseyquinn | 67:300418575137 | 109 | uint8_t f_sec, f_min, f_hour, f_date, f_month, f_year; |
joshuasmth04 | 59:a9b21b3d9afc | 110 | |
joshuasmth04 | 72:0b36575ab00d | 111 | // variables are only place holders for the US_Menu // |
joshuasmth04 | 72:0b36575ab00d | 112 | int refreshtime; |
joshuasmth04 | 72:0b36575ab00d | 113 | float home_lat, home_lon, work_lat, work_lon; |
joshuasmth04 | 77:24fbeb2bfe05 | 114 | //*************************************************// |
joshuasmth04 | 72:0b36575ab00d | 115 | |
caseyquinn | 67:300418575137 | 116 | //int refresh_Time = 10; // refresh time in s, note calling read_GPS()(or similar) will still take how ever long it needs(hopefully < 1s) |
caseyquinn | 42:fc2f2b9f07ae | 117 | |
caseyquinn | 57:0b554f7aa9a3 | 118 | char device_name[] = "---------------"; |
caseyquinn | 73:47910ee23ebf | 119 | char filename[] = "/sd/UPAS0012LOG000000000000---------------.txt"; |
caseyquinn | 7:a24d7156bc02 | 120 | SDFileSystem sd(SPIS_PSELMOSI, SPIS_PSELMISO, SPIS_PSELSCK, SPIS_PSELSS, "sd"); // I believe this matches Todd's pinout, let me know if this doesn't work. (p12, p13, p15, p14) |
caseyquinn | 7:a24d7156bc02 | 121 | |
caseyquinn | 7:a24d7156bc02 | 122 | |
joshuasmth04 | 71:78edbceff4fc | 123 | void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason) |
joshuasmth04 | 71:78edbceff4fc | 124 | { |
joshuasmth04 | 71:78edbceff4fc | 125 | bleMenu.disconnectionCallback(); |
joshuasmth04 | 71:78edbceff4fc | 126 | } |
joshuasmth04 | 71:78edbceff4fc | 127 | |
joshuasmth04 | 71:78edbceff4fc | 128 | void WrittenHandler(const GattCharacteristicWriteCBParams *Handler) // called any time the phone sends a message |
joshuasmth04 | 71:78edbceff4fc | 129 | { |
joshuasmth04 | 71:78edbceff4fc | 130 | bleMenu.WrittenHandler(pc, txPayload, txCharacteristic, Handler); |
joshuasmth04 | 71:78edbceff4fc | 131 | //returns things to the txPayload |
joshuasmth04 | 71:78edbceff4fc | 132 | } |
joshuasmth04 | 71:78edbceff4fc | 133 | |
joshuasmth04 | 62:edc9632bcc43 | 134 | void check_stop() // this checks if it's time to stop and shutdown |
caseyquinn | 57:0b554f7aa9a3 | 135 | { |
joshuasmth04 | 63:66796aef8d68 | 136 | //RTC.get_time(); //debug |
joshuasmth04 | 63:66796aef8d68 | 137 | //pc.printf("%02d:%02d:%02d on %d/%d/%d) \r\n",RTC.hour, RTC.minutes, RTC.seconds, RTC.month, RTC.date, RTC.year);//debig |
caseyquinn | 67:300418575137 | 138 | if(RTC.compare(f_sec, f_min, f_hour, f_date, f_month, f_year)) { |
caseyquinn | 57:0b554f7aa9a3 | 139 | pbKill = 0; // this is were we shut everything down |
caseyquinn | 57:0b554f7aa9a3 | 140 | } |
caseyquinn | 57:0b554f7aa9a3 | 141 | stop.detach(); |
joshuasmth04 | 77:24fbeb2bfe05 | 142 | stop.attach(&check_stop, 9); |
joshuasmth04 | 62:edc9632bcc43 | 143 | } |
caseyquinn | 58:7239c2ab2b65 | 144 | |
joshuasmth04 | 41:1fb3e0ac6f87 | 145 | |
caseyquinn | 57:0b554f7aa9a3 | 146 | void log_data() |
joshuasmth04 | 59:a9b21b3d9afc | 147 | { |
caseyquinn | 70:81f04e69e08a | 148 | logg.detach(); |
caseyquinn | 70:81f04e69e08a | 149 | logg.attach(&log_data, logInerval); |
joshuasmth04 | 59:a9b21b3d9afc | 150 | RTC.get_time(); |
caseyquinn | 70:81f04e69e08a | 151 | secondsD = RTC.seconds; |
joshuasmth04 | 77:24fbeb2bfe05 | 152 | while(fmod(secondsD,logInerval)!=0) { |
caseyquinn | 70:81f04e69e08a | 153 | RTC.get_time(); |
caseyquinn | 70:81f04e69e08a | 154 | secondsD = RTC.seconds; |
joshuasmth04 | 77:24fbeb2bfe05 | 155 | } |
joshuasmth04 | 77:24fbeb2bfe05 | 156 | |
joshuasmth04 | 77:24fbeb2bfe05 | 157 | |
joshuasmth04 | 59:a9b21b3d9afc | 158 | omronReading = ads.readADC_SingleEnded(0, 0xC583); // read channel 0 PGA = 2 : Full Scale Range = 2.048V |
joshuasmth04 | 59:a9b21b3d9afc | 159 | omronVolt = (omronReading*4.096)/(32768*2); |
joshuasmth04 | 59:a9b21b3d9afc | 160 | |
joshuasmth04 | 77:24fbeb2bfe05 | 161 | if(omronVolt<=calibrations.omronVMin) { |
joshuasmth04 | 77:24fbeb2bfe05 | 162 | massflow = calibrations.omronMFMin; |
joshuasmth04 | 77:24fbeb2bfe05 | 163 | } else if(omronVolt>=calibrations.omronVMax) { |
joshuasmth04 | 77:24fbeb2bfe05 | 164 | massflow = calibrations.omronMFMax; |
joshuasmth04 | 59:a9b21b3d9afc | 165 | } else { |
joshuasmth04 | 77:24fbeb2bfe05 | 166 | massflow = calibrations.MF4*pow(omronVolt,(float)4)+calibrations.MF3*pow(omronVolt,(float)3)+calibrations.MF2*pow(omronVolt,(float)2)+calibrations.MF1*omronVolt+calibrations.MF0; |
joshuasmth04 | 59:a9b21b3d9afc | 167 | } |
joshuasmth04 | 59:a9b21b3d9afc | 168 | |
joshuasmth04 | 59:a9b21b3d9afc | 169 | atmoRho = ((press-((6.1078*pow((float)10,(float)((7.5*temp)/(237.3+temp))))*(rh/100)))*100)/(287.0531*(temp+273.15))+((6.1078*pow((float)10,(float)((7.5*temp)/(237.3+temp))))*(rh/100)*100)/(461.4964*(temp+273.15)); |
joshuasmth04 | 59:a9b21b3d9afc | 170 | volflow = massflow/atmoRho; |
joshuasmth04 | 59:a9b21b3d9afc | 171 | sampledVol = sampledVol + ((((float)logInerval)/60.0)*volflow); |
joshuasmth04 | 59:a9b21b3d9afc | 172 | deltaVflow = volflow-volflowSet; |
joshuasmth04 | 59:a9b21b3d9afc | 173 | massflowSet = volflowSet*atmoRho; |
joshuasmth04 | 59:a9b21b3d9afc | 174 | deltaMflow = massflow-massflowSet; |
joshuasmth04 | 59:a9b21b3d9afc | 175 | |
joshuasmth04 | 59:a9b21b3d9afc | 176 | if(abs(deltaMflow)>.025) { |
joshuasmth04 | 59:a9b21b3d9afc | 177 | digital_pot_change = (int)(gainFlow*deltaMflow); |
joshuasmth04 | 59:a9b21b3d9afc | 178 | |
joshuasmth04 | 59:a9b21b3d9afc | 179 | |
joshuasmth04 | 59:a9b21b3d9afc | 180 | if(abs(digital_pot_change)>=50) { |
joshuasmth04 | 59:a9b21b3d9afc | 181 | digital_pot_set = (int)(digital_pot_set+(int)((10.0*deltaMflow))); |
joshuasmth04 | 59:a9b21b3d9afc | 182 | RGB_LED.set_led(1,0,0); |
joshuasmth04 | 41:1fb3e0ac6f87 | 183 | |
joshuasmth04 | 59:a9b21b3d9afc | 184 | } else if(digital_pot_change+digital_pot_set>=digitalpotMax&abs(digital_pot_change)<50) { |
joshuasmth04 | 59:a9b21b3d9afc | 185 | digital_pot_set = digitalpotMax; |
joshuasmth04 | 59:a9b21b3d9afc | 186 | RGB_LED.set_led(1,0,0); |
joshuasmth04 | 59:a9b21b3d9afc | 187 | } else if(digital_pot_change+digital_pot_set<=digitalpotMin&abs(digital_pot_change)<50) { |
joshuasmth04 | 59:a9b21b3d9afc | 188 | digital_pot_set = digitalpotMin; |
joshuasmth04 | 59:a9b21b3d9afc | 189 | RGB_LED.set_led(1,0,0); |
joshuasmth04 | 59:a9b21b3d9afc | 190 | } else { |
joshuasmth04 | 59:a9b21b3d9afc | 191 | digital_pot_set = (digital_pot_set+ digital_pot_change); |
joshuasmth04 | 59:a9b21b3d9afc | 192 | RGB_LED.set_led(1,1,0); |
joshuasmth04 | 59:a9b21b3d9afc | 193 | } |
joshuasmth04 | 59:a9b21b3d9afc | 194 | |
joshuasmth04 | 59:a9b21b3d9afc | 195 | DigPot.writeRegister(digital_pot_set); |
joshuasmth04 | 59:a9b21b3d9afc | 196 | |
joshuasmth04 | 59:a9b21b3d9afc | 197 | } else { |
joshuasmth04 | 59:a9b21b3d9afc | 198 | RGB_LED.set_led(0,1,0); |
joshuasmth04 | 59:a9b21b3d9afc | 199 | } |
joshuasmth04 | 59:a9b21b3d9afc | 200 | |
joshuasmth04 | 59:a9b21b3d9afc | 201 | movementsensor.getACCEL(); |
joshuasmth04 | 59:a9b21b3d9afc | 202 | movementsensor.getCOMPASS(); |
caseyquinn | 67:300418575137 | 203 | compass = movementsensor.getCOMPASS_HEADING(); |
joshuasmth04 | 59:a9b21b3d9afc | 204 | accel_x = movementsensor.AccelData.x; |
joshuasmth04 | 59:a9b21b3d9afc | 205 | accel_y = movementsensor.AccelData.y; |
joshuasmth04 | 59:a9b21b3d9afc | 206 | accel_z = movementsensor.AccelData.z; |
joshuasmth04 | 59:a9b21b3d9afc | 207 | accel_comp = pow(accel_x,(float)2)+pow(accel_y,(float)2)+pow(accel_z,(float)2)-1.0; |
joshuasmth04 | 59:a9b21b3d9afc | 208 | mag_x = movementsensor.MagData.x; |
joshuasmth04 | 59:a9b21b3d9afc | 209 | mag_y = movementsensor.MagData.y; |
joshuasmth04 | 59:a9b21b3d9afc | 210 | mag_z = movementsensor.MagData.z; |
joshuasmth04 | 59:a9b21b3d9afc | 211 | |
joshuasmth04 | 59:a9b21b3d9afc | 212 | vInReading = ads.readADC_SingleEnded(1, 0xD583); // read channel 0 |
joshuasmth04 | 59:a9b21b3d9afc | 213 | vBlowerReading = ads.readADC_SingleEnded(2, 0xE783); // read channel 0 |
joshuasmth04 | 59:a9b21b3d9afc | 214 | omronDiff = ads.readADC_Differential(0x8583); // differential channel 2-3 |
joshuasmth04 | 59:a9b21b3d9afc | 215 | press = bmesensor.getPressure(); |
joshuasmth04 | 59:a9b21b3d9afc | 216 | temp = bmesensor.getTemperature()-5.0; |
joshuasmth04 | 59:a9b21b3d9afc | 217 | rh = bmesensor.getHumidity(); |
joshuasmth04 | 59:a9b21b3d9afc | 218 | uv = lightsensor.getUV(); |
joshuasmth04 | 59:a9b21b3d9afc | 219 | vis = lightsensor.getVIS(); |
joshuasmth04 | 59:a9b21b3d9afc | 220 | ir = lightsensor.getIR(); |
joshuasmth04 | 59:a9b21b3d9afc | 221 | |
joshuasmth04 | 59:a9b21b3d9afc | 222 | //Mount the filesystem |
joshuasmth04 | 59:a9b21b3d9afc | 223 | //sd.mount(); |
joshuasmth04 | 59:a9b21b3d9afc | 224 | FILE *fp = fopen(filename, "a"); |
caseyquinn | 67:300418575137 | 225 | 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); |
joshuasmth04 | 59:a9b21b3d9afc | 226 | fclose(fp); |
joshuasmth04 | 59:a9b21b3d9afc | 227 | //Unmount the filesystem |
joshuasmth04 | 59:a9b21b3d9afc | 228 | //sd.unmount(); |
joshuasmth04 | 59:a9b21b3d9afc | 229 | |
caseyquinn | 70:81f04e69e08a | 230 | //wait(1.2); |
joshuasmth04 | 77:24fbeb2bfe05 | 231 | |
joshuasmth04 | 59:a9b21b3d9afc | 232 | } |
caseyquinn | 57:0b554f7aa9a3 | 233 | |
caseyquinn | 57:0b554f7aa9a3 | 234 | int main() |
caseyquinn | 57:0b554f7aa9a3 | 235 | { |
caseyquinn | 57:0b554f7aa9a3 | 236 | |
caseyquinn | 57:0b554f7aa9a3 | 237 | // Setup and Initialization |
caseyquinn | 57:0b554f7aa9a3 | 238 | //---------------------------------------------------------------------------------------------// |
joshuasmth04 | 77:24fbeb2bfe05 | 239 | 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 |
joshuasmth04 | 77:24fbeb2bfe05 | 240 | |
joshuasmth04 | 71:78edbceff4fc | 241 | //**************//BLE initialization//**************// |
joshuasmth04 | 78:a465de6cc47e | 242 | bleMenu.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 |
joshuasmth04 | 71:78edbceff4fc | 243 | uint8_t BLE_name[] = {device_name[0], device_name[1], device_name[2], device_name[3], device_name[4], device_name[5], device_name[6], device_name[7], device_name[8]}; |
joshuasmth04 | 77:24fbeb2bfe05 | 244 | ble.init(); |
joshuasmth04 | 77:24fbeb2bfe05 | 245 | // setup advertising |
joshuasmth04 | 71:78edbceff4fc | 246 | ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED); |
joshuasmth04 | 71:78edbceff4fc | 247 | ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); |
joshuasmth04 | 71:78edbceff4fc | 248 | ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,(const uint8_t *)BLE_name, sizeof(BLE_name) - 1); // ~8 char max! |
joshuasmth04 | 71:78edbceff4fc | 249 | ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,(const uint8_t *)uart_base_uuid_rev, sizeof(uart_base_uuid)); |
joshuasmth04 | 77:24fbeb2bfe05 | 250 | // 100ms; in multiples of 0.625ms. |
joshuasmth04 | 71:78edbceff4fc | 251 | ble.setAdvertisingInterval(160); |
joshuasmth04 | 71:78edbceff4fc | 252 | ble.addService(uartService); |
joshuasmth04 | 77:24fbeb2bfe05 | 253 | ble.startAdvertising(); |
joshuasmth04 | 71:78edbceff4fc | 254 | ble.onDisconnection(disconnectionCallback); //what happens when disconected |
joshuasmth04 | 71:78edbceff4fc | 255 | ble.onDataWritten(WrittenHandler); //what happens when the phone sends a message |
joshuasmth04 | 71:78edbceff4fc | 256 | //**************//BLE initialization//**************// |
joshuasmth04 | 77:24fbeb2bfe05 | 257 | |
joshuasmth04 | 77:24fbeb2bfe05 | 258 | |
joshuasmth04 | 77:24fbeb2bfe05 | 259 | |
caseyquinn | 57:0b554f7aa9a3 | 260 | //Test for errors |
joshuasmth04 | 71:78edbceff4fc | 261 | //RunReady = 0; //debug always open the menu |
joshuasmth04 | 76:8130cb6776c6 | 262 | //if(RTC.OSF()) { //Force the menu open if the RTC needs reset. |
joshuasmth04 | 76:8130cb6776c6 | 263 | // RunReady = 0; |
joshuasmth04 | 76:8130cb6776c6 | 264 | //} |
joshuasmth04 | 77:24fbeb2bfe05 | 265 | if(RunReady == 0) { |
joshuasmth04 | 71:78edbceff4fc | 266 | RGB_LED.set_led(0,1,1); // error code/color |
joshuasmth04 | 71:78edbceff4fc | 267 | pc.printf("Change Name\r\n"); |
joshuasmth04 | 77:24fbeb2bfe05 | 268 | while(RunReady == 0) { |
joshuasmth04 | 71:78edbceff4fc | 269 | RGB_LED.set_led(0,1,1); // error code/color |
joshuasmth04 | 77:24fbeb2bfe05 | 270 | RunReady = Menu.Start(pc, E2PROM, RTC, logInerval, refreshtime, volflowSet, device_name, dutyUp, dutyDown, home_lat, home_lon, work_lat, work_lon, Menu.menu_ops, 0.25, serial_num, calibrations); //Forces you to open the menu |
joshuasmth04 | 71:78edbceff4fc | 271 | RGB_LED.set_led(0,10,10); // error code/color |
joshuasmth04 | 78:a465de6cc47e | 272 | bleMenu.open_menu(txPayload, rxCharacteristic, E2PROM, RTC, logInerval, refreshtime, volflowSet, device_name, dutyUp, dutyDown, home_lat, home_lon, work_lat, work_lon, Menu.menu_ops ,RunReady, 0.25, serial_num, calibrations); |
joshuasmth04 | 71:78edbceff4fc | 273 | } |
joshuasmth04 | 77:24fbeb2bfe05 | 274 | if(Menu.crr == 0){ |
joshuasmth04 | 77:24fbeb2bfe05 | 275 | 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 |
joshuasmth04 | 77:24fbeb2bfe05 | 276 | pbKill = 0; |
joshuasmth04 | 77:24fbeb2bfe05 | 277 | } |
joshuasmth04 | 71:78edbceff4fc | 278 | } |
joshuasmth04 | 77:24fbeb2bfe05 | 279 | |
joshuasmth04 | 71:78edbceff4fc | 280 | RunReady = 0; |
joshuasmth04 | 77:24fbeb2bfe05 | 281 | 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 |
joshuasmth04 | 78:a465de6cc47e | 282 | calibrations.initialize(serial_num); |
joshuasmth04 | 78:a465de6cc47e | 283 | |
joshuasmth04 | 62:edc9632bcc43 | 284 | stop.attach(&check_stop, 60); // check if we should shut down every 5 seconds, starting 60s after the start. |
caseyquinn | 57:0b554f7aa9a3 | 285 | |
joshuasmth04 | 59:a9b21b3d9afc | 286 | if(volflowSet==1.0) { |
joshuasmth04 | 59:a9b21b3d9afc | 287 | gainFlow = 100; |
joshuasmth04 | 59:a9b21b3d9afc | 288 | } else if(volflowSet==2.0) { |
joshuasmth04 | 59:a9b21b3d9afc | 289 | gainFlow = 25; |
joshuasmth04 | 59:a9b21b3d9afc | 290 | } else { |
joshuasmth04 | 59:a9b21b3d9afc | 291 | gainFlow = 25; |
joshuasmth04 | 59:a9b21b3d9afc | 292 | } |
joshuasmth04 | 59:a9b21b3d9afc | 293 | |
caseyquinn | 57:0b554f7aa9a3 | 294 | RGB_LED.set_led(1,0,0); |
caseyquinn | 57:0b554f7aa9a3 | 295 | press = bmesensor.getPressure(); |
caseyquinn | 57:0b554f7aa9a3 | 296 | temp = bmesensor.getTemperature(); |
caseyquinn | 57:0b554f7aa9a3 | 297 | rh = bmesensor.getHumidity(); |
caseyquinn | 57:0b554f7aa9a3 | 298 | |
caseyquinn | 57:0b554f7aa9a3 | 299 | atmoRho = ((press-((6.1078*pow((float)10,(float)((7.5*temp)/(237.3+temp))))*(rh/100)))*100)/(287.0531*(temp+273.15))+((6.1078*pow((float)10,(float)((7.5*temp)/(237.3+temp))))*(rh/100)*100)/(461.4964*(temp+273.15)); |
caseyquinn | 57:0b554f7aa9a3 | 300 | massflowSet = volflowSet*atmoRho; |
caseyquinn | 57:0b554f7aa9a3 | 301 | //Digtal pot tf from file: UPAS v2 OSU-PrimaryFlowData FullSet 2015-05-29 CQ mods.xlsx |
joshuasmth04 | 77:24fbeb2bfe05 | 302 | digital_pot_setpoint = (int)floor(calibrations.DP4*pow(massflowSet,4)+calibrations.DP3*pow(massflowSet,3)+calibrations.DP2*pow(massflowSet,2)+calibrations.DP1*massflowSet+calibrations.DP0); //min = 0x7F, max = 0x00 |
joshuasmth04 | 59:a9b21b3d9afc | 303 | |
joshuasmth04 | 59:a9b21b3d9afc | 304 | if(digital_pot_setpoint>=digitalpotMax) { |
caseyquinn | 57:0b554f7aa9a3 | 305 | digital_pot_setpoint = digitalpotMax; |
joshuasmth04 | 59:a9b21b3d9afc | 306 | } else if(digital_pot_setpoint<=digitalpotMin) { |
caseyquinn | 57:0b554f7aa9a3 | 307 | digital_pot_setpoint = digitalpotMin; |
joshuasmth04 | 59:a9b21b3d9afc | 308 | } |
joshuasmth04 | 59:a9b21b3d9afc | 309 | |
caseyquinn | 57:0b554f7aa9a3 | 310 | DigPot.writeRegister(digital_pot_setpoint); |
caseyquinn | 57:0b554f7aa9a3 | 311 | wait(1); |
caseyquinn | 57:0b554f7aa9a3 | 312 | blower = 1; |
joshuasmth04 | 77:24fbeb2bfe05 | 313 | if(Menu.crr == 1) { |
joshuasmth04 | 77:24fbeb2bfe05 | 314 | RTC.get_time(); |
joshuasmth04 | 77:24fbeb2bfe05 | 315 | f_sec = RTC.seconds; |
joshuasmth04 | 77:24fbeb2bfe05 | 316 | f_min = RTC.minutes; |
joshuasmth04 | 77:24fbeb2bfe05 | 317 | f_hour = RTC.hour; |
joshuasmth04 | 77:24fbeb2bfe05 | 318 | if(RTC.month == 1 | RTC.month == 3 | RTC.month == 5 | RTC.month == 7 | RTC.month == 8 | RTC.month == 10) { |
joshuasmth04 | 77:24fbeb2bfe05 | 319 | if(RTC.date == 31) { |
caseyquinn | 67:300418575137 | 320 | f_date = 1; |
caseyquinn | 67:300418575137 | 321 | f_month = RTC.month +1; |
joshuasmth04 | 77:24fbeb2bfe05 | 322 | f_year = RTC.year; |
joshuasmth04 | 77:24fbeb2bfe05 | 323 | } else { |
joshuasmth04 | 77:24fbeb2bfe05 | 324 | f_date = RTC.date+1; |
joshuasmth04 | 77:24fbeb2bfe05 | 325 | f_month = RTC.month; |
joshuasmth04 | 77:24fbeb2bfe05 | 326 | f_year = RTC.year; |
joshuasmth04 | 77:24fbeb2bfe05 | 327 | } |
joshuasmth04 | 77:24fbeb2bfe05 | 328 | } else if(RTC.month == 4 | RTC.month == 6 | RTC.month == 9 | RTC.month == 11) { |
joshuasmth04 | 77:24fbeb2bfe05 | 329 | if(RTC.date == 30) { |
joshuasmth04 | 77:24fbeb2bfe05 | 330 | f_date = 1; |
joshuasmth04 | 77:24fbeb2bfe05 | 331 | f_month = RTC.month +1; |
joshuasmth04 | 77:24fbeb2bfe05 | 332 | f_year = RTC.year; |
joshuasmth04 | 77:24fbeb2bfe05 | 333 | } else { |
caseyquinn | 67:300418575137 | 334 | f_date = RTC.date+1; |
caseyquinn | 67:300418575137 | 335 | f_month = RTC.month; |
caseyquinn | 67:300418575137 | 336 | f_year = RTC.year; |
joshuasmth04 | 77:24fbeb2bfe05 | 337 | } |
joshuasmth04 | 77:24fbeb2bfe05 | 338 | } else if(RTC.month == 2) { |
joshuasmth04 | 77:24fbeb2bfe05 | 339 | if(RTC.year == 16 | RTC.year == 20 | RTC.year == 24| RTC.year == 28) { |
joshuasmth04 | 77:24fbeb2bfe05 | 340 | if(RTC.date == 29) { |
joshuasmth04 | 77:24fbeb2bfe05 | 341 | f_date = 1; |
joshuasmth04 | 77:24fbeb2bfe05 | 342 | f_month = RTC.month +1; |
joshuasmth04 | 77:24fbeb2bfe05 | 343 | f_year = RTC.year; |
joshuasmth04 | 77:24fbeb2bfe05 | 344 | } else { |
joshuasmth04 | 77:24fbeb2bfe05 | 345 | f_date = RTC.date+1; |
joshuasmth04 | 77:24fbeb2bfe05 | 346 | f_month = RTC.month; |
joshuasmth04 | 77:24fbeb2bfe05 | 347 | f_year = RTC.year; |
joshuasmth04 | 77:24fbeb2bfe05 | 348 | } |
joshuasmth04 | 77:24fbeb2bfe05 | 349 | } else { |
joshuasmth04 | 77:24fbeb2bfe05 | 350 | if(RTC.date == 28) { |
joshuasmth04 | 77:24fbeb2bfe05 | 351 | f_date = 1; |
joshuasmth04 | 77:24fbeb2bfe05 | 352 | f_month = RTC.month +1; |
joshuasmth04 | 77:24fbeb2bfe05 | 353 | f_year = RTC.year; |
joshuasmth04 | 77:24fbeb2bfe05 | 354 | } else { |
joshuasmth04 | 77:24fbeb2bfe05 | 355 | f_date = RTC.date+1; |
joshuasmth04 | 77:24fbeb2bfe05 | 356 | f_month = RTC.month; |
joshuasmth04 | 77:24fbeb2bfe05 | 357 | f_year = RTC.year; |
caseyquinn | 67:300418575137 | 358 | } |
caseyquinn | 67:300418575137 | 359 | } |
joshuasmth04 | 77:24fbeb2bfe05 | 360 | } else if(RTC.month == 12) { |
joshuasmth04 | 77:24fbeb2bfe05 | 361 | if(RTC.date == 31) { |
caseyquinn | 67:300418575137 | 362 | f_date = 1; |
joshuasmth04 | 77:24fbeb2bfe05 | 363 | f_month = 1; |
joshuasmth04 | 77:24fbeb2bfe05 | 364 | f_year = RTC.year+1; |
joshuasmth04 | 77:24fbeb2bfe05 | 365 | } else { |
caseyquinn | 67:300418575137 | 366 | f_date = RTC.date+1; |
caseyquinn | 67:300418575137 | 367 | f_month = RTC.month; |
caseyquinn | 67:300418575137 | 368 | f_year = RTC.year; |
joshuasmth04 | 77:24fbeb2bfe05 | 369 | } |
caseyquinn | 67:300418575137 | 370 | } |
joshuasmth04 | 77:24fbeb2bfe05 | 371 | } |
joshuasmth04 | 77:24fbeb2bfe05 | 372 | |
caseyquinn | 73:47910ee23ebf | 373 | sprintf(filename, "/sd/UPAS0012LOG_%02d-%02d-%02d_%02d=%02d=%02d_%s.txt",RTC.year,RTC.month,RTC.date,RTC.hour,RTC.minutes,RTC.seconds,device_name); |
caseyquinn | 57:0b554f7aa9a3 | 374 | FILE *fp = fopen(filename, "w"); |
caseyquinn | 57:0b554f7aa9a3 | 375 | fclose(fp); |
joshuasmth04 | 59:a9b21b3d9afc | 376 | //pc.printf("%d\r\n",digital_pot_setpoint); |
joshuasmth04 | 59:a9b21b3d9afc | 377 | |
joshuasmth04 | 59:a9b21b3d9afc | 378 | //---------------------------------------------------------------------------------------------// |
joshuasmth04 | 59:a9b21b3d9afc | 379 | //Following lines are needed to enter into the initiallization flow control loop |
joshuasmth04 | 59:a9b21b3d9afc | 380 | |
caseyquinn | 57:0b554f7aa9a3 | 381 | wait(10); |
joshuasmth04 | 59:a9b21b3d9afc | 382 | |
caseyquinn | 57:0b554f7aa9a3 | 383 | omronReading = ads.readADC_SingleEnded(0, 0xC583); // read channel 0 PGA = 2 : Full Scale Range = 2.048V |
caseyquinn | 57:0b554f7aa9a3 | 384 | omronVolt = (omronReading*4.096)/(32768*2); |
joshuasmth04 | 77:24fbeb2bfe05 | 385 | if(omronVolt<=calibrations.omronVMin) { |
joshuasmth04 | 77:24fbeb2bfe05 | 386 | massflow = calibrations.omronMFMin; |
joshuasmth04 | 77:24fbeb2bfe05 | 387 | } else if(omronVolt>=calibrations.omronVMax) { |
joshuasmth04 | 77:24fbeb2bfe05 | 388 | massflow = calibrations.omronMFMax; |
joshuasmth04 | 59:a9b21b3d9afc | 389 | } else { |
joshuasmth04 | 77:24fbeb2bfe05 | 390 | massflow = calibrations.MF4*pow(omronVolt,(float)4)+calibrations.MF3*pow(omronVolt,(float)3)+calibrations.MF2*pow(omronVolt,(float)2)+calibrations.MF1*omronVolt+calibrations.MF0; |
joshuasmth04 | 59:a9b21b3d9afc | 391 | } |
joshuasmth04 | 59:a9b21b3d9afc | 392 | deltaMflow = massflow-massflowSet; |
joshuasmth04 | 59:a9b21b3d9afc | 393 | digital_pot_set = digital_pot_setpoint; |
joshuasmth04 | 59:a9b21b3d9afc | 394 | wait(5); |
joshuasmth04 | 59:a9b21b3d9afc | 395 | |
joshuasmth04 | 59:a9b21b3d9afc | 396 | //---------------------------------------------------------------------------------------------// |
joshuasmth04 | 59:a9b21b3d9afc | 397 | //Sets the flow withen +-1.5% of the desired flow rate based on mass flow |
joshuasmth04 | 59:a9b21b3d9afc | 398 | |
joshuasmth04 | 59:a9b21b3d9afc | 399 | while(abs(deltaMflow)>.015) { |
joshuasmth04 | 77:24fbeb2bfe05 | 400 | |
joshuasmth04 | 59:a9b21b3d9afc | 401 | omronReading = ads.readADC_SingleEnded(0, 0xC583); // read channel 0 PGA = 2 : Full Scale Range = 2.048V |
joshuasmth04 | 59:a9b21b3d9afc | 402 | omronVolt = (omronReading*4.096)/(32768*2); |
joshuasmth04 | 59:a9b21b3d9afc | 403 | //Mass Flow tf from file: UPAS v2 OSU-PrimaryFlowData FullSet 2015-05-29 CQ mods.xlsx |
joshuasmth04 | 77:24fbeb2bfe05 | 404 | if(omronVolt<=calibrations.omronVMin) { |
joshuasmth04 | 77:24fbeb2bfe05 | 405 | massflow = calibrations.omronMFMin; |
joshuasmth04 | 77:24fbeb2bfe05 | 406 | } else if(omronVolt>=calibrations.omronVMax) { |
joshuasmth04 | 77:24fbeb2bfe05 | 407 | massflow = calibrations.omronMFMax; |
joshuasmth04 | 59:a9b21b3d9afc | 408 | } else { |
joshuasmth04 | 77:24fbeb2bfe05 | 409 | massflow = calibrations.MF4*pow(omronVolt,(float)4)+calibrations.MF3*pow(omronVolt,(float)3)+calibrations.MF2*pow(omronVolt,(float)2)+calibrations.MF1*omronVolt+calibrations.MF0; |
joshuasmth04 | 59:a9b21b3d9afc | 410 | } |
caseyquinn | 57:0b554f7aa9a3 | 411 | |
joshuasmth04 | 59:a9b21b3d9afc | 412 | atmoRho = ((press-((6.1078*pow((float)10,(float)((7.5*temp)/(237.3+temp))))*(rh/100)))*100)/(287.0531*(temp+273.15))+((6.1078*pow((float)10,(float)((7.5*temp)/(237.3+temp))))*(rh/100)*100)/(461.4964*(temp+273.15)); |
joshuasmth04 | 59:a9b21b3d9afc | 413 | volflow = massflow/atmoRho; |
joshuasmth04 | 59:a9b21b3d9afc | 414 | massflowSet = volflowSet*atmoRho; |
joshuasmth04 | 59:a9b21b3d9afc | 415 | deltaMflow = massflow-massflowSet; |
joshuasmth04 | 63:66796aef8d68 | 416 | //pc.printf("%f,%f,%f,%f,%d,%u,%x\r\n",volflow,massflow,massflowSet,deltaMflow,digital_pot_set,digital_pot_set,digital_pot_set); |
caseyquinn | 67:300418575137 | 417 | pc.printf("%d,%d,%d,%d,%d,%d\r\n",f_sec,f_min,f_hour,f_date,f_month,f_year,digital_pot_set); |
joshuasmth04 | 59:a9b21b3d9afc | 418 | digital_pot_set = (int)(digital_pot_set+(int)((gainFlow*deltaMflow))); |
joshuasmth04 | 59:a9b21b3d9afc | 419 | if(digital_pot_set>=digitalpotMax) { |
joshuasmth04 | 59:a9b21b3d9afc | 420 | digital_pot_set = digitalpotMax; |
joshuasmth04 | 59:a9b21b3d9afc | 421 | } else if(digital_pot_set<=digitalpotMin) { |
joshuasmth04 | 59:a9b21b3d9afc | 422 | digital_pot_set = digitalpotMin; |
joshuasmth04 | 59:a9b21b3d9afc | 423 | } |
joshuasmth04 | 59:a9b21b3d9afc | 424 | |
joshuasmth04 | 59:a9b21b3d9afc | 425 | wait(2); |
joshuasmth04 | 59:a9b21b3d9afc | 426 | DigPot.writeRegister(digital_pot_set); |
joshuasmth04 | 59:a9b21b3d9afc | 427 | wait(1); |
joshuasmth04 | 59:a9b21b3d9afc | 428 | |
joshuasmth04 | 59:a9b21b3d9afc | 429 | |
joshuasmth04 | 59:a9b21b3d9afc | 430 | } |
joshuasmth04 | 59:a9b21b3d9afc | 431 | |
joshuasmth04 | 59:a9b21b3d9afc | 432 | sampledVol = 0.0; |
joshuasmth04 | 59:a9b21b3d9afc | 433 | RGB_LED.set_led(0,1,0); |
joshuasmth04 | 77:24fbeb2bfe05 | 434 | |
caseyquinn | 67:300418575137 | 435 | |
joshuasmth04 | 59:a9b21b3d9afc | 436 | |
joshuasmth04 | 59:a9b21b3d9afc | 437 | //** end of initalization **// |
joshuasmth04 | 59:a9b21b3d9afc | 438 | |
joshuasmth04 | 59:a9b21b3d9afc | 439 | //---------------------------------------------------------------------------------------------// |
joshuasmth04 | 59:a9b21b3d9afc | 440 | //---------------------------------------------------------------------------------------------// |
joshuasmth04 | 59:a9b21b3d9afc | 441 | //---------------------------------------------------------------------------------------------// |
joshuasmth04 | 59:a9b21b3d9afc | 442 | // Main Control Loop |
joshuasmth04 | 59:a9b21b3d9afc | 443 | |
joshuasmth04 | 62:edc9632bcc43 | 444 | logg.attach(&log_data, logInerval); // uses callbacks or block Interrupts for anything that uses i2c |
joshuasmth04 | 59:a9b21b3d9afc | 445 | while(1) { |
joshuasmth04 | 62:edc9632bcc43 | 446 | //__disable_irq(); // Disable Interrupts |
joshuasmth04 | 62:edc9632bcc43 | 447 | //RTC.get_time(); |
joshuasmth04 | 62:edc9632bcc43 | 448 | //__enable_irq(); // Enable Interrupts |
joshuasmth04 | 62:edc9632bcc43 | 449 | //secondsD = (double)RTC.seconds; |
joshuasmth04 | 62:edc9632bcc43 | 450 | //if(fmod(secondsD,logInerval)==0) { |
joshuasmth04 | 77:24fbeb2bfe05 | 451 | //log_data(); |
joshuasmth04 | 64:2906b0c48403 | 452 | //} |
caseyquinn | 0:14d46ef4b6cb | 453 | } |
joshuasmth04 | 59:a9b21b3d9afc | 454 | |
caseyquinn | 0:14d46ef4b6cb | 455 | } |
caseyquinn | 0:14d46ef4b6cb | 456 | |
caseyquinn | 0:14d46ef4b6cb | 457 |