Browse Source

show multiple joules calculations with different weights

Thomas Buck 1 year ago
parent
commit
01e29dc6fb
2 changed files with 77 additions and 18 deletions
  1. 4
    1
      firmware/OpenChrono/config.h
  2. 73
    17
      firmware/OpenChrono/lcd.cpp

+ 4
- 1
firmware/OpenChrono/config.h View File

19
 
19
 
20
 #define SENSOR_DISTANCE 70.0 /* in mm */
20
 #define SENSOR_DISTANCE 70.0 /* in mm */
21
 #define BB_WEIGHT 0.25 /* in g */
21
 #define BB_WEIGHT 0.25 /* in g */
22
+#define BB_WEIGHTS { 0.20, 0.23, 0.25, 0.28, 0.475 } /* in g */
22
 
23
 
23
 // --------------------------------------
24
 // --------------------------------------
24
 
25
 
28
 #define IMPERIAL 1
29
 #define IMPERIAL 1
29
 #define JOULES 2
30
 #define JOULES 2
30
 
31
 
31
-#define PREFERRED_UNITS JOULES
32
+#define PREFERRED_UNITS METRIC
32
 
33
 
33
 // --------------------------------------
34
 // --------------------------------------
34
 
35
 
51
 }
52
 }
52
 
53
 
53
 #define SCREEN_TIMEOUT 2500 /* in ms */
54
 #define SCREEN_TIMEOUT 2500 /* in ms */
55
+#define FLIP_SCREEN 0
54
 
56
 
55
 // --------------------------------------
57
 // --------------------------------------
56
 
58
 
60
 
62
 
61
 #define HEADING_FONT u8g2_font_VCR_OSD_tr
63
 #define HEADING_FONT u8g2_font_VCR_OSD_tr
62
 #define TEXT_FONT u8g2_font_NokiaLargeBold_tr
64
 #define TEXT_FONT u8g2_font_NokiaLargeBold_tr
65
+#define SMALL_FONT u8g2_font_helvB08_tr
63
 
66
 
64
 // --------------------------------------
67
 // --------------------------------------
65
 
68
 

+ 73
- 17
firmware/OpenChrono/lcd.cpp View File

29
     u8g2.setFontPosBottom();
29
     u8g2.setFontPosBottom();
30
 
30
 
31
     u8g2.clearBuffer();
31
     u8g2.clearBuffer();
32
-    u8g2.setFlipMode(1);
32
+    u8g2.setFlipMode(FLIP_SCREEN);
33
 
33
 
34
     String s = F("OpenChrono");
34
     String s = F("OpenChrono");
35
     u8g2.setFont(HEADING_FONT);
35
     u8g2.setFont(HEADING_FONT);
54
     u8g2.setFont(TEXT_FONT);
54
     u8g2.setFont(TEXT_FONT);
55
     u8g2.drawStr(
55
     u8g2.drawStr(
56
         0,
56
         0,
57
-        u8g2.getDisplayHeight() - u8g2.getMaxCharHeight() - 4,
57
+        u8g2.getDisplayHeight() - u8g2.getMaxCharHeight() - 2,
58
         s.c_str()
58
         s.c_str()
59
     );
59
     );
60
 
60
 
63
     u8g2.setFont(TEXT_FONT);
63
     u8g2.setFont(TEXT_FONT);
64
     u8g2.drawStr(
64
     u8g2.drawStr(
65
         (u8g2.getDisplayWidth() - u8g2.getStrWidth(s.c_str())) / 2,
65
         (u8g2.getDisplayWidth() - u8g2.getStrWidth(s.c_str())) / 2,
66
-        u8g2.getDisplayHeight() - u8g2.getMaxCharHeight() - 4,
66
+        u8g2.getDisplayHeight() - u8g2.getMaxCharHeight() - 2,
67
         s.c_str()
67
         s.c_str()
68
     );
68
     );
69
 
69
 
72
     u8g2.setFont(TEXT_FONT);
72
     u8g2.setFont(TEXT_FONT);
73
     u8g2.drawStr(
73
     u8g2.drawStr(
74
         u8g2.getDisplayWidth() - u8g2.getStrWidth(s.c_str()),
74
         u8g2.getDisplayWidth() - u8g2.getStrWidth(s.c_str()),
75
-        u8g2.getDisplayHeight() - u8g2.getMaxCharHeight() - 4,
75
+        u8g2.getDisplayHeight() - u8g2.getMaxCharHeight() - 2,
76
         s.c_str()
76
         s.c_str()
77
     );
77
     );
78
 
78
 
