int main() { //Enable Peripherals SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); //Start specific Pin Ports GPIOPinTypeGPIOOutput(port_A, GPIO_PIN_5 |GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4); GPIOPinTypeGPIOOutput(port_C, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7); GPIOPinTypeGPIOOutput(port_D,GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_6 | GPIO_PIN_5); GPIOPinTypeGPIOOutput(port_E, GPIO_PIN_0); GPIOPinTypeGPIOOutput(port_F, GPIO_PIN_4); //Input Pins GPIOPinTypeGPIOInput(port_F, GPIO_PIN_2 | GPIO_PIN_3); //Initialize the display initializeDisplay(); //Write phrases write_phrases(); }
void pre_auton() { initializeDisplay(); initializeGyro(); //Uncomment when we start using Gyro Sensor initializePID(); initializeAutonomous(); while (bIfiRobotDisabled); //Keep the message displayed while robot is disabled }
// Change to a new signal channel. void SpikePlot_CV::setNewChannel(SignalChannel* newChannel) { selectedChannel = newChannel; numSpikeWaveforms = 0; startingNewChannel = true; rmsDisplayPeriod = 0; voltageTriggerMode = selectedChannel->voltageTriggerMode; voltageThreshold = selectedChannel->voltageThreshold; digitalTriggerChannel = selectedChannel->digitalTriggerChannel; digitalEdgePolarity = selectedChannel->digitalEdgePolarity; initializeDisplay(); }
/************************************************** * MAIN **************************************************/ int main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer P2SEL = 0x00; // Sets Port 2 for usage P1DIR = 0x00; P2DIR = 0x00; initializeControls(); initializeDisplay(); EEPromInit(); mainMenu(); return 0; }
int main() { //SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); //Enable Peripherals SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); //Start specific Pin Ports GPIOPinTypeGPIOOutput(port_A, GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4); GPIOPinTypeGPIOOutput(port_C, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7); GPIOPinTypeGPIOOutput(port_D, GPIO_PIN_6); GPIOPinTypeGPIOOutput(port_E, GPIO_PIN_0); GPIOPinTypeGPIOOutput(port_F, GPIO_PIN_4 | GPIO_PIN_1); //Input Pins GPIOPinTypeGPIOInput(port_F, GPIO_PIN_2 | GPIO_PIN_3); //Enable pin for interrupt GPIOIntEnable(GPIO_PORTF_BASE, (GPIO_INT_PIN_2 | GPIO_INT_PIN_3)); //Set ISR GPIOIntRegister(GPIO_PORTF_BASE, scroll_button_isr); //Set interrupt type GPIOIntTypeSet(GPIO_PORTF_BASE, (GPIO_PIN_2 | GPIO_PIN_3) , GPIO_FALLING_EDGE); ROM_SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_GPIOC); ROM_SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_GPIOD); ROM_SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_GPIOE); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOF); ROM_SysCtlPeripheralClockGating(true); //Initialize the display initializeDisplay(); //Write phrases write_phrases(); }
int main() { //Enable Peripherals SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); //Start specific Pin Ports GPIOPinTypeGPIOOutput(port_A, GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4); GPIOPinTypeGPIOOutput(port_C, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7); GPIOPinTypeGPIOOutput(port_D, GPIO_PIN_6); GPIOPinTypeGPIOOutput(port_E, GPIO_PIN_0); GPIOPinTypeGPIOOutput(port_F, GPIO_PIN_4); GPIOPinTypeGPIOInput(port_F, GPIO_PIN_2 | GPIO_PIN_3); //Timer Configuration TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); TimerLoadSet(TIMER0_BASE, TIMER_A, frequency); TimerControlEvent(TIMER0_BASE, TIMER_A, TIMER_EVENT_POS_EDGE); TimerEnable(TIMER0_BASE, TIMER_A); //Enable pin for interrupt GPIOIntEnable(GPIO_PORTF_BASE, (GPIO_INT_PIN_2 | GPIO_INT_PIN_3)); //Set ISR GPIOIntRegister(GPIO_PORTF_BASE, the_taco_meter); //Set interrupt type GPIOIntTypeSet(GPIO_PORTF_BASE, (GPIO_PIN_2 | GPIO_PIN_3) , GPIO_BOTH_EDGES); //Initialize the display initializeDisplay(); //RS High GPIOPinWrite(port_C, GPIO_PIN_5, pin_5); write_string("Speed = #### RPM"); while(1) { taco_display(); } }
// Main enters the scene... int main( int argc, char **argv ) { initializeGame( ); initializeDisplay( ); SDL_Event event; int startTime = 0; int over = 0; InputData inputdata = { DOWN, FALSE }; startTime = SDL_GetTicks( ); while( !over ) { while( SDL_PollEvent( &event ) ) { if( event.type == SDL_QUIT ) { over = 1; } if( event.type == SDL_KEYDOWN ) { switch( event.key.keysym.sym ) { case( SDLK_RIGHT ): inputdata.moveDir = RIGHT; break; case( SDLK_LEFT ): inputdata.moveDir = LEFT; break; case( SDLK_SPACE ): inputdata.shouldRotate = TRUE; break; default: inputdata.moveDir = DOWN; inputdata.shouldRotate = FALSE; } } } if( SDL_GetTicks( ) - startTime > TIMESTEP ) { progressGame( inputdata ); updateDisplay( ); resetInputData( &inputdata ); startTime = SDL_GetTicks( ); printf( "%d\n", startTime ); } } SDL_Quit( ); return 0; }
int main(int argc, char** argv){ GLint glfwStatus = glfwInit(); //TO use most GLFW functions we need to initiate this if (glfwStatus != GL_TRUE){ cout << "FAILED TO LOAD GLFW..bummer" << std::endl; glfwTerminate(); return 1; } GLFWwindow *window = glfwCreateWindow(800, 800, "BITCH PLEASE, I GOT THIS", glfwGetPrimaryMonitor(), NULL);//Makes FULL SCREEN //GLFWwindow *window = glfwCreateWindow(600, 600, "BITCH PLEASE, I GOT THIS", NULL, NULL); /////CHECK IF WINDOW HAS BEEN CREATED////// if (window == NULL){ cout << "FAILED TO CREATE WINDOW" << std::endl; return -1; glfwTerminate(); } /////END WINDOW CREATION CHECK/////// glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE); glfwMakeContextCurrent(window); cout << glGetString(GL_VERSION) << std::endl; ////INITIALIZE GLEW AND CHECK FOR SUCCESS////// GLenum res = glewInit(); //Initialize Glew and check for errors with initialization if (res != GLEW_OK){ fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res)); return 0; } ////END GLEW//// GLint windowWidth, windowHeight; glfwGetWindowSize(window, &windowWidth, &windowHeight); initializeDisplay(argc, argv, windowWidth, windowHeight); initGame(); gameLoop(window,windowWidth, windowHeight); //CLOSING GAME// delete(game); //glDeleteProgram(shaderProgram); glDeleteVertexArrays(1, &VAO); // glDeleteShader(fragmentShader); glDeleteBuffers(1,&VBO); // glDeleteShader(vertexShader); glfwDestroyWindow(window); glfwTerminate(); return 0; }
int main(void) { //Local Variables bool displayMode = true;//True if display mode, false if in data entry mode //Push buttons bool upPB = false; bool rightPB = false; bool downPB = false; bool leftPB = false; bool modePB = false; //Push buttons shift registers uint16_t shiftRegSW2 = 0xFFFF; uint16_t shiftRegSW3 = 0xFFFF; uint16_t shiftRegSW4 = 0xFFFF; uint16_t shiftRegSW5 = 0xFFFF; uint16_t shiftRegSW6 = 0xFFFF; //Initial display message uint8_t displayArray [SAVED_MSG_LEN_MAX] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; uint8_t inputArray [17] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; //Mark the indexcies of the array uint8_t endIndex = 19; uint8_t currIndex = 0; uint8_t inputIndex = 0; uint8_t tempIndex = 0; //Flag for overflwoing max char array length bool overflow = false; //Init color uint8_t color; //ADCval1 uint32_t ADCval1 = 0; uint32_t ADCval2 = 0; //Current string char myString[21] = "hello world"; char myChar; int8_t stringIndex=-1; // Initialize the PLLs so the the main CPU frequency is 80MHz PLL_Init(); //Configure Port C initPortC(); //Configure the SYSTICK timer 12.5uS ticks SYSTICKConfig(1000, true); //Configure Timer0 1mS ticks TIMER0Config(80000); //Configure watchdog with 1s reset WatchdogTIMERConfig(); // Initialize the GPIO Ports initializeGPIOPort(PORTA, &portA_config); initializeGPIOPort(PORTB, &portB_config); initializeGPIOPort(PORTC, &portC_config); initializeGPIOPort(PORTD, &portD_config); initializeGPIOPort(PORTE, &portE_config); initializeGPIOPort(PORTF, &portF_config); // Initialize SPI0 interface initializeSPI(SSI0, PHASE, POLARITY); //Init ADC ADCInit(); initializeDisplay(); // Set up the UARTS for 115200 8N1 InitializeUART(UART0); InitializeUART(UART2); InitializeUART(UART5); // Since PD7 is shared with the NMI, we need to clear the lock register and // set the commit register so that all the pins alternate functions can // be used. GPIO_PORTD_LOCK_R = 0x4C4F434B; GPIO_PORTD_CR_R = 0xFF; initializeGPIOPort(PORTD, &portD_config); EnableInterrupts(); //Get initial ADC values pwm = GetADCval(POT_RIGHT) / 40; ADCval2 = GetADCval(POT_LEFT) / 575; // Print out the current string uartTxPoll(UART0,"Hello World\n\r"); while(1) { if(checkADC){ pwm = GetADCval(POT_RIGHT) / 40; ADCval2 = GetADCval(POT_LEFT) / 600; checkADC = false; } //On systick interrupt display the current character and poll the buttons if (refreshLED){ if (displayMode){ displayLEDChar(displayArray[currIndex], ADCval2); } else{ displayLEDChar(inputArray[inputIndex], ADCval2); } refreshLED = false; } if (buttonPoll){ //Check if any buttons have been pushed //If so debounce them buttonPoll = false; //SW2 shiftRegSW2 = debounce(PORTA, SW2, shiftRegSW2); upPB = checkPB(shiftRegSW2); //SW3 shiftRegSW3 = debounce(PORTA, SW3, shiftRegSW3); rightPB = checkPB(shiftRegSW3); //SW4 shiftRegSW4 = debounce(PORTD, SW4, shiftRegSW4); downPB = checkPB(shiftRegSW4); //SW5 shiftRegSW5 = debounce(PORTD, SW5, shiftRegSW5); leftPB = checkPB(shiftRegSW5); //SW6 shiftRegSW6 = debounce(PORTF, SW6, shiftRegSW6); modePB = checkPB(shiftRegSW6); }//End polling //Display Mode if (displayMode){ //Check if right button is pressed if(rightPB){ //Clear the button press rightPB = false; //Display the next character in order in green color = GREEN_EN; if(currIndex == endIndex) currIndex = 0; else currIndex++; } //Check if left button is pressed else if(leftPB){ //Clear the button press leftPB = false; //Display the next character in reverse order in red color = RED_EN; if(currIndex == 0) currIndex = endIndex; else currIndex--; } //Check if mode button is pushed if(modePB){ //Clear the button press modePB = false; //change mode and reset parameters displayMode = false; inputIndex = 0; currIndex = 0; endIndex = 0; overflow = false; tempIndex = 0; displayArray[0] = 0; } } //Input Mode else{ //Check if right button is pressed if(rightPB || leftPB){ //Clear the button press rightPB = false; leftPB = false; //Save the current input character in the display array if //there is enough space if (tempIndex >= SAVED_MSG_LEN_MAX){ tempIndex= 0; overflow = true; } displayArray[tempIndex] = inputArray[inputIndex]; tempIndex++; } //Check if up button is pressed else if(upPB){ //Clear the button press upPB = false; //Display the next character in order in input array if(inputIndex == 15) inputIndex = 0; else inputIndex++; } //Check if down button is pressed else if(downPB){ //Clear the button press downPB = false; //Display the next character in reverse order input array if(inputIndex == 0) inputIndex = 15; else inputIndex--; } if(modePB){ //Clear the button press modePB = false; //change mode to display and reset parameters displayMode = true; color = GREEN_EN; if(overflow){ endIndex = SAVED_MSG_LEN_MAX - 1; } else if (tempIndex != 0) endIndex = tempIndex - 1; } } } }
void SpikePlot_CV::resizeEvent(QResizeEvent*) { // Pixel map used for double buffering. pixmap = QPixmap(size()); pixmap.fill(this, 0, 0); initializeDisplay(); }
// Set voltage scale. void SpikePlot_CV::setYScale(int newYScale) { yScale = newYScale; initializeDisplay(); }
int main() { //Set the Clock at 16MHZ SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); //Enable Timer Peripheral SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); //Enable Peripherals SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); //Initialize Output ports GPIOPinTypeGPIOOutput(port_A, GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4); GPIOPinTypeGPIOOutput(port_C, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7); GPIOPinTypeGPIOOutput(port_D, GPIO_PIN_6); GPIOPinTypeGPIOOutput(port_E, GPIO_PIN_0); GPIOPinTypeGPIOOutput(port_F, (GPIO_PIN_4 | GPIO_PIN_1 | GPIO_PIN_3)); //Input Pins GPIOPinTypeGPIOInput(port_F, GPIO_PIN_2 | GPIO_PIN_3); //Interrupt Enables GPIOIntEnable(GPIO_PORTF_BASE, (GPIO_INT_PIN_2 | GPIO_INT_PIN_3)); GPIOIntRegister(GPIO_PORTF_BASE, interrupt_handler); GPIOIntTypeSet(GPIO_PORTF_BASE, (GPIO_PIN_2 | GPIO_PIN_3) , GPIO_FALLING_EDGE); //Timer Setup TimerLoadSet(TIMER0_BASE, TIMER_A, 0xFFFF); TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); TimerControlEvent(TIMER0_BASE, TIMER_A, TIMER_EVENT_NEG_EDGE); TimerEnable(TIMER0_BASE, TIMER_A); //Initialize the display initializeDisplay(); while(1) { if(display_flag == 1) { //Software Debouncing display_flag = 0; SysCtlDelay(160000); //Clear scree clear_screen(); //RS High for writing GPIOPinWrite(port_C, GPIO_PIN_5, pin_5); write_char_to_pins((char)(((int)'0')+ (0x00FF & TimerValueGet(TIMER0_BASE, TIMER_A))% 10)); //Back to Low GPIOPinWrite(port_C, GPIO_PIN_5, 0x0); } } }
int main(int argc, char *argv[]) { parseCommandLineOptions(argc, argv); initializeRandomNumberGeneratorTo(rng_seed); initializeOutput(); setInitialConditions(); if (graphicsModeEnabled()) initializeDisplay(); perturbation_length=fixed_perturbation_length; for(monte_carlo_steps=start_mcs; monte_carlo_steps<=end_mcs; monte_carlo_steps++) { updatePairList(); generateOutput(); attempted_moves = 0; accepted_moves = 0; for (monte_carlo_step_counter=0; monte_carlo_step_counter<number_of_molecules; monte_carlo_step_counter++) { double boltzmann_factor; double the_exponential; delta_energy = 0; attemptMove(); attempted_moves++; if (delta_energy < 0) { change_flag = 1; accepted_moves++; continue; /* move accepted */ } // the following uses reduced temperature the_exponential = 0.0 - delta_energy/temperature; /* evaluate exponential, unless it's arbitrarily small */ if (the_exponential > -25) { boltzmann_factor = exp(the_exponential); if (boltzmann_factor > rnd()) { change_flag = 1; accepted_moves++; continue; /* move accepted */ } } // revert move x[particle_number] -= dx; y[particle_number] -= dy; z[particle_number] -= dz; } if (monte_carlo_steps < relaxation_allowance) { acceptance_ratio = (0.0 + accepted_moves)/(0.0 + attempted_moves); if (acceptance_ratio < target_acceptance_ratio) perturbation_length *= .9; else if (perturbation_length*perturbation_length*perturbation_length*16 < box_x*box_y*box_z) perturbation_length *=1.1; } else perturbation_length = fixed_perturbation_length; if (graphicsModeEnabled() && changeFlagIsSet()) drawGraphicalRepresentation(); } finalizeOutput(); return 0; } /* end main */
void main(void) { unsigned char state, menuState, x, y, menuButtonTouched, currentProgramEditing, currentPeriodEditing, currentMenuViewing = 0; unsigned char tempTime; char currentTempMenuViewing; unsigned char released = 1; // Semaphore unsigned char touched = 0; extern struct room rooms[2]; // For programs Tab extern unsigned char weeklySchedule[]; // For days tab //EnableInterrupts; /* enable interrupts */ /* include your code here */ CONFIG1_COPD = 1; INTSCR_MODE = 1; INTSCR_IMASK = 1; initI2C(); initPortX(); initADC(); initSCI(); configureTemp(); startTemp(); initFlash(); initializeDisplay(); initializeThermostat(); // Pass this function before enabling interrupts drawMainScreen(); drawSolidButton(homeButton); state = MAIN; menuState = NONE; //setModeMain(82,I_HEAT); EnableInterrupts; INTSCR_IMASK = 0; for(;;) { //sendModeAux(72, I_COOL); saveProgramData(); // Poll clock drawTopBar(); switch (state) { case MAIN: updateTemp(); break; case PROGRAMS_TAB: break; case DAYS_TAB: break; case SETTINGS: break; } // Poll touchscreen if (!isScreenTouched()) { released = 1; } if (isScreenTouched() && released) { released = 0; x = getX(); y = getY(); x = mapToXPixel(x); y = mapToYPixel(y); switch (state) { case MAIN: if (isOverride[currentRoom]) { if (isButtonTouched(x, y, overrideButton)) { isOverride[currentRoom] = 0; drawMainScreen(); } } if (isButtonTouched(x, y, programButton)) { drawProgramsTab(); state = PROGRAMS_TAB; menuState = NONE; } else if (isButtonTouched(x, y, settingsButton)) { drawSettingsScreen(); state = SETTINGS; menuState = NONE; } else { switch (menuState) { case NONE: if (isButtonTouched(x, y, setToButton)) { switch (isOverride[currentRoom]) { case 0: currentMenuViewing = determineTempMenu(currentPeriod[currentRoom].temperature); break; case 1: currentMenuViewing = determineTempMenu(overridePeriod[currentRoom].temperature); break; } goToText(20, 1); printNum(menuButtonTouched); drawMainSetToMenu(currentMenuViewing); menuState = SET_TO_MENU; } else if (isButtonTouched(x, y, roomButton)) { drawMainRoomMenu(); menuState = ROOM_MENU; } else if (isButtonTouched(x, y, fanButton)) { drawMainFanMenu(); menuState = FAN_MENU; } else if (isButtonTouched(x, y, modeButton)) { drawMainModeMenu(); menuState = MAIN_MODE_MENU; } break; case SET_TO_MENU: menuButtonTouched = isVerticalMenuButtonTouched(x, y, setToMenu); if(menuButtonTouched) { switch (currentMenuViewing) { case 1: if (menuButtonTouched == 5) drawMainSetToMenu(++currentMenuViewing); else { updateProgrammingTemp(&(rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].temperature), 59 + menuButtonTouched); drawMainScreen(); menuState = NONE; } break; case 2: if (menuButtonTouched == 1) drawMainSetToMenu(--currentMenuViewing); else if (menuButtonTouched == 5) drawMainSetToMenu(++currentMenuViewing); else { updateProgrammingTemp(&(rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].temperature), 62 + menuButtonTouched); drawMainScreen(); menuState = NONE; } break; case 3: if (menuButtonTouched == 1) drawMainSetToMenu(--currentMenuViewing); else if (menuButtonTouched == 5) drawMainSetToMenu(++currentMenuViewing); else { updateProgrammingTemp(&(rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].temperature), 65 + menuButtonTouched); drawMainScreen(); menuState = NONE; } break; case 4: if (menuButtonTouched == 1) drawMainSetToMenu(--currentMenuViewing); else if (menuButtonTouched == 5) drawMainSetToMenu(++currentMenuViewing); else { updateProgrammingTemp(&(rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].temperature), 68 + menuButtonTouched); drawMainScreen(); menuState = NONE; } break; case 5: if (menuButtonTouched == 1) drawMainSetToMenu(--currentMenuViewing); else if (menuButtonTouched == 5) drawMainSetToMenu(++currentMenuViewing); else { updateProgrammingTemp(&(rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].temperature), 71 + menuButtonTouched); drawMainScreen(); menuState = NONE; } break; case 6: if (menuButtonTouched == 1) drawMainSetToMenu(--currentMenuViewing); else if (menuButtonTouched == 5) drawMainSetToMenu(++currentMenuViewing); else { updateProgrammingTemp(&(rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].temperature), 74 + menuButtonTouched); drawMainScreen(); menuState = NONE; } break; case 7: if (menuButtonTouched == 1) drawMainSetToMenu(--currentMenuViewing); else if (menuButtonTouched == 5) drawMainSetToMenu(++currentMenuViewing); else { updateProgrammingTemp(&(rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].temperature), 77 + menuButtonTouched); drawMainScreen(); menuState = NONE; } break; case 8: if (menuButtonTouched == 1) { drawMainSetToMenu(--currentMenuViewing); } else if (menuButtonTouched == 5) drawMainSetToMenu(++currentMenuViewing); else { updateProgrammingTemp(&(rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].temperature), 80 + menuButtonTouched); drawMainScreen(); menuState = NONE; } break; case 9: if (menuButtonTouched == 1) { drawMainSetToMenu(--currentMenuViewing); } else { updateProgrammingTemp(&(rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].temperature), 83 + menuButtonTouched); drawMainScreen(); menuState = NONE; } break; } } break; case ROOM_MENU: menuButtonTouched = isHorizontalMenuButtonTouched(x, y, roomMenu); switch (menuButtonTouched) { case 1: currentRoom = ROOM_MAIN; drawMainScreen(); menuState = NONE; break; case 2: currentRoom = ROOM_AUX; drawMainScreen(); menuState = NONE; break; } break; case FAN_MENU: menuButtonTouched = isHorizontalMenuButtonTouched(x, y, fanMenu); switch (menuButtonTouched) { case 1: fanMode[currentRoom] = FAN_ON; drawMainScreen(); menuState = NONE; break; case 2: fanMode[currentRoom] = FAN_OFF; drawMainScreen(); menuState = NONE; break; case 3: fanMode[currentRoom] = FAN_AUTO; drawMainScreen(); menuState = NONE; break; } break; // Will cause manual override case MAIN_MODE_MENU: menuButtonTouched = isHorizontalMenuButtonTouched(x, y, modeMenu); switch (menuButtonTouched) { case 1: overridePeriod[currentRoom].mode = HEAT; menuState = NONE; break; case 2: overridePeriod[currentRoom].mode = COOL; menuState = NONE; break; case 3: overridePeriod[currentRoom].mode = OFF; menuState = NONE; break; } if (overridePeriod[currentRoom].mode != currentPeriod[currentRoom].mode) { isOverride[currentRoom] = 1; } else { isOverride[currentRoom] = 0; } if (menuButtonTouched) { drawMainScreen(); } break; } } /****END MENUSTATE****/ break; /****END MAIN****/ case PROGRAMS_TAB: if (isButtonTouched(x, y, homeButton)) { drawMainScreen(); state = MAIN; } else if (isButtonTouched(x, y, settingsButton)) { drawSettingsScreen(); state = SETTINGS; } else if (isButtonTouched(x, y, daysTab)) { drawDaysTab(); state = DAYS_TAB; } else if (isButtonTouched(x, y, program1Button)) { drawProgrammingScreen(0); state = PROGRAMMING_SCREEN; currentProgramEditing = 0; } else if (isButtonTouched(x, y, program2Button)) { drawProgrammingScreen(1); state = PROGRAMMING_SCREEN; currentProgramEditing = 1; } else if (isButtonTouched(x, y, program3Button)) { drawProgrammingScreen(2); state = PROGRAMMING_SCREEN; currentProgramEditing = 2; } else if (isButtonTouched(x, y, program4Button)) { drawProgrammingScreen(3); state = PROGRAMMING_SCREEN; currentProgramEditing = 3; } break; case PROGRAMMING_SCREEN: if (isButtonTouched(x, y, homeButton)) { drawMainScreen(); state = MAIN; menuState = NONE; } else if (isButtonTouched(x, y, settingsButton)) { drawSettingsScreen(); state = SETTINGS; menuState = NONE; } else if (isButtonTouched(x, y, okButton)) { drawProgramsTab(); state = PROGRAMS_TAB; menuState = NONE; } switch (menuState) { case NONE: if (isButtonTouched(x, y, hour1Button)) { currentPeriodEditing = 0; currentMenuViewing = determineHoursMenu(rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].startTime); drawHoursMenu(currentMenuViewing); menuState = HOURS_MENU; } else if (isButtonTouched(x, y, hour2Button)) { currentPeriodEditing = 1; currentMenuViewing = determineHoursMenu(rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].startTime); drawHoursMenu(currentMenuViewing); menuState = HOURS_MENU; } else if (isButtonTouched(x, y, hour3Button)) { currentPeriodEditing = 2; currentMenuViewing = determineHoursMenu(rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].startTime); drawHoursMenu(currentMenuViewing); menuState = HOURS_MENU; } else if (isButtonTouched(x, y, hour4Button)) { currentPeriodEditing = 3; currentMenuViewing = determineHoursMenu(rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].startTime); drawHoursMenu(currentMenuViewing); menuState = HOURS_MENU; } else if (isButtonTouched(x, y, minutes1Button)) { currentPeriodEditing = 0; drawMinutesMenu(rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].startTime); menuState = MINUTES_MENU; } else if (isButtonTouched(x, y, minutes2Button)) { currentPeriodEditing = 1; drawMinutesMenu(rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].startTime); menuState = MINUTES_MENU; } else if (isButtonTouched(x, y, minutes3Button)) { currentPeriodEditing = 2; drawMinutesMenu(rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].startTime); menuState = MINUTES_MENU; } else if (isButtonTouched(x, y, minutes4Button)) { currentPeriodEditing = 3; drawMinutesMenu(rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].startTime); menuState = MINUTES_MENU; } else if (isButtonTouched(x, y, amPm1Button)) { toggleAmPm(currentProgramEditing, 0); drawProgrammingScreen(currentProgramEditing); menuState = NONE; } else if (isButtonTouched(x, y, amPm2Button)) { toggleAmPm(currentProgramEditing, 1); drawProgrammingScreen(currentProgramEditing); menuState = NONE; } else if (isButtonTouched(x, y, amPm3Button)) { toggleAmPm(currentProgramEditing, 2); drawProgrammingScreen(currentProgramEditing); menuState = NONE; } else if (isButtonTouched(x, y, amPm4Button)) { toggleAmPm(currentProgramEditing, 3); drawProgrammingScreen(currentProgramEditing); menuState = NONE; } else if (isButtonTouched(x, y, temp1Button)) { currentPeriodEditing = 0; currentMenuViewing = determineTempMenu(rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].temperature); drawProgrammingTempMenu(currentMenuViewing); menuState = TEMP_MENU; } else if (isButtonTouched(x, y, temp2Button)) { currentPeriodEditing = 1; currentMenuViewing = determineTempMenu(rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].temperature); drawProgrammingTempMenu(currentMenuViewing); menuState = TEMP_MENU; } else if (isButtonTouched(x, y, temp3Button)) { currentPeriodEditing = 2; currentMenuViewing = determineTempMenu(rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].temperature); drawProgrammingTempMenu(currentMenuViewing); menuState = TEMP_MENU; } else if (isButtonTouched(x, y, temp4Button)) { currentPeriodEditing = 3; currentMenuViewing = determineTempMenu(rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].temperature); drawProgrammingTempMenu(currentMenuViewing); menuState = TEMP_MENU; } else if (isButtonTouched(x, y, mode1Button)) { currentPeriodEditing = 0; drawProgrammingModeMenu(currentPeriodEditing); menuState = PROGRAM_MODE_MENU; } else if (isButtonTouched(x, y, mode2Button)) { currentPeriodEditing = 1; drawProgrammingModeMenu(currentPeriodEditing); menuState = PROGRAM_MODE_MENU; } else if (isButtonTouched(x, y, mode3Button)) { currentPeriodEditing = 2; drawProgrammingModeMenu(currentPeriodEditing); menuState = PROGRAM_MODE_MENU; } else if (isButtonTouched(x, y, mode4Button)) { currentPeriodEditing = 3; drawProgrammingModeMenu(currentPeriodEditing); menuState = PROGRAM_MODE_MENU; } break; case HOURS_MENU: menuButtonTouched = isVerticalMenuButtonTouched(x, y, hoursMenu); if (menuButtonTouched) { switch (currentMenuViewing) { case 1: if (menuButtonTouched == 5) { drawHoursMenu(++currentMenuViewing); } else { updateHours(&(rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].startTime), menuButtonTouched); drawProgrammingScreen(currentProgramEditing); menuState = NONE; } break; case 2: if (menuButtonTouched == 1) drawHoursMenu(--currentMenuViewing); else if (menuButtonTouched == 5) drawHoursMenu(++currentMenuViewing); else { updateHours(&(rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].startTime), menuButtonTouched + 3); drawProgrammingScreen(currentProgramEditing); menuState = NONE; } break; case 3: if (menuButtonTouched == 1) drawHoursMenu(--currentMenuViewing); else if (menuButtonTouched == 5) drawHoursMenu(++currentMenuViewing); else { updateHours(&(rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].startTime), menuButtonTouched + 6); drawProgrammingScreen(currentProgramEditing); menuState = NONE; } break; case 4: if (menuButtonTouched == 1) drawHoursMenu(--currentMenuViewing); else if (menuButtonTouched == 2) { updateHours(&(rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].startTime), 11); drawProgrammingScreen(currentProgramEditing); menuState = NONE; } else if (menuButtonTouched == 3) { updateHours(&(rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].startTime), 12); drawProgrammingScreen(currentProgramEditing); menuState = NONE; } break; } } break; case MINUTES_MENU: menuButtonTouched = isVerticalMenuButtonTouched(x, y, minutesMenu); if(menuButtonTouched) { updateMinutes(&(rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].startTime), menuButtonTouched - 1); drawProgrammingScreen(currentProgramEditing); menuState = NONE; } break; case TEMP_MENU: menuButtonTouched = isVerticalMenuButtonTouched(x, y, programmingTempMenu); if(menuButtonTouched) { switch (currentMenuViewing) { case 1: if (menuButtonTouched == 5) drawProgrammingTempMenu(++currentMenuViewing); else { updateProgrammingTemp(&(rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].temperature), 59 + menuButtonTouched); drawProgrammingScreen(currentProgramEditing); menuState = NONE; } break; case 2: if (menuButtonTouched == 1) drawProgrammingTempMenu(--currentMenuViewing); else if (menuButtonTouched == 5) drawProgrammingTempMenu(++currentMenuViewing); else { updateProgrammingTemp(&(rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].temperature), 62 + menuButtonTouched); drawProgrammingScreen(currentProgramEditing); menuState = NONE; } break; case 3: if (menuButtonTouched == 1) drawProgrammingTempMenu(--currentMenuViewing); else if (menuButtonTouched == 5) drawProgrammingTempMenu(++currentMenuViewing); else { updateProgrammingTemp(&(rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].temperature), 65 + menuButtonTouched); drawProgrammingScreen(currentProgramEditing); menuState = NONE; } break; case 4: if (menuButtonTouched == 1) drawProgrammingTempMenu(--currentMenuViewing); else if (menuButtonTouched == 5) drawProgrammingTempMenu(++currentMenuViewing); else { updateProgrammingTemp(&(rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].temperature), 68 + menuButtonTouched); drawProgrammingScreen(currentProgramEditing); menuState = NONE; } break; case 5: if (menuButtonTouched == 1) drawProgrammingTempMenu(--currentMenuViewing); else if (menuButtonTouched == 5) drawProgrammingTempMenu(++currentMenuViewing); else { updateProgrammingTemp(&(rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].temperature), 71 + menuButtonTouched); drawProgrammingScreen(currentProgramEditing); menuState = NONE; } break; case 6: if (menuButtonTouched == 1) drawProgrammingTempMenu(--currentMenuViewing); else if (menuButtonTouched == 5) drawProgrammingTempMenu(++currentMenuViewing); else { updateProgrammingTemp(&(rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].temperature), 74 + menuButtonTouched); drawProgrammingScreen(currentProgramEditing); menuState = NONE; } break; case 7: if (menuButtonTouched == 1) drawProgrammingTempMenu(--currentMenuViewing); else if (menuButtonTouched == 5) drawProgrammingTempMenu(++currentMenuViewing); else { updateProgrammingTemp(&(rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].temperature), 77 + menuButtonTouched); drawProgrammingScreen(currentProgramEditing); menuState = NONE; } break; case 8: if (menuButtonTouched == 1) { drawProgrammingTempMenu(--currentMenuViewing); } else if (menuButtonTouched == 5) drawProgrammingTempMenu(++currentMenuViewing); else { updateProgrammingTemp(&(rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].temperature), 80 + menuButtonTouched); drawProgrammingScreen(currentProgramEditing); menuState = NONE; } break; case 9: if (menuButtonTouched == 1) { drawProgrammingTempMenu(--currentMenuViewing); } else { updateProgrammingTemp(&(rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].temperature), 83 + menuButtonTouched); drawProgrammingScreen(currentProgramEditing); menuState = NONE; } break; } } break; case PROGRAM_MODE_MENU: programmingModeMenu[1] = (1 + 3*(currentPeriodEditing+1)); menuButtonTouched = isHorizontalMenuButtonTouched(x, y, programmingModeMenu); switch (menuButtonTouched) { case 1: rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].mode = HEAT; drawProgrammingScreen(currentProgramEditing); menuState = NONE; break; case 2: rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].mode = COOL; drawProgrammingScreen(currentProgramEditing); menuState = NONE; break; case 3: rooms[currentRoom].programs[currentProgramEditing].periods[currentPeriodEditing].mode = OFF; drawProgrammingScreen(currentProgramEditing); menuState = NONE; break; } programmingModeMenu[1] = 1; break; } break; case DAYS_TAB: if (isButtonTouched(x, y, homeButton)) { drawMainScreen(); state = MAIN; menuState = NONE; } else if (isButtonTouched(x, y, settingsButton)) { drawSettingsScreen(); state = SETTINGS; menuState = NONE; } else if (isButtonTouched(x, y, programsTab)) { drawProgramsTab(); state = PROGRAMS_TAB; menuState = NONE; } switch (menuState) { case NONE: if (isButtonTouched(x, y, monButton)) { drawDaysMenu(monMenu); menuState = MONDAY; } else if (isButtonTouched(x, y, tueButton)) { drawDaysMenu(tueMenu); menuState = TUESDAY; } else if (isButtonTouched(x, y, wedButton)) { drawDaysMenu(wedMenu); menuState = WEDNESDAY; } else if (isButtonTouched(x, y, thuButton)) { drawDaysMenu(thuMenu); menuState = THURSDAY; } else if (isButtonTouched(x, y, friButton)) { drawDaysMenu(friMenu); menuState = FRIDAY; } else if (isButtonTouched(x, y, satButton)) { drawDaysMenu(satMenu); menuState = SATURDAY; } else if (isButtonTouched(x, y, sunButton)) { drawDaysMenu(sunMenu); menuState = SUNDAY; } break; case MONDAY: menuButtonTouched = isVerticalMenuButtonTouched(x, y, monMenu); if (menuButtonTouched) { weeklySchedule[0] = menuButtonTouched - 1; drawDaysTab(); menuState = NONE; } break; case TUESDAY: menuButtonTouched = isVerticalMenuButtonTouched(x, y, tueMenu); if (menuButtonTouched) { weeklySchedule[1] = menuButtonTouched - 1; drawDaysTab(); menuState = NONE; } break; case WEDNESDAY: menuButtonTouched = isVerticalMenuButtonTouched(x, y, wedMenu); if (menuButtonTouched) { weeklySchedule[2] = menuButtonTouched - 1; drawDaysTab(); menuState = NONE; } break; case THURSDAY: menuButtonTouched = isVerticalMenuButtonTouched(x, y, thuMenu); if (menuButtonTouched) { weeklySchedule[3] = menuButtonTouched - 1; drawDaysTab(); menuState = NONE; } break; case FRIDAY: menuButtonTouched = isVerticalMenuButtonTouched(x, y, friMenu); if (menuButtonTouched) { weeklySchedule[4] = menuButtonTouched - 1; drawDaysTab(); menuState = NONE; } break; case SATURDAY: menuButtonTouched = isVerticalMenuButtonTouched(x, y, satMenu); if (menuButtonTouched) { weeklySchedule[5] = menuButtonTouched - 1; drawDaysTab(); menuState = NONE; } break; case SUNDAY: menuButtonTouched = isVerticalMenuButtonTouched(x, y, sunMenu); if (menuButtonTouched) { weeklySchedule[6] = menuButtonTouched - 1; drawDaysTab(); menuState = NONE; } break; } break; case SETTINGS: if (isButtonTouched(x, y, homeButton)) { drawMainScreen(); state = MAIN; } else if (isButtonTouched(x, y, programButton)) { drawProgramsTab(); state = PROGRAMS_TAB; } break; } refreshThermostat(); } __RESET_WATCHDOG(); /* feeds the dog */ } /* loop forever */ /* please make sure that you never leave main */ }