*/
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)
#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.
while (1) {
- rect(0, 0, 480, 320, 0)
+ rect(0, 0, 480, 300, 0)
ppos(0, 0)
print("Free mem: ")
#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
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;
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;
#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]
static char keypad_buffer[BUFFER_SIZE];
static int keypad_buffer_pos = -1;
+int keypad_insert = 0;
+
void keypad_task(void)
{
unsigned int col = 0;
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;
\r
void kmain(void);\r
void task_interpreter(void);\r
+void task_status(void);\r
\r
int main(void)\r
{\r
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
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
char *s = malloc(64);
char c[2] = {0, 0};
int index = 0;
+ int furthest = 0;
do {
do {
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--;
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);
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);