103
             || (screen == SCREEN_MIN) || (screen == SCREEN_MAX)) {
103
             || (screen == SCREEN_MIN) || (screen == SCREEN_MAX)) {
104
         if (tick_count < 1) {
104
         if (tick_count < 1) {
105
             u8g2.clearBuffer();
105
             u8g2.clearBuffer();
106
-            u8g2.setFlipMode(1);
106
+            u8g2.setFlipMode(FLIP_SCREEN);
107
 
107
 
108
             String s = F("Ready!");
108
             String s = F("Ready!");
109
             u8g2.setFont(HEADING_FONT);
109
             u8g2.setFont(HEADING_FONT);
132
 
132
 
133
         double metric = tick_to_metric(tick);
133
         double metric = tick_to_metric(tick);
134
         double imperial = metric_to_imperial(metric);
134
         double imperial = metric_to_imperial(metric);
135
-        double joules = metric_to_joules(metric, BB_WEIGHT);
135
+
136
+        double weights[] = BB_WEIGHTS;
137
+        double joules[sizeof(weights) / sizeof(weights[0])];
138
+
139
+        for (uint8_t i = 0; i < (sizeof(weights) / sizeof(weights[0])); i++) {
140
+            joules[i] = metric_to_joules(metric, weights[i]);
141
+        }
136
 
142
 
137
         u8g2.clearBuffer();
143
         u8g2.clearBuffer();
138
-        u8g2.setFlipMode(1);
144
+        u8g2.setFlipMode(FLIP_SCREEN);
139
         u8g2.setFont(TEXT_FONT);
145
         u8g2.setFont(TEXT_FONT);
140
 
146
 
141
         String s;
147
         String s;
158
             s.c_str()
164
             s.c_str()
159
         );
165
         );
160
 
166
 
167
+        uint8_t left_off = (u8g2.getDisplayHeight() - (u8g2.getMaxCharHeight() * 4 + 3)) / 2;
168
+
161
         s = String(metric, 0);
169
         s = String(metric, 0);
162
         s += F(" m/s");
170
         s += F(" m/s");
171
+        uint8_t l1 = u8g2.getStrWidth(s.c_str());
163
         u8g2.drawStr(
172
         u8g2.drawStr(
164
             0,
173
             0,
165
-            u8g2.getMaxCharHeight() * 2 + 1,
174
+            u8g2.getMaxCharHeight() * 2 + 1 + left_off,
166
             s.c_str()
175
             s.c_str()
167
         );
176
         );
168
 
177
 
169
         s = String(imperial, 0);
178
         s = String(imperial, 0);
170
         s += F(" FPS");
179
         s += F(" FPS");
180
+        uint8_t l2 = u8g2.getStrWidth(s.c_str());
171
         u8g2.drawStr(
181
         u8g2.drawStr(
172
             0,
182
             0,
173
-            u8g2.getMaxCharHeight() * 3 + 2,
183
+            u8g2.getMaxCharHeight() * 3 + 2 + left_off,
174
             s.c_str()
184
             s.c_str()
175
         );
185
         );
176
 
186
 
177
-        s = String(joules, 2);
178
-        s += F(" J");
179
-        u8g2.drawStr(
180
-            0,
181
-            u8g2.getMaxCharHeight() * 4 + 3,
182
-            s.c_str()
187
+        uint8_t l3 = 0;
188
+        for (uint8_t i = 0; i < (sizeof(weights) / sizeof(weights[0])); i++) {
189
+            if (weights[i] == BB_WEIGHT) {
190
+                s = String(joules[i], 2);
191
+                s += F(" J");
192
+                l3 = u8g2.getStrWidth(s.c_str());
193
+                u8g2.drawStr(
194
+                    0,
195
+                    u8g2.getMaxCharHeight() * 4 + 3 + left_off,
196
+                    s.c_str()
197
+                );
198
+                break;
199
+            }
200
+        }
201
+
202
+        uint8_t l4 = 0;
203
+        uint8_t h = u8g2.getMaxCharHeight() + 1;
204
+        for (uint8_t i = 0; i < (sizeof(weights) / sizeof(weights[0])); i++) {
205
+            if (weights[i] == BB_WEIGHT) {
206
+                //u8g2.setFont(TEXT_FONT);
207
+                continue;
208
+            } else {
209
+                u8g2.setFont(SMALL_FONT);
210
+            }
211
+
212
+            s = String(weights[i], 2);
213
+            s += F("g ");
214
+            s += String(joules[i], 2);
215
+            s += F("J");
216
+
217
+            uint8_t l = u8g2.getStrWidth(s.c_str());
218
+            if (l > l4) {
219
+                l4 = l;
220
+            }
221
+
222
+            h += u8g2.getMaxCharHeight() + 1;
223
+
224
+            u8g2.drawStr(
225
+                u8g2.getDisplayWidth() - l,
226
+                h,
227
+                s.c_str()
228
+            );
229
+        }
230
+
231
+        uint8_t l_left = max(max(l1, l2), l3);
232
+        uint8_t l_right = u8g2.getDisplayWidth() - l4;
233
+        uint8_t lmax = (uint8_t)((((uint16_t)l_left) + ((uint16_t)l_right)) / 2);
234
+
235
+        u8g2.setFont(TEXT_FONT);
236
+        u8g2.drawLine(
237
+            lmax, u8g2.getMaxCharHeight() + 2,
238
+            lmax, u8g2.getDisplayHeight()
183
         );
239
         );
184
 
240
 
185
         u8g2.sendBuffer();
241
         u8g2.sendBuffer();
189
         String s;
245
         String s;
190
 
246
 
191
         u8g2.clearBuffer();
247
         u8g2.clearBuffer();
192
-        u8g2.setFlipMode(1);
248
+        u8g2.setFlipMode(FLIP_SCREEN);
193
         u8g2.setFont(TEXT_FONT);
249
         u8g2.setFont(TEXT_FONT);
194
 
250
 
195
         // max text
251
         // max text
274
     if ((millis() - lcd_rotate_time) > SCREEN_TIMEOUT) {
330
     if ((millis() - lcd_rotate_time) > SCREEN_TIMEOUT) {
275
         lcd_rotate_time = millis();
331
         lcd_rotate_time = millis();
276
         lcd_screen++;
332
         lcd_screen++;
277
-        if (lcd_screen >= sizeof(screens)) {
333
+        if (lcd_screen >= (sizeof(screens) / sizeof(screens[0]))) {
278
             lcd_screen = 0;
334
             lcd_screen = 0;
279
         }
335
         }
280
 
336
 

Loading…
Cancel
Save