void main(void) { initSysClock(); initUartDebug(); initLeds(); initLaunchpadSW1(); initSysTick(); initBluetooth(); initUSB(); initRfModule(false); setRfTxAddress(RF_DESTINATION_ADDR); Network_setSelfAddress(RF_CONTOLBOARD_ADDR); while (true) { if ((g_bConnected == false) || (g_bSuspended == true)) { GPIOPinWrite(LED_PORT_BASE, LED_ALL, LED_RED); continue; } GPIOPinWrite(LED_PORT_BASE, LED_ALL, LED_GREEN); if (g_USBRxState == USB_RX_DATA_AVAILABLE) { GPIOPinWrite(LED_PORT_BASE, LED_ALL, LED_BLUE); switch (usbBufferHostToDevice[0]) { //-----------------Bootloader Handle------------------- case BOOTLOADER_BROADCAST_PACKET: broadcastBslData(); break; case BOOTLOADER_SCAN_JAMMING: scanJammingSignal(); break; default: normalPacketHandle(); break; } g_USBRxState = USB_RX_IDLE; turnOffLED(LED_BLUE); } } }
int main(){ //It's inits time! initUartDebug(); DDRG = 0xFF; acc_init(); PORTG = 0xFF; adc_init(); //burn_init(); du_init(); DHT_Init(); //digipot_init(); //GPS_Init(); i2c_init(); OneWireInit(); //OPT_init(); radio_init(); sd_init(); //soilres_init(); spi_init(); TimeServiceInit(); dtpkt_t pkt; /*accpkt_t accpkt; accpkt.beacon = 0xACCC; accpkt.number = 0; accpkt.entries = 0; uint8_t dataaval=0;*/ pkt.beacon = 0xFFFF; pkt.number = 0; cli(); start_temperature(); //isBigLux = false; sei(); _delay_ms(1); // uint16_t opt_devid = 0;; // OPT_read(0x7F, &opt_devid); // GR_DEBUG("OPT DevID = 0x%02x\n", opt_devid);TempTime = TimeServiceGet(); pkt.humidity = 0; pkt.temperature2 = 0; while(1){ PORTG ^= 0xFF; /*for(int i = 0;i<1;i++) { dataaval = acc_read(accpkt.datax,accpkt.datay,accpkt.dataz); TempTime = TimeServiceGet(); accpkt.time = TempTime.seconds; accpkt.time_part = TempTime.subseconds; if(dataaval) { accpkt.entries = dataaval; accpkt.number++; du_write(&accpkt, 9); du_write(accpkt.datax, dataaval); du_write(accpkt.datay, dataaval); du_write(accpkt.dataz, dataaval); for(int i = 0; i < (sizeof(accpkt)-sizeof(accpkt.cntrl)); i++) { accpkt.cntrl += *((uint8_t*)(&accpkt)+i); } du_write(&accpkt.cntrl, 2); } }*/ TempTime = TimeServiceGet(); if(TempTime.seconds-startOfConv_time.seconds){ cli(); pkt.temperature1 = get_temperature(); sei(); startOfConv_time = TimeServiceGet(); } cli(); DHT_Read(&pkt.humidity,&pkt.temperature2); sei(); // if (rc != 0) // GR_DEBUG("dht22 error = %d\n", rc); pkt.pressure = adc_read(ADC_CHANNEL_PRESSURE); pkt.O2 = adc_read(ADC_CHANNEL_O2_SENS); pkt.CO2 = adc_read(ADC_CHANNEL_CO2_SENS); //OPT_result(&pkt.lum); TempTime = TimeServiceGet(); pkt.time = TempTime.seconds; pkt.time_part = TempTime.subseconds; pkt.number++; for(int i = 0; i < (sizeof(pkt)-sizeof(pkt.cntrl)); i++) { pkt.cntrl += *((uint8_t*)(&pkt)+i); } du_write(&pkt, sizeof(pkt)); //GR_DEBUG("Number %d, %d sec %d subsec, temp1 %d, temp2 %d, pres %d, hum %d, O2 %d, CO2 %d, lum %d\n", pkt.number, pkt.time, pkt.time_part, pkt.temperature1,pkt.temperature2,pkt.pressure,pkt.humidity,pkt.O2,pkt.CO2,pkt.lum); /*dataaval = acc_read(accpkt.datax,accpkt.datay,accpkt.dataz); TempTime = TimeServiceGet(); accpkt.time = TempTime.seconds; accpkt.time_part = TempTime.subseconds; if(dataaval) { accpkt.entries = dataaval; accpkt.number++; du_write(&accpkt, 9); du_write(accpkt.datax, dataaval); du_write(accpkt.datay, dataaval); du_write(accpkt.dataz, dataaval); for(int i = 0; i < (sizeof(accpkt)-sizeof(accpkt.cntrl)); i++) { accpkt.cntrl += *((uint8_t*)(&accpkt)+i); } du_write(&accpkt.cntrl, 2); }*/ if(OnLaunchpad) { if(StartPres - adc_read(ADC_CHANNEL_PRESSURE) > 20) { OnLaunchpad = 0; Started = 1; } } if(Started){ if(WaitLand){ int treshhold = 1; PresBuf[PresBufi] = pkt.pressure; bool onePres = 1; for(int i = 1;i<5;i++){ if((PresBuf[0]-PresBuf[i]>treshhold)||(PresBuf[i]-PresBuf[0])>treshhold) onePres=0; } if(onePres){ FRPORT |= (1<<FRSEEDS); Started = 0; SeedStarted = 1; startOfSeeds_time = TimeServiceGet(); } } PresBuf[PresBufi] = pkt.pressure; if(PresBufi == 4) { PresBufi = 0; WaitLand = 1; } else PresBufi++; } if(SeedStarted){ if(startOfSeeds_time.seconds - TimeServiceGet().seconds) { FRPORT &= ~(1<<FRSEEDS); SeedStarted = 0; pkt.seeds = 1; } } _delay_ms(900); } }