mirror of
https://github.com/travisgoodspeed/goodwatch
synced 2024-11-22 08:09:13 +00:00
Refactoring and minor cleanup of RNG applet.
This commit is contained in:
parent
21da7246ca
commit
22b1e6ce10
@ -1,11 +1,11 @@
|
|||||||
/*! \file rngapp.c
|
/*! \file rngapp.c
|
||||||
\brief Demo random number generator app
|
\brief Demo random number generator app
|
||||||
|
|
||||||
This app will display random numbers on the display.
|
This app will display random numbers.
|
||||||
|
|
||||||
Press 0 to generate a new random number
|
Press 0 to generate a new random number.
|
||||||
Press 7 to diaply it in hexadecimal
|
Press 7 to display it in hexadecimal.
|
||||||
Press / to display it in decimal
|
Press / to display it in decimal.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
enum rng_disp_format_enum {DECIMAL, HEX};
|
enum rng_disp_format_enum {DECIMAL, HEX};
|
||||||
enum rng_disp_format_enum rng_disp_format;
|
enum rng_disp_format_enum rng_disp_format;
|
||||||
static unsigned int last_num = 0;
|
static unsigned int num = 0, last_num = 0;
|
||||||
|
|
||||||
//! Enter the rng tool.
|
//! Enter the rng tool.
|
||||||
void rngapp_init(){
|
void rngapp_init(){
|
||||||
@ -24,7 +24,7 @@ void rngapp_init(){
|
|||||||
}
|
}
|
||||||
//! Exit the rng tool.
|
//! Exit the rng tool.
|
||||||
int rngapp_exit(){
|
int rngapp_exit(){
|
||||||
last_num = 0; //leave only your footprints!
|
num = last_num = 0; //leave only your footprints!
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,29 +32,32 @@ int rngapp_exit(){
|
|||||||
int rngapp_keypress(char ch){
|
int rngapp_keypress(char ch){
|
||||||
switch(ch){
|
switch(ch){
|
||||||
case '0':
|
case '0':
|
||||||
last_num = true_rand();
|
num = true_rand();
|
||||||
break;
|
break;
|
||||||
case '7':
|
case '7':
|
||||||
rng_disp_format = HEX;
|
rng_disp_format = HEX;
|
||||||
|
last_num=0; //Dump old number to reconvert.
|
||||||
break;
|
break;
|
||||||
case '/':
|
case '/':
|
||||||
rng_disp_format = DECIMAL;
|
rng_disp_format = DECIMAL;
|
||||||
|
last_num=0; //Dump old number to reconvert.
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return 1; //Redraw.
|
return 1; //Redraw.
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Draw the screen
|
//! Draw the screen, only if the number has changed.
|
||||||
void rngapp_draw(){
|
void rngapp_draw(){
|
||||||
lcd_string(" ");
|
if (!num) {
|
||||||
if (!last_num) {
|
|
||||||
lcd_string("press 0 ");
|
lcd_string("press 0 ");
|
||||||
} else {
|
} else if (num!=last_num) {
|
||||||
|
last_num=num;
|
||||||
|
lcd_string(" ");
|
||||||
if (rng_disp_format == DECIMAL) {
|
if (rng_disp_format == DECIMAL) {
|
||||||
lcd_number(last_num);
|
lcd_number(num);
|
||||||
} else {
|
} else {
|
||||||
lcd_hex(last_num);
|
lcd_hex(num);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user