/* Description: Forecast state + Calculation of forecast State from Diagram: S07 */ state do_DISP_FC() { int averagePressure = 0; for (int i=0; i<5; i++) averagePressure += pressureData[i]; averagePressure /= 5; //TODO: should all this be floats?ich if (pressureData[3] > averagePressure && pressureData[4] > averagePressure) { GotoLCD_Location(1,1); Send_String("Forecast: Good"); GotoLCD_Location(1,2); Send_String("Weather Expected"); howistheweather = 1; } else { GotoLCD_Location(1,1); Send_String("Forecast: Bad"); GotoLCD_Location(1,2); Send_String("Weather Expected"); howistheweather = 0; } if (isforecast ==0) { clear_display(); return DISP_TEMP; } else return DISP_FC; }
/*lint -save -e970 Disable MISRA rule (6.3) checking. */ int main(void) /*lint -restore Enable MISRA rule (6.3) checking. */ { /* Write your local variable definition here */ uint16 countServo; int i; /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/ PE_low_level_init(); ADC0_CFG2 |= ADC_CFG2_MUXSEL_MASK; /*** End of Processor Expert internal initialization. ***/ /* Write your code here */ /* For example: for(;;) { } */ /* * Motores são setados com valores de 0 a 255, 2o argumento resolve o sentido. */ cameraSIBit_ClrVal(); sMachine_Init(); Serial_Init(); enableMotor(); setMotor(0,1,0); setMotor(1,1,0); servoPWM_Enable(servoPWM_DeviceData); countServo = 19000; servoPWM_SetDutyUS(servoPWM_DeviceData,countServo); cameraCLK_Enable(); cameraCLK_EnableEvent(); cameraCLKBit_ClrVal(); while(1){ for (i=0; i < 128; i++){ vetorCamera[i] = getCamPixel(i); } for (i=0; i < 128; i++){ itoa(vetorCamera[i], buffer0); Send_String(buffer0); Send_String(" "); } Send_String("\r\n"); } /*** Don't write any code pass this line, or it will be deleted during code generation. ***/ /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/ #ifdef PEX_RTOS_START PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */ #endif /*** End of RTOS startup code. ***/ /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/ for(;;){} /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/ } /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
/* Description: State of Welcome message State from Diagram: S01 */ state do_WELCOME() { GotoLCD_Location(1,1); Send_String("Welcome to the"); GotoLCD_Location(1,2); Send_String("Weathermeister"); if (iswelcome==0) { clear_display(); return DISP_TEMP; } else return WELCOME; }
/* Description: End of Setup, Store changed data to RTC and display end message State from Diagram: S13 */ state do_DISP_SETUP_MSG() { GotoLCD_Location(1,1); Send_String("Time&Date Set!"); ds1307_setdate(time[0],time[1],time[2],time[3],time[4],0); _delay_ms(10000); clear_display(); issetup=0; return DISP_TEMP; }
/* Description: Setup state, Adjusting Day State from Diagram: S10 */ state do_SET_DAY() { GotoLCD_Location(1,1); Send_String("Set Day:"); GotoLCD_Location(1,2); Send_Int(time[2]); if (bu==1) { clear_display(); bu=0; if (time[2]<=30) time[2]++; else time[2]=1; } if (bd==1) { bd=0; clear_display(); if (time[2]>=2) time[2]--; else time[2]=31; } if (bs==1) { clear_display(); bs=0; issetup=0; return DISP_TEMP; } if (bf==1) { clear_display(); bf=0; return SET_MONTH; } return SET_DAY; }
/* Description: Setup state, Adjusting minute State from Diagram: S09 */ state do_SET_MIN() { GotoLCD_Location(1,1); Send_String("Set Minute:"); GotoLCD_Location(1,2); Send_Int(time[4]); if (bu==1) { clear_display(); bu=0; if (time[4]<=58) time[4]++; else time[4]=0; } if (bd==1) { bd=0; clear_display(); if (time[4]>=1) time[4]--; else time[4]=59; } if (bs==1) { clear_display(); bs=0; issetup=0; return DISP_TEMP; } if (bf==1) { clear_display(); bf=0; return SET_DAY; } return SET_MIN; }
/* Description: First Setup state, Adjusting hour State from Diagram: S08 */ state do_SET_HOUR() { GotoLCD_Location(1,1); Send_String("Set Hour:"); GotoLCD_Location(1,2); Send_Int(time[3]); if (bu==1) { clear_display(); bu=0; if (time[3]<=22) time[3]++; else time[3]=0; } if (bd==1) { bd=0; clear_display(); if (time[3]>=1) time[3]--; else time[3]=23; } if (bs==1) { clear_display(); bs=0; issetup=0; return DISP_TEMP; } if (bf==1) { clear_display(); bf=0; return SET_MIN; } return SET_HOUR; }
/* Description: Setup state, Adjusting Year State from Diagram: S12 */ state do_SET_YEAR() { GotoLCD_Location(1,1); Send_String("Set Year:"); GotoLCD_Location(1,2); Send_Int(time[0]); if (bu==1) { clear_display(); bu=0; if (time[0]<=99) time[0]++; else time[0]=14; } if (bd==1) { bd=0; clear_display(); if (time[0]>=15) time[0]--; else time[0]=99; } if (bs==1) { clear_display(); bs=0; issetup=0; return DISP_TEMP; } if (bf==1) { clear_display(); bf=0; return DISP_SETUP_MSG; } return SET_YEAR; }
/* Description: Setup state, Adjusting Month State from Diagram: S11 */ state do_SET_MONTH() { GotoLCD_Location(1,1); Send_String("Set Month:"); GotoLCD_Location(1,2); Send_Int(time[1]); if (bu==1) { clear_display(); bu=0; if (time[1]<=11) time[1]++; else time[1]=1; } if (bd==1) { bd=0; clear_display(); if (time[1]>=2) time[1]--; else time[1]=12; } if (bs==1) { clear_display(); bs=0; issetup=0; return DISP_TEMP; } if (bf==1) { clear_display(); bf=0; return SET_YEAR; } return SET_MONTH; }
/* Description: Home state, displaying date, time and temperature State from Diagram: S02 */ state do_DISP_TEMP() { GotoLCD_Location(1,1); if (time[3]<=9) { Send_String("0"); Send_Int(time[3]); } else { Send_Int(time[3]); } Send_String(":"); if (time[4]<=9) { Send_String("0"); Send_Int(time[4]); } else { Send_Int(time[4]); } Send_String(" "); Send_Int(time[2]); Send_String("."); Send_Int(time[1]); Send_String("."); Send_Int(time[0]); GotoLCD_Location(1,2); Send_String("Temp.: "); Send_Double(weather.temp,2,1); Send_String("C"); if(my_state != DISP_TEMP) //if any interrupt has changed the destination state, shut up. return my_state; if (bd==1) { clear_display(); bd=0; return DISP_HUM; } if (bu==1) { clear_display(); bu=0; return DISP_LIGHT; } if (bs==1) { clear_display(); bs=0; issetup=1; return SET_HOUR; } if (bf==1) { clear_display(); bf=0; isforecast =1; timer5s = 0; return DISP_FC; } return DISP_TEMP; }
/* Description: Humidity state, displaying date, time and humidity State from Diagram: S04 */ state do_DISP_HUM() { GotoLCD_Location(1,1); if (time[3]<=9) { Send_String("0"); Send_Int(time[3]); } else { Send_Int(time[3]); } Send_String(":"); if (time[4]<=9) { Send_String("0"); Send_Int(time[4]); } else { Send_Int(time[4]); } Send_String(" "); Send_Int(time[2]); Send_String("."); Send_Int(time[1]); Send_String("."); Send_Int(time[0]); GotoLCD_Location(1,2); Send_String("Humidity: "); Send_Double((weather.hum)-17000,2,0); //don't ask me why the value is 17000 + humidity in percent, but works Send_String(" % "); if(my_state != DISP_HUM) //if any interrupt has changed the destination state, shut up. return my_state; if (bu==1) { clear_display(); bu=0; return DISP_TEMP; } if (bd==1) { clear_display(); bd=0; return DISP_PRESS; } if (bs==1) { clear_display(); issetup=1; bs=0; return SET_HOUR; } if (bf==1) { clear_display(); bf=0; isforecast =1; timer5s = 0; return DISP_FC; } return DISP_HUM; }