Commit 0b4ee8ca authored by Matthieu Cattin's avatar Matthieu Cattin

sw: bitmap display test (status icons).

parent 8f30f534
static const uint8_t battery_data[] = {
0x8d,
0x00,
0x80,
0x0b,
0x80,
0x00,
0x80,
0x0b,
0x80,
0x00,
0x80,
0x0b,
0x82,
0x0b,
0x82,
0x0b,
0x82,
0x0b,
0x82,
0x0b,
0x82,
0x0b,
0x82,
0x0b,
0x80,
0x00,
0x80,
0x0b,
0x80,
0x00,
0x8d,
0x00};
static const struct rle_bitmap battery = { 15, 12, battery_data };
static const uint8_t battery_charging_data[] = {
0x8d,
0x00,
0x80,
0x0b,
0x80,
0x00,
0x80,
0x0b,
0x80,
0x00,
0x80,
0x05,
0x81,
0x03,
0x82,
0x04,
0x84,
0x01,
0x82,
0x00,
0x86,
0x03,
0x82,
0x00,
0x86,
0x03,
0x82,
0x04,
0x84,
0x01,
0x82,
0x05,
0x81,
0x03,
0x82,
0x0b,
0x80,
0x00,
0x80,
0x0b,
0x80,
0x00,
0x8d,
0x00};
static const struct rle_bitmap battery_charging = { 15, 12, battery_charging_data };
static const uint8_t gps_disconnected_data[] = {
0x0a,
0x80,
0x0d,
0x80,
0x0b,
0x84,
0x03,
0x82,
0x04,
0x80,
0x04,
0x81,
0x06,
0x80,
0x03,
0x81,
0x03,
0x81,
0x06,
0x82,
0x00,
0x83,
0x06,
0x82,
0x02,
0x80,
0x07,
0x83,
0x01,
0x80,
0x01,
0x80,
0x05,
0x83,
0x03,
0x80,
0x06,
0x84,
0x00,
0x81,
0x07,
0x85,
0x0a,
0x81,
0x09,
0x84,
0x08,
0x86,
0x05};
static const struct rle_bitmap gps_disconnected = { 15, 15, gps_disconnected_data };
static const uint8_t gps_receiving_data[] = {
0x06,
0x83,
0x0e,
0x80,
0x0a,
0x81,
0x01,
0x80,
0x04,
0x82,
0x03,
0x80,
0x01,
0x80,
0x02,
0x81,
0x06,
0x80,
0x00,
0x80,
0x01,
0x81,
0x03,
0x81,
0x01,
0x80,
0x00,
0x80,
0x01,
0x82,
0x00,
0x83,
0x03,
0x80,
0x01,
0x82,
0x02,
0x80,
0x07,
0x83,
0x01,
0x80,
0x01,
0x80,
0x05,
0x83,
0x03,
0x80,
0x06,
0x84,
0x00,
0x81,
0x07,
0x85,
0x0a,
0x81,
0x09,
0x84,
0x08,
0x86,
0x05};
static const struct rle_bitmap gps_receiving = { 15, 15, gps_receiving_data };
static const uint8_t gps_searching_data[] = {
0x0c,
0x80,
0x0c,
0x80,
0x13,
0x82,
0x03,
0x80,
0x05,
0x81,
0x04,
0x80,
0x05,
0x81,
0x03,
0x81,
0x06,
0x82,
0x00,
0x83,
0x06,
0x82,
0x02,
0x80,
0x07,
0x83,
0x01,
0x80,
0x01,
0x80,
0x05,
0x83,
0x03,
0x80,
0x06,
0x84,
0x00,
0x81,
0x07,
0x85,
0x0a,
0x81,
0x09,
0x84,
0x08,
0x86,
0x05};
static const struct rle_bitmap gps_searching = { 15, 15, gps_searching_data };
#include "ui.h"
#include "../bitmaps/battery_charging.h"
#include "../bitmaps/battery.h"
#include "../bitmaps/gps_disconnected.h"
#include "../bitmaps/gps_searching.h"
#include "../bitmaps/gps_receiving.h"
extern int64_t sys_get_tics();
......@@ -132,7 +139,7 @@ static void pls_redraw(struct ui_widget *w)
{
struct pls_cycle *cyc = &cycles[i];
char buf[10];
sprintf(buf,"%-02d %s", i + 1, cyc->name);
sprintf(buf,"%02d %s", i + 1, cyc->name);
gfx_text(&w->dc, &font_xm5x8, 0, n * 8, buf);
if(n == 3)
gfx_box(&w->dc, 0, n*8-1, 60, n*8+7, COLOR_TOGGLE);
......@@ -182,7 +189,48 @@ struct ui_widget home_screen = {
static void status_bar_event(struct ui_widget *w, struct ui_event event)
{
static int8_t level;
switch(event.type)
{
case EVT_UP:
{
level += 10;
if(level > 100)
level = 100;
printf("UP : level %3d\n",level);
gfx_box(&w->dc, 127-15, 1, 127-3, 11, COLOR_WHITE);
gfx_box(&w->dc, 127-15, 1, 127-15+((level * 12)/100), 11, COLOR_BLACK);
gfx_box(&w->dc, 0, 0, 15, 15, COLOR_WHITE);
gfx_draw_bitmap(&w->dc, 0, 0, &gps_disconnected);
w->flags |= WF_DIRTY;
break;
}
case EVT_DOWN:
{
level -= 10;
if(level < 0)
level = 0;
printf("DOWN: level %3d\n",level);
gfx_box(&w->dc, 127-15, 1, 127-3, 11, COLOR_WHITE);
gfx_box(&w->dc, 127-15, 1, 127-15+((level * 12)/100), 11, COLOR_BLACK);
gfx_box(&w->dc, 0, 0, 15, 15, COLOR_WHITE);
gfx_draw_bitmap(&w->dc, 0, 0, &gps_receiving);
w->flags |= WF_DIRTY;
break;
}
case EVT_RIGHT:
{
gfx_box(&w->dc, 127-15, 1, 127-3, 11, COLOR_WHITE);
gfx_draw_bitmap(&w->dc, 127-15, 0, &battery_charging);
gfx_box(&w->dc, 0, 0, 15, 15, COLOR_WHITE);
gfx_draw_bitmap(&w->dc, 0, 0, &gps_searching);
w->flags |= WF_DIRTY;
break;
}
default:
break;
}
}
static void status_bar_redraw(struct ui_widget *w)
......@@ -190,6 +238,7 @@ static void status_bar_redraw(struct ui_widget *w)
//gfx_line(&w->dc, 0, w->pos.y1, 127, w->pos.y1, COLOR_BLACK);
gfx_round_box(&w->dc, 30, -10, 127-30, 10, 9, COLOR_BLACK);
gfx_centered_text(&w->dc, &font_helv11, 0, "Home");
gfx_draw_bitmap(&w->dc, 127-15, 0, &battery);
}
struct ui_widget status_bar = {
......
......@@ -208,3 +208,28 @@ void gfx_round_box(struct surface *surf, int x0, int y0, int x1, int y1, int rad
gfx_fill_circle(surf, x1-radius, y1-radius, radius, value);
gfx_fill_circle(surf, x0+radius, y1-radius, radius, value);
}
void gfx_draw_bitmap(struct surface *surf, int x0, int y0, const struct rle_bitmap *b)
{
int x=0, y=0;
uint8_t *d = b->data;
while ( y != b->h)
{
int pix = (*d) & 0x80 ? 1: 0;
int rep = ( (*d) & 0x7f) + 1;
d++;
while(rep--)
{
if(pix)
gfx_set_pixel(surf, x0+x, y0+y, COLOR_BLACK);
x++;
if(x == b->w)
{
x=0;
y++;
}
}
}
}
......@@ -26,6 +26,13 @@ struct surface
void *data;
};
struct rle_bitmap
{
uint8_t w;
uint8_t h;
uint8_t *data;
};
static inline void gfx_set_pixel ( struct surface *surf, int x, int y, int value )
{
......@@ -56,5 +63,6 @@ void gfx_set_clip (struct surface *surf, int x0, int y0, int x1, int y1 );
void gfx_reset_clip (struct surface *surf );
void gfx_fill_circle(struct surface *surf, int x0, int y0, int radius, int value);
void gfx_round_box(struct surface *surf, int x0, int y0, int x1, int y1, int radius, int value);
void gfx_draw_bitmap(struct surface *surf, int x0, int y0, const struct rle_bitmap *b);
#endif
\ No newline at end of file
#endif
......@@ -20,6 +20,10 @@
#define EVT_TAP 5
#define EVT_ACTIVATE 6
#define EVT_NEXT_CYCLE 7
#define EVT_UP 8
#define EVT_DOWN 9
#define EVT_RIGHT 10
#define UI_TICK_RATE 30 /* UI refresh ticks = 30 milliseconds */
#define UI_CYCLE_RATE 1200 /* The Machine Cycle */
......
......@@ -67,7 +67,18 @@ int sys_update()
{
switch(ev.key.keysym.sym)
{
case SDLK_ESCAPE: exit(0); break;
case SDLK_ESCAPE:
exit(0);
break;
case SDLK_UP:
ui_post_event(EVT_UP, 0);
break;
case SDLK_DOWN:
ui_post_event(EVT_DOWN, 0);
break;
case SDLK_RIGHT:
ui_post_event(EVT_RIGHT, 0);
break;
#if 0
case SDLK_LEFT: cur_key=KEY_L; break;
case SDLK_RIGHT: cur_key=KEY_R; break;
......@@ -175,4 +186,4 @@ main()
ui_update();
}
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment