mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
Add the trig menu.
Change-Id: Ifbe2518cb3a089dace82d56031987fbc7a2e6181
This commit is contained in:
@@ -34,6 +34,85 @@ static void print_prompt(char* text, int index) {
|
||||
KDDrawChar(text[index], KDPointMake(index * font_size.width, SCREEN_HEIGHT - (PROMPT_HEIGHT / 2)), true);
|
||||
}
|
||||
|
||||
static void clear_trig_menu() {
|
||||
{
|
||||
KDRect r;
|
||||
r.x = SCREEN_WIDTH / 4 - 1;
|
||||
r.y = SCREEN_HEIGHT / 4 - 1;
|
||||
r.width = SCREEN_WIDTH / 2 + 2;
|
||||
r.height = SCREEN_HEIGHT / 2 + 2;
|
||||
KDFillRect(r, 0x00);
|
||||
}
|
||||
}
|
||||
|
||||
static void print_trig_menu() {
|
||||
{
|
||||
KDRect r;
|
||||
r.x = SCREEN_WIDTH / 4 - 1;
|
||||
r.y = SCREEN_HEIGHT / 4 - 1;
|
||||
r.width = SCREEN_WIDTH / 2 + 2;
|
||||
r.height = SCREEN_HEIGHT / 2 + 2;
|
||||
KDFillRect(r, 0xFF);
|
||||
}
|
||||
{
|
||||
KDRect r;
|
||||
r.x = SCREEN_WIDTH / 4;
|
||||
r.y = SCREEN_HEIGHT / 4;
|
||||
r.width = SCREEN_WIDTH / 2;
|
||||
r.height = SCREEN_HEIGHT / 2;
|
||||
KDFillRect(r, 0x00);
|
||||
}
|
||||
}
|
||||
|
||||
static int get_trig_input(char* input) {
|
||||
int pos = 0;
|
||||
const char* kTexts[] = {
|
||||
"sine",
|
||||
"cosine",
|
||||
"tangent",
|
||||
"cancel"
|
||||
};
|
||||
const char* kOutputs[] = {
|
||||
"sin( )",
|
||||
"cos( )",
|
||||
"tan( )",
|
||||
};
|
||||
const KDPoint orig = KDPointMake(SCREEN_WIDTH / 4, SCREEN_HEIGHT / 4);
|
||||
while (true) {
|
||||
print_trig_menu();
|
||||
|
||||
uint16_t vert_acc = 0;
|
||||
for (int i(0); i<4; i++) {
|
||||
KDSize text_size = KDStringSize(kTexts[i]);
|
||||
KDDrawString(kTexts[i],
|
||||
KDPointMake(orig.x, orig.y + vert_acc + text_size.height / 2),
|
||||
i==pos);
|
||||
vert_acc += text_size.height;
|
||||
}
|
||||
|
||||
ion_event_t event = ion_get_event();
|
||||
if (event == UP_ARROW) {
|
||||
pos--;
|
||||
if (pos < 0) {
|
||||
pos = 0;
|
||||
}
|
||||
} else if (event == DOWN_ARROW) {
|
||||
pos++;
|
||||
if (pos >= 4) {
|
||||
pos = 3;
|
||||
}
|
||||
} else if (event == '=') {
|
||||
clear_trig_menu();
|
||||
if (pos == 3) {
|
||||
return 0;
|
||||
} else {
|
||||
memcpy(input, kOutputs[pos], (size_t) strlen(kOutputs[pos]));
|
||||
return strlen(kOutputs[pos]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
char* get_text() {
|
||||
char input[255] = {0};
|
||||
int index = 0;
|
||||
@@ -60,10 +139,20 @@ char* get_text() {
|
||||
input[index++] = (char) event;
|
||||
// We are at the end of the line.
|
||||
if (index > max) {
|
||||
max++;
|
||||
max=index;
|
||||
input[max] = ' ';
|
||||
input[max+1] = '\0';
|
||||
}
|
||||
} else if (event == TRIG_MENU) {
|
||||
int tmp = get_trig_input(&input[index]);
|
||||
index+=tmp;
|
||||
if (index > max) {
|
||||
max=index;
|
||||
input[max] = ' ';
|
||||
input[max+1] = '\0';
|
||||
}
|
||||
// we want to be inside the parenthese if there are some.
|
||||
index -= (tmp > 2) ? 2 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,9 @@ typedef enum {
|
||||
LOWER_CASE_Z,
|
||||
LEFT_ARROW = 0x100, // events for things outside of ASCII.
|
||||
RIGHT_ARROW,
|
||||
MENU_TRIG,
|
||||
UP_ARROW,
|
||||
DOWN_ARROW,
|
||||
TRIG_MENU,
|
||||
ERROR = 0xffffffff,
|
||||
} ion_event_t;
|
||||
|
||||
|
||||
@@ -49,8 +49,8 @@ static ion_key_event_t ion_get_key_event() {
|
||||
// For now this is a bit silly but needed for instreface purpose.
|
||||
static const ion_event_t kEventForKeyDown[ION_NUMBER_OF_KEYS] = {
|
||||
UPPER_CASE_A, UPPER_CASE_B, UPPER_CASE_C, UPPER_CASE_D, UPPER_CASE_E,
|
||||
UPPER_CASE_F, UPPER_CASE_G, UPPER_CASE_H, UPPER_CASE_I, UPPER_CASE_J,
|
||||
UPPER_CASE_K, UPPER_CASE_L, UPPER_CASE_M, LEFT_ARROW, RIGHT_ARROW,
|
||||
UPPER_CASE_F, UPPER_CASE_G, UPPER_CASE_H, UP_ARROW, DOWN_ARROW,
|
||||
UPPER_CASE_K, UPPER_CASE_L, TRIG_MENU, LEFT_ARROW, RIGHT_ARROW,
|
||||
SEVEN, EIGHT, NINE, LEFT_PARENTHESIS, RIGHT_PARENTHESIS,
|
||||
FOUR, FIVE, SIX, PRODUCT, DIVISION,
|
||||
ONE, TWO, THREE, PLUS, MINUS,
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
|
||||
static const char* kCharForKey[KEYBOARD_ROWS * KEYBOARD_COLUMNS] = {
|
||||
"A", "B", "C", "D", "E",
|
||||
"F", "G", "H", "I", "J",
|
||||
"K", "L", "M", "LEFT", "RIGHT",
|
||||
"F", "G", "H", "UP", "DOWN",
|
||||
"K", "L", "TRIG", "LEFT", "RIGHT",
|
||||
"7", "8", "9", "(", ")",
|
||||
"4", "5", "6", "*", "/",
|
||||
"1", "2", "3", "+", "-",
|
||||
|
||||
@@ -5,6 +5,6 @@
|
||||
|
||||
void KDDrawChar(char character, KDPoint p, uint8_t inverse);
|
||||
void KDDrawString(const char * text, KDPoint p, uint8_t inverse);
|
||||
KDSize KDStringSize(char * text);
|
||||
KDSize KDStringSize(const char * text);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,7 +23,7 @@ void KDDrawString(const char * text, KDPoint p, uint8_t inverse) {
|
||||
}
|
||||
}
|
||||
|
||||
KDSize KDStringSize(char * text) {
|
||||
KDSize KDStringSize(const char * text) {
|
||||
return (KDSize){
|
||||
.width = strlen(text)*BITMAP_FONT_CHARACTER_WIDTH,
|
||||
.height = BITMAP_FONT_CHARACTER_HEIGHT
|
||||
|
||||
Reference in New Issue
Block a user