Contains the main program, which is a basic state machine.
Definition in file main.c.
#include <ioavr.h>
#include <inavr.h>
#include <stdlib.h>
#include "structs.h"
#include "main.h"
#include "ADC.h"
#include "statefunc.h"
#include "battery.h"
#include "menu.h"
#include "OWI.h"
#include "PWM.h"
#include "time.h"
#include "USI.h"
Go to the source code of this file.
Functions | |
int | main (void) |
Main program. | |
Variables | |
unsigned char | CurrentState |
Global that indicates current state. |
int main | ( | void | ) |
Main program.
The main function goes into an infinite loop, keeping track of the current state and the next one. If the next state is different from the current, it looks up the address to the next state function, in menu_state[], and updates CurrentState. The state function is then called and will eventually return a new state, and so the loop reiterates.
Definition at line 98 of file main.c.
References CurrentState, menu_state, MENU_STATE_struct::pFunc, ST_INIT, MENU_STATE_struct::state, TRUE, and ZERO.
00099 { 00100 unsigned char nextstate, inp, i; 00101 unsigned char (*pStateFunc)(unsigned char); // Function pointer. 00102 00103 // Initialize local state variables. 00104 inp = ZERO; 00105 CurrentState = nextstate = ST_INIT; 00106 pStateFunc = NULL; 00107 00108 // Look for function associated with current state, get its address. 00109 for (i = 0; menu_state[i].state != 0; i++) { 00110 if (menu_state[i].state == CurrentState) { 00111 pStateFunc = menu_state[i].pFunc; 00112 } 00113 } 00114 00115 while (TRUE) { 00116 // Run function associated with current state, get next state in return. 00117 if (pStateFunc != NULL){ 00118 nextstate = pStateFunc(inp); 00119 } 00120 00121 // Look up function for next state, if it differs from the current. 00122 if (nextstate != CurrentState) { 00123 CurrentState = nextstate; 00124 for ( i = 0; menu_state[i].state != 0; i++) { 00125 if (menu_state[i].state == CurrentState) { 00126 pStateFunc = menu_state[i].pFunc; 00127 } 00128 } 00129 } 00130 } 00131 }
unsigned char CurrentState |