105 */ |
105 */ |
106 int getkey(int *curkey, int type, int x, int y) |
106 int getkey(int *curkey, int type, int x, int y) |
107 { |
107 { |
108 int key = *curkey; |
108 int key = *curkey; |
109 int rc = 0; |
109 int rc = 0; |
|
110 int8_t ascent = u8g2_GetAscent(&u8g2); |
|
111 int8_t charheight = u8g2_GetMaxCharHeight(&u8g2); |
|
112 int8_t charwidth = u8g2_GetMaxCharWidth(&u8g2); |
110 |
113 |
111 u8g2_DrawHLine(&u8g2, x, y+3, 12); |
114 u8g2_DrawHLine(&u8g2, x, y+3, 12); |
112 u8g2_SendBuffer(&u8g2); |
115 u8g2_SendBuffer(&u8g2); |
|
116 |
|
117 ESP_LOGI(TAG, "getkey(%c, %d, %d, %d) a %d h %d w %d", key, type, x, y, ascent, charheight, charwidth); |
113 |
118 |
114 for (;;) { |
119 for (;;) { |
115 if (xQueueReceive(event_queue, &event, 100 / portTICK_PERIOD_MS) == pdTRUE) { |
120 if (xQueueReceive(event_queue, &event, 100 / portTICK_PERIOD_MS) == pdTRUE) { |
116 UserTimer = INACTIVITY; |
121 UserTimer = INACTIVITY; |
117 if (event.state.position != 0) { |
122 if (event.state.position != 0) { |
118 |
123 |
119 u8g2_SetDrawColor(&u8g2, 0); |
124 // u8g2_SetDrawColor(&u8g2, 0); |
120 u8g2_DrawGlyph(&u8g2, x, y, key); |
125 // u8g2_DrawGlyph(&u8g2, x, y, key); |
121 u8g2_SetDrawColor(&u8g2, 1); |
126 // u8g2_SetDrawColor(&u8g2, 1); |
|
127 |
|
128 u8g2_DrawBox(&u8g2, x, y - ascent, 16, 16); |
|
129 // u8g2_UpdateDisplayArea(&u8g2, x, y, 16, 16); |
122 u8g2_SendBuffer(&u8g2); |
130 u8g2_SendBuffer(&u8g2); |
123 |
131 |
124 if (event.state.position > 0) { |
132 if (event.state.position > 0) { |
125 if (key == 126) |
133 // if (key == 126) |
126 key = 171; |
134 // key = 171; |
127 else if (key < 126) |
135 // else |
|
136 if (key < 127) |
128 key++; |
137 key++; |
129 } else if (event.state.position < 0) { |
138 } else if (event.state.position < 0) { |
130 if (key == 171) |
139 // if (key == 171) |
131 key = 126; |
140 // key = 126; |
132 else if (key > 32) |
141 // else |
|
142 if (key > 32) |
133 key--; |
143 key--; |
134 } |
144 } |
135 |
145 |
136 ESP_ERROR_CHECK(rotary_encoder_reset(&rinfo)); |
146 ESP_ERROR_CHECK(rotary_encoder_reset(&rinfo)); |
137 u8g2_DrawGlyph(&u8g2, x, y, key); |
147 u8g2_DrawGlyph(&u8g2, x, y, key); |
181 |
191 |
182 if (strlen(errmsg)) { |
192 if (strlen(errmsg)) { |
183 u8g2_SetFont(&u8g2, u8g2_font_t0_12b_tf); |
193 u8g2_SetFont(&u8g2, u8g2_font_t0_12b_tf); |
184 u8g2_DrawStr(&u8g2, 0, 61, errmsg); |
194 u8g2_DrawStr(&u8g2, 0, 61, errmsg); |
185 } |
195 } |
186 u8g2_SetFont(&u8g2, u8g2_font_t0_12_tf); |
196 u8g2_SetFont(&u8g2, u8g2_font_unifont_t_symbols); |
|
197 // u8g2_SetFont(&u8g2, u8g2_font_t0_12_tf); |
187 y = 36; |
198 y = 36; |
188 u8g2_DrawStr(&u8g2, 0, y, txt); |
199 u8g2_DrawStr(&u8g2, 0, y, txt); |
189 u8g2_SendBuffer(&u8g2); |
200 u8g2_SendBuffer(&u8g2); |
|
201 ESP_LOGI(TAG, "rotary_editer(%s, %s, %s, %d, %d)", label, txt, errmsg, len, type); |
190 |
202 |
191 for (;;) { |
203 for (;;) { |
192 x = u8g2_GetUTF8Width(&u8g2, txt); |
204 x = u8g2_GetUTF8Width(&u8g2, txt); |
193 key = 'a'; |
205 key = 'a'; |
194 rc = getkey(&key, type, x, y); |
206 rc = getkey(&key, type, x, y); |
297 sprintf(buf, "%.1f", units[i].pressure / 1000.0); |
309 sprintf(buf, "%.1f", units[i].pressure / 1000.0); |
298 w = u8g2_GetUTF8Width(&u8g2, buf); |
310 w = u8g2_GetUTF8Width(&u8g2, buf); |
299 u8g2_DrawUTF8(&u8g2, ((42 - w) / 2) + i * 43,63, buf); |
311 u8g2_DrawUTF8(&u8g2, ((42 - w) / 2) + i * 43,63, buf); |
300 } |
312 } |
301 xSemaphoreGive(xSemaphoreUnits); |
313 xSemaphoreGive(xSemaphoreUnits); |
|
314 } else { |
|
315 ESP_LOGE(TAG, "screen_main() lock error"); |
302 } |
316 } |
303 u8g2_SendBuffer(&u8g2); |
317 u8g2_SendBuffer(&u8g2); |
304 u8g2_SetPowerSave(&u8g2, 0); // wake up display |
318 u8g2_SetPowerSave(&u8g2, 0); // wake up display |
305 } |
319 } |
306 |
320 |
324 u8g2_DrawUTF8(&u8g2, (128 - w) / 2,40, buf); |
338 u8g2_DrawUTF8(&u8g2, (128 - w) / 2,40, buf); |
325 |
339 |
326 sprintf(buf, "%.2f bar", units[no].pressure / 1000.0); |
340 sprintf(buf, "%.2f bar", units[no].pressure / 1000.0); |
327 w = u8g2_GetUTF8Width(&u8g2, buf); |
341 w = u8g2_GetUTF8Width(&u8g2, buf); |
328 u8g2_DrawUTF8(&u8g2, (128 - w) / 2,63, buf); |
342 u8g2_DrawUTF8(&u8g2, (128 - w) / 2,63, buf); |
|
343 u8g2_SendBuffer(&u8g2); |
329 |
344 |
330 xSemaphoreGive(xSemaphoreUnits); |
345 xSemaphoreGive(xSemaphoreUnits); |
331 } |
346 } else { |
332 u8g2_SendBuffer(&u8g2); |
347 ESP_LOGE(TAG, "screen_unit(%d) lock error", no); |
|
348 } |
333 } |
349 } |
334 |
350 |
335 |
351 |
336 |
352 |
337 /** |
353 /** |