-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathscope_display.c
169 lines (149 loc) · 4.29 KB
/
scope_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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
* Graphical Oscilloscope Display
*
* @Company
* 1o1 Oscilloscope Team
*
* @File Name
* scope_display.c
*
* @Summary
* Contains the glue logic to run the display for the oscilloscope.
*/
#include "scope_display.h"
#include <stdbool.h>
#include <stdint.h>
#include "common/screen.h"
#include "common/sw_timer.h"
#include "drivers/ssd1305.h"
#include "graphics/font.h"
#include "graphics/graphics.h"
#include "graphics/packed_graphics.h"
// Basic graphical objects
FULLSIZE_LAYER(l_grid);
FULLSIZE_LAYER(l_plot);
FULLSIZE_LAYER(m_toast);
FULLSIZE_LAYER(l_toast);
screen_t * layers[LAYER_COUNT] = {
&l_grid,
&l_plot,
&m_toast,
&l_toast
};
bool layer_is_mask[LAYER_COUNT] = {
false,
false,
true,
false
};
uint8_t output_values[XALG_COLUMNS][XALG_PAGES] = { 0 };
packed_graphics_t output = {
XALG_COLUMNS,
XALG_PAGES,
(uint8_t *)output_values
};
sw_timer toast_timeout = TIMER(2500);
sw_timer splash_timeout = TIMER(1500);
bool update = false;
static void
display_layers ()
{
graphics_pack_layers(layers, LAYER_COUNT, &output, layer_is_mask);
ssd1305_write_all(&output);
}
static void
generate_grid (screen_t * layer)
{
graphics_fill_screen(layer, false);
graphics_dotted_line(layer, S_VECTOR(16, 0), layer->size.y, true, 5, true);
graphics_dotted_line(layer, S_VECTOR(32, 0), layer->size.y, true, 5, true);
graphics_dotted_line(layer, S_VECTOR(48, 0), layer->size.y, true, 2, true);
graphics_dotted_line(layer, S_VECTOR(64, 0), layer->size.y, true, 5, true);
graphics_dotted_line(layer, S_VECTOR(80, 0), layer->size.y, true, 5, true);
graphics_dotted_line(layer, S_VECTOR(0, 16), layer->size.x, false, 5, true);
graphics_dotted_line(layer, S_VECTOR(0, 32), layer->size.x, false, 2, true);
graphics_dotted_line(layer, S_VECTOR(0, 48), layer->size.x, false, 5, true);
}
void
sd_init ()
{
ssd1305_write_all(&graphics_logo);
sw_timer_reset(&splash_timeout);
graphics_fill_screen(&l_grid, false);
graphics_fill_screen(&l_plot, false);
graphics_fill_screen(&m_toast, true);
graphics_fill_screen(&l_toast, false);
}
void
sd_task ()
{
if (splash_timeout.running && !sw_timer_expired(splash_timeout))
{
return;
}
else if (splash_timeout.running)
{
splash_timeout.running = false;
generate_grid(&l_grid);
update = true;
}
if (sw_timer_expired(toast_timeout))
{ // Toast already displayed, reset.
graphics_fill_screen(&m_toast, true);
graphics_fill_screen(&l_toast, false);
update = true;
toast_timeout.running = false;
}
if (update)
{
display_layers();
update = false;
}
}
void
sd_show_toast (char * text)
{
char buffer[TOAST_MAX_LENGTH] = { 0 };
unsigned int textlen = font_process_string(text, buffer, TOAST_MAX_LENGTH);
s_vector_t text_size = { 0 };
font_error_t error = font_size(&font_standard, buffer, textlen,
m_toast.size.x - 16, &text_size);
text_size = S_VECTOR_SUB(text_size, S_VECTOR(1, 3));
if ((error != FONT_ERROR_NONE) || (text_size.y > (m_toast.size.y - 16)))
{ // Text invalid
return;
}
const s_coord_t padding = 3;
const s_coord_t border = 2;
const s_coord_t margin_bottom = 6;
s_coord_t x_center = m_toast.size.x / 2;
s_vector_t outline = S_VECTOR_MUL(S_VECTOR_ONE, padding + border);
s_vector_t size = S_VECTOR_ADD(text_size, S_VECTOR_MUL(outline, 2));
s_vector_t topleft = S_VECTOR(x_center - size.x / 2,\
m_toast.size.y - size.y - margin_bottom);
graphics_fill_screen(&m_toast, true);
graphics_fill_screen(&l_toast, false);
graphics_fill_rect(&m_toast, topleft, S_VECTOR_ADD(topleft, size), false);
graphics_draw_rect(&l_toast, S_VECTOR_ADD(topleft, S_VECTOR_ONE),
S_VECTOR_SUB(S_VECTOR_ADD(topleft, size), S_VECTOR_ONE), true);
font_write(&font_standard, buffer, textlen, &l_toast,
S_VECTOR_ADD(topleft, outline), m_toast.size.x - 16, false);
update = true;
sw_timer_reset(&toast_timeout);
}
void
sd_plot_data (uint8_t * buffer, uint8_t size)
{
graphics_fill_screen(&l_plot, false);
s_coord_t y_max = l_plot.size.y - 1;
for (uint8_t i = 0; i < SMIN(size - 1, l_plot.size.x - 1); i++)
{
graphics_draw_line(
&l_plot,
S_VECTOR(i, y_max - SMIN(buffer[i], y_max)),
S_VECTOR(i + 1, y_max - SMIN(buffer[i + 1], y_max)),
true
);
}
update = true;
}