p2p-pingpong-clickbutton
Dependencies: PingPong-P2P-ClickButtonToWork-SX1272 Lora_SX1272_Coragem
main.cpp@4:05d5aa4d3f2d, 2019-11-13 (annotated)
- Committer:
- marcoantonioara
- Date:
- Wed Nov 13 16:42:06 2019 +0000
- Revision:
- 4:05d5aa4d3f2d
- Parent:
- 3:cbe3f441353e
Test version firmware Coragem using all sensors
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
marcoantonioara | 4:05d5aa4d3f2d | 1 | #include "mbed.h" |
marcoantonioara | 4:05d5aa4d3f2d | 2 | |
marcoantonioara | 4:05d5aa4d3f2d | 3 | /////////////////////////////////////// |
marcoantonioara | 4:05d5aa4d3f2d | 4 | // Defines |
marcoantonioara | 4:05d5aa4d3f2d | 5 | /////////////////////////////////////// |
marcoantonioara | 4:05d5aa4d3f2d | 6 | //#define BMX160 |
marcoantonioara | 4:05d5aa4d3f2d | 7 | //#define BME280 |
marcoantonioara | 4:05d5aa4d3f2d | 8 | //#define SI1133 |
marcoantonioara | 4:05d5aa4d3f2d | 9 | #define LORA_SX1272 |
marcoantonioara | 4:05d5aa4d3f2d | 10 | //#define MEM_MX25R |
marcoantonioara | 4:05d5aa4d3f2d | 11 | #define GPS_ZOE |
marcoantonioara | 4:05d5aa4d3f2d | 12 | |
marcoantonioara | 4:05d5aa4d3f2d | 13 | |
marcoantonioara | 4:05d5aa4d3f2d | 14 | /////////////////////////////////////// |
marcoantonioara | 4:05d5aa4d3f2d | 15 | // Globals variables |
marcoantonioara | 4:05d5aa4d3f2d | 16 | /////////////////////////////////////// |
marcoantonioara | 4:05d5aa4d3f2d | 17 | |
marcoantonioara | 4:05d5aa4d3f2d | 18 | DigitalOut led1(P1_13); |
marcoantonioara | 4:05d5aa4d3f2d | 19 | DigitalOut led2(P1_14); |
marcoantonioara | 4:05d5aa4d3f2d | 20 | DigitalIn button1(P1_11); |
marcoantonioara | 4:05d5aa4d3f2d | 21 | DigitalIn button2(P1_12); |
marcoantonioara | 4:05d5aa4d3f2d | 22 | DigitalIn button3(P0_30); |
marcoantonioara | 4:05d5aa4d3f2d | 23 | EventQueue queue; |
marcoantonioara | 4:05d5aa4d3f2d | 24 | |
marcoantonioara | 4:05d5aa4d3f2d | 25 | |
marcoantonioara | 4:05d5aa4d3f2d | 26 | |
marcoantonioara | 4:05d5aa4d3f2d | 27 | //============= internet of turtles ============= |
marcoantonioara | 4:05d5aa4d3f2d | 28 | Timer time_breathing; |
marcoantonioara | 4:05d5aa4d3f2d | 29 | Timer time_diving; |
marcoantonioara | 4:05d5aa4d3f2d | 30 | bool beathing = false; |
marcoantonioara | 4:05d5aa4d3f2d | 31 | float last_breathing_time = 0.0; |
marcoantonioara | 4:05d5aa4d3f2d | 32 | float last_diving_time = 0.0; |
marcoantonioara | 4:05d5aa4d3f2d | 33 | |
marcoantonioara | 4:05d5aa4d3f2d | 34 | char float_breathing_time[10]; |
marcoantonioara | 4:05d5aa4d3f2d | 35 | char float_diving_time[10]; |
marcoantonioara | 4:05d5aa4d3f2d | 36 | |
marcoantonioara | 4:05d5aa4d3f2d | 37 | //Timer seconds; |
marcoantonioara | 4:05d5aa4d3f2d | 38 | #ifdef BMX160 |
marcoantonioara | 4:05d5aa4d3f2d | 39 | #include "bmx160.txt" |
marcoantonioara | 4:05d5aa4d3f2d | 40 | #endif |
marcoantonioara | 4:05d5aa4d3f2d | 41 | |
marcoantonioara | 4:05d5aa4d3f2d | 42 | #ifdef BME280 |
marcoantonioara | 4:05d5aa4d3f2d | 43 | #include "bme280.txt" |
marcoantonioara | 4:05d5aa4d3f2d | 44 | #endif |
marcoantonioara | 4:05d5aa4d3f2d | 45 | |
marcoantonioara | 4:05d5aa4d3f2d | 46 | #ifdef LORA_SX1272 |
marcoantonioara | 4:05d5aa4d3f2d | 47 | #include "lora.txt" |
marcoantonioara | 4:05d5aa4d3f2d | 48 | #endif |
marcoantonioara | 4:05d5aa4d3f2d | 49 | |
marcoantonioara | 4:05d5aa4d3f2d | 50 | #ifdef GPS_ZOE |
marcoantonioara | 4:05d5aa4d3f2d | 51 | #include "gps.txt" |
marcoantonioara | 4:05d5aa4d3f2d | 52 | #endif |
marcoantonioara | 4:05d5aa4d3f2d | 53 | |
marcoantonioara | 4:05d5aa4d3f2d | 54 | #ifdef MEM_MX25R |
marcoantonioara | 4:05d5aa4d3f2d | 55 | #include "memory.txt" |
marcoantonioara | 4:05d5aa4d3f2d | 56 | SPI_MX25R mem(P0_17, P0_20, P0_22, P0_24); |
marcoantonioara | 4:05d5aa4d3f2d | 57 | #endif |
marcoantonioara | 4:05d5aa4d3f2d | 58 | |
marcoantonioara | 4:05d5aa4d3f2d | 59 | #ifdef SI1133 |
marcoantonioara | 4:05d5aa4d3f2d | 60 | #include "Si1133.h" |
marcoantonioara | 4:05d5aa4d3f2d | 61 | Si1133 si1133(P0_13, P0_15); |
marcoantonioara | 4:05d5aa4d3f2d | 62 | #endif |
marcoantonioara | 4:05d5aa4d3f2d | 63 | |
marcoantonioara | 4:05d5aa4d3f2d | 64 | |
marcoantonioara | 4:05d5aa4d3f2d | 65 | void coragem_sleep (){ |
marcoantonioara | 4:05d5aa4d3f2d | 66 | |
marcoantonioara | 4:05d5aa4d3f2d | 67 | #ifdef BMX160 |
marcoantonioara | 4:05d5aa4d3f2d | 68 | bmx_sleep (); |
marcoantonioara | 4:05d5aa4d3f2d | 69 | #endif |
marcoantonioara | 4:05d5aa4d3f2d | 70 | |
marcoantonioara | 4:05d5aa4d3f2d | 71 | #ifdef BME280 |
marcoantonioara | 4:05d5aa4d3f2d | 72 | bme_sleep (); |
marcoantonioara | 4:05d5aa4d3f2d | 73 | #endif |
marcoantonioara | 4:05d5aa4d3f2d | 74 | |
marcoantonioara | 4:05d5aa4d3f2d | 75 | #ifdef LORA_SX1272 |
marcoantonioara | 4:05d5aa4d3f2d | 76 | lora_sleep(); |
marcoantonioara | 4:05d5aa4d3f2d | 77 | #endif |
marcoantonioara | 4:05d5aa4d3f2d | 78 | |
marcoantonioara | 4:05d5aa4d3f2d | 79 | #ifdef SI1133 |
marcoantonioara | 4:05d5aa4d3f2d | 80 | si1133.wait_until_sleep();//ligth sensor sleep |
marcoantonioara | 4:05d5aa4d3f2d | 81 | #endif |
marcoantonioara | 4:05d5aa4d3f2d | 82 | |
marcoantonioara | 4:05d5aa4d3f2d | 83 | #ifdef MEM_MX25R |
marcoantonioara | 4:05d5aa4d3f2d | 84 | mem.deepPowerdown();//memory sleep |
marcoantonioara | 4:05d5aa4d3f2d | 85 | #endif |
marcoantonioara | 4:05d5aa4d3f2d | 86 | |
marcoantonioara | 4:05d5aa4d3f2d | 87 | |
marcoantonioara | 4:05d5aa4d3f2d | 88 | } |
marcoantonioara | 4:05d5aa4d3f2d | 89 | |
marcoantonioara | 4:05d5aa4d3f2d | 90 | void coragem_wake(){ |
marcoantonioara | 4:05d5aa4d3f2d | 91 | |
marcoantonioara | 4:05d5aa4d3f2d | 92 | #ifdef BMX160 |
marcoantonioara | 4:05d5aa4d3f2d | 93 | bmx_wake(); |
marcoantonioara | 4:05d5aa4d3f2d | 94 | #endif |
marcoantonioara | 4:05d5aa4d3f2d | 95 | |
marcoantonioara | 4:05d5aa4d3f2d | 96 | #ifdef BME280 |
marcoantonioara | 4:05d5aa4d3f2d | 97 | bme_wake(); |
marcoantonioara | 4:05d5aa4d3f2d | 98 | #endif |
marcoantonioara | 4:05d5aa4d3f2d | 99 | |
marcoantonioara | 4:05d5aa4d3f2d | 100 | |
marcoantonioara | 4:05d5aa4d3f2d | 101 | #ifdef LORA_SX1272 |
marcoantonioara | 4:05d5aa4d3f2d | 102 | lora_wake(); |
marcoantonioara | 4:05d5aa4d3f2d | 103 | #endif |
marcoantonioara | 4:05d5aa4d3f2d | 104 | |
marcoantonioara | 4:05d5aa4d3f2d | 105 | |
marcoantonioara | 4:05d5aa4d3f2d | 106 | |
marcoantonioara | 4:05d5aa4d3f2d | 107 | #ifdef SI1133 |
marcoantonioara | 4:05d5aa4d3f2d | 108 | si1133.wake();//ligth sensor wake up |
marcoantonioara | 4:05d5aa4d3f2d | 109 | #endif |
marcoantonioara | 4:05d5aa4d3f2d | 110 | |
marcoantonioara | 4:05d5aa4d3f2d | 111 | //memory wake |
marcoantonioara | 4:05d5aa4d3f2d | 112 | #ifdef MEM_MX25R |
marcoantonioara | 4:05d5aa4d3f2d | 113 | mem.m_cs = CS_LOW ; |
marcoantonioara | 4:05d5aa4d3f2d | 114 | wait_ms(0.1); |
marcoantonioara | 4:05d5aa4d3f2d | 115 | mem.m_cs = CS_HIGH ; |
marcoantonioara | 4:05d5aa4d3f2d | 116 | #endif |
marcoantonioara | 4:05d5aa4d3f2d | 117 | |
marcoantonioara | 4:05d5aa4d3f2d | 118 | } |
marcoantonioara | 4:05d5aa4d3f2d | 119 | |
marcoantonioara | 4:05d5aa4d3f2d | 120 | int main(void) { |
marcoantonioara | 4:05d5aa4d3f2d | 121 | |
marcoantonioara | 4:05d5aa4d3f2d | 122 | /////////////////////////////////////// |
marcoantonioara | 4:05d5aa4d3f2d | 123 | // Configuraion |
marcoantonioara | 4:05d5aa4d3f2d | 124 | /////////////////////////////////////// |
marcoantonioara | 4:05d5aa4d3f2d | 125 | printf("------Coragem all sensor-------------\n---------Configuration initied----------"); |
marcoantonioara | 4:05d5aa4d3f2d | 126 | //led1=1;//on leds |
marcoantonioara | 4:05d5aa4d3f2d | 127 | led2=1; |
marcoantonioara | 4:05d5aa4d3f2d | 128 | |
marcoantonioara | 4:05d5aa4d3f2d | 129 | #ifdef BMX160//bmx160 configuration |
marcoantonioara | 4:05d5aa4d3f2d | 130 | bmx_config(); |
marcoantonioara | 4:05d5aa4d3f2d | 131 | #endif |
marcoantonioara | 4:05d5aa4d3f2d | 132 | |
marcoantonioara | 4:05d5aa4d3f2d | 133 | #ifdef BME280 //sensor bme280 |
marcoantonioara | 4:05d5aa4d3f2d | 134 | BME_ADDR = 0; |
marcoantonioara | 4:05d5aa4d3f2d | 135 | bme_init(); |
marcoantonioara | 4:05d5aa4d3f2d | 136 | #endif |
marcoantonioara | 4:05d5aa4d3f2d | 137 | |
marcoantonioara | 4:05d5aa4d3f2d | 138 | |
marcoantonioara | 4:05d5aa4d3f2d | 139 | #ifdef LORA_SX1272 |
marcoantonioara | 4:05d5aa4d3f2d | 140 | //configura sx1272 |
marcoantonioara | 4:05d5aa4d3f2d | 141 | Thread eventThread; |
marcoantonioara | 4:05d5aa4d3f2d | 142 | eventThread.start(callback(&queue, &EventQueue::dispatch_forever)); |
marcoantonioara | 4:05d5aa4d3f2d | 143 | dio0.rise(queue.event(&lora_print_packet)); //configure interrupt rotine ro recieve packet |
marcoantonioara | 4:05d5aa4d3f2d | 144 | lora_setup(); |
marcoantonioara | 4:05d5aa4d3f2d | 145 | sx1272.writeRegister(REG_OP_MODE,133); //leitura continua |
marcoantonioara | 4:05d5aa4d3f2d | 146 | #endif |
marcoantonioara | 4:05d5aa4d3f2d | 147 | |
marcoantonioara | 4:05d5aa4d3f2d | 148 | |
marcoantonioara | 4:05d5aa4d3f2d | 149 | //gps configuration |
marcoantonioara | 4:05d5aa4d3f2d | 150 | #ifdef GPS_ZOE |
marcoantonioara | 4:05d5aa4d3f2d | 151 | gps_config(); |
marcoantonioara | 4:05d5aa4d3f2d | 152 | #endif |
marcoantonioara | 4:05d5aa4d3f2d | 153 | |
marcoantonioara | 4:05d5aa4d3f2d | 154 | |
marcoantonioara | 4:05d5aa4d3f2d | 155 | |
marcoantonioara | 4:05d5aa4d3f2d | 156 | |
marcoantonioara | 4:05d5aa4d3f2d | 157 | //wait_ms(2100); |
marcoantonioara | 4:05d5aa4d3f2d | 158 | |
marcoantonioara | 4:05d5aa4d3f2d | 159 | //led1=0;//off leds |
marcoantonioara | 4:05d5aa4d3f2d | 160 | led2=0; |
marcoantonioara | 4:05d5aa4d3f2d | 161 | printf("------Configuration finished------------\n"); |
marcoantonioara | 4:05d5aa4d3f2d | 162 | |
marcoantonioara | 4:05d5aa4d3f2d | 163 | |
marcoantonioara | 4:05d5aa4d3f2d | 164 | /////////////////////////////////////// |
marcoantonioara | 4:05d5aa4d3f2d | 165 | // Main Loop |
marcoantonioara | 4:05d5aa4d3f2d | 166 | /////////////////////////////////////// |
marcoantonioara | 4:05d5aa4d3f2d | 167 | uint8_t packet[]={0,1,2,3}; |
marcoantonioara | 4:05d5aa4d3f2d | 168 | while (1) { |
marcoantonioara | 4:05d5aa4d3f2d | 169 | |
marcoantonioara | 4:05d5aa4d3f2d | 170 | //TEST all sensors |
marcoantonioara | 4:05d5aa4d3f2d | 171 | #ifdef BMX160 |
marcoantonioara | 4:05d5aa4d3f2d | 172 | bmx_read(); |
marcoantonioara | 4:05d5aa4d3f2d | 173 | #endif |
marcoantonioara | 4:05d5aa4d3f2d | 174 | |
marcoantonioara | 4:05d5aa4d3f2d | 175 | #ifdef BME280 |
marcoantonioara | 4:05d5aa4d3f2d | 176 | printf("Temp %2.2f degC, Press %04.2f hPa, Hum %2.2f %%\n", getTemperature(), getPressure(), getHumidity()); |
marcoantonioara | 4:05d5aa4d3f2d | 177 | #endif |
marcoantonioara | 4:05d5aa4d3f2d | 178 | |
marcoantonioara | 4:05d5aa4d3f2d | 179 | #ifdef LORA_SX1272 |
marcoantonioara | 4:05d5aa4d3f2d | 180 | lora_send_packet (packet,sizeof(packet)); |
marcoantonioara | 4:05d5aa4d3f2d | 181 | #endif |
marcoantonioara | 4:05d5aa4d3f2d | 182 | |
marcoantonioara | 4:05d5aa4d3f2d | 183 | #ifdef SI1133 |
marcoantonioara | 4:05d5aa4d3f2d | 184 | if (si1133.open()) printf("Lux = %.3f UV index = %.3f\n", (float)si1133.get_light_level(), (float)si1133.get_uv_index()); |
marcoantonioara | 4:05d5aa4d3f2d | 185 | #endif |
marcoantonioara | 4:05d5aa4d3f2d | 186 | |
marcoantonioara | 4:05d5aa4d3f2d | 187 | #ifdef MEM_MX25R |
marcoantonioara | 4:05d5aa4d3f2d | 188 | memory_test(); |
marcoantonioara | 4:05d5aa4d3f2d | 189 | #endif |
marcoantonioara | 4:05d5aa4d3f2d | 190 | |
marcoantonioara | 4:05d5aa4d3f2d | 191 | #ifdef GPS_ZOE |
marcoantonioara | 4:05d5aa4d3f2d | 192 | //gps_print_local(); |
marcoantonioara | 4:05d5aa4d3f2d | 193 | send_nav_pvt(); |
marcoantonioara | 4:05d5aa4d3f2d | 194 | #endif |
marcoantonioara | 4:05d5aa4d3f2d | 195 | |
marcoantonioara | 4:05d5aa4d3f2d | 196 | |
marcoantonioara | 4:05d5aa4d3f2d | 197 | wait(1); |
marcoantonioara | 4:05d5aa4d3f2d | 198 | |
marcoantonioara | 4:05d5aa4d3f2d | 199 | |
marcoantonioara | 4:05d5aa4d3f2d | 200 | } |
marcoantonioara | 4:05d5aa4d3f2d | 201 | |
marcoantonioara | 4:05d5aa4d3f2d | 202 | } |
marcoantonioara | 4:05d5aa4d3f2d | 203 | |
marcoantonioara | 4:05d5aa4d3f2d | 204 |