]> code.bitgloo.com Git - clyne/calculator.git/commitdiff
better keypad stuff
authorClyne Sullivan <tullivan99@gmail.com>
Fri, 30 Mar 2018 03:08:11 +0000 (23:08 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Fri, 30 Mar 2018 03:08:11 +0000 (23:08 -0400)
Makefile
libinterp.a
src/keypad.c
src/script.c

index 9620aa46bdff0c6cc61b5f2f4bedf031efad557c..b3acc2af2576d524b4d28d58a9c694834c121d0f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -53,7 +53,7 @@ $(OUT): $(OFILES) initrd/init libinterp.a
        @$(CROSS)$(AR) r $(INITRD) initrd/*
        @$(CROSS)$(OBJCOPY) -B arm -I binary -O elf32-littlearm $(INITRD) out/initrd.img.o
        @echo "  LINK   " $(OUT)
-       @$(CROSS)$(CC) $(CFLAGS) $(LFLAGS) out/*.o -o $(OUT) -L. -linterp
+       @$(CROSS)$(CC) $(CFLAGS) $(LFLAGS) out/*.o -o $(OUT) -L. -linterp -lm
 
 $(OUTDIR)/%.o: src/%.c
        @echo "  CC     " $<
index a485352ff9c5eb2672f03a312ff0e174cb2487a4..7c9e7a9a51dede0cc646cc5be8663838b5e2fc2f 100644 (file)
Binary files a/libinterp.a and b/libinterp.a differ
index 5fe25379f27e3c04ab6c2b51daa14f158fd9a4e6..5b04eec040b23bd70ab15270fbb578287b5b6775 100644 (file)
@@ -53,18 +53,20 @@ static const port_t keypad_cols[COLS] = {
        { COL_3 }, { COL_4 }
 };
 
-static const int keypad_map[ROWS][COLS] = {
-       { '&', '|', '^',  ' ',  ' ' },
-       { 'x', 'y', 'z',  '=',  ' ' },
-       { '7', '8', '9',  '(',  ')' },
-       { '4', '5', '6',  '/',  '%' },
-       { '1', '2', '3',  '*',  '-' },
-       { '.', '0', '\b', '\n', '+' }
+static const char keypad_map[ROWS * COLS * 4] = {
+       "&\0\0\0" "|\0\0\0" "pi\0\0"  "==\0\0"   "!=\0\0"
+       "x\0\0\0" "y\0\0\0" "z\0\0\0"  "=\0\0\0"  "sin\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" "\b\0\0\0" "\n\0\0\0" "+\0\0\0"
 };
 
+#define KEY(r, c, i) keypad_map[r * COLS * 4 + c * 4 + i]
+
 #define BUFFER_SIZE 8
-static char keypad_buffer = 0;//[BUFFER_SIZE];
-//static int keypad_buffer_pos = -1;
+static char keypad_buffer[BUFFER_SIZE];
+static int keypad_buffer_pos = -1;
 
 void keypad_task(void)
 {
@@ -74,8 +76,10 @@ void keypad_task(void)
                delay(10);
                for (unsigned int row = 0; row < ROWS; row++) {
                        if (gpio_din(keypad_rows[row].port, keypad_rows[row].pin)) {
-                               //if (keypad_buffer_pos < BUFFER_SIZE)
-                                       keypad_buffer/*[++keypad_buffer_pos]*/ = keypad_map[row][col];
+                               if (keypad_buffer_pos < BUFFER_SIZE) {
+                                       for (unsigned int i = 0; KEY(row, col, i) != '\0'; i++)
+                                               keypad_buffer[++keypad_buffer_pos] = KEY(row, col, i);
+                               }
                                while (gpio_din(keypad_rows[row].port, keypad_rows[row].pin))
                                        delay(1);
                                break;
@@ -117,15 +121,12 @@ void keypad_start(void)
 
 int keypad_get(void)
 {
-       //if (keypad_buffer_pos < 0)
-       //      return 0;
-
-       //int key = keypad_buffer[0];
-       //for (int i = keypad_buffer_pos - 1; i > 0; i--)
-       //      keypad_buffer[i - 1] = keypad_buffer[i];
-       //keypad_buffer_pos--;
-       //return key;
-       int ret = keypad_buffer;
-       keypad_buffer = 0;
-       return ret;
+       if (keypad_buffer_pos < 0)
+               return 0;
+
+       int key = keypad_buffer[0];
+       for (int i = 0; i < BUFFER_SIZE - 1; i++)
+               keypad_buffer[i] = keypad_buffer[i + 1];
+       keypad_buffer_pos--;
+       return key;
 }
index 049608b999b96aa03d524b13d43cc2f989c5bb1d..733bc4ac4bf548453d70fc78ea7cc9582e0ebeed 100644 (file)
 #include <display_draw.h>
 #include <heap.h>
 #include <initrd.h>
+#include <it/string.h>
+#include <keypad.h>
+#include <math.h>
 #include <random.h>
 #include <serial.h>
 #include <stdlib.h>
-#include <it/string.h>
-#include <keypad.h>
 
 #define igetarg_integer(it, n) ((int)igetarg(it, n)->value.f)
 
@@ -48,8 +49,12 @@ int script_pixel(instance *it);
 int script_menu(instance *it);
 int script_filemenu(instance *it);
 
+int math_sin(instance *it);
+
 void script_loadlib(instance *it)
 {
+       inew_number(it, "pi", 3.1415926f);
+
        inew_cfunc(it, "print", script_puts);
        inew_cfunc(it, "putchar", script_putchar);
        inew_cfunc(it, "gets", script_gets);
@@ -66,6 +71,16 @@ void script_loadlib(instance *it)
 
        inew_cfunc(it, "menu", script_menu);
        inew_cfunc(it, "filemenu", script_filemenu);
+
+       inew_cfunc(it, "sin", math_sin);
+}
+
+int math_sin(instance *it)
+{
+       variable *n = igetarg(it, 0);
+       variable *v = make_varf(0, sinf(n->value.f));
+       ipush(it, (uint32_t)v);
+       return 0;
 }
 
 int script_menu(instance *it)