added not working guiDrawKeymatrix()
This commit is contained in:
parent
634908c66d
commit
94e949bd63
3 changed files with 123 additions and 17 deletions
2
glcd.h
2
glcd.h
|
@ -1,7 +1,7 @@
|
||||||
#ifndef GLCD_H
|
#ifndef GLCD_H
|
||||||
#define GLCD_H
|
#define GLCD_H
|
||||||
|
|
||||||
#include <ch.h> // types
|
#include <ch.h>
|
||||||
#include <hal.h>
|
#include <hal.h>
|
||||||
|
|
||||||
#define SCREEN_WIDTH 240
|
#define SCREEN_WIDTH 240
|
||||||
|
|
112
gui.c
112
gui.c
|
@ -6,13 +6,64 @@
|
||||||
|
|
||||||
volatile uint16_t x, y;
|
volatile uint16_t x, y;
|
||||||
|
|
||||||
static msg_t buttonThread(struct buttonStruct_t *a) {
|
static msg_t buttonThread(struct button_t *a) {
|
||||||
|
uint16_t x0, y0, x1, y1;
|
||||||
|
|
||||||
|
x0 = a->x0;
|
||||||
|
y0 = a->y0;
|
||||||
|
x1 = a->x1;
|
||||||
|
y1 = a->y1;
|
||||||
|
|
||||||
while(TRUE) {
|
while(TRUE) {
|
||||||
if(x >= a->x0 && x <= a->x1 && y >= a->y0 && y <= a->y1)
|
if(x >= x0 && x <= x1 && y >= y0 && y <= y1)
|
||||||
*(a->state) = 1;
|
*(a->state) = 1;
|
||||||
else
|
else
|
||||||
*(a->state) = 0;
|
*(a->state) = 0;
|
||||||
chThdSleepMilliseconds(50);
|
|
||||||
|
chThdSleepMilliseconds(a->interval);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static msg_t keymatrixThread(struct keymatrix_t *a) {
|
||||||
|
uint16_t i, x0, y0, size, off;
|
||||||
|
|
||||||
|
x0 = a->x0;
|
||||||
|
y0 = a->y0;
|
||||||
|
off = a->off;
|
||||||
|
size = a->size;
|
||||||
|
memset(a->number, 0, sizeof(a->number));
|
||||||
|
|
||||||
|
while(TRUE) {
|
||||||
|
|
||||||
|
for(i = 0; i < a->digits; i++) {
|
||||||
|
while(tpIRQ());
|
||||||
|
if(x >= x0 && x <= x0+size && y >= y0 && y <= y0+size)
|
||||||
|
a->number[i] = 7;
|
||||||
|
else if(x >= x0+off && x <= x0+off+size && y >= y0 && y <= y0+size)
|
||||||
|
a->number[i] = 8;
|
||||||
|
else if(x >= x0+off+off && x <= x0+off+off+size && y >= y0 && y <= y0+size)
|
||||||
|
a->number[i] = 9;
|
||||||
|
else if(x >= x0 && x <= x0+size && y >= y0+off && y <= y0+off+size)
|
||||||
|
a->number[i] = 4;
|
||||||
|
else if(x >= x0+off && x <= x0+off+size && y >= y0+off && y <= y0+off+size)
|
||||||
|
a->number[i] = 5;
|
||||||
|
else if(x >= x0+off+off && x <= x0+off+off+size && y >= y0+off && y <= y0+off+size)
|
||||||
|
a->number[i] = 6;
|
||||||
|
else if(x >= x0 && x <= x0+size && y >= y0+off+off && y <= y0+off+off+size)
|
||||||
|
a->number[i] = 1;
|
||||||
|
else if(x >= x0+off && x <= x0+off+size && y >= y0+off+off && y <= y0+off+off+size)
|
||||||
|
a->number[i] = 2;
|
||||||
|
else if(x >= x0+off+off && x <= x0+off+off+size && y >= y0+off+off && y <= y0+off+off+size)
|
||||||
|
a->number[i] = 3;
|
||||||
|
else if(x >= x0 && x <= x0+size && y >= y0+off+off+off && y <= y0+off+off+off+size)
|
||||||
|
a->number[i] = 0;
|
||||||
|
else if(x >= x0+off && x <= x0+off+size && y >= y0+off+off+off && y <= y0+off+off+off+size)
|
||||||
|
a->number[i] = 0;
|
||||||
|
else if(x >= x0+off+off && x <= x0+off+off+size && y >= y0+off+off+off && y <= y0+off+off+off+size)
|
||||||
|
a->number[i] = 0;
|
||||||
|
while(!tpIRQ());
|
||||||
|
chThdSleepMilliseconds(a->interval);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,20 +84,55 @@ void guiInit(uint16_t updateInterval) {
|
||||||
tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(64), HIGHPRIO-1, TouchPadThread, updateInterval);
|
tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(64), HIGHPRIO-1, TouchPadThread, updateInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread *guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, unsigned char *str, uint16_t fontColor, uint16_t buttonColor, uint8_t *state) {
|
Thread *guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, unsigned char *str, uint16_t fontColor, uint16_t buttonColor, uint16_t interval, uint8_t *state) {
|
||||||
struct buttonStruct_t *buttonStruct;
|
struct button_t *button;
|
||||||
Thread *tp = NULL;
|
Thread *tp = NULL;
|
||||||
|
|
||||||
buttonStruct = chHeapAlloc(NULL, sizeof(struct buttonStruct_t));
|
button = chHeapAlloc(NULL, sizeof(struct button_t));
|
||||||
|
button->x0 = x0;
|
||||||
buttonStruct->x0 = x0;
|
button->y0 = y0;
|
||||||
buttonStruct->y0 = y0;
|
button->x1 = x1;
|
||||||
buttonStruct->x1 = x1;
|
button->y1 = y1;
|
||||||
buttonStruct->y1 = y1;
|
button->state = state;
|
||||||
buttonStruct->state = state;
|
button->interval = interval;
|
||||||
|
|
||||||
lcdDrawRectString(x0, y0, x1, y1, str, fontColor, buttonColor);
|
lcdDrawRectString(x0, y0, x1, y1, str, fontColor, buttonColor);
|
||||||
tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(64), NORMALPRIO+1, buttonThread, buttonStruct);
|
tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(512), NORMALPRIO, buttonThread, button);
|
||||||
|
|
||||||
|
return tp;
|
||||||
|
}
|
||||||
|
|
||||||
|
Thread *guiDrawKeymatrix(uint16_t x0, uint16_t y0, uint16_t size, uint16_t space, uint16_t fontColor, uint16_t buttonColor, uint16_t interval, uint16_t digits, uint32_t *number) {
|
||||||
|
struct keymatrix_t *keymatrix;
|
||||||
|
Thread *tp = NULL;
|
||||||
|
uint16_t off;
|
||||||
|
uint8_t i, j;
|
||||||
|
|
||||||
|
off = size+space;
|
||||||
|
|
||||||
|
keymatrix = chHeapAlloc(NULL, sizeof(struct keymatrix_t));
|
||||||
|
keymatrix->x0 = x0;
|
||||||
|
keymatrix->y0 = y0;
|
||||||
|
keymatrix->off = off;
|
||||||
|
keymatrix->size = size;
|
||||||
|
keymatrix->digits = digits;
|
||||||
|
keymatrix->number = number;
|
||||||
|
keymatrix->interval = interval;
|
||||||
|
|
||||||
|
lcdDrawRectString(x0, y0, x0+size, y0+size, "7", fontColor, buttonColor);
|
||||||
|
lcdDrawRectString(x0+off, y0, x0+off+size, y0+size, "8", fontColor, buttonColor);
|
||||||
|
lcdDrawRectString(x0+off+off, y0, x0+off+off+size, y0+size, "9", fontColor, buttonColor);
|
||||||
|
lcdDrawRectString(x0, y0+off, x0+size, y0+off+size, "4", fontColor, buttonColor);
|
||||||
|
lcdDrawRectString(x0+off, y0+off, x0+off+size, y0+off+size, "5", fontColor, buttonColor);
|
||||||
|
lcdDrawRectString(x0+off+off, y0+off, x0+off+off+size, y0+off+size, "6", fontColor, buttonColor);
|
||||||
|
lcdDrawRectString(x0, y0+off+off, x0+size, y0+off+off+size, "1", fontColor, buttonColor);
|
||||||
|
lcdDrawRectString(x0+off, y0+off+off, x0+off+size, y0+off+off+size, "2", fontColor, buttonColor);
|
||||||
|
lcdDrawRectString(x0+off+off, y0+off+off, x0+off+off+size, y0+off+off+size, "3", fontColor, buttonColor);
|
||||||
|
lcdDrawRectString(x0, y0+off+off+off, x0+size, y0+off+off+off+size, "*", fontColor, buttonColor);
|
||||||
|
lcdDrawRectString(x0+off, y0+off+off+off, x0+off+size, y0+off+off+off+size, "0", fontColor, buttonColor);
|
||||||
|
lcdDrawRectString(x0+off+off, y0+off+off+off, x0+off+off+size, y0+off+off+off+size, "#", fontColor, buttonColor);
|
||||||
|
|
||||||
|
tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(64), NORMALPRIO, keymatrixThread, keymatrix);
|
||||||
|
|
||||||
return tp;
|
return tp;
|
||||||
}
|
}
|
||||||
|
|
26
gui.h
26
gui.h
|
@ -1,12 +1,23 @@
|
||||||
#ifndef GUI_H
|
#ifndef GUI_H
|
||||||
#define GUI_H
|
#define GUI_H
|
||||||
|
|
||||||
struct buttonStruct_t {
|
struct button_t {
|
||||||
uint16_t x0;
|
uint16_t x0;
|
||||||
uint16_t y0;
|
uint16_t y0;
|
||||||
uint16_t x1;
|
uint16_t x1;
|
||||||
uint16_t y1;
|
uint16_t y1;
|
||||||
uint8_t *state;
|
uint32_t *state;
|
||||||
|
uint16_t interval;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct keymatrix_t {
|
||||||
|
uint16_t x0;
|
||||||
|
uint16_t y0;
|
||||||
|
uint16_t off;
|
||||||
|
uint16_t size;
|
||||||
|
uint16_t digits;
|
||||||
|
uint32_t *number;
|
||||||
|
uint16_t interval;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -31,7 +42,16 @@ void guiInit(uint16_t updateIntervl);
|
||||||
*
|
*
|
||||||
* return: pointer to created thread
|
* return: pointer to created thread
|
||||||
*/
|
*/
|
||||||
Thread *guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, unsigned char *str, uint16_t fontColor, uint16_t buttonColor, uint8_t *state);
|
Thread *guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, unsigned char *str, uint16_t fontColor, uint16_t buttonColor, uint16_t inverval, uint8_t *state);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Description: draws keymatrix
|
||||||
|
*
|
||||||
|
* param:
|
||||||
|
*
|
||||||
|
* return: pointer to created thread
|
||||||
|
*/
|
||||||
|
Thread *guiDrawKeymatrix(uint16_t x0, uint16_t y0, uint16_t size, uint16_t space, uint16_t fontColor, uint16_t buttonColor, uint16_t inverval, uint16_t digits, uint32_t *number);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue