some cleanup and light color effects
This commit is contained in:
parent
6d920e7bd1
commit
6c3c870f5e
105
fbdash.c
105
fbdash.c
@ -34,9 +34,15 @@
|
|||||||
#define WIDTH 240
|
#define WIDTH 240
|
||||||
#define HEIGHT 320
|
#define HEIGHT 320
|
||||||
|
|
||||||
|
|
||||||
char *fbp = 0;
|
char *fbp = 0;
|
||||||
|
|
||||||
|
struct s_color {
|
||||||
|
unsigned char r;
|
||||||
|
unsigned char g;
|
||||||
|
unsigned char b;
|
||||||
|
};
|
||||||
|
typedef struct s_color color;
|
||||||
|
|
||||||
struct s_sourcedata {
|
struct s_sourcedata {
|
||||||
char* text;
|
char* text;
|
||||||
@ -45,14 +51,24 @@ struct s_sourcedata {
|
|||||||
};
|
};
|
||||||
typedef struct s_sourcedata sourcedata;
|
typedef struct s_sourcedata sourcedata;
|
||||||
|
|
||||||
|
|
||||||
void finish_with_error(MYSQL *con) {
|
void finish_with_error(MYSQL *con) {
|
||||||
fprintf(stderr, "%s\n", mysql_error(con));
|
fprintf(stderr, "%s\n", mysql_error(con));
|
||||||
mysql_close(con);
|
mysql_close(con);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateSlot(char *fbp, sourcedata data, int x_offset, int y_offset, color c) {
|
||||||
|
render_string(fbp, ubuntu_mono_24, data.text, x_offset, y_offset, c.r, c.g, c.b);
|
||||||
|
|
||||||
|
render_string(fbp, ubuntu_mono_48, data.temperature, x_offset + 115, y_offset - 9, c.r, c.g, c.b);
|
||||||
|
render_string(fbp, ubuntu_mono_48, "C", x_offset + 195, y_offset - 9, c.r, c.g, c.b);
|
||||||
|
|
||||||
|
render_string(fbp, ubuntu_mono_48, data.humidity, x_offset + 115, y_offset + 26, c.r, c.g, c.b);
|
||||||
|
render_string(fbp, ubuntu_mono_48, "%", x_offset + 195, y_offset + 26, c.r, c.g, c.b);
|
||||||
|
}
|
||||||
|
|
||||||
void updateData() {
|
void updateData(char *fbp, int slot_height) {
|
||||||
// query database for latest values
|
// query database for latest values
|
||||||
printf("MySQL client version: %s\n", mysql_get_client_info());
|
printf("MySQL client version: %s\n", mysql_get_client_info());
|
||||||
MYSQL *con = mysql_init(NULL);
|
MYSQL *con = mysql_init(NULL);
|
||||||
@ -77,11 +93,12 @@ INNER JOIN metrics AS m ON r.metric_id = m.id \
|
|||||||
WHERE \
|
WHERE \
|
||||||
time > (NOW() - 60 * 15) AND \
|
time > (NOW() - 60 * 15) AND \
|
||||||
metric IN ('Luftfeuchte','Temperatur') AND \
|
metric IN ('Luftfeuchte','Temperatur') AND \
|
||||||
source IN ('Esszimmer','Wohnzimmer') \
|
source IN ('Esszimmer','Wohnzimmer', 'Schlafzimmer', 'Abstellkammer') \
|
||||||
ORDER BY time DESC \
|
ORDER BY time DESC \
|
||||||
LIMIT 100;";
|
LIMIT 100;";
|
||||||
|
|
||||||
printf("%s\n",query);
|
//printf("%s\n",query);
|
||||||
|
printf("Fetching data ...\n");
|
||||||
|
|
||||||
if (mysql_query(con, query)) {
|
if (mysql_query(con, query)) {
|
||||||
finish_with_error(con);
|
finish_with_error(con);
|
||||||
@ -91,55 +108,51 @@ printf("%s\n",query);
|
|||||||
finish_with_error(con);
|
finish_with_error(con);
|
||||||
}
|
}
|
||||||
|
|
||||||
sourcedata esszimmer = { "Esszimmer", NULL, NULL };
|
// define what to display
|
||||||
sourcedata wohnzimmer = { "Wohnzimmer", NULL, NULL };
|
sourcedata data[4] = {
|
||||||
|
{ "Esszimmer", NULL, NULL },
|
||||||
|
{ "Wohnzimmer", NULL, NULL },
|
||||||
|
{ "Schlafzimmer", NULL, NULL },
|
||||||
|
{ "Abstellkammer", NULL, NULL }
|
||||||
|
};
|
||||||
|
|
||||||
int num_fields = mysql_num_fields(result);
|
int num_fields = mysql_num_fields(result);
|
||||||
MYSQL_ROW row;
|
if (num_fields > 3) {
|
||||||
while ((row = mysql_fetch_row(result))) {
|
MYSQL_ROW row;
|
||||||
row[3][5] = '\0'; // loose the third decimal ...
|
while ((row = mysql_fetch_row(result))) {
|
||||||
|
if (strlen(row[3]) > 4) row[3][4] = '\0'; // loose the secnod and third decimal ...
|
||||||
|
|
||||||
// data binding
|
// data binding
|
||||||
if (strcmp(row[1], "Esszimmer") == 0) {
|
for (int i = 0; i < 4; i++) {
|
||||||
if (strcmp(row[2], "Temperatur") == 0 && esszimmer.temperature == NULL) esszimmer.temperature = row[3];
|
if (strcmp(row[1], data[i].text) == 0) {
|
||||||
else if (strcmp(row[2], "Luftfeuchte") == 0 && esszimmer.humidity == NULL) esszimmer.humidity = row[3];
|
if (strcmp(row[2], "Temperatur") == 0 && data[i].temperature == NULL) data[i].temperature = row[3];
|
||||||
}
|
else if (strcmp(row[2], "Luftfeuchte") == 0 && data[i].humidity == NULL) data[i].humidity = row[3];
|
||||||
if (strcmp(row[1], "Wohnzimmer") == 0) {
|
}
|
||||||
if (strcmp(row[2], "Temperatur") == 0 && wohnzimmer.temperature == NULL) wohnzimmer.temperature = row[3];
|
}
|
||||||
else if (strcmp(row[2], "Luftfeuchte") == 0 && wohnzimmer.humidity == NULL) wohnzimmer.humidity = row[3];
|
|
||||||
}
|
|
||||||
|
|
||||||
// debugging
|
// debugging
|
||||||
for(int i = 0; i < num_fields; i++) {
|
//for(int i = 0; i < num_fields; i++) printf("%s ", row[i] ? row[i] : "NULL");
|
||||||
printf("%s ", row[i] ? row[i] : "NULL");
|
//printf("\n");
|
||||||
}
|
}
|
||||||
printf("\n");
|
}
|
||||||
}
|
|
||||||
|
printf("Updating dashboard...\n");
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
color c = {255,125 + 25*i,25 + 25*i};
|
||||||
|
updateSlot(fbp, data[i], 15, 7 + slot_height * i, c);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
render_string(fbp, ubuntu_mono_24, esszimmer.text, 15, 7, 255, 255, 255);
|
printf("Done!\n");
|
||||||
|
|
||||||
render_string(fbp, ubuntu_mono_48, esszimmer.temperature, 115, -2, 255, 255, 255);
|
|
||||||
render_string(fbp, ubuntu_mono_48, "C", 200, -2, 255, 255, 255);
|
|
||||||
|
|
||||||
render_string(fbp, ubuntu_mono_48, esszimmer.humidity, 115, 33, 255, 255, 255);
|
|
||||||
render_string(fbp, ubuntu_mono_48, "%", 200, 33, 255, 255, 255);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
render_string(fbp, ubuntu_mono_24, wohnzimmer.text, 15, 87, 255, 255, 255);
|
|
||||||
|
|
||||||
render_string(fbp, ubuntu_mono_48, wohnzimmer.temperature, 115, 77, 255, 255, 255);
|
|
||||||
render_string(fbp, ubuntu_mono_48, "C", 200, 77, 255, 255, 255);
|
|
||||||
|
|
||||||
render_string(fbp, ubuntu_mono_48, wohnzimmer.humidity, 115, 113, 255, 255, 255);
|
|
||||||
render_string(fbp, ubuntu_mono_48, "%", 200, 113, 255, 255, 255);
|
|
||||||
|
|
||||||
mysql_free_result(result);
|
mysql_free_result(result);
|
||||||
mysql_close(con);
|
mysql_close(con);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void draw() {
|
void draw() {
|
||||||
clear_screen(fbp);
|
clear_screen(fbp);
|
||||||
|
|
||||||
@ -159,14 +172,8 @@ void draw() {
|
|||||||
draw_line(fbp, x0, y+1, x1, y+1, r, g, b);
|
draw_line(fbp, x0, y+1, x1, y+1, r, g, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fetch data from database and update screen
|
||||||
updateData();
|
updateData(fbp, y_step_width);
|
||||||
/*
|
|
||||||
char *text = "Hell O_o!";
|
|
||||||
render_string(fbp, ubuntu_mono_48, text, 15, 0, 255, 255, 255);
|
|
||||||
render_string(fbp, ubuntu_mono_24, text, 15, 50, 255, 255, 255);
|
|
||||||
render_string(fbp, basic_8, text, 15, 100, 255, 255, 255);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
6
fblib.c
6
fblib.c
@ -169,10 +169,10 @@ void draw_line(char *fbp, int x0, int y0, int x1, int y1, int r, int g, int b) {
|
|||||||
void render_string(char *fbp, fbfont font, char *text, int x, int y, int r, int g, int b)
|
void render_string(char *fbp, fbfont font, char *text, int x, int y, int r, int g, int b)
|
||||||
{
|
{
|
||||||
int text_length = strlen(text);
|
int text_length = strlen(text);
|
||||||
printf("text_length = %d\n", text_length);
|
//printf("text_length = %d\n", text_length);
|
||||||
|
|
||||||
int bytes_per_line = ceil(font.width / 8.0);
|
int bytes_per_line = ceil(font.width / 8.0);
|
||||||
printf("bytes_per_line = %d\n", bytes_per_line);
|
//printf("bytes_per_line = %d\n", bytes_per_line);
|
||||||
|
|
||||||
int char_offset = bytes_per_line * font.height;
|
int char_offset = bytes_per_line * font.height;
|
||||||
|
|
||||||
@ -199,7 +199,7 @@ void render_string(char *fbp, fbfont font, char *text, int x, int y, int r, int
|
|||||||
//printf("x");
|
//printf("x");
|
||||||
|
|
||||||
int x_pos = x_offset + byte_num * 8 + bit_number;
|
int x_pos = x_offset + byte_num * 8 + bit_number;
|
||||||
put_pixel(fbp, x_pos, y_pos, 255, 255, 255);
|
put_pixel(fbp, x_pos, y_pos, r, g, b);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// leave empty (or maybe plot 'text backgr color')
|
// leave empty (or maybe plot 'text backgr color')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user