Coragem Adaptation
main.cpp@5:ef21a65a3450, 2019-12-04 (annotated)
- Committer:
- marcoantonioara
- Date:
- Wed Dec 04 11:50:35 2019 +0000
- Revision:
- 5:ef21a65a3450
- Parent:
- 3:cbe3f441353e
Test Coragem using Lora
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cdupaty | 0:9859cc8476f2 | 1 | #include "mbed.h" |
marcoantonioara | 5:ef21a65a3450 | 2 | #include "bme280.txt" |
cdupaty | 0:9859cc8476f2 | 3 | |
cdupaty | 2:4eef0eca4d26 | 4 | /////////////////////////////////////// |
cdupaty | 2:4eef0eca4d26 | 5 | // Globals variables |
cdupaty | 2:4eef0eca4d26 | 6 | /////////////////////////////////////// |
marcoantonioara | 3:cbe3f441353e | 7 | |
marcoantonioara | 5:ef21a65a3450 | 8 | //declaraao gerais |
marcoantonioara | 3:cbe3f441353e | 9 | DigitalOut led1(P1_13); |
marcoantonioara | 3:cbe3f441353e | 10 | DigitalOut led2(P1_14); |
marcoantonioara | 3:cbe3f441353e | 11 | InterruptIn dio0(P0_12); |
marcoantonioara | 3:cbe3f441353e | 12 | DigitalIn button1(P1_11); |
marcoantonioara | 3:cbe3f441353e | 13 | DigitalIn button2(P1_12); |
marcoantonioara | 3:cbe3f441353e | 14 | DigitalIn button3(P0_30); |
marcoantonioara | 3:cbe3f441353e | 15 | |
marcoantonioara | 3:cbe3f441353e | 16 | EventQueue queue; |
marcoantonioara | 3:cbe3f441353e | 17 | |
marcoantonioara | 5:ef21a65a3450 | 18 | //============= internet of turtles ============= |
marcoantonioara | 3:cbe3f441353e | 19 | Timer time_breathing; |
marcoantonioara | 3:cbe3f441353e | 20 | Timer time_diving; |
marcoantonioara | 3:cbe3f441353e | 21 | bool beathing = false; |
marcoantonioara | 3:cbe3f441353e | 22 | float last_breathing_time = 0.0; |
marcoantonioara | 3:cbe3f441353e | 23 | float last_diving_time = 0.0; |
marcoantonioara | 3:cbe3f441353e | 24 | |
marcoantonioara | 3:cbe3f441353e | 25 | char float_breathing_time[10]; |
marcoantonioara | 3:cbe3f441353e | 26 | char float_diving_time[10]; |
marcoantonioara | 3:cbe3f441353e | 27 | |
marcoantonioara | 5:ef21a65a3450 | 28 | //Timer seconds; |
marcoantonioara | 3:cbe3f441353e | 29 | //================================================ |
marcoantonioara | 3:cbe3f441353e | 30 | |
marcoantonioara | 5:ef21a65a3450 | 31 | #include "lora.txt" |
marcoantonioara | 3:cbe3f441353e | 32 | |
marcoantonioara | 5:ef21a65a3450 | 33 | int main(void) { |
marcoantonioara | 3:cbe3f441353e | 34 | |
marcoantonioara | 3:cbe3f441353e | 35 | |
marcoantonioara | 3:cbe3f441353e | 36 | |
marcoantonioara | 5:ef21a65a3450 | 37 | /////////////////////////////////////// |
marcoantonioara | 5:ef21a65a3450 | 38 | // Variables |
marcoantonioara | 5:ef21a65a3450 | 39 | /////////////////////////////////////// |
marcoantonioara | 3:cbe3f441353e | 40 | |
marcoantonioara | 3:cbe3f441353e | 41 | |
marcoantonioara | 5:ef21a65a3450 | 42 | |
marcoantonioara | 5:ef21a65a3450 | 43 | // uint8_t big_message[] = "1234567890qwertyuiopasdfghjklzxcvbnm1234567890qwertyuiopasdfghjklzxcvbnm1234567890qwertyuiopasdfghjklzxcvbnm1234567890qwertyuiopasdfghjklzxcvbnm1234567890qwertyuiopasdfghjklzxcvbnm1234567890qwertyuiopasdfghjklzxcvbnm01234567890123456789"; |
marcoantonioara | 5:ef21a65a3450 | 44 | // uint8_t reset_message[] = "Reset"; |
marcoantonioara | 3:cbe3f441353e | 45 | |
marcoantonioara | 5:ef21a65a3450 | 46 | //long int time_start = seconds.read(); |
marcoantonioara | 5:ef21a65a3450 | 47 | //printf ("timestart=%d leitura = %d\n",time_start,seconds.read()); |
marcoantonioara | 3:cbe3f441353e | 48 | |
marcoantonioara | 3:cbe3f441353e | 49 | |
marcoantonioara | 5:ef21a65a3450 | 50 | /////////////////////////////////////// |
marcoantonioara | 5:ef21a65a3450 | 51 | // Configuration |
marcoantonioara | 5:ef21a65a3450 | 52 | /////////////////////////////////////// |
marcoantonioara | 3:cbe3f441353e | 53 | |
marcoantonioara | 3:cbe3f441353e | 54 | |
marcoantonioara | 5:ef21a65a3450 | 55 | led1=1;//----on leds--- |
marcoantonioara | 3:cbe3f441353e | 56 | led2=1; |
marcoantonioara | 3:cbe3f441353e | 57 | |
marcoantonioara | 5:ef21a65a3450 | 58 | //____Configuration bme280 |
marcoantonioara | 5:ef21a65a3450 | 59 | bme_init(); |
marcoantonioara | 5:ef21a65a3450 | 60 | |
marcoantonioara | 5:ef21a65a3450 | 61 | //____Configuration Lora |
marcoantonioara | 3:cbe3f441353e | 62 | Thread eventThread; |
marcoantonioara | 3:cbe3f441353e | 63 | eventThread.start(callback(&queue, &EventQueue::dispatch_forever)); |
marcoantonioara | 3:cbe3f441353e | 64 | |
marcoantonioara | 5:ef21a65a3450 | 65 | dio0.rise(queue.event(&print_packet)); //configure interrupt rotine ro recieve packet |
marcoantonioara | 3:cbe3f441353e | 66 | setup(); //configura sx1272 |
marcoantonioara | 5:ef21a65a3450 | 67 | |
marcoantonioara | 3:cbe3f441353e | 68 | //TESTE_COMUNICAÇAO LABRADOR |
marcoantonioara | 3:cbe3f441353e | 69 | //sx1272.writeRegister(0x0B,0x3B); |
marcoantonioara | 3:cbe3f441353e | 70 | //sx1272.writeRegister(0x18,0x10); |
marcoantonioara | 3:cbe3f441353e | 71 | //sx1272.writeRegister(0x33,0x26); |
marcoantonioara | 5:ef21a65a3450 | 72 | // sx1272.writeRegister(REG_MODEM_CONFIG1,0x0D); |
marcoantonioara | 5:ef21a65a3450 | 73 | // sx1272.writeRegister(REG_MODEM_CONFIG2,0xC4); |
marcoantonioara | 5:ef21a65a3450 | 74 | |
marcoantonioara | 3:cbe3f441353e | 75 | sx1272.writeRegister(REG_OP_MODE,133); //leitura continua |
marcoantonioara | 5:ef21a65a3450 | 76 | sx1272.writeRegister(REG_IRQ_FLAGS_MASK,187);//configure interrupt mask to interrupt only when a packet receive and packet envied |
marcoantonioara | 5:ef21a65a3450 | 77 | |
marcoantonioara | 5:ef21a65a3450 | 78 | led1=0;//----off leds--- |
marcoantonioara | 3:cbe3f441353e | 79 | led2=0; |
marcoantonioara | 3:cbe3f441353e | 80 | |
marcoantonioara | 3:cbe3f441353e | 81 | |
marcoantonioara | 5:ef21a65a3450 | 82 | |
marcoantonioara | 5:ef21a65a3450 | 83 | |
marcoantonioara | 5:ef21a65a3450 | 84 | /////////////////////////////////////// |
marcoantonioara | 5:ef21a65a3450 | 85 | //LOOP |
marcoantonioara | 5:ef21a65a3450 | 86 | /////////////////////////////////////// |
marcoantonioara | 5:ef21a65a3450 | 87 | |
marcoantonioara | 5:ef21a65a3450 | 88 | while(1){ |
marcoantonioara | 5:ef21a65a3450 | 89 | |
marcoantonioara | 5:ef21a65a3450 | 90 | if (!button1){ |
marcoantonioara | 5:ef21a65a3450 | 91 | led2=1; |
marcoantonioara | 5:ef21a65a3450 | 92 | send_data(PING); |
marcoantonioara | 5:ef21a65a3450 | 93 | led2=0; |
marcoantonioara | 5:ef21a65a3450 | 94 | } |
marcoantonioara | 5:ef21a65a3450 | 95 | |
marcoantonioara | 5:ef21a65a3450 | 96 | // if (button3 != beathing) { |
marcoantonioara | 5:ef21a65a3450 | 97 | // beathing = !beathing; |
marcoantonioara | 5:ef21a65a3450 | 98 | // if(button3){ |
marcoantonioara | 5:ef21a65a3450 | 99 | // send_packet(DATA); |
marcoantonioara | 5:ef21a65a3450 | 100 | // |
marcoantonioara | 5:ef21a65a3450 | 101 | // time_breathing.reset(); |
marcoantonioara | 5:ef21a65a3450 | 102 | // time_breathing.start(); |
marcoantonioara | 5:ef21a65a3450 | 103 | // |
marcoantonioara | 5:ef21a65a3450 | 104 | // time_diving.stop(); |
marcoantonioara | 5:ef21a65a3450 | 105 | // last_diving_time = time_diving.read(); |
marcoantonioara | 5:ef21a65a3450 | 106 | // } |
marcoantonioara | 5:ef21a65a3450 | 107 | // else{ |
marcoantonioara | 5:ef21a65a3450 | 108 | // time_diving.reset(); |
marcoantonioara | 5:ef21a65a3450 | 109 | // time_diving.start(); |
marcoantonioara | 5:ef21a65a3450 | 110 | // |
marcoantonioara | 5:ef21a65a3450 | 111 | // time_breathing.stop(); |
marcoantonioara | 5:ef21a65a3450 | 112 | // last_breathing_time = time_breathing.read(); |
marcoantonioara | 5:ef21a65a3450 | 113 | // |
marcoantonioara | 5:ef21a65a3450 | 114 | // } |
marcoantonioara | 5:ef21a65a3450 | 115 | // |
marcoantonioara | 5:ef21a65a3450 | 116 | // } |
marcoantonioara | 5:ef21a65a3450 | 117 | // if (button3){ |
marcoantonioara | 5:ef21a65a3450 | 118 | // // send_data(DATA); |
marcoantonioara | 5:ef21a65a3450 | 119 | //// send_packet(big_message,sizeof(big_message)); |
marcoantonioara | 5:ef21a65a3450 | 120 | //// send_packet(reset_message,sizeof(reset_message)); |
marcoantonioara | 5:ef21a65a3450 | 121 | //// wait_ms(400); |
marcoantonioara | 5:ef21a65a3450 | 122 | |
marcoantonioara | 3:cbe3f441353e | 123 | |
marcoantonioara | 5:ef21a65a3450 | 124 | |
marcoantonioara | 3:cbe3f441353e | 125 | wait_ms(50); |
marcoantonioara | 3:cbe3f441353e | 126 | } |
marcoantonioara | 3:cbe3f441353e | 127 | |
marcoantonioara | 3:cbe3f441353e | 128 | } |