]> code.bitgloo.com Git - clyne/calculator.git/commitdiff
status bar, arrow keys, ins/del
authorClyne Sullivan <tullivan99@gmail.com>
Thu, 12 Apr 2018 00:49:32 +0000 (20:49 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Thu, 12 Apr 2018 00:49:32 +0000 (20:49 -0400)
include/display_draw.h
include/keypad.h
initrd/init
src/display_draw.c
src/keypad.c
src/main.c
src/script.c

index 8db3e2ce22c4d259328e14e4951e442b59acc0a5..1057a1c58851af29822d8a544e7b846542798895 100644 (file)
@@ -63,6 +63,11 @@ void dsp_rect(int x, int y, int w, int h, uint16_t color);
  */
 void dsp_cpos(int x, int y);
 
+/*
+ * Shifts the cursor the given amount of characters.
+ */
+void dsp_spos(int x, int y);
+
 /**
  * Sets the pixel offset of the text cursor.
  * @param x x-pixel offset from (0, 0)
index 5263a0d65b676215048067b604a5a9561e02e666..d55b86776f3922fd8994bfae1ac611b2b33a6dfb 100644 (file)
 
 #include <stdint.h>
 
+#define K_UP    0x18
+#define K_DOWN  0x19
+#define K_LEFT  0x1B
+#define K_RIGHT 0x1A
+
 /**
  * Initializes GPIO for the keypad.
  * Starts a task to poll the buttons. Must be called before any keypad reading.
index 6c5acace97143e09e8e4ced2205917597c1b69e3..68ef07d2567303b087c6232ef6433149a4d4d872 100644 (file)
@@ -1,5 +1,5 @@
 while (1) {
-       rect(0, 0, 480, 320, 0)
+       rect(0, 0, 480, 300, 0)
        ppos(0, 0)
 
        print("Free mem: ")
index f02b8a028787af9475a6344f3b34347b4bff9f41..97ee386266f81ca39d7afd251de1ae8b908ae42c 100644 (file)
@@ -28,7 +28,7 @@
 #define C_WIDTH  12
 #define C_HEIGHT 16
 #define S_WIDTH  40
-#define S_HEIGHT 20
+#define S_HEIGHT 18
 
 volatile uint8_t lock = 0;
 #define LOCK while (lock) { delay(5); } task_hold(1); lock = 1
@@ -66,7 +66,7 @@ void dsp_putchar(int c)
                curx = 0;
                if (++cury == S_HEIGHT) {
                        UNLOCK;
-                       dsp_rect(0, 0, LCD_WIDTH, LCD_HEIGHT, 0);
+                       dsp_rect(0, 0, C_WIDTH * S_WIDTH, C_HEIGHT * S_HEIGHT, 0);
                        cury = 0;
                }
                UNLOCK;
@@ -120,6 +120,14 @@ void dsp_cpos(int x, int y)
        cury = y;
 }
 
+void dsp_spos(int x, int y)
+{
+       if ((int)curx + x >= 0)
+               curx += x;
+       if ((int)cury + y >= 0)
+               cury += y;
+}
+
 void dsp_coff(int x, int y)
 {
        curxo = x;
index 58bc50813f83536cca5930e90c74e967f69ba573..b00cf4105bed508e33d4ddf00cb990591e5827a8 100644 (file)
@@ -55,23 +55,24 @@ static const port_t keypad_cols[COLS] = {
 
 #define K_2ND  0x000000FF
 #define K_HOLD 0x000001FF
+#define K_INS  0x000002FF
 
 static const char keypad_map[ROWS * COLS * 4] = {
-       "\x7F\0\0\0" ">\0\0\0" ">=\0\0"     "==\0\0"   "=\0\0\0"
-       "x\0\0\0"    "<\0\0\0" "<=\0\0"     "!=\0\0"   "%\0\0\0"
-       "7\0\0\0"    "8\0\0\0" "9\0\0\0"    "(\0\0\0"  ")\0\0\0"
-       "4\0\0\0"    "5\0\0\0" "6\0\0\0"    "/\0\0\0"  "*\0\0\0"
-       "1\0\0\0"    "2\0\0\0" "3\0\0\0"    "-\0\0\0"  "+\0\0\0"
-       ".\0\0\0"    "0\0\0\0" "\xFF\0\0\0" "\b\0\0\0" "\n\0\0\0"
+       "\x7F\0\0\0" "\xFF\0\0\0" "\xFF\x02\0\0" "\x19\0\0\0" "\x18\0\0\0"
+       "x\0\0\0"    "\0\0\0\0"   "\0\0\0\0" "\x1B\0\0\0" "\x1A\0\0\0"
+       "7\0\0\0"    "8\0\0\0"    "9\0\0\0"  "(\0\0\0"    ")\0\0\0"
+       "4\0\0\0"    "5\0\0\0"    "6\0\0\0"  "/\0\0\0"    "*\0\0\0"
+       "1\0\0\0"    "2\0\0\0"    "3\0\0\0"  "-\0\0\0"    "+\0\0\0"
+       ".\0\0\0"    "0\0\0\0"    "=\0\0\0"  "\b\0\0\0"   "\n\0\0\0"
 };
 
 static const char keypad_map_2nd[ROWS * COLS * 4] = {
-       "a\0\0\0" "b\0\0\0"  "c\0\0\0"  "d\0\0\0"      "e\0\0\0"
-       "f\0\0\0" "g\0\0\0"  "h\0\0\0"  "i\0\0\0"      "j\0\0\0"
-       "k\0\0\0" "l\0\0\0"  "m\0\0\0"  "n\0\0\0"      "o\0\0\0"
-       "p\0\0\0" "q\0\0\0"  "r\0\0\0"  "s\0\0\0"      "t\0\0\0"
-       "u\0\0\0" "v\0\0\0"  "w\0\0\0"  "x\0\0\0"      "y\0\0\0"
-       "z\0\0\0" "\0\0\0\0" "\0\0\0\0" "\x7F\0\0\0" "\xFF\x01\0\0"
+       "a\0\0\0" "b\0\0\0"  "c\0\0\0"  "d\0\0\0"  "e\0\0\0"
+       "f\0\0\0" "g\0\0\0"  "h\0\0\0"  "i\0\0\0"  "j\0\0\0"
+       "k\0\0\0" "l\0\0\0"  "m\0\0\0"  "n\0\0\0"  "o\0\0\0"
+       "p\0\0\0" "q\0\0\0"  "r\0\0\0"  "s\0\0\0"  "t\0\0\0"
+       "u\0\0\0" "v\0\0\0"  "w\0\0\0"  "x\0\0\0"  "y\0\0\0"
+       "z\0\0\0" "\0\0\0\0" "\0\0\0\0" "\0\0\0\0" "\xFF\x01\0\0"
 };
 
 #define KEY(r, c, i) map[r * COLS * 4 + c * 4 + i]
@@ -81,6 +82,8 @@ static const char keypad_map_2nd[ROWS * COLS * 4] = {
 static char keypad_buffer[BUFFER_SIZE];
 static int keypad_buffer_pos = -1;
 
+int keypad_insert = 0;
+
 void keypad_task(void)
 {
        unsigned int col = 0;
@@ -99,6 +102,8 @@ void keypad_task(void)
                                                if ((hold ^= 1) == 0)
                                                        use2nd = 0;
                                        }
+                               } else if (KEYCODE(row, col) == K_INS) {
+                                       keypad_insert ^= 1;
                                } else if (keypad_buffer_pos < BUFFER_SIZE) {
                                        if (use2nd != 0 && hold == 0)
                                                use2nd = 0;
index 4d6f140fbce7a6f43635064a91f4e47df1a35540..a86db6aa79aa608020ae2107366f5116056654bc 100644 (file)
@@ -40,6 +40,7 @@ extern char *itoa(int, char *, int);
 \r
 void kmain(void);\r
 void task_interpreter(void);\r
+void task_status(void);\r
 \r
 int main(void)\r
 {\r
@@ -77,6 +78,7 @@ void kmain(void)
        keypad_start();\r
 \r
        task_start(task_interpreter, 4096);\r
+       task_start(task_status, 512);\r
 \r
        while (1) {\r
                gpio_dout(GPIOA, 5, 1);\r
@@ -125,6 +127,34 @@ fail:
        return 0;\r
 }\r
 \r
\r
+\r
+void task_status(void)\r
+{\r
+       extern int keypad_insert;\r
+\r
+       int lastInsert = -1;\r
+\r
+       int16_t bg = dsp_color(0x3F, 0x3F, 0x3F);\r
+       int16_t red = dsp_color(0xFF, 0, 0);\r
+       int16_t green = dsp_color(0, 0xFF, 0);\r
+\r
+       dsp_rect(0, 300, 480, 20, bg);\r
+\r
+       while (1) {\r
+               if (lastInsert != keypad_insert) {\r
+                       lastInsert = keypad_insert;\r
+                       dsp_rect(0, 300, 480, 20, bg);\r
+                       if (lastInsert > 0)\r
+                               dsp_rect(4, 304, 12, 12, green);\r
+                       else\r
+                               dsp_rect(4, 304, 12, 12, red);\r
+               }\r
+\r
+               delay(500);\r
+       }\r
+}\r
+\r
 void task_interpreter(void)\r
 {\r
        instance *it = load_program("init");\r
index 61ff598b1bb85bddb38a7475acfff86698bffcdf..51a3bb7eb06eb1a33a60aad1a5665d40bfec869f 100644 (file)
@@ -168,6 +168,7 @@ int script_gets(instance *it)
        char *s = malloc(64);
        char c[2] = {0, 0};
        int index = 0;
+       int furthest = 0;
 
        do {
                do {
@@ -178,9 +179,32 @@ int script_gets(instance *it)
                if (c[0] == 0x7F) {
                        it->lnidx = 998;
                        break;
+               } else if (c[0] == K_LEFT) {
+                       if (index > 0) {
+                               dsp_spos(-1, 0);
+                               index--;
+                       }
+                       continue;
+               } else if (c[0] == K_RIGHT) {
+                       if (index < furthest) {
+                               dsp_spos(1, 0);
+                               index++;
+                       }
+                       continue;
+               } else if (c[0] == K_UP || c[0] == K_DOWN)
+                       continue;
+
+               if (c[0] == '\n') {
+                       s[furthest] = '\n';
+                       break;
+               }
+
+               extern int keypad_insert;
+               if (keypad_insert != 0 && index < furthest) {
+                       for (int i = furthest; i >= index; i--)
+                               s[i] = s[i - 1];
                }
 
-               //c[0] = serial_get();
                s[index] = c[0];
                if (c[0] == '\b' || c[0] == 127) {
                        index--;
@@ -188,11 +212,20 @@ int script_gets(instance *it)
                                dsp_puts("\b");
                                index--;
                        }
+               } else if (keypad_insert != 0) {
+                       dsp_spos(-index, 0);
+                       s[furthest + 1] = '\0';
+                       dsp_puts(s);
+                       dsp_spos(-(furthest - index), 0);
+                       furthest++;
                } else if (c[0] != '\n'/*'\r'*/) {
                        dsp_puts(c);
                }
-       } while (s[index] != '\n'/*'\r'*/ && index++ < 63);
-       s[index] = '\0';
+
+               if (++index > furthest)
+                       furthest = index;
+       } while (furthest < 63);
+       s[furthest] = '\0';
 
        variable *r = make_vars(0, s);
        ipush(it, (uint32_t)r);
@@ -274,7 +307,7 @@ int script_program(instance *it)
        int initrdOffset = (int)igetarg(it, 0)->value.f;
        char *name = initrd_getname(initrdOffset);
 
-       dsp_rect(0, 0, 480, 320, 0);
+       dsp_rect(0, 0, 480, 300, 0);
        dsp_cpos(0, 0);
        dsp_coff(0, 0);