-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_monitor.c
More file actions
122 lines (116 loc) · 2.81 KB
/
debug_monitor.c
File metadata and controls
122 lines (116 loc) · 2.81 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**
* @file debug_monitor.c
* @author BlaCkinkGJ (ss5kijun@gmil.com)
* @brief debug monitor implementation files
* @version 0.1
* @date 2019-06-06
*
*/
#include <debug_monitor.h>
static const char* headers[] = {
"# Flex Ratio",
"# Gyro Value",
"# 3-axis accelerometers",
};
static const int numOfHeader = sizeof(headers) / sizeof(const char*);
static char flexString[256];
static char gyroString[256];
static char accelString[256];
/**
* @brief To use something specific format.
* this is the private function.
* it can't be accessed by other location.
*
* @param data
* @return const char*
*/
static const char* formatter(const char* format, const char* data)
{
static char strBuf[MAX_LCD_CHAR_POSX];
sprintf(strBuf, format, data);
return strBuf;
}
/**
* @brief draw the title
*
* @param title
*/
void drawTitle(const char* title)
{
// LCD Screen: x, y,
LCD_ShowString(1, 1,
(CPU_INT08U*)formatter("[[ %s ]]", title),
BLACK, // foreground color
WHITE); // background color
}
/**
* @brief draw the header
*
*/
void drawHeader()
{
int i = 0;
for (i = 0; i < numOfHeader; i++) {
LCD_ShowString(1, FONT_SIZE * (i * 3 + 2),
(CPU_INT08U*)formatter("%s", headers[i]),
BLACK,
WHITE);
}
}
/**
* @brief content formatting
*
* @param id
* @param ptr
* @return const char*
*/
static const char* contentFormatter(int id, const void* ptr)
{
static char strContentBuf[MAX_LCD_CHAR_POSX];
switch (id) {
case 0:
case 1:
case 2:
sprintf(strContentBuf, "%s", (char*)(ptr));
break;
default:
sprintf(strContentBuf, "NOT IMPLEMENTED");
}
return strContentBuf;
}
/**
* @brief draw the contents
*
* @param contents
*/
void drawContents(const struct DebugContents* contents)
{
int i = 0;
//@TODO: you have to change this section for debug contents
void* const* structStartPtr = &(contents->flexRatio);
for (i = 0; i < numOfHeader; i++) {
LCD_ShowString(1, FONT_SIZE * (i * 3 + 3),
(CPU_INT08U*)contentFormatter(i, *structStartPtr),
BLACK,
WHITE);
structStartPtr++;
}
}
/**
* @brief Set the Contents object.
* But sadly I think this will be changed
* because this dependent on the value(int *)
* in other words, THIS IS NOT GENERIC FUNCTION!
*
* @param contents, flex, gyro
* @param pack
*/
void setContents(struct DebugContents* contents, CPU_INT16S* flex, CPU_INT16S* gyro)
{
sprintf(flexString, "%-4d%-4d%-4d", flex[0], flex[1], flex[2]);
sprintf(gyroString, "%-6d%-6d%-6d", gyro[0], gyro[1], gyro[2]);
sprintf(accelString, "%-6d%-6d%-6d", gyro[3], gyro[4], gyro[5]);
contents->flexRatio = flexString;
contents->gyroValue = gyroString;
contents->axisAccel3 = accelString;
}