forked from ic11b025/wetterstation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
writeLCD.c
67 lines (60 loc) · 1.85 KB
/
writeLCD.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "common.h"
#include <lcd.h>
extern int8_t writeLCD(const int fd_lcd, const double value, const char mode, const struct tm *time)
{
const char *FNAME = "writeLCD()";
char *shour = NULL;
char *smin = NULL;
char *ssec = NULL;
char *svalue = NULL;
shour = (char *) alloca(sizeof(char)*3 + 1);
smin = (char *) alloca(sizeof(char)*3 + 1);
ssec = (char *) alloca(sizeof(char)*3 + 1);
svalue = (char *) alloca(sizeof(char)*7 + 1);
snprintf(shour, 3, "%02d", time->tm_hour);
snprintf(smin, 3, "%02d", time->tm_min);
snprintf(ssec, 3, "%02d", time->tm_sec);
snprintf(svalue, 7, "%4.1f", value);
fprintf(stdout, "DEBUG: %s: hour=%s min=%s sec=%s mode=%c value=%s\n", FNAME, shour, smin, ssec, mode, svalue);
/* switch off backlight */
lcdDisplay(fd_lcd, 1);
/* set the cursor position: column 0-15, row 0-1*/
/* set cursor top row, position 0 */
lcdPosition(fd_lcd, 0, 0);
/* clear the screen (fill with blanks) */
lcdPuts(fd_lcd, " ");
/* set cursor bottom row, position 0 */
lcdPosition(fd_lcd, 0, 1);
/* clear the screen (fill with blanks) */
lcdPuts(fd_lcd, " ");
lcdPosition(fd_lcd, 0, 0);
lcdPuts(fd_lcd, shour);
lcdPutchar(fd_lcd, ':');
lcdPuts(fd_lcd, smin);
lcdPutchar(fd_lcd, ':');
lcdPuts(fd_lcd, ssec);
lcdPosition(fd_lcd, 0, 1);
switch (mode) {
case 't':
lcdPuts(fd_lcd, "Temperatur ");
lcdPosition(fd_lcd, 11, 1);
snprintf(svalue, 5, "%2.1f", value);
lcdPrintf(fd_lcd, svalue);
break;
case 'h':
lcdPuts(fd_lcd, "Feuchte ");
lcdPosition(fd_lcd, 8, 1);
snprintf(svalue, 3, "%2.0f", value);
lcdPrintf(fd_lcd, svalue);
lcdPutchar(fd_lcd, '%');
break;
case 'p':
lcdPuts(fd_lcd, "Druck ");
lcdPosition(fd_lcd, 6, 1);
snprintf(svalue, 5, "%4.0f", value);
lcdPrintf(fd_lcd, svalue);
lcdPuts(fd_lcd, " HPa");
break;
}
return 0;
}