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