Program test for Coragem
Dependencies: SX1272 SPI_MX25R
main.cpp
00001 #include "mbed.h" 00002 00003 /////////////////////////////////////// 00004 // Defines 00005 /////////////////////////////////////// 00006 //#define BMX160 00007 //#define BME280 00008 //#define SI1133 00009 #define LORA_SX1272 00010 //#define MEM_MX25R 00011 #define GPS_ZOE 00012 00013 00014 /////////////////////////////////////// 00015 // Globals variables 00016 /////////////////////////////////////// 00017 00018 DigitalOut led1(P1_13); 00019 DigitalOut led2(P1_14); 00020 DigitalIn button1(P1_11); 00021 DigitalIn button2(P1_12); 00022 DigitalIn button3(P0_30); 00023 EventQueue queue; 00024 00025 00026 00027 //============= internet of turtles ============= 00028 Timer time_breathing; 00029 Timer time_diving; 00030 bool beathing = false; 00031 float last_breathing_time = 0.0; 00032 float last_diving_time = 0.0; 00033 00034 char float_breathing_time[10]; 00035 char float_diving_time[10]; 00036 00037 //Timer seconds; 00038 #ifdef BMX160 00039 #include "bmx160.txt" 00040 #endif 00041 00042 #ifdef BME280 00043 #include "bme280.txt" 00044 #endif 00045 00046 #ifdef LORA_SX1272 00047 #include "lora.txt" 00048 #endif 00049 00050 #ifdef GPS_ZOE 00051 #include "gps.txt" 00052 #endif 00053 00054 #ifdef MEM_MX25R 00055 #include "memory.txt" 00056 SPI_MX25R mem(P0_17, P0_20, P0_22, P0_24); 00057 #endif 00058 00059 #ifdef SI1133 00060 #include "Si1133.h " 00061 Si1133 si1133(P0_13, P0_15); 00062 #endif 00063 00064 00065 void coragem_sleep (){ 00066 00067 #ifdef BMX160 00068 bmx_sleep (); 00069 #endif 00070 00071 #ifdef BME280 00072 bme_sleep (); 00073 #endif 00074 00075 #ifdef LORA_SX1272 00076 lora_sleep(); 00077 #endif 00078 00079 #ifdef SI1133 00080 si1133.wait_until_sleep();//ligth sensor sleep 00081 #endif 00082 00083 #ifdef MEM_MX25R 00084 mem.deepPowerdown();//memory sleep 00085 #endif 00086 00087 00088 } 00089 00090 void coragem_wake(){ 00091 00092 #ifdef BMX160 00093 bmx_wake(); 00094 #endif 00095 00096 #ifdef BME280 00097 bme_wake(); 00098 #endif 00099 00100 00101 #ifdef LORA_SX1272 00102 lora_wake(); 00103 #endif 00104 00105 00106 00107 #ifdef SI1133 00108 si1133.wake();//ligth sensor wake up 00109 #endif 00110 00111 //memory wake 00112 #ifdef MEM_MX25R 00113 mem.m_cs = CS_LOW ; 00114 wait_ms(0.1); 00115 mem.m_cs = CS_HIGH ; 00116 #endif 00117 00118 } 00119 00120 int main(void) { 00121 00122 /////////////////////////////////////// 00123 // Configuraion 00124 /////////////////////////////////////// 00125 printf("------Coragem all sensor-------------\n---------Configuration initied----------"); 00126 //led1=1;//on leds 00127 led2=1; 00128 00129 #ifdef BMX160//bmx160 configuration 00130 bmx_config(); 00131 #endif 00132 00133 #ifdef BME280 //sensor bme280 00134 BME_ADDR = 0; 00135 bme_init(); 00136 #endif 00137 00138 00139 #ifdef LORA_SX1272 00140 //configura sx1272 00141 Thread eventThread; 00142 eventThread.start(callback(&queue, &EventQueue::dispatch_forever)); 00143 dio0.rise(queue.event(&lora_print_packet)); //configure interrupt rotine ro recieve packet 00144 lora_setup(); 00145 sx1272.writeRegister(REG_OP_MODE,133); //leitura continua 00146 #endif 00147 00148 00149 //gps configuration 00150 #ifdef GPS_ZOE 00151 gps_config(); 00152 #endif 00153 00154 00155 00156 00157 //wait_ms(2100); 00158 00159 //led1=0;//off leds 00160 led2=0; 00161 printf("------Configuration finished------------\n"); 00162 00163 00164 /////////////////////////////////////// 00165 // Main Loop 00166 /////////////////////////////////////// 00167 uint8_t packet[]={0,1,2,3}; 00168 while (1) { 00169 00170 //TEST all sensors 00171 #ifdef BMX160 00172 bmx_read(); 00173 #endif 00174 00175 #ifdef BME280 00176 printf("Temp %2.2f degC, Press %04.2f hPa, Hum %2.2f %%\n", getTemperature(), getPressure(), getHumidity()); 00177 #endif 00178 00179 #ifdef LORA_SX1272 00180 lora_send_packet (packet,sizeof(packet)); 00181 #endif 00182 00183 #ifdef SI1133 00184 if (si1133.open()) printf("Lux = %.3f UV index = %.3f\n", (float)si1133.get_light_level(), (float)si1133.get_uv_index()); 00185 #endif 00186 00187 #ifdef MEM_MX25R 00188 memory_test(); 00189 #endif 00190 00191 #ifdef GPS_ZOE 00192 //gps_print_local(); 00193 send_nav_pvt(); 00194 #endif 00195 00196 00197 wait(1); 00198 00199 00200 } 00201 00202 } 00203 00204
Generated on Sat Jul 30 2022 05:15:02 by 1.7.2