Tue, 08 Oct 2019 12:00:31 +0200
Initial import of the CO2 meter application.
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1 | /* |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
2 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
3 | u8g22_polygon.c |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
4 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
5 | */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
6 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
7 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
8 | #include "u8g2.h" |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
9 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
10 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
11 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
12 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
13 | /*===========================================*/ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
14 | /* local definitions */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
15 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
16 | typedef int16_t pg_word_t; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
17 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
18 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
19 | struct pg_point_struct |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
20 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
21 | pg_word_t x; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
22 | pg_word_t y; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
23 | }; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
24 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
25 | typedef struct _pg_struct pg_struct; /* forward declaration */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
26 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
27 | struct pg_edge_struct |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
28 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
29 | pg_word_t x_direction; /* 1, if x2 is greater than x1, -1 otherwise */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
30 | pg_word_t height; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
31 | pg_word_t current_x_offset; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
32 | pg_word_t error_offset; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
33 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
34 | /* --- line loop --- */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
35 | pg_word_t current_y; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
36 | pg_word_t max_y; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
37 | pg_word_t current_x; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
38 | pg_word_t error; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
39 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
40 | /* --- outer loop --- */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
41 | uint8_t (*next_idx_fn)(pg_struct *pg, uint8_t i); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
42 | uint8_t curr_idx; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
43 | }; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
44 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
45 | /* maximum number of points in the polygon */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
46 | /* can be redefined, but highest possible value is 254 */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
47 | #define PG_MAX_POINTS 6 |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
48 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
49 | /* index numbers for the pge structures below */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
50 | #define PG_LEFT 0 |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
51 | #define PG_RIGHT 1 |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
52 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
53 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
54 | struct _pg_struct |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
55 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
56 | struct pg_point_struct list[PG_MAX_POINTS]; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
57 | uint8_t cnt; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
58 | uint8_t is_min_y_not_flat; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
59 | pg_word_t total_scan_line_cnt; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
60 | struct pg_edge_struct pge[2]; /* left and right line draw structures */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
61 | }; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
62 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
63 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
64 | /*===========================================*/ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
65 | /* procedures, which should not be inlined (save as much flash ROM as possible */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
66 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
67 | #define PG_NOINLINE U8G2_NOINLINE |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
68 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
69 | static uint8_t pge_Next(struct pg_edge_struct *pge) PG_NOINLINE; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
70 | static uint8_t pg_inc(pg_struct *pg, uint8_t i) PG_NOINLINE; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
71 | static uint8_t pg_dec(pg_struct *pg, uint8_t i) PG_NOINLINE; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
72 | static void pg_expand_min_y(pg_struct *pg, pg_word_t min_y, uint8_t pge_idx) PG_NOINLINE; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
73 | static void pg_line_init(pg_struct * const pg, uint8_t pge_index) PG_NOINLINE; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
74 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
75 | /*===========================================*/ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
76 | /* line draw algorithm */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
77 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
78 | static uint8_t pge_Next(struct pg_edge_struct *pge) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
79 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
80 | if ( pge->current_y >= pge->max_y ) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
81 | return 0; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
82 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
83 | pge->current_x += pge->current_x_offset; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
84 | pge->error += pge->error_offset; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
85 | if ( pge->error > 0 ) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
86 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
87 | pge->current_x += pge->x_direction; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
88 | pge->error -= pge->height; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
89 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
90 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
91 | pge->current_y++; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
92 | return 1; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
93 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
94 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
95 | /* assumes y2 > y1 */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
96 | static void pge_Init(struct pg_edge_struct *pge, pg_word_t x1, pg_word_t y1, pg_word_t x2, pg_word_t y2) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
97 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
98 | pg_word_t dx = x2 - x1; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
99 | pg_word_t width; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
100 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
101 | pge->height = y2 - y1; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
102 | pge->max_y = y2; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
103 | pge->current_y = y1; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
104 | pge->current_x = x1; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
105 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
106 | if ( dx >= 0 ) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
107 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
108 | pge->x_direction = 1; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
109 | width = dx; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
110 | pge->error = 0; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
111 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
112 | else |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
113 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
114 | pge->x_direction = -1; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
115 | width = -dx; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
116 | pge->error = 1 - pge->height; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
117 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
118 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
119 | pge->current_x_offset = dx / pge->height; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
120 | pge->error_offset = width % pge->height; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
121 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
122 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
123 | /*===========================================*/ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
124 | /* convex polygon algorithm */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
125 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
126 | static uint8_t pg_inc(pg_struct *pg, uint8_t i) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
127 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
128 | i++; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
129 | if ( i >= pg->cnt ) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
130 | i = 0; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
131 | return i; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
132 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
133 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
134 | static uint8_t pg_dec(pg_struct *pg, uint8_t i) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
135 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
136 | i--; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
137 | if ( i >= pg->cnt ) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
138 | i = pg->cnt-1; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
139 | return i; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
140 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
141 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
142 | static void pg_expand_min_y(pg_struct *pg, pg_word_t min_y, uint8_t pge_idx) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
143 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
144 | uint8_t i = pg->pge[pge_idx].curr_idx; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
145 | for(;;) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
146 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
147 | i = pg->pge[pge_idx].next_idx_fn(pg, i); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
148 | if ( pg->list[i].y != min_y ) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
149 | break; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
150 | pg->pge[pge_idx].curr_idx = i; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
151 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
152 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
153 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
154 | static uint8_t pg_prepare(pg_struct *pg) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
155 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
156 | pg_word_t max_y; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
157 | pg_word_t min_y; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
158 | uint8_t i; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
159 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
160 | /* setup the next index procedures */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
161 | pg->pge[PG_RIGHT].next_idx_fn = pg_inc; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
162 | pg->pge[PG_LEFT].next_idx_fn = pg_dec; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
163 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
164 | /* search for highest and lowest point */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
165 | max_y = pg->list[0].y; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
166 | min_y = pg->list[0].y; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
167 | pg->pge[PG_LEFT].curr_idx = 0; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
168 | for( i = 1; i < pg->cnt; i++ ) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
169 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
170 | if ( max_y < pg->list[i].y ) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
171 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
172 | max_y = pg->list[i].y; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
173 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
174 | if ( min_y > pg->list[i].y ) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
175 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
176 | pg->pge[PG_LEFT].curr_idx = i; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
177 | min_y = pg->list[i].y; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
178 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
179 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
180 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
181 | /* calculate total number of scan lines */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
182 | pg->total_scan_line_cnt = max_y; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
183 | pg->total_scan_line_cnt -= min_y; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
184 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
185 | /* exit if polygon height is zero */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
186 | if ( pg->total_scan_line_cnt == 0 ) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
187 | return 0; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
188 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
189 | /* if the minimum y side is flat, try to find the lowest and highest x points */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
190 | pg->pge[PG_RIGHT].curr_idx = pg->pge[PG_LEFT].curr_idx; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
191 | pg_expand_min_y(pg, min_y, PG_RIGHT); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
192 | pg_expand_min_y(pg, min_y, PG_LEFT); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
193 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
194 | /* check if the min side is really flat (depends on the x values) */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
195 | pg->is_min_y_not_flat = 1; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
196 | if ( pg->list[pg->pge[PG_LEFT].curr_idx].x != pg->list[pg->pge[PG_RIGHT].curr_idx].x ) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
197 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
198 | pg->is_min_y_not_flat = 0; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
199 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
200 | else |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
201 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
202 | pg->total_scan_line_cnt--; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
203 | if ( pg->total_scan_line_cnt == 0 ) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
204 | return 0; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
205 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
206 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
207 | return 1; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
208 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
209 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
210 | static void pg_hline(pg_struct *pg, u8g2_t *u8g2) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
211 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
212 | pg_word_t x1, x2, y; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
213 | x1 = pg->pge[PG_LEFT].current_x; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
214 | x2 = pg->pge[PG_RIGHT].current_x; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
215 | y = pg->pge[PG_RIGHT].current_y; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
216 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
217 | if ( y < 0 ) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
218 | return; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
219 | if ( y >= u8g2_GetDisplayHeight(u8g2) ) // does not work for 256x64 display??? |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
220 | return; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
221 | if ( x1 < x2 ) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
222 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
223 | if ( x2 < 0 ) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
224 | return; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
225 | if ( x1 >= u8g2_GetDisplayWidth(u8g2) ) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
226 | return; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
227 | if ( x1 < 0 ) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
228 | x1 = 0; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
229 | if ( x2 >= u8g2_GetDisplayWidth(u8g2) ) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
230 | x2 = u8g2_GetDisplayWidth(u8g2); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
231 | u8g2_DrawHLine(u8g2, x1, y, x2 - x1); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
232 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
233 | else |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
234 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
235 | if ( x1 < 0 ) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
236 | return; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
237 | if ( x2 >= u8g2_GetDisplayWidth(u8g2) ) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
238 | return; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
239 | if ( x2 < 0 ) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
240 | x1 = 0; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
241 | if ( x1 >= u8g2_GetDisplayWidth(u8g2) ) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
242 | x1 = u8g2_GetDisplayWidth(u8g2); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
243 | u8g2_DrawHLine(u8g2, x2, y, x1 - x2); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
244 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
245 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
246 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
247 | static void pg_line_init(pg_struct * const pg, uint8_t pge_index) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
248 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
249 | struct pg_edge_struct *pge = pg->pge+pge_index; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
250 | uint8_t idx; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
251 | pg_word_t x1; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
252 | pg_word_t y1; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
253 | pg_word_t x2; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
254 | pg_word_t y2; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
255 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
256 | idx = pge->curr_idx; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
257 | y1 = pg->list[idx].y; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
258 | x1 = pg->list[idx].x; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
259 | idx = pge->next_idx_fn(pg, idx); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
260 | y2 = pg->list[idx].y; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
261 | x2 = pg->list[idx].x; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
262 | pge->curr_idx = idx; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
263 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
264 | pge_Init(pge, x1, y1, x2, y2); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
265 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
266 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
267 | static void pg_exec(pg_struct *pg, u8g2_t *u8g2) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
268 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
269 | pg_word_t i = pg->total_scan_line_cnt; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
270 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
271 | /* first line is skipped if the min y line is not flat */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
272 | pg_line_init(pg, PG_LEFT); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
273 | pg_line_init(pg, PG_RIGHT); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
274 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
275 | if ( pg->is_min_y_not_flat != 0 ) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
276 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
277 | pge_Next(&(pg->pge[PG_LEFT])); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
278 | pge_Next(&(pg->pge[PG_RIGHT])); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
279 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
280 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
281 | do |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
282 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
283 | pg_hline(pg, u8g2); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
284 | while ( pge_Next(&(pg->pge[PG_LEFT])) == 0 ) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
285 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
286 | pg_line_init(pg, PG_LEFT); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
287 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
288 | while ( pge_Next(&(pg->pge[PG_RIGHT])) == 0 ) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
289 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
290 | pg_line_init(pg, PG_RIGHT); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
291 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
292 | i--; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
293 | } while( i > 0 ); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
294 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
295 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
296 | /*===========================================*/ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
297 | /* API procedures */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
298 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
299 | static void pg_ClearPolygonXY(pg_struct *pg) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
300 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
301 | pg->cnt = 0; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
302 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
303 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
304 | static void pg_AddPolygonXY(pg_struct *pg, int16_t x, int16_t y) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
305 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
306 | if ( pg->cnt < PG_MAX_POINTS ) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
307 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
308 | pg->list[pg->cnt].x = x; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
309 | pg->list[pg->cnt].y = y; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
310 | pg->cnt++; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
311 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
312 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
313 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
314 | static void pg_DrawPolygon(pg_struct *pg, u8g2_t *u8g2) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
315 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
316 | if ( pg_prepare(pg) == 0 ) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
317 | return; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
318 | pg_exec(pg, u8g2); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
319 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
320 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
321 | pg_struct u8g2_pg; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
322 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
323 | void u8g2_ClearPolygonXY(void) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
324 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
325 | pg_ClearPolygonXY(&u8g2_pg); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
326 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
327 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
328 | void u8g2_AddPolygonXY(U8X8_UNUSED u8g2_t *u8g2, int16_t x, int16_t y) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
329 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
330 | pg_AddPolygonXY(&u8g2_pg, x, y); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
331 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
332 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
333 | void u8g2_DrawPolygon(u8g2_t *u8g2) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
334 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
335 | pg_DrawPolygon(&u8g2_pg, u8g2); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
336 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
337 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
338 | void u8g2_DrawTriangle(u8g2_t *u8g2, int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
339 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
340 | u8g2_ClearPolygonXY(); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
341 | u8g2_AddPolygonXY(u8g2, x0, y0); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
342 | u8g2_AddPolygonXY(u8g2, x1, y1); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
343 | u8g2_AddPolygonXY(u8g2, x2, y2); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
344 | u8g2_DrawPolygon(u8g2); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
345 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
346 |