// In display.h...
enum text_widget_ids
{
ID_ST_MEANINGFUL_NAME_1=1, // Start your widget id's at 1
ID_ST_MEANINGFUL_NAME_2,
ID_ST_MEANINGFUL_NAME_3,
ID_ST_SPLASH_TEXT,
ID_ST_ADC_DISPLAY,
// add new ID's above this line
END_OF_ST_WIDGET_LIST,
NBR_ST_WIDGETS=END_OF_ST_WIDGET_LIST-1,
};
#define MAX_TXT_LENGTH 20
enum draw_states
{
DRAW_STATE_CLEAR=0;
DRAW_STATE_CREATE_ITEMS,
DRAW_STATE_REFRESH,
};
typedef enum draw_states draw_state_type;
extern void Service_Display( void );
// In display.c...
char display_buffer[NBR_ST_WIDGETS][MAX_TXT_LENGTH+10]; // add 10 bytes in case of accidental overflows
int last_drawn_display;
GOL_SCHEME *white_on_blue;
GOL_SCHEME *white_on_black;
void Draw_Screen_1( void );
void Draw_Screen_2( void );
void Draw_ADC_Screen( void );
void Draw_Power_Down_Screen( void );
void Draw_Startup_Screen( void );
void Init_Schemes( void );
void Init_Schemes( void )
{
static unsigned char initialized = FALSE;
GOLFree(); // blow away all of the widgets
if (!initialized)
{
initialized = TRUE;
white_on_blue = GOLCreateScheme();
white_on_black = GOLCreateScheme();
white_on_blue -> TextColor0 = WHITE;
white_on_blue -> CommonBkColor = SCREEN_SELECTED_COLOR;
white_on_blue -> pFont = (void*)&verdana_14;
white_on_black -> TextColor0 = WHITE;
white_on_black -> CommonBkColor = SCREEN_NOT_SELECTED_COLOR;
white_on_black -> pFont = (void*)&verdana_14;
}
}
void Service_Display( void )
{
switch (app_state) // I have app_state defined elsewhere. app state is used to
{ // control the flow of the program... app_state may be
case STARTUP: // WAIT_FOR_USER_INPUT, or MEASURE_ADC_VALUE, or STARTUP, etc
Draw_Startup_Screen();
break;
case MEASURE_ADC_VALUE:
Draw_ADC_Screen();
break;
case POWER_DOWN:
Draw_Power_Down_Screen();
break;
}
}
void Draw_Startup_Screen( void )
{
static draw_state_type draw_state;
if (last_drawn_display != __LINE__) // this will detect when the screen changes
{
last_drawn_display = __LINE__-2;
draw_state = DRAW_CLEAR;
}
case DRAW_STATE_CLEAR:
SetColor( BACKGROUND_COLOR );
ClearDevice();
draw_state = DRAW_CREATE_ITEMS;
break;
case DRAW_CREATE_ITEMS:
StCreate( ID_ST_SPLASH_TEXT, 10, 10, GetMaxX()-10, 20, ST_DRAW | ST_CENTER_ALIGN, display_buffer[ID_ST_SPLASH_TEXT], white_on_black );
sprintf( display_buffer[ID_ST_SPLASH_TEXT], "My Awesome Program!" );
break;
case DRAW_STATE_REFRESH:
GOLDraw();
break;
}
void Draw_ADC_Screen( void )
{
static draw_state_type draw_state;
static int initialized = FALSE;
static int last_displayed_voltage;
static int adc_update_counter = 0;
#define ADC_UPDATE_DELAY (250/SERVICE_DISPLAY_DELAY) // SERVICE_DISPLAY_DELAY should be defined as the number of mS between calls to Service_Display
// That will make this delay equal to 250 mS (refresh the display 4 times per second)
if (last_drawn_display != __LINE__) // this will detect when the screen changes
{
last_drawn_display = __LINE__-2;
draw_state = DRAW_CLEAR;
initialized = FALSE;
}
case DRAW_STATE_CLEAR:
SetColor( BACKGROUND_COLOR );
ClearDevice();
draw_state = DRAW_CREATE_ITEMS;
break;
case DRAW_CREATE_ITEMS:
StCreate( ID_ST_ADC_DISPLAY, 10, 10, GetMaxX()-10, 20, ST_DRAW | ST_CENTER_ALIGN, display_buffer[ID_ST_ADC_DISPLAY], white_on_black );
break;
case DRAW_STATE_REFRESH:
if (((last_displayed_voltage != voltage_x1000) && (adc_update_counter < ADC_UPDATE_DELAY)) || !initialized)
{
adc_update_counter = 0;
last_displayed_voltage = voltage_x1000;
sprintf( display_buffer[ID_ST_ADC_DISPLAY], "%5u.%03u", voltage_x1000 / 1000, voltage_x1000 % 1000 );
SetState( (STATICTEXT*)GOLFindObject(ID_ST_ADC_DISPLAY), ST_DRAW );
}
if (adc_update_counter < ADC_UPDATE_DELAY)
adc_update_counter++;
initialized = TRUE;
GOLDraw();
break;
}
// in main.c
void main( void )
{
Init_Stuff();
Init_Display_Timer();
while (1)
{
Do_Stuff_1();
Do_Stuff_2();
Do_Stuff_3();
if (Display_Timer_Expired())
{
Init_Display_Timer();
Service_Display();
}
}
}