Kaynağa Gözat

show multiple joules calculations with different weights

Thomas Buck 2 yıl önce
ebeveyn
işleme
01e29dc6fb
2 değiştirilmiş dosya ile 77 ekleme ve 18 silme
  1. 4
    1
      firmware/OpenChrono/config.h
  2. 73
    17
      firmware/OpenChrono/lcd.cpp

+ 4
- 1
firmware/OpenChrono/config.h Dosyayı Görüntüle

@@ -19,6 +19,7 @@
19 19
 
20 20
 #define SENSOR_DISTANCE 70.0 /* in mm */
21 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,7 +29,7 @@
28 29
 #define IMPERIAL 1
29 30
 #define JOULES 2
30 31
 
31
-#define PREFERRED_UNITS JOULES
32
+#define PREFERRED_UNITS METRIC
32 33
 
33 34
 // --------------------------------------
34 35
 
@@ -51,6 +52,7 @@
51 52
 }
52 53
 
53 54
 #define SCREEN_TIMEOUT 2500 /* in ms */
55
+#define FLIP_SCREEN 0
54 56
 
55 57
 // --------------------------------------
56 58
 
@@ -60,6 +62,7 @@
60 62
 
61 63
 #define HEADING_FONT u8g2_font_VCR_OSD_tr
62 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 Dosyayı Görüntüle

@@ -29,7 +29,7 @@ void lcd_init(void) {
29 29
     u8g2.setFontPosBottom();
30 30
 
31 31
     u8g2.clearBuffer();
32
-    u8g2.setFlipMode(1);
32
+    u8g2.setFlipMode(FLIP_SCREEN);
33 33
 
34 34
     String s = F("OpenChrono");
35 35
     u8g2.setFont(HEADING_FONT);
@@ -54,7 +54,7 @@ void lcd_init(void) {
54 54
     u8g2.setFont(TEXT_FONT);
55 55
     u8g2.drawStr(
56 56
         0,
57
-        u8g2.getDisplayHeight() - u8g2.getMaxCharHeight() - 4,
57
+        u8g2.getDisplayHeight() - u8g2.getMaxCharHeight() - 2,
58 58
         s.c_str()
59 59
     );
60 60
 
@@ -63,7 +63,7 @@ void lcd_init(void) {
63 63
     u8g2.setFont(TEXT_FONT);
64 64
     u8g2.drawStr(
65 65
         (u8g2.getDisplayWidth() - u8g2.getStrWidth(s.c_str())) / 2,
66
-        u8g2.getDisplayHeight() - u8g2.getMaxCharHeight() - 4,
66
+        u8g2.getDisplayHeight() - u8g2.getMaxCharHeight() - 2,
67 67
         s.c_str()
68 68
     );
69 69
 
@@ -72,7 +72,7 @@ void lcd_init(void) {
72 72
     u8g2.setFont(TEXT_FONT);
73 73
     u8g2.drawStr(
74 74
         u8g2.getDisplayWidth() - u8g2.getStrWidth(s.c_str()),
75
-        u8g2.getDisplayHeight() - u8g2.getMaxCharHeight() - 4,
75
+        u8g2.getDisplayHeight() - u8g2.getMaxCharHeight() - 2,
76 76
         s.c_str()
77 77
     );
78 78
 
@@ -103,7 +103,7 @@ void lcd_draw(uint8_t screen) {
103 103
             || (screen == SCREEN_MIN) || (screen == SCREEN_MAX)) {
104 104
         if (tick_count < 1) {
105 105
             u8g2.clearBuffer();
106
-            u8g2.setFlipMode(1);
106
+            u8g2.setFlipMode(FLIP_SCREEN);
107 107
 
108 108
             String s = F("Ready!");
109 109
             u8g2.setFont(HEADING_FONT);
@@ -132,10 +132,16 @@ void lcd_draw(uint8_t screen) {
132 132
 
133 133
         double metric = tick_to_metric(tick);
134 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 143
         u8g2.clearBuffer();
138
-        u8g2.setFlipMode(1);
144
+        u8g2.setFlipMode(FLIP_SCREEN);
139 145
         u8g2.setFont(TEXT_FONT);
140 146
 
141 147
         String s;
@@ -158,28 +164,78 @@ void lcd_draw(uint8_t screen) {
158 164
             s.c_str()
159 165
         );
160 166
 
167
+        uint8_t left_off = (u8g2.getDisplayHeight() - (u8g2.getMaxCharHeight() * 4 + 3)) / 2;
168
+
161 169
         s = String(metric, 0);
162 170
         s += F(" m/s");
171
+        uint8_t l1 = u8g2.getStrWidth(s.c_str());
163 172
         u8g2.drawStr(
164 173
             0,
165
-            u8g2.getMaxCharHeight() * 2 + 1,
174
+            u8g2.getMaxCharHeight() * 2 + 1 + left_off,
166 175
             s.c_str()
167 176
         );
168 177
 
169 178
         s = String(imperial, 0);
170 179
         s += F(" FPS");
180
+        uint8_t l2 = u8g2.getStrWidth(s.c_str());
171 181
         u8g2.drawStr(
172 182
             0,
173
-            u8g2.getMaxCharHeight() * 3 + 2,
183
+            u8g2.getMaxCharHeight() * 3 + 2 + left_off,
174 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 241
         u8g2.sendBuffer();
@@ -189,7 +245,7 @@ void lcd_draw(uint8_t screen) {
189 245
         String s;
190 246
 
191 247
         u8g2.clearBuffer();
192
-        u8g2.setFlipMode(1);
248
+        u8g2.setFlipMode(FLIP_SCREEN);
193 249
         u8g2.setFont(TEXT_FONT);
194 250
 
195 251
         // max text
@@ -274,7 +330,7 @@ void lcd_loop(void) {
274 330
     if ((millis() - lcd_rotate_time) > SCREEN_TIMEOUT) {
275 331
         lcd_rotate_time = millis();
276 332
         lcd_screen++;
277
-        if (lcd_screen >= sizeof(screens)) {
333
+        if (lcd_screen >= (sizeof(screens) / sizeof(screens[0]))) {
278 334
             lcd_screen = 0;
279 335
         }
280 336
 

Loading…
İptal
Kaydet