status bar, arrow keys, ins/del

master
Clyne Sullivan 7 years ago
parent 0726b60a6e
commit 8e11f269ce

@ -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); 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. * Sets the pixel offset of the text cursor.
* @param x x-pixel offset from (0, 0) * @param x x-pixel offset from (0, 0)

@ -23,6 +23,11 @@
#include <stdint.h> #include <stdint.h>
#define K_UP 0x18
#define K_DOWN 0x19
#define K_LEFT 0x1B
#define K_RIGHT 0x1A
/** /**
* Initializes GPIO for the keypad. * Initializes GPIO for the keypad.
* Starts a task to poll the buttons. Must be called before any keypad reading. * Starts a task to poll the buttons. Must be called before any keypad reading.

@ -1,5 +1,5 @@
while (1) { while (1) {
rect(0, 0, 480, 320, 0) rect(0, 0, 480, 300, 0)
ppos(0, 0) ppos(0, 0)
print("Free mem: ") print("Free mem: ")

@ -28,7 +28,7 @@
#define C_WIDTH 12 #define C_WIDTH 12
#define C_HEIGHT 16 #define C_HEIGHT 16
#define S_WIDTH 40 #define S_WIDTH 40
#define S_HEIGHT 20 #define S_HEIGHT 18
volatile uint8_t lock = 0; volatile uint8_t lock = 0;
#define LOCK while (lock) { delay(5); } task_hold(1); lock = 1 #define LOCK while (lock) { delay(5); } task_hold(1); lock = 1
@ -66,7 +66,7 @@ void dsp_putchar(int c)
curx = 0; curx = 0;
if (++cury == S_HEIGHT) { if (++cury == S_HEIGHT) {
UNLOCK; 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; cury = 0;
} }
UNLOCK; UNLOCK;
@ -120,6 +120,14 @@ void dsp_cpos(int x, int y)
cury = 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) void dsp_coff(int x, int y)
{ {
curxo = x; curxo = x;

@ -55,14 +55,15 @@ static const port_t keypad_cols[COLS] = {
#define K_2ND 0x000000FF #define K_2ND 0x000000FF
#define K_HOLD 0x000001FF #define K_HOLD 0x000001FF
#define K_INS 0x000002FF
static const char keypad_map[ROWS * COLS * 4] = { static const char keypad_map[ROWS * COLS * 4] = {
"\x7F\0\0\0" ">\0\0\0" ">=\0\0" "==\0\0" "=\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\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" "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" "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" "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" ".\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] = { static const char keypad_map_2nd[ROWS * COLS * 4] = {
@ -71,7 +72,7 @@ static const char keypad_map_2nd[ROWS * COLS * 4] = {
"k\0\0\0" "l\0\0\0" "m\0\0\0" "n\0\0\0" "o\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" "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" "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" "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] #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 char keypad_buffer[BUFFER_SIZE];
static int keypad_buffer_pos = -1; static int keypad_buffer_pos = -1;
int keypad_insert = 0;
void keypad_task(void) void keypad_task(void)
{ {
unsigned int col = 0; unsigned int col = 0;
@ -99,6 +102,8 @@ void keypad_task(void)
if ((hold ^= 1) == 0) if ((hold ^= 1) == 0)
use2nd = 0; use2nd = 0;
} }
} else if (KEYCODE(row, col) == K_INS) {
keypad_insert ^= 1;
} else if (keypad_buffer_pos < BUFFER_SIZE) { } else if (keypad_buffer_pos < BUFFER_SIZE) {
if (use2nd != 0 && hold == 0) if (use2nd != 0 && hold == 0)
use2nd = 0; use2nd = 0;

@ -40,6 +40,7 @@ extern char *itoa(int, char *, int);
void kmain(void); void kmain(void);
void task_interpreter(void); void task_interpreter(void);
void task_status(void);
int main(void) int main(void)
{ {
@ -77,6 +78,7 @@ void kmain(void)
keypad_start(); keypad_start();
task_start(task_interpreter, 4096); task_start(task_interpreter, 4096);
task_start(task_status, 512);
while (1) { while (1) {
gpio_dout(GPIOA, 5, 1); gpio_dout(GPIOA, 5, 1);
@ -125,6 +127,34 @@ fail:
return 0; return 0;
} }
void task_status(void)
{
extern int keypad_insert;
int lastInsert = -1;
int16_t bg = dsp_color(0x3F, 0x3F, 0x3F);
int16_t red = dsp_color(0xFF, 0, 0);
int16_t green = dsp_color(0, 0xFF, 0);
dsp_rect(0, 300, 480, 20, bg);
while (1) {
if (lastInsert != keypad_insert) {
lastInsert = keypad_insert;
dsp_rect(0, 300, 480, 20, bg);
if (lastInsert > 0)
dsp_rect(4, 304, 12, 12, green);
else
dsp_rect(4, 304, 12, 12, red);
}
delay(500);
}
}
void task_interpreter(void) void task_interpreter(void)
{ {
instance *it = load_program("init"); instance *it = load_program("init");

@ -168,6 +168,7 @@ int script_gets(instance *it)
char *s = malloc(64); char *s = malloc(64);
char c[2] = {0, 0}; char c[2] = {0, 0};
int index = 0; int index = 0;
int furthest = 0;
do { do {
do { do {
@ -178,9 +179,32 @@ int script_gets(instance *it)
if (c[0] == 0x7F) { if (c[0] == 0x7F) {
it->lnidx = 998; it->lnidx = 998;
break; 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]; s[index] = c[0];
if (c[0] == '\b' || c[0] == 127) { if (c[0] == '\b' || c[0] == 127) {
index--; index--;
@ -188,11 +212,20 @@ int script_gets(instance *it)
dsp_puts("\b"); dsp_puts("\b");
index--; 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'*/) { } else if (c[0] != '\n'/*'\r'*/) {
dsp_puts(c); 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); variable *r = make_vars(0, s);
ipush(it, (uint32_t)r); ipush(it, (uint32_t)r);
@ -274,7 +307,7 @@ int script_program(instance *it)
int initrdOffset = (int)igetarg(it, 0)->value.f; int initrdOffset = (int)igetarg(it, 0)->value.f;
char *name = initrd_getname(initrdOffset); char *name = initrd_getname(initrdOffset);
dsp_rect(0, 0, 480, 320, 0); dsp_rect(0, 0, 480, 300, 0);
dsp_cpos(0, 0); dsp_cpos(0, 0);
dsp_coff(0, 0); dsp_coff(0, 0);

Loading…
Cancel
Save