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