goodwatch/firmware/apps/rngapp.c
Travis Goodspeed 6e42d34da4 Major cleanup to keyscanning code, prevents right column from being stuck.
Apps can now opt to redraw by returning non-zero from a keypress.
Flicker is now more reliable.
2018-02-08 17:21:58 -05:00

61 lines
1.1 KiB
C

/*! \file rngapp.c
\brief Demo random number generator app
This app will display random numbers on the display.
Press 0 to generate a new random number
Press 7 to diaply it in hexadecimal
Press / to display it in decimal
*/
#include <stdio.h>
#include <stdlib.h>
#include <msp430.h>
#include "api.h"
#include "rng.h"
enum rng_disp_format_enum {DECIMAL, HEX};
enum rng_disp_format_enum rng_disp_format;
static unsigned int last_num = 0;
//! Enter the rng tool.
void rngapp_init(){
rng_disp_format = DECIMAL;
}
//! Exit the rng tool.
int rngapp_exit(){
last_num = 0; //leave only your footprints!
return 0;
}
//! Handle a keypress in the rng application.
int rngapp_keypress(char ch){
switch(ch){
case '0':
last_num = true_rand();
break;
case '7':
rng_disp_format = HEX;
break;
case '/':
rng_disp_format = DECIMAL;
break;
}
return 1; //Redraw.
}
//! Draw the screen
void rngapp_draw(){
lcd_string(" ");
if (!last_num) {
lcd_string("press 0 ");
} else {
if (rng_disp_format == DECIMAL) {
lcd_number(last_num);
} else {
lcd_hex(last_num);
}
}
}