components/u8g2/csrc/u8log.c

Tue, 03 Oct 2023 17:24:06 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Tue, 03 Oct 2023 17:24:06 +0200
changeset 77
15dc572a7fcb
parent 0
88d965579617
permissions
-rw-r--r--

Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.

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 u8log.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 Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
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 Copyright (c) 2018, olikraus@gmail.com
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 All rights reserved.
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 Redistribution and use in source and binary forms, with or without modification,
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 are permitted provided that the following conditions are met:
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 * Redistributions of source code must retain the above copyright notice, this list
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 of conditions and the following disclaimer.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 * Redistributions in binary form must reproduce the above copyright notice, this
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 list of conditions and the following disclaimer in the documentation and/or other
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 materials provided with the distribution.
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 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35 */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37 #include <stdint.h>
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 #include <string.h>
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39 #include "u8x8.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42 /*
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43 static uint8_t u8log_is_on_screen(u8log_t *u8log, uint8_t x, uint8_t y)
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 if ( x >= u8log->width )
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46 return 0;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47 if ( y >= u8log->height )
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48 return 0;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49 return 1;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51 */
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 static void u8log_clear_screen(u8log_t *u8log)
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55 uint8_t *dest = u8log->screen_buffer;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56 uint16_t cnt = u8log->height;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57 cnt *= u8log->width;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58 do
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59 {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60 *dest++ = ' ';
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61 cnt--;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62 } while( cnt > 0 );
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
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 /* scroll the content of the complete buffer, set redraw_line to 255 */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68 static void u8log_scroll_up(u8log_t *u8log)
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69 {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
70 uint8_t *dest = u8log->screen_buffer;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
71 uint8_t *src = dest+u8log->width;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72 uint16_t cnt = u8log->height;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73 cnt--;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74 cnt *= u8log->width;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75 do
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76 {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
77 *dest++ = *src++;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
78 cnt--;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79 } while( cnt > 0 );
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80 cnt = u8log->width;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81 do
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 *dest++ = ' ';
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
84 cnt--;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
85 } while(cnt > 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 if ( u8log->is_redraw_line_for_each_char )
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
88 u8log->is_redraw_all = 1;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
89 else
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
90 u8log->is_redraw_all_required_for_next_nl = 1;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
91 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
92
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 Place the cursor on the screen. This will also scroll, if required
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
95 */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
96 static void u8log_cursor_on_screen(u8log_t *u8log)
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 //printf("u8log_cursor_on_screen, cursor_y=%d\n", u8log->cursor_y);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
99 if ( u8log->cursor_x >= u8log->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 u8log->cursor_x = 0;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
102 u8log->cursor_y++;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
103 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
104 while ( u8log->cursor_y >= u8log->height )
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 u8log_scroll_up(u8log);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
107 u8log->cursor_y--;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
108 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
109 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
110
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 Write a printable, single char on the screen, do any kind of scrolling
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 static void u8log_write_to_screen(u8log_t *u8log, uint8_t c)
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
115 {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
116 u8log_cursor_on_screen(u8log);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
117 u8log->screen_buffer[u8log->cursor_y * u8log->width + u8log->cursor_x] = c;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
118 u8log->cursor_x++;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
119
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
120 if ( u8log->is_redraw_line_for_each_char )
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 u8log->is_redraw_line = 1;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
123 u8log->redraw_line = u8log->cursor_y;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
124 }
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
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 Handle control codes or write the char to the screen.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
129 Supported control codes are:
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
130
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
131 \n 10 Goto first position of the next line. Line is marked for redraw.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
132 \r 13 Goto first position in the same line. Line is marked for redraw.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
133 \t 9 Jump to the next tab position
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
134 \f 12 Clear the screen and mark redraw for whole screen
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
135 any other char Write char to screen. Line redraw mark depends on
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
136 is_redraw_line_for_each_char flag.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
137 */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
138 void u8log_write_char(u8log_t *u8log, uint8_t c)
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
139 {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
140 switch(c)
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 case '\n': // 10
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
143 u8log->is_redraw_line = 1;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
144 u8log->redraw_line = u8log->cursor_y;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
145 if ( u8log->is_redraw_all_required_for_next_nl )
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
146 u8log->is_redraw_all = 1;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
147 u8log->is_redraw_all_required_for_next_nl = 0;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
148 u8log->cursor_y++;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
149 u8log->cursor_x = 0;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
150 break;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
151 case '\r': // 13
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
152 u8log->is_redraw_line = 1;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
153 u8log->redraw_line = u8log->cursor_y;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
154 u8log->cursor_x = 0;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
155 break;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
156 case '\t': // 9
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
157 u8log->cursor_x = (u8log->cursor_x + 8) & 0xf8;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
158 break;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
159 case '\f': // 12
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
160 u8log_clear_screen(u8log);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
161 u8log->is_redraw_all = 1;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
162 u8log->cursor_x = 0;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
163 u8log->cursor_y = 0;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
164 break;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
165 default:
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
166 u8log_write_to_screen(u8log, c);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
167 break;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
168 }
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
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
171 void u8log_Init(u8log_t *u8log, uint8_t width, uint8_t height, uint8_t *buf)
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
172 {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
173 memset(u8log, 0, sizeof(u8log_t));
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
174 u8log->width = width;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
175 u8log->height = height;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
176 u8log->screen_buffer = buf;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
177 u8log_clear_screen(u8log);
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 void u8log_SetCallback(u8log_t *u8log, u8log_cb cb, void *aux_data)
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
181 {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
182 u8log->cb = cb;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
183 u8log->aux_data = aux_data;
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
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
186 void u8log_SetRedrawMode(u8log_t *u8log, uint8_t is_redraw_line_for_each_char)
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
187 {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
188 u8log->is_redraw_line_for_each_char = is_redraw_line_for_each_char;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
189 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
190
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
191 /* offset can be negative or positive, it is 0 by default */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
192 void u8log_SetLineHeightOffset(u8log_t *u8log, int8_t line_height_offset)
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 u8log->line_height_offset = line_height_offset;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
195 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
196
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
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
199 void u8log_WriteChar(u8log_t *u8log, uint8_t c)
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
200 {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
201 u8log_write_char(u8log, c);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
202 if ( u8log->is_redraw_line || u8log->is_redraw_all )
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
203 {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
204 if ( u8log->cb != 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 u8log->cb(u8log);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
207 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
208 u8log->is_redraw_line = 0;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
209 u8log->is_redraw_all = 0;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
210 }
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
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
213 void u8log_WriteString(u8log_t *u8log, const char *s)
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
214 {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
215 while( *s != '\0' )
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 u8log_WriteChar(u8log, *s);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
218 s++;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
219 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
220 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
221
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
222 static void u8log_WriteHexHalfByte(u8log_t *u8log, uint8_t b) U8X8_NOINLINE;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
223 static void u8log_WriteHexHalfByte(u8log_t *u8log, uint8_t b)
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
224 {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
225 b &= 0x0f;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
226 if ( b < 10 )
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
227 u8log_WriteChar(u8log, b+'0');
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
228 else
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
229 u8log_WriteChar(u8log, b+'a'-10);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
230 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
231
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
232 void u8log_WriteHex8(u8log_t *u8log, uint8_t b)
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
233 {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
234 u8log_WriteHexHalfByte(u8log, b >> 4);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
235 u8log_WriteHexHalfByte(u8log, b);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
236 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
237
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
238 void u8log_WriteHex16(u8log_t *u8log, uint16_t v)
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
239 {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
240 u8log_WriteHex8(u8log, v>>8);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
241 u8log_WriteHex8(u8log, v);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
242 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
243
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
244 void u8log_WriteHex32(u8log_t *u8log, uint32_t v)
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 u8log_WriteHex16(u8log, v>>16);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
247 u8log_WriteHex16(u8log, v);
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
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
250 /* v = value, d = number of digits (1..3) */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
251 void u8log_WriteDec8(u8log_t *u8log, uint8_t v, uint8_t d)
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
252 {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
253 u8log_WriteString(u8log, u8x8_u8toa(v, d));
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
254 }
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 /* v = value, d = number of digits (1..5) */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
257 void u8log_WriteDec16(u8log_t *u8log, uint16_t v, uint8_t d)
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
258 {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
259 u8log_WriteString(u8log, u8x8_u16toa(v, d));
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
260 }

mercurial