forked from Velho/stm32-demo-master
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlcd_display.c
94 lines (78 loc) · 2.02 KB
/
lcd_display.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* lcd_display.c
*
* Created on: Oct 28, 2021
* Author: Velho
* Edited: Petri Pihla
*/
#include "lcd_display.h"
#include <string.h>
#include "data_storage.h"
#include <os.h>
#include <lcd16x2/LCD16x2.h>
#include <sensor_datatype.h>
#include <stdio.h>
#define LCD_BUFFER_SIZE 34
/*TypeDisplayInfo gTypeDisplayInfo[] = { { "BME 280 Temp \n %0.2f C",
SENSOR_TYPE_TEMP }, { "BME 280 Hum \n %0.2f %%", SENSOR_TYPE_HUMD }, {
"BME 280 Pres \n %0.2f Pa", SENSOR_TYPE_PRESS } };*/
static SensorDataType g_display_mode = 0;
static uint8_t g_is_updating = 0;
static char lcd_buffer[LCD_BUFFER_SIZE];
static char lcd_current[LCD_BUFFER_SIZE];
//static uint8_t dummy_temperature = 0;
//static char dummy_string[] = "counter :%d";
typedef struct {
const char *text;
SensorDataType type;
} TypeDisplayInfo;
/*
static TypeDisplayInfo* Get_DisplayInfo(SensorDataType datatype) {
TypeDisplayInfo *display = gTypeDisplayInfo;
while (display++ != NULL) {
if (display->type == datatype) {
return display;
}
}
return NULL;
}
*/
void Display_Init() {
LCD_Init();
}
void Update_Buffer() {
snprintf(lcd_buffer, LCD_BUFFER_SIZE, "still\nworking");
}
void Render_Buffer_to_LCD() {
LCD_Clear();
LCD_Set_Cursor(1, 1);
char *p = lcd_buffer;
while (*p != '\0') {
if (*p == '\n') {
LCD_Set_Cursor(2, 1);
} else {
LCD_Write_Char(*p);
}
p++;
}
}
void Display_Draw() {
OS_ERR err;
// I don't have any clue why this delay is needed.
// I encountered a problem that the project gave random outputs
// to the screen while running without breakpoints in debug. So I
// had to manually insert dummy "breakpoint"
OSTimeDly(200, OS_OPT_TIME_DLY, &err);
Update_Buffer();
// Currently expects that the buffer is correctly structured
if (memcmp(lcd_current, lcd_buffer, LCD_BUFFER_SIZE * sizeof(char)) != 0) {
Render_Buffer_to_LCD();
memcpy(lcd_current, lcd_buffer, LCD_BUFFER_SIZE * sizeof(char));
}
}
void Display_SetMode(SensorDataType mode) {
g_display_mode = mode;
}
uint8_t Display_IsUpdating() {
return g_is_updating;
}