/** * @brief Main program. * @param None * @retval None */ int main(void) { NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0000); Redbull_Init(); char buff[128] = { 0 }; LCD_DisplayStringLine(LINE(10), (uint8_t*) " Analog .............................."); Analog_Config(); printRight(10, "ok"); LCD_DisplayStringLine(LINE(11), (uint8_t*) " DAC ................................."); DAC_Config(); printRight(11, "ok"); f_mount(0, &fatfs); LCD_DisplayStringLine(LINE(12), (uint8_t*) " TEMP ................................"); OneWireInit(); float c = Read_Temperature(); sprintf(buff, "%.1f", c); printRight(12, buff); printf("%s\n", buff); RGBLED_GPIO_Config(0xff); RGBLED_Update(0xff,0xff,0xff); Delay(200); RGBLED_Update(0xff,0,0); Delay(200); RGBLED_Update(0,0xff,0); Delay(200); RGBLED_Update(0,0,0xff); Delay(200); RGBLED_Update(0,0,0); //static char path[1024] = "0:"; //LCD_Clear(LCD_COLOR_BLUE); //LCD_DisplayStringLine(0, (uint8_t*) "Loading..."); Delay(1000); //int i = 10; LCD_Clear(LCD_COLOR_BLACK); LCD_SetDisplayWindow(0, 0, 239, 319); LCD_WriteReg(3, 0x1000); LCD_WriteRAM_Prepare(); TIM_Cmd(TIM7, ENABLE); DMARead(); //float h = 0, s = 1, v = 1; while (1) { while (DMA_GetFlagStatus(DMA1_FLAG_TE1) == SET) { printf("DMA error\n"); Delay(100); } //uint32_t ms = millis(); uint16_t rem = DMA_GetCurrDataCounter(DMA1_Channel1); uint16_t cnt = 0xffff - rem; if (cnt >= 80 && cnt < 512) { continue; } uint32_t buff[160] = { 0 }; uint16_t tillend = cnt > 160 ? 160 : cnt; uint16_t fromstart = 160 - tillend; uint16_t bcnt = cnt - 160; // before SRAM_ReadBuffer((uint16_t*) &buff[0], bcnt * 4, tillend * 2); // after if (fromstart) { SRAM_ReadBuffer((uint16_t*) &buff[tillend], 0, fromstart * 2); } uint8_t prevsv = 0; for (uint16_t i = 0; i < 320; i++) { uint16_t val = 0; if (i & 1) { val = buff[i >> 1] & 0x0fff; } else { val = (buff[i >> 1] >> 16) & 0x0fff; } #define MAXV (17 * 238) val = val > MAXV ? MAXV : val; uint8_t sv = val / 17; sv = sv > 238 ? 238 : sv; sv++; if (!prevsv) { prevsv = sv; } uint16_t pbuf[240]; uint8_t minv = sv > prevsv ? prevsv : sv; uint8_t maxv = sv < prevsv ? prevsv : sv; for (uint8_t y = 0; y < 240; y++) { if (y >= minv && y <= maxv) { pbuf[y] = LCD_COLOR_YELLOW; } else { pbuf[y] = LCD_COLOR_BLACK; } } prevsv = sv; DMA_InitTypeDef DMA_InitStructure; DMA_DeInit(DMA2_Channel5); DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t) pbuf; DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t) &LCD->LCD_RAM; // FSMC DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; DMA_InitStructure.DMA_BufferSize = 240; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Enable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; DMA_InitStructure.DMA_Priority = DMA_Priority_Low; DMA_InitStructure.DMA_M2M = DMA_M2M_Enable; DMA_Init(DMA2_Channel5, &DMA_InitStructure); DMA_Cmd(DMA2_Channel5, ENABLE); RTC_t rtc; RTC_GetTime(&rtc); //RGBLED_Update((rtc.min & 1) ? 0 : (rtc.hour * 10), ((rtc.sec >> 2) & 1) ? 0 : (rtc.min * 4), rtc.sec * 4); while (!DMA_GetFlagStatus(DMA2_FLAG_TC5)) ; DMA_ClearFlag(DMA2_FLAG_TC5); while (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_8) == RESET) ; }
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); } }