mDot EVB to M2X demo.
Dependencies: DOGS102 ISL29011 MMA845x MPL3115A2 NCP5623B libmDot mbed-rtos mbed-src
Fork of MTDOT-EVBDemo by
main.cpp@2:75adc72aa6a0, 2015-07-09 (annotated)
- Committer:
- falingtrea
- Date:
- Thu Jul 09 20:32:03 2015 +0000
- Revision:
- 2:75adc72aa6a0
- Parent:
- 1:ac9595d0f0e7
- Child:
- 3:68e974f5f532
Send logo to LCD before attempting connection to LoRa network. Added information on setting up for public LoRa network. Moved SW setup to beginning of main. Removed printf call from ISR functions. Added additional checks for exit_program.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
falingtrea | 0:bdd16076aaa5 | 1 | /** |
falingtrea | 0:bdd16076aaa5 | 2 | * @file main.cpp |
falingtrea | 0:bdd16076aaa5 | 3 | * @brief Main application for mDot-EVB demo |
falingtrea | 0:bdd16076aaa5 | 4 | * @author Tim Barr MultiTech Systems Inc. |
falingtrea | 2:75adc72aa6a0 | 5 | * @version 1.02 |
falingtrea | 0:bdd16076aaa5 | 6 | * @see |
falingtrea | 0:bdd16076aaa5 | 7 | * |
falingtrea | 0:bdd16076aaa5 | 8 | * Copyright (c) 2015 |
falingtrea | 0:bdd16076aaa5 | 9 | * |
falingtrea | 0:bdd16076aaa5 | 10 | * Licensed under the Apache License, Version 2.0 (the "License"); |
falingtrea | 0:bdd16076aaa5 | 11 | * you may not use this file except in compliance with the License. |
falingtrea | 0:bdd16076aaa5 | 12 | * You may obtain a copy of the License at |
falingtrea | 0:bdd16076aaa5 | 13 | * |
falingtrea | 0:bdd16076aaa5 | 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
falingtrea | 0:bdd16076aaa5 | 15 | * |
falingtrea | 0:bdd16076aaa5 | 16 | * Unless required by applicable law or agreed to in writing, software |
falingtrea | 0:bdd16076aaa5 | 17 | * distributed under the License is distributed on an "AS IS" BASIS, |
falingtrea | 0:bdd16076aaa5 | 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
falingtrea | 0:bdd16076aaa5 | 19 | * See the License for the specific language governing permissions and |
falingtrea | 0:bdd16076aaa5 | 20 | * limitations under the License. |
falingtrea | 1:ac9595d0f0e7 | 21 | * |
falingtrea | 1:ac9595d0f0e7 | 22 | * 1.01 TAB 7/6/15 Removed NULL pointer from evbAmbientLight creation call. |
falingtrea | 2:75adc72aa6a0 | 23 | * |
falingtrea | 2:75adc72aa6a0 | 24 | * 1.02 TAB 7/9/15 Send logo to LCD before attempting connection to LoRa network. Added |
falingtrea | 2:75adc72aa6a0 | 25 | * information on setting up for public LoRa network. Moved SW setup to |
falingtrea | 2:75adc72aa6a0 | 26 | * beginning of main. Removed printf call from ISR functions. Added |
falingtrea | 2:75adc72aa6a0 | 27 | * additional checks for exit_program. |
falingtrea | 0:bdd16076aaa5 | 28 | */ |
falingtrea | 0:bdd16076aaa5 | 29 | |
falingtrea | 0:bdd16076aaa5 | 30 | #include "mbed.h" |
falingtrea | 0:bdd16076aaa5 | 31 | #include "MMA845x.h" |
falingtrea | 0:bdd16076aaa5 | 32 | #include "MPL3115A2.h" |
falingtrea | 0:bdd16076aaa5 | 33 | #include "ISL29011.h" |
falingtrea | 0:bdd16076aaa5 | 34 | #include "NCP5623B.h" |
falingtrea | 0:bdd16076aaa5 | 35 | #include "DOGS102.h" |
falingtrea | 0:bdd16076aaa5 | 36 | #include "font_6x8.h" |
falingtrea | 0:bdd16076aaa5 | 37 | #include "MultiTech_Logo.h" |
falingtrea | 0:bdd16076aaa5 | 38 | #include "mDot.h" |
falingtrea | 0:bdd16076aaa5 | 39 | #include "rtos.h" |
falingtrea | 0:bdd16076aaa5 | 40 | #include <string> |
falingtrea | 0:bdd16076aaa5 | 41 | #include <vector> |
falingtrea | 0:bdd16076aaa5 | 42 | |
falingtrea | 0:bdd16076aaa5 | 43 | enum LED1_COLOR { |
falingtrea | 0:bdd16076aaa5 | 44 | RED = 0, |
falingtrea | 0:bdd16076aaa5 | 45 | GREEN = 1 |
falingtrea | 0:bdd16076aaa5 | 46 | }; |
falingtrea | 0:bdd16076aaa5 | 47 | |
falingtrea | 0:bdd16076aaa5 | 48 | /* |
falingtrea | 0:bdd16076aaa5 | 49 | * union for converting from 32-bit to 4 8-bit values |
falingtrea | 0:bdd16076aaa5 | 50 | */ |
falingtrea | 0:bdd16076aaa5 | 51 | union convert32 { |
falingtrea | 0:bdd16076aaa5 | 52 | int32_t f_s; // convert from signed 32 bit int |
falingtrea | 0:bdd16076aaa5 | 53 | uint32_t f_u; // convert from unsigned 32 bit int |
falingtrea | 0:bdd16076aaa5 | 54 | uint8_t t_u[4]; // convert to 8 bit unsigned array |
falingtrea | 0:bdd16076aaa5 | 55 | }; |
falingtrea | 0:bdd16076aaa5 | 56 | |
falingtrea | 0:bdd16076aaa5 | 57 | /* |
falingtrea | 0:bdd16076aaa5 | 58 | * union for converting from 16- bit to 2 8-bit values |
falingtrea | 0:bdd16076aaa5 | 59 | */ |
falingtrea | 0:bdd16076aaa5 | 60 | union convert16 { |
falingtrea | 0:bdd16076aaa5 | 61 | int16_t f_s; // convert from signed 16 bit int |
falingtrea | 0:bdd16076aaa5 | 62 | uint16_t f_u; // convert from unsigned 16 bit int |
falingtrea | 0:bdd16076aaa5 | 63 | uint8_t t_u[2]; // convert to 8 bit unsigned array |
falingtrea | 0:bdd16076aaa5 | 64 | }; |
falingtrea | 0:bdd16076aaa5 | 65 | |
falingtrea | 0:bdd16076aaa5 | 66 | //DigitalIn mDot02(PA_2); // GPIO/UART_TX |
falingtrea | 0:bdd16076aaa5 | 67 | //DigitalOut mDot03(PA_3); // GPIO/UART_RX |
falingtrea | 0:bdd16076aaa5 | 68 | //DigitalIn mDot04(PA_6); // GPIO/SPI_MISO |
falingtrea | 0:bdd16076aaa5 | 69 | //DigitalIn mDot06(PA_8); // GPIO/I2C_SCL |
falingtrea | 0:bdd16076aaa5 | 70 | //DigitalIn mDot07(PC_9); // GPIO/I2C_SDA |
falingtrea | 0:bdd16076aaa5 | 71 | |
falingtrea | 0:bdd16076aaa5 | 72 | InterruptIn mDot08(PA_12); // GPIO/USB PB S1 on EVB |
falingtrea | 0:bdd16076aaa5 | 73 | InterruptIn mDot09(PA_11); // GPIO/USB PB S2 on EVB |
falingtrea | 0:bdd16076aaa5 | 74 | |
falingtrea | 0:bdd16076aaa5 | 75 | //DigitalIn mDot11(PA_7); // GPIO/SPI_MOSI |
falingtrea | 0:bdd16076aaa5 | 76 | |
falingtrea | 0:bdd16076aaa5 | 77 | InterruptIn mDot12(PA_0); // GPIO/UART_CTS PRESSURE_INT2 on EVB |
falingtrea | 0:bdd16076aaa5 | 78 | DigitalOut mDot13(PC_13,1); // GPIO LCD_C/D |
falingtrea | 0:bdd16076aaa5 | 79 | InterruptIn mDot15(PC_1); // GPIO LIGHT_PROX_INT on EVB |
falingtrea | 0:bdd16076aaa5 | 80 | InterruptIn mDot16(PA_1); // GPIO/UART_RTS ACCEL_INT2 on EVB |
falingtrea | 0:bdd16076aaa5 | 81 | DigitalOut mDot17(PA_4,1); // GPIO/SPI_NCS LCD_CS on EVB |
falingtrea | 0:bdd16076aaa5 | 82 | |
falingtrea | 0:bdd16076aaa5 | 83 | //DigitalIn mDot18(PA_5); // GPIO/SPI_SCK |
falingtrea | 0:bdd16076aaa5 | 84 | |
falingtrea | 0:bdd16076aaa5 | 85 | //DigitalInOut mDot19(PB_0,PIN_INPUT,PullNone,0); // GPIO PushPull LED Low=Red High=Green set MODE=INPUT to turn off |
falingtrea | 0:bdd16076aaa5 | 86 | AnalogIn mDot20(PB_1); // GPIO Current Sense Analog in on EVB |
falingtrea | 0:bdd16076aaa5 | 87 | |
falingtrea | 0:bdd16076aaa5 | 88 | Serial debugUART(PA_9, PA_10); // mDot debug UART |
falingtrea | 0:bdd16076aaa5 | 89 | |
falingtrea | 0:bdd16076aaa5 | 90 | //Serial mDotUART(PA_2, PA_3); // mDot external UART mDot02 and mDot03 |
falingtrea | 0:bdd16076aaa5 | 91 | |
falingtrea | 0:bdd16076aaa5 | 92 | I2C mDoti2c(PC_9,PA_8); // mDot External I2C mDot6 and mDot7 |
falingtrea | 0:bdd16076aaa5 | 93 | |
falingtrea | 0:bdd16076aaa5 | 94 | SPI mDotspi(PA_7,PA_6,PA_5); // mDot external SPI mDot11, mDot4, and mDot18 |
falingtrea | 0:bdd16076aaa5 | 95 | |
falingtrea | 2:75adc72aa6a0 | 96 | /* **** replace these values with the proper public or private network settings **** |
falingtrea | 2:75adc72aa6a0 | 97 | * config_network_nameand config_network_pass are for private networks. |
falingtrea | 2:75adc72aa6a0 | 98 | */ |
falingtrea | 0:bdd16076aaa5 | 99 | static std::string config_network_name = "TAB-CubeNet"; |
falingtrea | 0:bdd16076aaa5 | 100 | static std::string config_network_pass = "1nt3gral"; |
falingtrea | 0:bdd16076aaa5 | 101 | static uint8_t config_frequency_sub_band = 5; |
falingtrea | 0:bdd16076aaa5 | 102 | |
falingtrea | 2:75adc72aa6a0 | 103 | /* config_app_id and config_app_key are for public networks. |
falingtrea | 2:75adc72aa6a0 | 104 | static uint8_t app_id[8] = {0x00,0x01,0x02,0x03,0x0A,0x0B,0x0C,0x0D}; |
falingtrea | 2:75adc72aa6a0 | 105 | std::vector<uint8_t> config_app_id; |
falingtrea | 2:75adc72aa6a0 | 106 | static uint8_t app_key[16] = {0x00,0x01,0x02,0x03,0x0A,0x0B,0x0C,0x0D}; |
falingtrea | 2:75adc72aa6a0 | 107 | std::vector<uint8_t> config_app_key; |
falingtrea | 2:75adc72aa6a0 | 108 | */ |
falingtrea | 2:75adc72aa6a0 | 109 | |
falingtrea | 0:bdd16076aaa5 | 110 | uint8_t result, pckt_time=10; |
falingtrea | 0:bdd16076aaa5 | 111 | char data; |
falingtrea | 0:bdd16076aaa5 | 112 | unsigned char test; |
falingtrea | 0:bdd16076aaa5 | 113 | char txtstr[17]; |
falingtrea | 0:bdd16076aaa5 | 114 | int32_t num_whole, mdot_ret; |
falingtrea | 0:bdd16076aaa5 | 115 | uint32_t pressure; |
falingtrea | 0:bdd16076aaa5 | 116 | int16_t num_frac; |
falingtrea | 0:bdd16076aaa5 | 117 | |
falingtrea | 0:bdd16076aaa5 | 118 | bool exit_program = false; |
falingtrea | 0:bdd16076aaa5 | 119 | |
falingtrea | 0:bdd16076aaa5 | 120 | MMA845x_DATA accel_data; |
falingtrea | 0:bdd16076aaa5 | 121 | MPL3115A2_DATA baro_data; |
falingtrea | 0:bdd16076aaa5 | 122 | uint16_t lux_data; |
falingtrea | 0:bdd16076aaa5 | 123 | MMA845x* evbAccel; |
falingtrea | 0:bdd16076aaa5 | 124 | MPL3115A2* evbBaro; |
falingtrea | 0:bdd16076aaa5 | 125 | ISL29011* evbAmbLight; |
falingtrea | 0:bdd16076aaa5 | 126 | NCP5623B* evbBackLight; |
falingtrea | 0:bdd16076aaa5 | 127 | DOGS102* evbLCD; |
falingtrea | 0:bdd16076aaa5 | 128 | mDot* mdot_radio; |
falingtrea | 0:bdd16076aaa5 | 129 | |
falingtrea | 0:bdd16076aaa5 | 130 | convert32 convertl; |
falingtrea | 0:bdd16076aaa5 | 131 | convert16 converts; |
falingtrea | 0:bdd16076aaa5 | 132 | |
falingtrea | 0:bdd16076aaa5 | 133 | void pb1ISR(void); |
falingtrea | 0:bdd16076aaa5 | 134 | void pb2ISR(void); |
falingtrea | 0:bdd16076aaa5 | 135 | |
falingtrea | 0:bdd16076aaa5 | 136 | void log_error(mDot* dot, const char* msg, int32_t retval); |
falingtrea | 0:bdd16076aaa5 | 137 | |
falingtrea | 0:bdd16076aaa5 | 138 | void config_pkt_xmit (void const *args); |
falingtrea | 0:bdd16076aaa5 | 139 | |
falingtrea | 0:bdd16076aaa5 | 140 | Thread* thread1; |
falingtrea | 0:bdd16076aaa5 | 141 | |
falingtrea | 0:bdd16076aaa5 | 142 | int main() |
falingtrea | 0:bdd16076aaa5 | 143 | { |
falingtrea | 0:bdd16076aaa5 | 144 | |
falingtrea | 0:bdd16076aaa5 | 145 | std::vector<uint8_t> mdot_data; |
falingtrea | 0:bdd16076aaa5 | 146 | std::vector<uint8_t> mdot_EUI; |
falingtrea | 0:bdd16076aaa5 | 147 | uint16_t i = 0; |
falingtrea | 0:bdd16076aaa5 | 148 | |
falingtrea | 0:bdd16076aaa5 | 149 | debugUART.baud(921600); |
falingtrea | 0:bdd16076aaa5 | 150 | // mDotUART.baud(9600); // mdot UART unused but available on external connector |
falingtrea | 0:bdd16076aaa5 | 151 | |
falingtrea | 2:75adc72aa6a0 | 152 | thread1 = new Thread(config_pkt_xmit); // start thread that sends LoRa packet when SW2 pressed |
falingtrea | 2:75adc72aa6a0 | 153 | |
falingtrea | 1:ac9595d0f0e7 | 154 | evbAccel = new MMA845x(mDoti2c,MMA845x::SA0_VSS); // setup Accelerometer |
falingtrea | 0:bdd16076aaa5 | 155 | evbBaro = new MPL3115A2(mDoti2c); // setup Barometric sensor |
falingtrea | 1:ac9595d0f0e7 | 156 | evbAmbLight = new ISL29011(mDoti2c); // Setup Ambient Light Sensor |
falingtrea | 0:bdd16076aaa5 | 157 | evbBackLight = new NCP5623B(mDoti2c); // setup backlight and LED 2 driver chip |
falingtrea | 1:ac9595d0f0e7 | 158 | evbLCD = new DOGS102(mDotspi, mDot17, mDot13); // setup LCD |
falingtrea | 0:bdd16076aaa5 | 159 | |
falingtrea | 2:75adc72aa6a0 | 160 | /* |
falingtrea | 2:75adc72aa6a0 | 161 | * Setup SW1 as program stop function |
falingtrea | 2:75adc72aa6a0 | 162 | */ |
falingtrea | 2:75adc72aa6a0 | 163 | mDot08.disable_irq(); |
falingtrea | 2:75adc72aa6a0 | 164 | mDot08.fall(&pb1ISR); |
falingtrea | 2:75adc72aa6a0 | 165 | |
falingtrea | 2:75adc72aa6a0 | 166 | /* |
falingtrea | 2:75adc72aa6a0 | 167 | * need to call this function after rise or fall because rise/fall sets |
falingtrea | 2:75adc72aa6a0 | 168 | * mode to PullNone |
falingtrea | 2:75adc72aa6a0 | 169 | */ |
falingtrea | 2:75adc72aa6a0 | 170 | mDot08.mode(PullUp); |
falingtrea | 2:75adc72aa6a0 | 171 | |
falingtrea | 2:75adc72aa6a0 | 172 | mDot08.enable_irq(); |
falingtrea | 2:75adc72aa6a0 | 173 | |
falingtrea | 2:75adc72aa6a0 | 174 | /* |
falingtrea | 2:75adc72aa6a0 | 175 | * Setup SW2 as packet time change |
falingtrea | 2:75adc72aa6a0 | 176 | */ |
falingtrea | 2:75adc72aa6a0 | 177 | mDot09.disable_irq(); |
falingtrea | 2:75adc72aa6a0 | 178 | mDot09.fall(&pb2ISR); |
falingtrea | 2:75adc72aa6a0 | 179 | |
falingtrea | 2:75adc72aa6a0 | 180 | /* |
falingtrea | 2:75adc72aa6a0 | 181 | * need to call this function after rise or fall because rise/fall sets |
falingtrea | 2:75adc72aa6a0 | 182 | * mode to PullNone |
falingtrea | 2:75adc72aa6a0 | 183 | */ |
falingtrea | 2:75adc72aa6a0 | 184 | mDot09.mode(PullUp); |
falingtrea | 2:75adc72aa6a0 | 185 | |
falingtrea | 2:75adc72aa6a0 | 186 | mDot09.enable_irq(); |
falingtrea | 2:75adc72aa6a0 | 187 | |
falingtrea | 2:75adc72aa6a0 | 188 | /* |
falingtrea | 2:75adc72aa6a0 | 189 | * Setting other InterruptIn pins with Pull Ups |
falingtrea | 2:75adc72aa6a0 | 190 | */ |
falingtrea | 2:75adc72aa6a0 | 191 | mDot12.mode(PullUp); |
falingtrea | 2:75adc72aa6a0 | 192 | mDot15.mode(PullUp); |
falingtrea | 2:75adc72aa6a0 | 193 | mDot16.mode(PullUp); |
falingtrea | 2:75adc72aa6a0 | 194 | |
falingtrea | 2:75adc72aa6a0 | 195 | printf("font table address %p\n\r",&font_6x8); |
falingtrea | 2:75adc72aa6a0 | 196 | printf("bitmap address %p\n\r",&MultiTech_Logo); |
falingtrea | 2:75adc72aa6a0 | 197 | |
falingtrea | 2:75adc72aa6a0 | 198 | // Setup and display logo on LCD |
falingtrea | 2:75adc72aa6a0 | 199 | evbLCD->startUpdate(); |
falingtrea | 2:75adc72aa6a0 | 200 | |
falingtrea | 2:75adc72aa6a0 | 201 | evbLCD->writeBitmap(0,0,MultiTech_Logo); |
falingtrea | 2:75adc72aa6a0 | 202 | |
falingtrea | 2:75adc72aa6a0 | 203 | sprintf(txtstr,"MTDOT"); |
falingtrea | 2:75adc72aa6a0 | 204 | evbLCD->writeText(24,3,font_6x8,txtstr,strlen(txtstr)); |
falingtrea | 2:75adc72aa6a0 | 205 | sprintf(txtstr,"Evaluation"); |
falingtrea | 2:75adc72aa6a0 | 206 | evbLCD->writeText(24,4,font_6x8,txtstr,strlen(txtstr)); |
falingtrea | 2:75adc72aa6a0 | 207 | sprintf(txtstr,"Board"); |
falingtrea | 2:75adc72aa6a0 | 208 | evbLCD->writeText(24,5,font_6x8,txtstr,strlen(txtstr)); |
falingtrea | 2:75adc72aa6a0 | 209 | |
falingtrea | 2:75adc72aa6a0 | 210 | evbLCD->endUpdate(); |
falingtrea | 2:75adc72aa6a0 | 211 | |
falingtrea | 2:75adc72aa6a0 | 212 | printf("\n\r setup mdot\n\r"); |
falingtrea | 0:bdd16076aaa5 | 213 | |
falingtrea | 0:bdd16076aaa5 | 214 | // get a mDot handle |
falingtrea | 0:bdd16076aaa5 | 215 | mdot_radio = mDot::getInstance(); |
falingtrea | 0:bdd16076aaa5 | 216 | |
falingtrea | 0:bdd16076aaa5 | 217 | if (mdot_radio) { |
falingtrea | 0:bdd16076aaa5 | 218 | // reset to default config so we know what state we're in |
falingtrea | 0:bdd16076aaa5 | 219 | mdot_radio->resetConfig(); |
falingtrea | 0:bdd16076aaa5 | 220 | |
falingtrea | 0:bdd16076aaa5 | 221 | // Setting up LED1 as activity LED |
falingtrea | 0:bdd16076aaa5 | 222 | mdot_radio->setActivityLedPin(PB_0); |
falingtrea | 0:bdd16076aaa5 | 223 | mdot_radio->setActivityLedEnable(true); |
falingtrea | 0:bdd16076aaa5 | 224 | |
falingtrea | 0:bdd16076aaa5 | 225 | // Read node ID |
falingtrea | 0:bdd16076aaa5 | 226 | mdot_EUI = mdot_radio->getDeviceId(); |
falingtrea | 0:bdd16076aaa5 | 227 | printf("mDot EUI = "); |
falingtrea | 0:bdd16076aaa5 | 228 | |
falingtrea | 0:bdd16076aaa5 | 229 | for (i=0; i<mdot_EUI.size(); i++) { |
falingtrea | 0:bdd16076aaa5 | 230 | printf("%02x ", mdot_EUI[i]); |
falingtrea | 0:bdd16076aaa5 | 231 | } |
falingtrea | 0:bdd16076aaa5 | 232 | printf("\n\r"); |
falingtrea | 0:bdd16076aaa5 | 233 | |
falingtrea | 0:bdd16076aaa5 | 234 | |
falingtrea | 2:75adc72aa6a0 | 235 | // Setting up the mDot with network information. |
falingtrea | 2:75adc72aa6a0 | 236 | |
falingtrea | 2:75adc72aa6a0 | 237 | /* |
falingtrea | 2:75adc72aa6a0 | 238 | * This call sets up private or public mode on the MTDOT. Set the function to true if |
falingtrea | 2:75adc72aa6a0 | 239 | * connecting to a public network |
falingtrea | 2:75adc72aa6a0 | 240 | */ |
falingtrea | 2:75adc72aa6a0 | 241 | printf("setting Private Network Mode\r\n"); |
falingtrea | 2:75adc72aa6a0 | 242 | if ((mdot_ret = mdot_radio->setPublicNetwork(false)) != mDot::MDOT_OK) { |
falingtrea | 2:75adc72aa6a0 | 243 | log_error(mdot_radio, "failed to set Public Network Mode", mdot_ret); |
falingtrea | 2:75adc72aa6a0 | 244 | } |
falingtrea | 2:75adc72aa6a0 | 245 | |
falingtrea | 2:75adc72aa6a0 | 246 | /* |
falingtrea | 2:75adc72aa6a0 | 247 | * Frequency sub-band is valid for NAM only and for Private networks should be set to a value |
falingtrea | 2:75adc72aa6a0 | 248 | * between 1-8 that matches the the LoRa gateway setting. Public networks use sub-band 0 only. |
falingtrea | 2:75adc72aa6a0 | 249 | * This function can be commented out for EU networks |
falingtrea | 2:75adc72aa6a0 | 250 | */ |
falingtrea | 0:bdd16076aaa5 | 251 | printf("setting frequency sub band\r\n"); |
falingtrea | 0:bdd16076aaa5 | 252 | if ((mdot_ret = mdot_radio->setFrequencySubBand(config_frequency_sub_band)) != mDot::MDOT_OK) { |
falingtrea | 0:bdd16076aaa5 | 253 | log_error(mdot_radio, "failed to set frequency sub band", mdot_ret); |
falingtrea | 0:bdd16076aaa5 | 254 | } |
falingtrea | 0:bdd16076aaa5 | 255 | |
falingtrea | 2:75adc72aa6a0 | 256 | /* |
falingtrea | 2:75adc72aa6a0 | 257 | * setNetworkName is used for private networks. |
falingtrea | 2:75adc72aa6a0 | 258 | * Use setNetworkID(AppID) for public networks |
falingtrea | 2:75adc72aa6a0 | 259 | */ |
falingtrea | 2:75adc72aa6a0 | 260 | |
falingtrea | 2:75adc72aa6a0 | 261 | // config_app_id.assign(app_id,app_id+7); |
falingtrea | 2:75adc72aa6a0 | 262 | |
falingtrea | 0:bdd16076aaa5 | 263 | printf("setting network name\r\n"); |
falingtrea | 0:bdd16076aaa5 | 264 | if ((mdot_ret = mdot_radio->setNetworkName(config_network_name)) != mDot::MDOT_OK) { |
falingtrea | 2:75adc72aa6a0 | 265 | // if ((mdot_ret = mdot_radio->setNetworkID(config_app_id)) != mDot::MDOT_OK) { |
falingtrea | 0:bdd16076aaa5 | 266 | log_error(mdot_radio, "failed to set network name", mdot_ret); |
falingtrea | 0:bdd16076aaa5 | 267 | } |
falingtrea | 0:bdd16076aaa5 | 268 | |
falingtrea | 2:75adc72aa6a0 | 269 | /* |
falingtrea | 2:75adc72aa6a0 | 270 | * setNetworkPassphrase is used for private networks |
falingtrea | 2:75adc72aa6a0 | 271 | * Use setNetworkKey for public networks |
falingtrea | 2:75adc72aa6a0 | 272 | */ |
falingtrea | 2:75adc72aa6a0 | 273 | |
falingtrea | 2:75adc72aa6a0 | 274 | // config_app_key.assign(app_key,app_key+15); |
falingtrea | 2:75adc72aa6a0 | 275 | |
falingtrea | 0:bdd16076aaa5 | 276 | printf("setting network password\r\n"); |
falingtrea | 0:bdd16076aaa5 | 277 | if ((mdot_ret = mdot_radio->setNetworkPassphrase(config_network_pass)) != mDot::MDOT_OK) { |
falingtrea | 2:75adc72aa6a0 | 278 | // if ((mdot_ret = mdot_radio->setNetworkKey(config_app_key)) != mDot::MDOT_OK) { |
falingtrea | 0:bdd16076aaa5 | 279 | log_error(mdot_radio, "failed to set network password", mdot_ret); |
falingtrea | 0:bdd16076aaa5 | 280 | } |
falingtrea | 0:bdd16076aaa5 | 281 | |
falingtrea | 0:bdd16076aaa5 | 282 | // attempt to join the network |
falingtrea | 0:bdd16076aaa5 | 283 | printf("joining network\r\n"); |
falingtrea | 2:75adc72aa6a0 | 284 | while (((mdot_ret = mdot_radio->joinNetwork()) != mDot::MDOT_OK) && (!exit_program)) { |
falingtrea | 0:bdd16076aaa5 | 285 | log_error(mdot_radio,"failed to join network:", mdot_ret); |
falingtrea | 0:bdd16076aaa5 | 286 | if (mdot_radio->getFrequencyBand() == mDot::FB_868){ |
falingtrea | 0:bdd16076aaa5 | 287 | mdot_ret = mdot_radio->getNextTxMs(); |
falingtrea | 0:bdd16076aaa5 | 288 | } |
falingtrea | 0:bdd16076aaa5 | 289 | else { |
falingtrea | 0:bdd16076aaa5 | 290 | mdot_ret = 0; |
falingtrea | 2:75adc72aa6a0 | 291 | } |
falingtrea | 0:bdd16076aaa5 | 292 | |
falingtrea | 0:bdd16076aaa5 | 293 | printf("delay = %lu\n\r",mdot_ret); |
falingtrea | 0:bdd16076aaa5 | 294 | osDelay(mdot_ret + 1); |
falingtrea | 0:bdd16076aaa5 | 295 | } |
falingtrea | 2:75adc72aa6a0 | 296 | |
falingtrea | 2:75adc72aa6a0 | 297 | /* |
falingtrea | 2:75adc72aa6a0 | 298 | * Check for PB1 press during network join attempt |
falingtrea | 2:75adc72aa6a0 | 299 | */ |
falingtrea | 2:75adc72aa6a0 | 300 | if (exit_program) { |
falingtrea | 2:75adc72aa6a0 | 301 | printf("Exiting program\n\r"); |
falingtrea | 2:75adc72aa6a0 | 302 | evbLCD->clearBuffer(); |
falingtrea | 2:75adc72aa6a0 | 303 | sprintf(txtstr,"Exiting Program"); |
falingtrea | 2:75adc72aa6a0 | 304 | evbLCD->writeText(0,4,font_6x8,txtstr,strlen(txtstr)); |
falingtrea | 2:75adc72aa6a0 | 305 | exit(1); |
falingtrea | 2:75adc72aa6a0 | 306 | } |
falingtrea | 2:75adc72aa6a0 | 307 | |
falingtrea | 0:bdd16076aaa5 | 308 | } else { |
falingtrea | 0:bdd16076aaa5 | 309 | printf("radio setup failed\n\r"); |
falingtrea | 0:bdd16076aaa5 | 310 | //exit(1); |
falingtrea | 0:bdd16076aaa5 | 311 | } |
falingtrea | 0:bdd16076aaa5 | 312 | |
falingtrea | 0:bdd16076aaa5 | 313 | osDelay(200); |
falingtrea | 0:bdd16076aaa5 | 314 | evbBackLight->setPWM(NCP5623B::LED_3,16); // enable LED2 on EVB and set to 50% PWM |
falingtrea | 0:bdd16076aaa5 | 315 | |
falingtrea | 2:75adc72aa6a0 | 316 | // sets LED2 to 50% max current |
falingtrea | 0:bdd16076aaa5 | 317 | evbBackLight->setLEDCurrent(16); |
falingtrea | 0:bdd16076aaa5 | 318 | |
falingtrea | 0:bdd16076aaa5 | 319 | printf("Start of Test\n\r"); |
falingtrea | 0:bdd16076aaa5 | 320 | |
falingtrea | 2:75adc72aa6a0 | 321 | osDelay (500); // allows other threads to process |
falingtrea | 2:75adc72aa6a0 | 322 | printf("shutdown LED:\n\r"); |
falingtrea | 2:75adc72aa6a0 | 323 | evbBackLight->shutdown(); |
falingtrea | 0:bdd16076aaa5 | 324 | |
falingtrea | 0:bdd16076aaa5 | 325 | osDelay (500); // allows other threads to process |
falingtrea | 0:bdd16076aaa5 | 326 | printf("Turn on LED2\n\r"); |
falingtrea | 0:bdd16076aaa5 | 327 | evbBackLight->setLEDCurrent(16); |
falingtrea | 0:bdd16076aaa5 | 328 | |
falingtrea | 0:bdd16076aaa5 | 329 | data = evbAccel->getWhoAmI(); |
falingtrea | 0:bdd16076aaa5 | 330 | printf("Accelerometer who_am_i value = %x \n\r", data); |
falingtrea | 0:bdd16076aaa5 | 331 | |
falingtrea | 0:bdd16076aaa5 | 332 | result = evbAccel->getStatus(); |
falingtrea | 0:bdd16076aaa5 | 333 | printf("status byte = %x \n\r", result); |
falingtrea | 0:bdd16076aaa5 | 334 | |
falingtrea | 0:bdd16076aaa5 | 335 | printf("Barometer who_am_i check = %s \n\r", evbBaro->testWhoAmI() ? "TRUE" : "FALSE"); |
falingtrea | 0:bdd16076aaa5 | 336 | |
falingtrea | 0:bdd16076aaa5 | 337 | result = evbBaro->getStatus(); |
falingtrea | 0:bdd16076aaa5 | 338 | printf("status byte = %x \n\r", result); |
falingtrea | 0:bdd16076aaa5 | 339 | |
falingtrea | 0:bdd16076aaa5 | 340 | /* |
falingtrea | 0:bdd16076aaa5 | 341 | * Setup the Accelerometer for 8g range, 14 bit resolution, Noise reduction off, sample rate 1.56 Hz |
falingtrea | 0:bdd16076aaa5 | 342 | * normal oversample mode, High pass filter off |
falingtrea | 0:bdd16076aaa5 | 343 | */ |
falingtrea | 0:bdd16076aaa5 | 344 | evbAccel->setCommonParameters(MMA845x::RANGE_8g,MMA845x::RES_MAX,MMA845x::LN_OFF, |
falingtrea | 0:bdd16076aaa5 | 345 | MMA845x::DR_1_56,MMA845x::OS_NORMAL,MMA845x::HPF_OFF ); |
falingtrea | 0:bdd16076aaa5 | 346 | |
falingtrea | 0:bdd16076aaa5 | 347 | /* |
falingtrea | 0:bdd16076aaa5 | 348 | * Setup the Barometric sensor for post processed Ambient pressure, 4 samples per data acquisition. |
falingtrea | 0:bdd16076aaa5 | 349 | * and a sample taken every second when in active mode |
falingtrea | 0:bdd16076aaa5 | 350 | */ |
falingtrea | 0:bdd16076aaa5 | 351 | evbBaro->setParameters(MPL3115A2::DATA_NORMAL, MPL3115A2::DM_BAROMETER, MPL3115A2::OR_16, |
falingtrea | 0:bdd16076aaa5 | 352 | MPL3115A2::AT_1); |
falingtrea | 0:bdd16076aaa5 | 353 | /* |
falingtrea | 0:bdd16076aaa5 | 354 | * Setup the Ambient Light Sensor for continuous Ambient Light Sensing, 16 bit resolution, |
falingtrea | 0:bdd16076aaa5 | 355 | * and 16000 lux range |
falingtrea | 0:bdd16076aaa5 | 356 | */ |
falingtrea | 0:bdd16076aaa5 | 357 | |
falingtrea | 0:bdd16076aaa5 | 358 | evbAmbLight->setMode(ISL29011::ALS_CONT); |
falingtrea | 0:bdd16076aaa5 | 359 | evbAmbLight->setResolution(ISL29011::ADC_16BIT); |
falingtrea | 0:bdd16076aaa5 | 360 | evbAmbLight->setRange(ISL29011::RNG_16000); |
falingtrea | 0:bdd16076aaa5 | 361 | |
falingtrea | 0:bdd16076aaa5 | 362 | /* |
falingtrea | 0:bdd16076aaa5 | 363 | * Set the accelerometer for active mode |
falingtrea | 0:bdd16076aaa5 | 364 | */ |
falingtrea | 0:bdd16076aaa5 | 365 | evbAccel->activeMode(); |
falingtrea | 0:bdd16076aaa5 | 366 | |
falingtrea | 0:bdd16076aaa5 | 367 | /* |
falingtrea | 0:bdd16076aaa5 | 368 | * Clear the min-max registers in the Barometric Sensor |
falingtrea | 0:bdd16076aaa5 | 369 | */ |
falingtrea | 0:bdd16076aaa5 | 370 | evbBaro->clearMinMaxRegs(); |
falingtrea | 0:bdd16076aaa5 | 371 | |
falingtrea | 0:bdd16076aaa5 | 372 | evbBackLight->setLEDCurrent(0); |
falingtrea | 0:bdd16076aaa5 | 373 | |
falingtrea | 0:bdd16076aaa5 | 374 | /* |
falingtrea | 2:75adc72aa6a0 | 375 | * Check for PB1 press during network join attempt |
falingtrea | 2:75adc72aa6a0 | 376 | */ |
falingtrea | 2:75adc72aa6a0 | 377 | if (exit_program) { |
falingtrea | 2:75adc72aa6a0 | 378 | printf("Exiting program\n\r"); |
falingtrea | 2:75adc72aa6a0 | 379 | evbLCD->clearBuffer(); |
falingtrea | 2:75adc72aa6a0 | 380 | sprintf(txtstr,"Exiting Program"); |
falingtrea | 2:75adc72aa6a0 | 381 | evbLCD->writeText(0,4,font_6x8,txtstr,strlen(txtstr)); |
falingtrea | 2:75adc72aa6a0 | 382 | exit(1); |
falingtrea | 2:75adc72aa6a0 | 383 | } |
falingtrea | 2:75adc72aa6a0 | 384 | |
falingtrea | 2:75adc72aa6a0 | 385 | /* |
falingtrea | 0:bdd16076aaa5 | 386 | * Main data acquisition loop |
falingtrea | 0:bdd16076aaa5 | 387 | */ |
falingtrea | 0:bdd16076aaa5 | 388 | pckt_time = 10; |
falingtrea | 0:bdd16076aaa5 | 389 | i = 0; |
falingtrea | 0:bdd16076aaa5 | 390 | |
falingtrea | 0:bdd16076aaa5 | 391 | do { |
falingtrea | 0:bdd16076aaa5 | 392 | evbLCD->startUpdate(); |
falingtrea | 0:bdd16076aaa5 | 393 | evbLCD->clearBuffer(); |
falingtrea | 0:bdd16076aaa5 | 394 | |
falingtrea | 0:bdd16076aaa5 | 395 | /* |
falingtrea | 0:bdd16076aaa5 | 396 | * Test Accelerometer XYZ data ready bit to see if acquisition complete |
falingtrea | 0:bdd16076aaa5 | 397 | */ |
falingtrea | 0:bdd16076aaa5 | 398 | do { |
falingtrea | 0:bdd16076aaa5 | 399 | osDelay(100); // allows other threads to process |
falingtrea | 0:bdd16076aaa5 | 400 | result = evbAccel->getStatus(); |
falingtrea | 0:bdd16076aaa5 | 401 | } while ((result & MMA845x::XYZDR) == 0 ); |
falingtrea | 0:bdd16076aaa5 | 402 | |
falingtrea | 0:bdd16076aaa5 | 403 | /* |
falingtrea | 0:bdd16076aaa5 | 404 | * Retrieve and print out accelerometer data |
falingtrea | 0:bdd16076aaa5 | 405 | */ |
falingtrea | 0:bdd16076aaa5 | 406 | accel_data = evbAccel->getXYZ(); |
falingtrea | 0:bdd16076aaa5 | 407 | |
falingtrea | 0:bdd16076aaa5 | 408 | sprintf(txtstr,"Accelerometer"); |
falingtrea | 0:bdd16076aaa5 | 409 | evbLCD->writeText(0,0,font_6x8,txtstr,strlen(txtstr)); |
falingtrea | 0:bdd16076aaa5 | 410 | sprintf(txtstr, "x = %d", accel_data._x); |
falingtrea | 0:bdd16076aaa5 | 411 | evbLCD->writeText(20,1,font_6x8,txtstr,strlen(txtstr)); |
falingtrea | 0:bdd16076aaa5 | 412 | sprintf(txtstr, "y = %d", accel_data._y); |
falingtrea | 0:bdd16076aaa5 | 413 | evbLCD->writeText(20,2,font_6x8,txtstr,strlen(txtstr)); |
falingtrea | 0:bdd16076aaa5 | 414 | sprintf(txtstr, "z = %d", accel_data._z ); |
falingtrea | 0:bdd16076aaa5 | 415 | evbLCD->writeText(20,3,font_6x8,txtstr,strlen(txtstr)); |
falingtrea | 0:bdd16076aaa5 | 416 | |
falingtrea | 0:bdd16076aaa5 | 417 | /* |
falingtrea | 0:bdd16076aaa5 | 418 | * Trigger a Pressure reading |
falingtrea | 0:bdd16076aaa5 | 419 | */ |
falingtrea | 0:bdd16076aaa5 | 420 | evbBaro->setParameters(MPL3115A2::DATA_NORMAL, MPL3115A2::DM_BAROMETER, MPL3115A2::OR_16, |
falingtrea | 0:bdd16076aaa5 | 421 | MPL3115A2::AT_1); |
falingtrea | 0:bdd16076aaa5 | 422 | evbBaro->triggerOneShot(); |
falingtrea | 0:bdd16076aaa5 | 423 | |
falingtrea | 0:bdd16076aaa5 | 424 | /* |
falingtrea | 0:bdd16076aaa5 | 425 | * Test barometer device status to see if acquisition is complete |
falingtrea | 0:bdd16076aaa5 | 426 | */ |
falingtrea | 0:bdd16076aaa5 | 427 | do { |
falingtrea | 0:bdd16076aaa5 | 428 | osDelay(100); // allows other threads to process |
falingtrea | 0:bdd16076aaa5 | 429 | result = evbBaro->getStatus(); |
falingtrea | 0:bdd16076aaa5 | 430 | } while ((result & MPL3115A2::PTDR) == 0 ); |
falingtrea | 0:bdd16076aaa5 | 431 | |
falingtrea | 0:bdd16076aaa5 | 432 | /* |
falingtrea | 0:bdd16076aaa5 | 433 | * Retrieve and print out barometric pressure |
falingtrea | 0:bdd16076aaa5 | 434 | */ |
falingtrea | 0:bdd16076aaa5 | 435 | pressure = evbBaro->getBaroData() >> 12; // convert 32 bit signed to 20 bit unsigned value |
falingtrea | 0:bdd16076aaa5 | 436 | num_whole = pressure >> 2; // 18 bit integer significant |
falingtrea | 0:bdd16076aaa5 | 437 | num_frac = (pressure & 0x3) * 25; // 2 bit fractional 0.25 per bit |
falingtrea | 0:bdd16076aaa5 | 438 | sprintf(txtstr,"Press=%ld.%02d Pa", num_whole, num_frac); |
falingtrea | 0:bdd16076aaa5 | 439 | evbLCD->writeText(0,4,font_6x8,txtstr,strlen(txtstr)); |
falingtrea | 0:bdd16076aaa5 | 440 | |
falingtrea | 0:bdd16076aaa5 | 441 | /* |
falingtrea | 0:bdd16076aaa5 | 442 | * Trigger a Altitude reading |
falingtrea | 0:bdd16076aaa5 | 443 | */ |
falingtrea | 0:bdd16076aaa5 | 444 | evbBaro->setParameters(MPL3115A2::DATA_NORMAL, MPL3115A2::DM_ALTIMETER, MPL3115A2::OR_16, |
falingtrea | 0:bdd16076aaa5 | 445 | MPL3115A2::AT_1); |
falingtrea | 0:bdd16076aaa5 | 446 | evbBaro->triggerOneShot(); |
falingtrea | 0:bdd16076aaa5 | 447 | |
falingtrea | 0:bdd16076aaa5 | 448 | /* |
falingtrea | 0:bdd16076aaa5 | 449 | * Test barometer device status to see if acquisition is complete |
falingtrea | 0:bdd16076aaa5 | 450 | */ |
falingtrea | 0:bdd16076aaa5 | 451 | do { |
falingtrea | 0:bdd16076aaa5 | 452 | osDelay(100); // allows other threads to process |
falingtrea | 0:bdd16076aaa5 | 453 | result = evbBaro->getStatus(); |
falingtrea | 0:bdd16076aaa5 | 454 | } while ((result & MPL3115A2::PTDR) == 0 ); |
falingtrea | 0:bdd16076aaa5 | 455 | |
falingtrea | 0:bdd16076aaa5 | 456 | /* |
falingtrea | 0:bdd16076aaa5 | 457 | * Retrieve and print out altitude and temperature |
falingtrea | 0:bdd16076aaa5 | 458 | */ |
falingtrea | 0:bdd16076aaa5 | 459 | baro_data = evbBaro->getAllData(false); |
falingtrea | 0:bdd16076aaa5 | 460 | baro_data._baro /= 4096; // convert 32 bit signed to 20 bit signed value |
falingtrea | 0:bdd16076aaa5 | 461 | num_whole = baro_data._baro / 16; // 18 bit signed significant integer |
falingtrea | 0:bdd16076aaa5 | 462 | num_frac = (baro_data._baro & 0xF) * 625 / 100; // 4 bit fractional .0625 per bit |
falingtrea | 0:bdd16076aaa5 | 463 | sprintf(txtstr,"Alti=%ld.%03d m", num_whole, num_frac); |
falingtrea | 0:bdd16076aaa5 | 464 | evbLCD->writeText(0,5,font_6x8,txtstr,strlen(txtstr)); |
falingtrea | 0:bdd16076aaa5 | 465 | num_whole = baro_data._temp / 16; // 8 bit signed significant integer |
falingtrea | 0:bdd16076aaa5 | 466 | num_frac = (baro_data._temp & 0x0F) * 625 / 100; // 4 bit fractional .0625 per bit |
falingtrea | 0:bdd16076aaa5 | 467 | sprintf(txtstr,"Temp=%ld.%03d C", num_whole, num_frac); |
falingtrea | 0:bdd16076aaa5 | 468 | evbLCD->writeText(0,6,font_6x8,txtstr,strlen(txtstr)); |
falingtrea | 0:bdd16076aaa5 | 469 | |
falingtrea | 0:bdd16076aaa5 | 470 | /* |
falingtrea | 0:bdd16076aaa5 | 471 | * retrieve and print out Ambient Light level |
falingtrea | 0:bdd16076aaa5 | 472 | */ |
falingtrea | 0:bdd16076aaa5 | 473 | lux_data = evbAmbLight->getData(); |
falingtrea | 0:bdd16076aaa5 | 474 | num_whole = lux_data * 24 / 100; // 16000 lux full scale .24 lux per bit |
falingtrea | 0:bdd16076aaa5 | 475 | num_frac = lux_data * 24 % 100; |
falingtrea | 0:bdd16076aaa5 | 476 | sprintf(txtstr, "Light=%ld.%02d lux", num_whole, num_frac ); |
falingtrea | 0:bdd16076aaa5 | 477 | evbLCD->writeText(0,7,font_6x8,txtstr,strlen(txtstr)); |
falingtrea | 0:bdd16076aaa5 | 478 | |
falingtrea | 0:bdd16076aaa5 | 479 | evbLCD->endUpdate(); |
falingtrea | 0:bdd16076aaa5 | 480 | printf("finished iteration %d\n\r",(++i)); |
falingtrea | 0:bdd16076aaa5 | 481 | |
falingtrea | 0:bdd16076aaa5 | 482 | if (i % pckt_time == 0) { // check packet counter will send packet every 2-5-10 data collection loops |
falingtrea | 0:bdd16076aaa5 | 483 | mdot_data.clear(); |
falingtrea | 0:bdd16076aaa5 | 484 | mdot_data.push_back(0x0E); // key for Current Acceleration 3-Axis Value |
falingtrea | 0:bdd16076aaa5 | 485 | converts.f_s = accel_data._x *4; // shift data 2 bits while retaining sign |
falingtrea | 0:bdd16076aaa5 | 486 | mdot_data.push_back(converts.t_u[1]); // get 8 MSB of 14 bit value |
falingtrea | 0:bdd16076aaa5 | 487 | converts.f_s = accel_data._y * 4; // shift data 2 bits while retaining sign |
falingtrea | 0:bdd16076aaa5 | 488 | mdot_data.push_back(converts.t_u[1]); // get 8 MSB of 14 bit value |
falingtrea | 0:bdd16076aaa5 | 489 | converts.f_s = accel_data._z * 4; // shift data 2 bits while retaining sign |
falingtrea | 0:bdd16076aaa5 | 490 | mdot_data.push_back(converts.t_u[1]); // get 8 MSB of 14 bit value |
falingtrea | 0:bdd16076aaa5 | 491 | mdot_data.push_back(0x08); // key for Current Pressure Value |
falingtrea | 0:bdd16076aaa5 | 492 | convertl.f_u = pressure; // pressure data is 20 bits unsigned |
falingtrea | 0:bdd16076aaa5 | 493 | mdot_data.push_back(convertl.t_u[2]); |
falingtrea | 0:bdd16076aaa5 | 494 | mdot_data.push_back(convertl.t_u[1]); |
falingtrea | 0:bdd16076aaa5 | 495 | mdot_data.push_back(convertl.t_u[0]); |
falingtrea | 0:bdd16076aaa5 | 496 | mdot_data.push_back(0x05); // key for Current Ambient Light Value |
falingtrea | 0:bdd16076aaa5 | 497 | converts.f_u = lux_data; // data is 16 bits unsigned |
falingtrea | 0:bdd16076aaa5 | 498 | mdot_data.push_back(converts.t_u[1]); |
falingtrea | 0:bdd16076aaa5 | 499 | mdot_data.push_back(converts.t_u[0]); |
falingtrea | 0:bdd16076aaa5 | 500 | mdot_data.push_back(0x0B); // key for Current Temperature Value |
falingtrea | 0:bdd16076aaa5 | 501 | converts.f_s = baro_data._temp; // temperature is signed 12 bit |
falingtrea | 0:bdd16076aaa5 | 502 | mdot_data.push_back(converts.t_u[1]); |
falingtrea | 0:bdd16076aaa5 | 503 | mdot_data.push_back(converts.t_u[0]); |
falingtrea | 0:bdd16076aaa5 | 504 | |
falingtrea | 0:bdd16076aaa5 | 505 | if ((mdot_ret = mdot_radio->send(mdot_data)) != mDot::MDOT_OK) { |
falingtrea | 0:bdd16076aaa5 | 506 | log_error(mdot_radio, "failed to send", mdot_ret); |
falingtrea | 0:bdd16076aaa5 | 507 | } else { |
falingtrea | 0:bdd16076aaa5 | 508 | printf("successfully sent data to gateway\r\n"); |
falingtrea | 0:bdd16076aaa5 | 509 | } |
falingtrea | 0:bdd16076aaa5 | 510 | } |
falingtrea | 2:75adc72aa6a0 | 511 | } while(!exit_program && (i < 65000)); |
falingtrea | 0:bdd16076aaa5 | 512 | |
falingtrea | 0:bdd16076aaa5 | 513 | evbBaro->triggerOneShot(); |
falingtrea | 0:bdd16076aaa5 | 514 | |
falingtrea | 0:bdd16076aaa5 | 515 | do { |
falingtrea | 0:bdd16076aaa5 | 516 | osDelay(200); // allows other threads to process |
falingtrea | 0:bdd16076aaa5 | 517 | result = evbBaro->getStatus(); |
falingtrea | 0:bdd16076aaa5 | 518 | } while ((result & MPL3115A2::PTDR) == 0 ); |
falingtrea | 0:bdd16076aaa5 | 519 | |
falingtrea | 0:bdd16076aaa5 | 520 | baro_data = evbBaro->getAllData(true); |
falingtrea | 0:bdd16076aaa5 | 521 | printf ("minBaro=%ld maxBaro=%ld minTemp=%d maxTemp=%d\n\r", baro_data._minbaro, baro_data._maxbaro, |
falingtrea | 0:bdd16076aaa5 | 522 | baro_data._mintemp, baro_data._maxtemp); |
falingtrea | 0:bdd16076aaa5 | 523 | |
falingtrea | 0:bdd16076aaa5 | 524 | printf("End of Test\n\r"); |
falingtrea | 0:bdd16076aaa5 | 525 | |
falingtrea | 2:75adc72aa6a0 | 526 | evbLCD->clearBuffer(); |
falingtrea | 2:75adc72aa6a0 | 527 | sprintf(txtstr,"Exiting Program"); |
falingtrea | 2:75adc72aa6a0 | 528 | evbLCD->writeText(0,4,font_6x8,txtstr,strlen(txtstr)); |
falingtrea | 2:75adc72aa6a0 | 529 | |
falingtrea | 0:bdd16076aaa5 | 530 | } |
falingtrea | 0:bdd16076aaa5 | 531 | |
falingtrea | 0:bdd16076aaa5 | 532 | /* |
falingtrea | 0:bdd16076aaa5 | 533 | * Ends program when button 1 pushed |
falingtrea | 0:bdd16076aaa5 | 534 | */ |
falingtrea | 0:bdd16076aaa5 | 535 | void pb1ISR(void) |
falingtrea | 0:bdd16076aaa5 | 536 | { |
falingtrea | 0:bdd16076aaa5 | 537 | |
falingtrea | 0:bdd16076aaa5 | 538 | exit_program = true; |
falingtrea | 0:bdd16076aaa5 | 539 | } |
falingtrea | 0:bdd16076aaa5 | 540 | |
falingtrea | 0:bdd16076aaa5 | 541 | /* |
falingtrea | 2:75adc72aa6a0 | 542 | * changes packet transmit time to every other, every fifth, or every tenth sample when SW2 pushed |
falingtrea | 0:bdd16076aaa5 | 543 | * Also triggers a thread to transmit a configuration packet |
falingtrea | 0:bdd16076aaa5 | 544 | */ |
falingtrea | 0:bdd16076aaa5 | 545 | void pb2ISR(void) |
falingtrea | 0:bdd16076aaa5 | 546 | { |
falingtrea | 0:bdd16076aaa5 | 547 | |
falingtrea | 0:bdd16076aaa5 | 548 | if (pckt_time >= 5) |
falingtrea | 0:bdd16076aaa5 | 549 | pckt_time /= 2; |
falingtrea | 0:bdd16076aaa5 | 550 | else pckt_time = 20; |
falingtrea | 0:bdd16076aaa5 | 551 | |
falingtrea | 0:bdd16076aaa5 | 552 | thread1->signal_set(0x10); // signal config_pkt_xmit to send packet |
falingtrea | 0:bdd16076aaa5 | 553 | |
falingtrea | 0:bdd16076aaa5 | 554 | } |
falingtrea | 0:bdd16076aaa5 | 555 | |
falingtrea | 2:75adc72aa6a0 | 556 | /* |
falingtrea | 2:75adc72aa6a0 | 557 | * Function that print clear text verion of mDot errors |
falingtrea | 2:75adc72aa6a0 | 558 | */ |
falingtrea | 0:bdd16076aaa5 | 559 | void log_error(mDot* dot, const char* msg, int32_t retval) |
falingtrea | 0:bdd16076aaa5 | 560 | { |
falingtrea | 0:bdd16076aaa5 | 561 | printf("%s - %ld:%s, %s\r\n", msg, retval, mDot::getReturnCodeString(retval).c_str(), dot->getLastError().c_str()); |
falingtrea | 0:bdd16076aaa5 | 562 | } |
falingtrea | 0:bdd16076aaa5 | 563 | |
falingtrea | 2:75adc72aa6a0 | 564 | /* |
falingtrea | 2:75adc72aa6a0 | 565 | * Thread that is triggered by SW2 ISR. Sends a packet to the LoRa server with the new Packet Transmission time setting |
falingtrea | 2:75adc72aa6a0 | 566 | */ |
falingtrea | 0:bdd16076aaa5 | 567 | void config_pkt_xmit (void const *args) |
falingtrea | 0:bdd16076aaa5 | 568 | { |
falingtrea | 0:bdd16076aaa5 | 569 | |
falingtrea | 0:bdd16076aaa5 | 570 | std::vector<uint8_t> data; |
falingtrea | 0:bdd16076aaa5 | 571 | |
falingtrea | 0:bdd16076aaa5 | 572 | while (true) { |
falingtrea | 0:bdd16076aaa5 | 573 | Thread::signal_wait(0x10); // wait for pb2ISR to signal send |
falingtrea | 0:bdd16076aaa5 | 574 | data.clear(); |
falingtrea | 0:bdd16076aaa5 | 575 | data.push_back(0x0F); // key for Configuration data (packet transmission timer) |
falingtrea | 0:bdd16076aaa5 | 576 | data.push_back(pckt_time); |
falingtrea | 0:bdd16076aaa5 | 577 | |
falingtrea | 0:bdd16076aaa5 | 578 | if ((mdot_ret = mdot_radio->send(data)) != mDot::MDOT_OK) { |
falingtrea | 0:bdd16076aaa5 | 579 | log_error(mdot_radio, "failed to send config data", mdot_ret); |
falingtrea | 0:bdd16076aaa5 | 580 | } else { |
falingtrea | 0:bdd16076aaa5 | 581 | printf("sent config data to gateway\r\n"); |
falingtrea | 0:bdd16076aaa5 | 582 | } |
falingtrea | 0:bdd16076aaa5 | 583 | } |
falingtrea | 0:bdd16076aaa5 | 584 | } |