Repository navigation
Expand file tree
/
Copy pathui_main.cpp
More file actions
8635 lines (7644 loc) · 403 KB
/
Copy pathui_main.cpp
File metadata and controls
8635 lines (7644 loc) · 403 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// =============================================================================
// ui_main.cpp — LVGL UI for Tab5 Weather Dashboard
// Display: 1280 × 720 px
//
// Layout philosophy: dark background, large readable text, minimal chrome.
// Status bar (40 px) sits at the top of every screen.
// Left/right arrow buttons navigate between screens.
// =============================================================================
#include "ui_main.h"
#include "config.h"
#include "space_weather_api.h"
#include "astro_api.h"
#include "bom_warnings_api.h"
#include "earthquake_api.h"
#include "earthquake_map_data.h"
#include <Preferences.h> // for settings_save()
#include <M5Unified.h> // safe here — M5.begin() already called in .ino setup()
#include <WiFi.h>
#include <math.h>
#include <SPI.h> // required for SD File type in tides screen
#include <SD.h> // required for SD File type in tides screen
// =============================================================================
// COLOUR PALETTE (all via lv_color_hex)
// =============================================================================
#define C_BG lv_color_hex(0x0D1117) // near-black
#define C_CARD lv_color_hex(0x161B22) // card background
#define C_BORDER lv_color_hex(0x30363D) // subtle border
#define C_TEXT lv_color_hex(0xE6EDF3) // primary text
#define C_DIM lv_color_hex(0x8B949E) // secondary text
#define C_ACCENT lv_color_hex(0x58A6FF) // blue accent
#define C_WARM lv_color_hex(0xFF7B50) // warm orange (temp)
#define C_COOL lv_color_hex(0x79C0FF) // cool blue (humidity)
#define C_GREEN lv_color_hex(0x3FB950) // good / connected
#define C_YELLOW lv_color_hex(0xD29922) // warning
#define C_RED lv_color_hex(0xF85149) // error / low battery
// =============================================================================
// LAYOUT CONSTANTS
// =============================================================================
#define STATUSBAR_H 44
#define NAV_BTN_W 70
#define SCREEN_W 1280
#define SCREEN_H 720
#define CONTENT_Y STATUSBAR_H
#define CONTENT_H (SCREEN_H - STATUSBAR_H)
#define PAD 24
// =============================================================================
// GLOBALS — screens and shared widgets
// =============================================================================
static lv_obj_t *screens[SCREEN_COUNT] = {};
static int cur_screen = SCREEN_CLOCK;
// Status bar widgets — one per screen, populated in build_statusbar()
// (arrays declared alongside build_statusbar definition below)
// =============================================================================
// SCREEN 0 — Combined Clock + Indoor Sensors + Today's Weather
// =============================================================================
// ── Clock column ──────────────────────────────────────────────────────────────
static lv_obj_t *clk_hh = nullptr; // "HH" segment
static lv_obj_t *clk_col1 = nullptr; // first ":"
static lv_obj_t *clk_mm = nullptr; // "MM" segment
static lv_obj_t *clk_col2 = nullptr; // second ":"
static lv_obj_t *clk_ss = nullptr; // "SS" segment
static lv_obj_t *clk_date = nullptr;
static lv_obj_t *clk_tz = nullptr;
// ── Indoor sensor row (right panel, top) ─────────────────────────────────────
static lv_obj_t *clk_s_temp = nullptr;
static lv_obj_t *clk_s_hum = nullptr;
static lv_obj_t *clk_s_press = nullptr;
// ── Today's weather panel (right panel, below sensors) ────────────────────────
static lv_obj_t *clk_wx_temp = nullptr;
static lv_obj_t *clk_wx_feels = nullptr;
static lv_obj_t *clk_wx_cond = nullptr; // primary condition line
static lv_obj_t *clk_wx_desc1 = nullptr; // description line 1
static lv_obj_t *clk_wx_desc2 = nullptr; // description line 2
static lv_obj_t *clk_wx_wind = nullptr;
static lv_obj_t *clk_wx_hum = nullptr;
static lv_obj_t *clk_wx_uv = nullptr;
static lv_obj_t *clk_wx_vis = nullptr;
static lv_obj_t *clk_wx_rain = nullptr;
static lv_obj_t *clk_wx_sun = nullptr; // sunrise / sunset (two lines)
static lv_obj_t *clk_wx_forecast = nullptr; // tomorrow + day-after paragraph
static lv_obj_t *clk_wx_updated = nullptr;
// ── 5-slot weather outlook strip (bottom of left column) ─────────────────────
#define OUTLOOK_SLOTS 5
static lv_obj_t *out_canvas[OUTLOOK_SLOTS] = {}; // icon canvas per slot
static lv_color_t *out_canvas_buf[OUTLOOK_SLOTS] = {};
static lv_obj_t *out_day[OUTLOOK_SLOTS] = {}; // day name label
static lv_obj_t *out_temp[OUTLOOK_SLOTS] = {}; // hi/lo label
static lv_obj_t *out_rain[OUTLOOK_SLOTS] = {}; // rain % label
// Screen 1 — Local (BME688)
static lv_obj_t *loc_temp = nullptr;
static lv_obj_t *loc_temp_sub = nullptr; // offset note
static lv_obj_t *loc_hum = nullptr;
static lv_obj_t *loc_hum_sub = nullptr; // comfort label
static lv_obj_t *loc_press = nullptr;
static lv_obj_t *loc_trend = nullptr;
// trend chart canvas
static lv_obj_t *loc_chart_canvas = nullptr;
static lv_color_t *loc_chart_buf = nullptr;
static lv_obj_t *loc_wait_lbl = nullptr; // "Collecting data" — hidden once data arrives
#define LOC_CHART_W 802 // RIGHT_W(850) - PAD*2
#define LOC_CHART_H 280 // CHART_CARD_H(361) - PAD*2 - header(20) - small margin
// comfort panel
static lv_obj_t *loc_dewpoint = nullptr;
static lv_obj_t *loc_heatidx = nullptr;
static lv_obj_t *loc_comfort = nullptr;
static lv_obj_t *loc_dewbar = nullptr; // bar fill object
static lv_obj_t *loc_heatbar = nullptr;
static lv_obj_t *loc_comfbar = nullptr;
// keep these for update function compatibility (no-ops if null-checked)
static lv_obj_t *loc_iaq = nullptr;
static lv_obj_t *loc_iaq_label = nullptr;
static lv_obj_t *loc_iaq_acc_badge = nullptr;
static lv_obj_t *loc_iaq_bar_fill = nullptr;
static lv_obj_t *loc_iaq_resist = nullptr;
static lv_obj_t *loc_iaq_base = nullptr;
static lv_obj_t *loc_iaq_scale_lbl = nullptr;
static lv_obj_t *loc_co2 = nullptr;
static lv_obj_t *loc_voc = nullptr;
static lv_obj_t *loc_accuracy = nullptr;
// Screen 2 — Weather current
static lv_obj_t *wx_temp = nullptr;
static lv_obj_t *wx_feels = nullptr;
static lv_obj_t *wx_cond = nullptr;
static lv_obj_t *wx_wind = nullptr;
static lv_obj_t *wx_hum = nullptr;
static lv_obj_t *wx_uv = nullptr;
static lv_obj_t *wx_updated = nullptr;
// expanded fields
static lv_obj_t *wx_vis = nullptr;
static lv_obj_t *wx_precip = nullptr;
static lv_obj_t *wx_pressure = nullptr;
static lv_obj_t *wx_pressure_trend = nullptr;
static lv_obj_t *wx_dewpoint = nullptr;
static lv_obj_t *wx_cloud = nullptr;
static lv_obj_t *wx_aqi_cat = nullptr; // AQI category "Good" / "Moderate" etc
static lv_obj_t *wx_aqi_epa = nullptr; // EPA index "EPA 1/6"
static lv_obj_t *wx_aqi_pm25 = nullptr; // PM2.5 value
static lv_obj_t *wx_aqi_pm10 = nullptr; // PM10 value
static lv_obj_t *wx_aqi_o3 = nullptr; // O3 value
static lv_obj_t *wx_aqi_no2 = nullptr; // NO2 value
static lv_obj_t *wx_wind_gust = nullptr; // gust sub-label on wind card
static lv_obj_t *wx_hum_hero = nullptr; // humidity value in hero mid-zone
// hero icon canvas
static lv_obj_t *wx_icon_canvas = nullptr;
static lv_color_t *wx_icon_buf = nullptr;
// UV card
static lv_obj_t *wx_uv_num = nullptr;
static lv_obj_t *wx_uv_cat = nullptr;
static lv_obj_t *wx_uv_peak = nullptr;
static lv_obj_t *wx_uv_marker = nullptr;
static lv_obj_t *wx_uv_advice = nullptr;
static int wx_uv_bar_w = 0; // bar pixel width, set during build
// bottom-right detail card
static lv_obj_t *wx_sunrise = nullptr;
static lv_obj_t *wx_sunrise_sub = nullptr;
static lv_obj_t *wx_solarnoon = nullptr;
static lv_obj_t *wx_solarnoon_sub = nullptr;
static lv_obj_t *wx_sunset = nullptr;
static lv_obj_t *wx_sunset_sub = nullptr;
static lv_obj_t *wx_moon_phase = nullptr;
static lv_obj_t *wx_moon_sub = nullptr;
static lv_obj_t *wx_next_event = nullptr;
static lv_obj_t *wx_next_event_sub = nullptr;
static lv_obj_t *wx_season = nullptr;
// hourly strip — icon canvas matches OUTLOOK_ICON_W/H so draw_wx_icon works correctly
#define WX_HOURLY_SLOTS 6
#define WX_HOURLY_ICON_W OUTLOOK_ICON_W
#define WX_HOURLY_ICON_H OUTLOOK_ICON_H
static lv_obj_t *wx_h_card[WX_HOURLY_SLOTS] = {};
static lv_obj_t *wx_h_time[WX_HOURLY_SLOTS] = {};
static lv_obj_t *wx_h_canvas[WX_HOURLY_SLOTS] = {};
static lv_color_t *wx_h_buf[WX_HOURLY_SLOTS] = {};
static lv_obj_t *wx_h_temp[WX_HOURLY_SLOTS] = {};
static lv_obj_t *wx_h_rain[WX_HOURLY_SLOTS] = {};
// sparkline canvas — drawn below the hourly slot cards
#define WX_SPARK_H 34 // height of sparkline strip below cards
static lv_obj_t *wx_spark_canvas = nullptr;
static lv_color_t *wx_spark_buf = nullptr;
static int wx_spark_w = 0; // set during build, used during draw
// Screen 3 — Forecast
static lv_obj_t *fc_cards[3] = {};
// Screen 4 — Astronomy
static lv_obj_t *as_sunrise = nullptr;
static lv_obj_t *as_sunrise_sub = nullptr;
static lv_obj_t *as_solarnoon = nullptr;
static lv_obj_t *as_solarnoon_sub = nullptr;
static lv_obj_t *as_sunset = nullptr;
static lv_obj_t *as_sunset_sub = nullptr;
static lv_obj_t *as_daylen = nullptr;
static lv_obj_t *as_next_event = nullptr;
static lv_obj_t *as_next_event_sub= nullptr;
static lv_obj_t *as_season = nullptr;
// sun arc canvas
static lv_obj_t *as_sun_canvas = nullptr;
static lv_color_t *as_sun_buf = nullptr;
#define AS_ARC_W 492 // inner card width
#define AS_ARC_H 178 // top section minus header
// moon
static lv_obj_t *as_moon_canvas = nullptr;
static lv_color_t *as_moon_buf = nullptr;
#define AS_MOON_D 110
static lv_obj_t *as_moon_phase = nullptr;
static lv_obj_t *as_moon_illum = nullptr;
static lv_obj_t *as_moon_age = nullptr;
static lv_obj_t *as_moonrise = nullptr;
static lv_obj_t *as_moonrise_sub = nullptr;
static lv_obj_t *as_moonset = nullptr;
static lv_obj_t *as_moonset_sub = nullptr;
static lv_obj_t *as_moon_illum_pct= nullptr;
static lv_obj_t *as_moon_age_val = nullptr;
static lv_obj_t *as_next_full = nullptr;
static lv_obj_t *as_next_new = nullptr;
// =============================================================================
// SCREEN 5 — Solar Elevation Chart
// =============================================================================
#define SOL_CHART_W 1140 // SCREEN_W - 2*NAV_BTN_W
#define SOL_CHART_H 500 // canvas height — fills CHART_CARD_H (~506px)
static lv_obj_t *sol_canvas = nullptr;
static lv_color_t *sol_canvas_buf = nullptr;
// Stat labels (updated each minute)
static lv_obj_t *sol_sunrise = nullptr;
static lv_obj_t *sol_sunrise_cd = nullptr;
static lv_obj_t *sol_noon = nullptr;
static lv_obj_t *sol_noon_cd = nullptr;
static lv_obj_t *sol_sunset = nullptr;
static lv_obj_t *sol_sunset_cd = nullptr;
static lv_obj_t *sol_daylen = nullptr;
static lv_obj_t *sol_peak = nullptr;
static lv_obj_t *sol_cur_elev = nullptr;
static lv_obj_t *sol_cur_az = nullptr;
// Screen 6 — Seasons orbit (LVGL canvas drawn at runtime)
static lv_obj_t *sea_canvas = nullptr;
static lv_obj_t *sea_season = nullptr;
static lv_obj_t *sea_next_event = nullptr;
static lv_obj_t *sea_earth_dot = nullptr; // animated overlay dot on Earth position
static int sea_pulse_phase = 0; // 0-3 step for pulse animation
// Per-quadrant season progress overlays (updated each minute in render_seasons)
static lv_obj_t *sea_q_dates[4] = {}; // "22 Dec → 20 Mar"
static lv_obj_t *sea_q_status[4] = {}; // "Day 42 of 89 · 47 left" / "in 62 days"
// Screen 7 — Lunar orbit (LVGL canvas drawn at runtime)
static lv_obj_t *lun_canvas = nullptr;
// Lunar overlay labels — updated each minute by render_lunar
static lv_obj_t *lun_phase = nullptr; // current phase name (large)
static lv_obj_t *lun_illum = nullptr; // illumination % value
static lv_obj_t *lun_illum_bar = nullptr; // illumination bar fill
static lv_obj_t *lun_age = nullptr; // age in days
static lv_obj_t *lun_next = nullptr; // next phase + days
static lv_obj_t *lun_moonrise = nullptr;
static lv_obj_t *lun_moonrise_sub= nullptr; // countdown
static lv_obj_t *lun_moonset = nullptr;
static lv_obj_t *lun_moonset_sub = nullptr;
static lv_obj_t *lun_full = nullptr; // days to full
static lv_obj_t *lun_new = nullptr; // days to new
// =============================================================================
// SCREEN 8 — Planets Tonight (AstronomyAPI)
// =============================================================================
#define PL_COMPASS_W 608 // compass canvas width (RIGHT_W - PAD*2)
#define PL_COMPASS_H 430 // compass canvas height — matches COMPASS_CARD_H - label
static lv_obj_t *pl_compass_canvas = nullptr;
static lv_color_t *pl_compass_buf = nullptr;
// Per-planet widgets in the list (7 planets)
static lv_obj_t *pl_name[ASTRO_PLANET_COUNT] = {};
static lv_obj_t *pl_pill[ASTRO_PLANET_COUNT] = {}; // visibility pill
static lv_obj_t *pl_bar[ASTRO_PLANET_COUNT] = {}; // altitude fill bar
static lv_obj_t *pl_alt[ASTRO_PLANET_COUNT] = {}; // altitude value
static lv_obj_t *pl_az[ASTRO_PLANET_COUNT] = {}; // azimuth + direction
static lv_obj_t *pl_mag[ASTRO_PLANET_COUNT] = {}; // magnitude
static lv_obj_t *pl_con[ASTRO_PLANET_COUNT] = {}; // constellation
// Summary / footer labels
static lv_obj_t *pl_best = nullptr; // "Best tonight: Venus & Jupiter"
static lv_obj_t *pl_best_sub = nullptr;
static lv_obj_t *pl_updated = nullptr;
// =============================================================================
// SCREEN 9 — Space Weather (BOM SWS) [was 8]
// =============================================================================
// Canvas for K-index bar chart — taller now to fill the chart card
static lv_obj_t *sw_canvas = nullptr;
static lv_color_t *sw_canvas_buf = nullptr;
#define SW_CHART_W 440
// SW_CHART_H is computed at build time from CHART_CARD_H; use a generous fixed value
// CHART_CARD_H = CH - K_HERO_H - PAD*3 = 650-160-72 = 418; minus label(20)+pad(24) = 374
#define SW_CHART_H 374
// Aurora / alert panel (left column)
static lv_obj_t *sw_alert_badge = nullptr; // big status badge label
static lv_obj_t *sw_alert_band = nullptr; // lat_band label
static lv_obj_t *sw_alert_desc = nullptr; // aurora description text
static lv_obj_t *sw_mag_status = nullptr; // mag alert status pill label
static lv_obj_t *sw_mag_desc = nullptr; // mag alert full description text (NEW)
static lv_obj_t *sw_geo_pill = nullptr; // geo warning status pill label (NEW)
static lv_obj_t *sw_geo_desc = nullptr; // geo warning full description text (NEW)
// K-index (centre column)
static lv_obj_t *sw_k_value = nullptr; // big current K number
static lv_obj_t *sw_k_label = nullptr; // "Quiet" / "Storm G1" etc.
static lv_obj_t *sw_k_time = nullptr; // timestamp
// Right column indices
static lv_obj_t *sw_a_value = nullptr;
static lv_obj_t *sw_a_label = nullptr;
static lv_obj_t *sw_a_bar = nullptr; // A-index bar fill
static lv_obj_t *sw_dst_value = nullptr;
static lv_obj_t *sw_dst_label = nullptr;
static lv_obj_t *sw_geo_status = nullptr; // geo status on right card (combined)
static lv_obj_t *sw_updated = nullptr;
// =============================================================================
// SCREEN 11 — Sensor Stats (tabbed temp/hum/pressure, 8h/24h/7d)
// =============================================================================
// Chart canvas — full width of content area minus stats column
#define SS_CHART_W 800 // chart canvas pixel width
#define SS_CHART_H 490 // chart canvas pixel height
#define SS_STATS_COL 260 // right stats column width
#define SS_CONTENT_X NAV_BTN_W
#define SS_CONTENT_W (SCREEN_W - NAV_BTN_W * 2) // 1140
// Tab / window state
static int ss_tab = 0; // 0=Temp 1=Humidity 2=Pressure
static int ss_window = 0; // 0=8h 1=24h 2=7d
// Tab buttons
static lv_obj_t *ss_tab_btn[3] = {};
// Window buttons
static lv_obj_t *ss_win_btn[3] = {};
// Chart canvas
static lv_obj_t *ss_canvas = nullptr;
static lv_color_t *ss_buf = nullptr;
// Chart header labels
static lv_obj_t *ss_cur_val = nullptr; // large current reading
static lv_obj_t *ss_hi_lo = nullptr; // "Hi x Lo x Avg x" right side
static lv_obj_t *ss_avg_rng = nullptr; // "Avg x Range x" second line
// Stats column cards (today / yesterday / 7d / trend)
static lv_obj_t *ss_today_val = nullptr;
static lv_obj_t *ss_today_hi = nullptr;
static lv_obj_t *ss_today_lo = nullptr;
static lv_obj_t *ss_today_avg = nullptr;
static lv_obj_t *ss_yest_val = nullptr;
static lv_obj_t *ss_yest_hi = nullptr;
static lv_obj_t *ss_yest_lo = nullptr;
static lv_obj_t *ss_yest_avg = nullptr;
static lv_obj_t *ss_7d_hi = nullptr;
static lv_obj_t *ss_7d_lo = nullptr;
static lv_obj_t *ss_7d_avg = nullptr;
static lv_obj_t *ss_7d_trend = nullptr;
static lv_obj_t *ss_trend_dir = nullptr; // "Rising / Falling / Steady"
static lv_obj_t *ss_trend_rate = nullptr; // "+0.4/hr"
// Extended history buffers (heap-allocated on first 24h/7d fetch)
static float *ss_ext_temp = nullptr;
static float *ss_ext_hum = nullptr;
static float *ss_ext_pres = nullptr;
static int ss_ext_count = 0;
static int ss_ext_window = -1; // which window the ext data was loaded for
static SdExtResult ss_ext_stats = {}; // cached stats from last extended read
// =============================================================================
// SCREEN 9 — Settings + System Info
// =============================================================================
// ── Settings live values (volatile — written by UI, read by loop()) ───────────
volatile int g_setting_brightness = 180;
volatile int g_setting_timeout_sec = 300;
volatile bool g_setting_dim_before_sleep = true;
volatile int g_setting_wx_interval_sec = 900;
volatile int g_setting_sw_interval_sec = 900;
volatile bool g_setting_wake_to_clock = false;
volatile bool g_force_wx_refresh = false;
volatile bool g_force_sw_refresh = false;
// ── Timeout / wake state (managed by ui_notify_touch + loop) ─────────────────
// Non-static so the main .ino loop can read/write via extern declarations
unsigned long s_last_touch_ms = 0; // millis() of last touch event
bool s_display_dimmed = false; // true when dimmed to warning level
bool s_display_off = false; // true when blanked (brightness=0)
static int s_pre_dim_brightness = 180; // saved brightness before dim
// ── Settings screen LVGL widgets ─────────────────────────────────────────────
// Brightness row buttons (5 steps)
#define BRIGHT_STEPS 5
static const int BRIGHT_VALS[BRIGHT_STEPS] = {30, 80, 130, 180, 230};
static lv_obj_t *set_bright_btns[BRIGHT_STEPS] = {};
// Timeout row buttons (6 options)
#define TIMEOUT_OPTS 6
static const int TIMEOUT_VALS[TIMEOUT_OPTS] = {0, 60, 120, 300, 600, 1800};
static const char *TIMEOUT_LBLS[TIMEOUT_OPTS] = {"Off","1m","2m","5m","10m","30m"};
static lv_obj_t *set_timeout_btns[TIMEOUT_OPTS] = {};
// Dim toggle
static lv_obj_t *set_dim_on = nullptr;
static lv_obj_t *set_dim_off = nullptr;
// Weather refresh (4 options)
#define WX_OPTS 4
static const int WX_VALS[WX_OPTS] = {300, 600, 900, 1800};
static const char *WX_LBLS[WX_OPTS] = {"5m","10m","15m","30m"};
static lv_obj_t *set_wx_btns[WX_OPTS] = {};
// Space wx refresh (3 options)
#define SW_OPTS 3
static const int SW_VALS[SW_OPTS] = {900, 1800, 3600};
static const char *SW_LBLS[SW_OPTS] = {"15m","30m","1h"};
static lv_obj_t *set_sw_btns[SW_OPTS] = {};
// Wake screen (2 options)
static lv_obj_t *set_wake_last = nullptr;
static lv_obj_t *set_wake_clock = nullptr;
// System info labels (right column, updated by ui_update_settings_sysinfo)
static lv_obj_t *sys_bat_status = nullptr;
static lv_obj_t *sys_bat_level = nullptr;
static lv_obj_t *sys_bat_voltage = nullptr;
static lv_obj_t *sys_wifi_ssid = nullptr;
static lv_obj_t *sys_wifi_rssi = nullptr;
static lv_obj_t *sys_wifi_chan = nullptr;
static lv_obj_t *sys_wifi_ip = nullptr;
static lv_obj_t *sys_heap = nullptr;
static lv_obj_t *sys_psram = nullptr;
static lv_obj_t *sys_uptime = nullptr;
static lv_obj_t *sys_chip = nullptr;
static lv_obj_t *sys_fetch_wx = nullptr;
static lv_obj_t *sys_fetch_sw = nullptr;
static lv_obj_t *sys_fetch_ntp = nullptr;
// =============================================================================
// HELPER — styled label factory
// =============================================================================
static lv_obj_t* make_label(lv_obj_t *parent, const char *text,
const lv_font_t *font, lv_color_t color,
lv_align_t align, int x, int y) {
lv_obj_t *l = lv_label_create(parent);
lv_label_set_text(l, text);
lv_obj_set_style_text_font(l, font, 0);
lv_obj_set_style_text_color(l, color, 0);
lv_obj_align(l, align, x, y);
return l;
}
// Card container
static lv_obj_t* make_card(lv_obj_t *parent,
int x, int y, int w, int h) {
lv_obj_t *c = lv_obj_create(parent);
lv_obj_set_size(c, w, h);
lv_obj_set_pos(c, x, y);
lv_obj_set_style_bg_color(c, C_CARD, 0);
lv_obj_set_style_bg_opa(c, LV_OPA_COVER, 0);
lv_obj_set_style_border_color(c, C_BORDER, 0);
lv_obj_set_style_border_width(c, 1, 0);
lv_obj_set_style_radius(c, 12, 0);
lv_obj_set_style_pad_all(c, PAD, 0);
lv_obj_clear_flag(c, LV_OBJ_FLAG_SCROLLABLE);
return c;
}
// Card with zero internal padding — for screens that position children absolutely
static lv_obj_t* make_card_nopad(lv_obj_t *parent, int x, int y, int w, int h,
lv_color_t border_col = C_BORDER) {
lv_obj_t *c = lv_obj_create(parent);
lv_obj_set_size(c, w, h);
lv_obj_set_pos(c, x, y);
lv_obj_set_style_bg_color(c, C_CARD, 0);
lv_obj_set_style_bg_opa(c, LV_OPA_COVER, 0);
lv_obj_set_style_border_color(c, border_col, 0);
lv_obj_set_style_border_width(c, 1, 0);
lv_obj_set_style_radius(c, 10, 0);
lv_obj_set_style_pad_all(c, 0, 0);
lv_obj_clear_flag(c, LV_OBJ_FLAG_SCROLLABLE);
return c;
}
// Navigation arrow button — transparent, full-height touch zone
static lv_obj_t* make_nav_btn(lv_obj_t *parent, const char *symbol,
lv_align_t align,
lv_event_cb_t cb) {
lv_obj_t *b = lv_btn_create(parent);
lv_obj_set_size(b, NAV_BTN_W, CONTENT_H);
lv_obj_align(b, align, 0, STATUSBAR_H);
lv_obj_set_style_bg_opa(b, LV_OPA_TRANSP, 0);
lv_obj_set_style_border_width(b, 0, 0);
lv_obj_set_style_shadow_width(b, 0, 0);
lv_obj_add_event_cb(b, cb, LV_EVENT_CLICKED, nullptr);
lv_obj_t *lbl = lv_label_create(b);
lv_label_set_text(lbl, symbol);
lv_obj_set_style_text_font(lbl, &lv_font_montserrat_28, 0);
lv_obj_set_style_text_color(lbl, C_DIM, 0);
lv_obj_center(lbl);
return b;
}
// =============================================================================
// NAVIGATION SYSTEM
// Three complementary methods:
// 1. Tap left/right arrow buttons (always visible, full-height touch zone)
// 2. Swipe left/right anywhere on the screen content area
// 3. Long-press anywhere to open the quick-pick menu overlay
// =============================================================================
// ── Dot indicator ─────────────────────────────────────────────────────────────
#define DOT_R 6
#define DOT_GAP 18
#define DOT_Y (SCREEN_H - 16)
// All dots on all screens — [screen_index][dot_index]
static lv_obj_t *all_dots[SCREEN_COUNT][SCREEN_COUNT] = {};
static void update_dots(int active) {
for (int s = 0; s < SCREEN_COUNT; s++) {
for (int d = 0; d < SCREEN_COUNT; d++) {
if (!all_dots[s][d]) continue;
lv_obj_set_style_bg_color(all_dots[s][d],
d == active ? C_TEXT : C_BORDER, 0);
}
}
}
// ── Screen names for quick-pick menu ─────────────────────────────────────────
// Indices 0–13 match SCREEN_CLOCK through SCREEN_EARTHQUAKE.
// SCREEN_SETTINGS (14) is excluded from this array — it has its own footer button.
static const char *SCREEN_NAMES[SCREEN_COUNT - 1] = {
LV_SYMBOL_HOME " Clock",
LV_SYMBOL_WIFI " Local Sensor",
LV_SYMBOL_IMAGE " Weather",
LV_SYMBOL_LIST " Forecast",
LV_SYMBOL_LOOP " Astronomy",
LV_SYMBOL_LOOP " Solar Elevation",
LV_SYMBOL_LOOP " Seasons",
LV_SYMBOL_LOOP " Lunar Orbit",
LV_SYMBOL_LOOP " Planets Tonight",
LV_SYMBOL_WARNING " Alerts",
LV_SYMBOL_WARNING " Space Weather",
LV_SYMBOL_CHARGE " Sensor History",
LV_SYMBOL_DRIVE " Tides - Fort Denison",
LV_SYMBOL_WARNING " Earthquake Activity",
};
// ── Quick-pick overlay ────────────────────────────────────────────────────────
static lv_obj_t *qp_overlay = nullptr;
static void qp_btn_cb(lv_event_t *e) {
int idx = (int)(intptr_t)lv_event_get_user_data(e);
if (qp_overlay) {
lv_obj_del(qp_overlay);
qp_overlay = nullptr;
}
ui_show_screen(idx);
}
static void qp_bg_cb(lv_event_t *e) {
if (qp_overlay) {
lv_obj_del(qp_overlay);
qp_overlay = nullptr;
}
}
static void open_quick_pick() {
if (qp_overlay) return;
lv_obj_t *scr = screens[cur_screen];
qp_overlay = lv_obj_create(scr);
lv_obj_set_size(qp_overlay, SCREEN_W, SCREEN_H);
lv_obj_set_pos(qp_overlay, 0, 0);
lv_obj_set_style_bg_color(qp_overlay, lv_color_hex(0x000000), 0);
lv_obj_set_style_bg_opa(qp_overlay, LV_OPA_70, 0);
lv_obj_set_style_border_width(qp_overlay, 0, 0);
lv_obj_set_style_radius(qp_overlay, 0, 0);
lv_obj_clear_flag(qp_overlay, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_add_event_cb(qp_overlay, qp_bg_cb, LV_EVENT_CLICKED, nullptr);
// ── Panel — 2-column grid, fits all 10 content screens + settings footer ──
const int MW = 700;
const int MBTN_H = 52;
const int MPAD = 10;
const int COLS = 2;
const int NAV_CNT = SCREEN_COUNT - 1; // 10 swipeable screens
const int ROWS = (NAV_CNT + COLS - 1) / COLS; // ceil(10/2) = 5
const int BTN_W = (MW - MPAD * (COLS + 1)) / COLS; // (700-30)/2 = 335
// Panel height: header(44) + rows*(btn+gap) + gap before settings + settings + bottom pad
int panel_h = 44 + ROWS * (MBTN_H + MPAD) + 10 + (MBTN_H + MPAD) + MPAD;
lv_obj_t *panel = lv_obj_create(qp_overlay);
lv_obj_set_size(panel, MW, panel_h);
lv_obj_align(panel, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_style_bg_color(panel, lv_color_hex(0x161B22), 0);
lv_obj_set_style_bg_opa(panel, LV_OPA_COVER, 0);
lv_obj_set_style_border_color(panel, C_BORDER, 0);
lv_obj_set_style_border_width(panel, 1, 0);
lv_obj_set_style_radius(panel, 16, 0);
lv_obj_set_style_pad_all(panel, MPAD, 0);
lv_obj_clear_flag(panel, LV_OBJ_FLAG_SCROLLABLE);
// Header
lv_obj_t *hdr = lv_label_create(panel);
lv_label_set_text(hdr, "Go to screen");
lv_obj_set_style_text_font(hdr, &lv_font_montserrat_20, 0);
lv_obj_set_style_text_color(hdr, C_DIM, 0);
lv_obj_align(hdr, LV_ALIGN_TOP_MID, 0, 6);
// 2-column grid of screen buttons (screens 0 to NAV_CNT-1)
for (int i = 0; i < NAV_CNT; i++) {
int col = i % COLS;
int row = i / COLS;
int bx = MPAD + col * (BTN_W + MPAD);
int by = 44 + row * (MBTN_H + MPAD);
lv_obj_t *btn = lv_btn_create(panel);
lv_obj_set_size(btn, BTN_W, MBTN_H);
lv_obj_set_pos(btn, bx, by);
bool active = (i == cur_screen);
lv_obj_set_style_bg_color(btn,
active ? lv_color_hex(0x1C3A5E) : lv_color_hex(0x0D1117), 0);
lv_obj_set_style_bg_opa(btn, LV_OPA_COVER, 0);
lv_obj_set_style_border_color(btn, active ? C_ACCENT : C_BORDER, 0);
lv_obj_set_style_border_width(btn, active ? 2 : 1, 0);
lv_obj_set_style_radius(btn, 8, 0);
lv_obj_set_style_shadow_width(btn, 0, 0);
lv_obj_add_event_cb(btn, qp_btn_cb, LV_EVENT_CLICKED, (void *)(intptr_t)i);
lv_obj_t *lbl = lv_label_create(btn);
lv_label_set_text(lbl, SCREEN_NAMES[i]);
lv_obj_set_style_text_font(lbl, &lv_font_montserrat_16, 0);
lv_obj_set_style_text_color(lbl, active ? C_ACCENT : C_TEXT, 0);
lv_obj_align(lbl, LV_ALIGN_LEFT_MID, 8, 0);
}
// ── Settings button — full-width footer ───────────────────────────────────
{
int by = 44 + ROWS * (MBTN_H + MPAD) + 10;
lv_obj_t *btn = lv_btn_create(panel);
lv_obj_set_size(btn, MW - MPAD * 2, MBTN_H);
lv_obj_set_pos(btn, MPAD, by);
lv_obj_set_style_bg_color(btn, lv_color_hex(0x21262D), 0);
lv_obj_set_style_bg_opa(btn, LV_OPA_COVER, 0);
lv_obj_set_style_border_color(btn, C_BORDER, 0);
lv_obj_set_style_border_width(btn, 1, 0);
lv_obj_set_style_radius(btn, 8, 0);
lv_obj_set_style_shadow_width(btn, 0, 0);
lv_obj_add_event_cb(btn, qp_btn_cb, LV_EVENT_CLICKED,
(void*)(intptr_t)SCREEN_SETTINGS);
lv_obj_t *lbl = lv_label_create(btn);
lv_label_set_text(lbl, LV_SYMBOL_SETTINGS " Settings & System");
lv_obj_set_style_text_font(lbl, &lv_font_montserrat_16, 0);
lv_obj_set_style_text_color(lbl, C_DIM, 0);
lv_obj_align(lbl, LV_ALIGN_LEFT_MID, 12, 0);
}
}
// ── Swipe + long-press gesture handler (attached to every screen) ─────────────
#define SWIPE_MIN_PX 80 // minimum horizontal travel to count as swipe
#define SWIPE_MAX_PY 120 // maximum vertical travel (reject diagonal)
#define LONGPRESS_MS 600 // hold duration to open quick-pick
static int32_t gesture_start_x = 0;
static int32_t gesture_start_y = 0;
static uint32_t gesture_start_t = 0;
static bool gesture_active = false;
static bool gesture_fired = false; // prevent double-fire on same press
static void gesture_cb(lv_event_t *e) {
lv_event_code_t code = lv_event_get_code(e);
if (code == LV_EVENT_PRESSED) {
ui_notify_touch(); // reset inactivity timer / wake display
lv_indev_t *indev = lv_indev_get_act();
lv_point_t pt;
lv_indev_get_point(indev, &pt);
gesture_start_x = pt.x;
gesture_start_y = pt.y;
gesture_start_t = lv_tick_get();
gesture_active = true;
gesture_fired = false;
}
else if (code == LV_EVENT_PRESSING && gesture_active && !gesture_fired) {
// Long-press detection
if ((lv_tick_get() - gesture_start_t) >= LONGPRESS_MS) {
gesture_fired = true;
gesture_active = false;
open_quick_pick();
}
}
else if (code == LV_EVENT_RELEASED && gesture_active && !gesture_fired) {
gesture_active = false;
lv_indev_t *indev = lv_indev_get_act();
lv_point_t pt;
lv_indev_get_point(indev, &pt);
int32_t dx = pt.x - gesture_start_x;
int32_t dy = pt.y - gesture_start_y;
if (abs(dx) >= SWIPE_MIN_PX && abs(dy) <= SWIPE_MAX_PY) {
gesture_fired = true;
if (dx < 0) {
// Swipe left → next screen
ui_show_screen((cur_screen + 1) % (SCREEN_COUNT - 1)); // wrap 0-11, settings excluded
} else {
// Swipe right → previous screen
ui_show_screen((cur_screen - 1 + (SCREEN_COUNT-1)) % (SCREEN_COUNT - 1)); // wrap 0-11
}
}
}
}
// ── Simple nav callbacks (still used by arrow buttons) ────────────────────────
static void nav_left_cb(lv_event_t *e) {
ui_show_screen((cur_screen - 1 + (SCREEN_COUNT-1)) % (SCREEN_COUNT - 1)); // wrap 0-11
}
static void nav_right_cb(lv_event_t *e) {
ui_show_screen((cur_screen + 1) % (SCREEN_COUNT - 1)); // wrap 0-11, settings excluded
}
// =============================================================================
// SCREEN BUILDERS
// =============================================================================
// ── Shared status bar ─────────────────────────────────────────────────────────
// Each screen gets its own statusbar with its own wifi/battery labels.
// ui_update_statusbar() walks all screens and updates every instance.
//
// We keep one pointer per screen in these arrays:
static lv_obj_t *sb_wifi[SCREEN_COUNT] = {};
static lv_obj_t *sb_bat[SCREEN_COUNT] = {};
// Extended statusbar widgets
static lv_obj_t *sb_rssi[SCREEN_COUNT] = {}; // RSSI value next to wifi icon
static lv_obj_t *sb_bat_pct[SCREEN_COUNT]= {}; // battery % next to battery icon
static lv_obj_t *sb_time[SCREEN_COUNT] = {}; // HH:MM clock (centre-left)
static lv_obj_t *sb_temp[SCREEN_COUNT] = {}; // indoor temp
static lv_obj_t *sb_hum[SCREEN_COUNT] = {}; // indoor humidity
static lv_obj_t *sb_press[SCREEN_COUNT] = {}; // indoor pressure
static void build_statusbar(lv_obj_t *scr, const char *title) {
// Find which screen index this is
int idx = -1;
for (int i = 0; i < SCREEN_COUNT; i++) {
if (screens[i] == scr) { idx = i; break; }
}
lv_obj_t *bar = lv_obj_create(scr);
lv_obj_set_size(bar, SCREEN_W, STATUSBAR_H);
lv_obj_set_pos(bar, 0, 0);
lv_obj_set_style_bg_color(bar, lv_color_hex(0x161B22), 0);
lv_obj_set_style_bg_opa(bar, LV_OPA_COVER, 0);
lv_obj_set_style_border_width(bar, 0, 0);
lv_obj_set_style_radius(bar, 0, 0);
lv_obj_clear_flag(bar, LV_OBJ_FLAG_SCROLLABLE);
// Title
lv_obj_t *t = lv_label_create(bar);
lv_label_set_text(t, title);
lv_obj_set_style_text_font(t, &lv_font_montserrat_20, 0);
lv_obj_set_style_text_color(t, C_DIM, 0);
lv_obj_align(t, LV_ALIGN_CENTER, 0, 0);
// ── Left side: WiFi icon + RSSI ──────────────────────────────────────────
lv_obj_t *wifi = lv_label_create(bar);
lv_label_set_text(wifi, LV_SYMBOL_WIFI);
lv_obj_set_style_text_font(wifi, &lv_font_montserrat_20, 0);
lv_obj_set_style_text_color(wifi, C_DIM, 0);
lv_obj_align(wifi, LV_ALIGN_LEFT_MID, PAD, 0);
if (idx >= 0) sb_wifi[idx] = wifi;
// RSSI value (font_14, right of wifi icon)
lv_obj_t *rssi_lbl = lv_label_create(bar);
lv_label_set_text(rssi_lbl, "--");
lv_obj_set_style_text_font(rssi_lbl, &lv_font_montserrat_14, 0);
lv_obj_set_style_text_color(rssi_lbl, C_DIM, 0);
lv_obj_align(rssi_lbl, LV_ALIGN_LEFT_MID, PAD + 26, 0);
if (idx >= 0) sb_rssi[idx] = rssi_lbl;
// ── Left side: sensor values (temp · hum · press) ──────────────────────
// Positioned after RSSI, before centre title
lv_obj_t *sb_t = lv_label_create(bar);
lv_label_set_text(sb_t, "--");
lv_obj_set_style_text_font(sb_t, &lv_font_montserrat_14, 0);
lv_obj_set_style_text_color(sb_t, C_WARM, 0);
lv_obj_align(sb_t, LV_ALIGN_LEFT_MID, PAD + 72, 0);
if (idx >= 0) sb_temp[idx] = sb_t;
lv_obj_t *sb_h = lv_label_create(bar);
lv_label_set_text(sb_h, "--");
lv_obj_set_style_text_font(sb_h, &lv_font_montserrat_14, 0);
lv_obj_set_style_text_color(sb_h, C_COOL, 0);
lv_obj_align(sb_h, LV_ALIGN_LEFT_MID, PAD + 136, 0);
if (idx >= 0) sb_hum[idx] = sb_h;
lv_obj_t *sb_p = lv_label_create(bar);
lv_label_set_text(sb_p, "--");
lv_obj_set_style_text_font(sb_p, &lv_font_montserrat_14, 0);
lv_obj_set_style_text_color(sb_p, C_DIM, 0);
lv_obj_align(sb_p, LV_ALIGN_LEFT_MID, PAD + 200, 0);
if (idx >= 0) sb_press[idx] = sb_p;
// ── Centre-right: clock HH:MM ──────────────────────────────────────────
// Offset right of centre so it doesn't clash with the page title
lv_obj_t *tclk = lv_label_create(bar);
lv_label_set_text(tclk, "--:--");
lv_obj_set_style_text_font(tclk, &lv_font_montserrat_20, 0);
lv_obj_set_style_text_color(tclk, C_TEXT, 0);
lv_obj_align(tclk, LV_ALIGN_RIGHT_MID, -(PAD + 170), 0);
if (idx >= 0) sb_time[idx] = tclk;
// ── Right side: battery icon + % ──────────────────────────────────────
lv_obj_t *bat = lv_label_create(bar);
lv_label_set_text(bat, LV_SYMBOL_BATTERY_FULL);
lv_obj_set_style_text_font(bat, &lv_font_montserrat_20, 0);
lv_obj_set_style_text_color(bat, C_GREEN, 0);
lv_obj_align(bat, LV_ALIGN_RIGHT_MID, -(PAD + 44), 0);
if (idx >= 0) sb_bat[idx] = bat;
lv_obj_t *bat_pct = lv_label_create(bar);
lv_label_set_text(bat_pct, "--%");
lv_obj_set_style_text_font(bat_pct, &lv_font_montserrat_14, 0);
lv_obj_set_style_text_color(bat_pct, C_GREEN, 0);
lv_obj_align(bat_pct, LV_ALIGN_RIGHT_MID, -PAD, 0);
if (idx >= 0) sb_bat_pct[idx] = bat_pct;
}
// ── Screen 0: Combined Clock + Indoor Sensors + Today's Weather ───────────────
//
// NEW LAYOUT (1280 × 720):
//
// ┌─ status bar (1280 × 44) ──────────────────────────────────────────────┐
// ├─ NAV ─┬──── LEFT COLUMN (~700 px) ──────┬──── RIGHT PANEL (~424 px) ─┤
// │ 70 │ HH:MM:SS (font_48) top 55% │ [sensor row, 62 px] │
// │ │ date + location pill │ [weather card, fills rest]│
// │ │ ───────────────────────────── │ │
// │ │ Condition + description 45% │ │
// ├─ NAV ─┴─────────────────────────────────┴────────────────────────────┤
// └─ dot row ──────────────────────────────────────────────────────────────┘
// =============================================================================
#define CLK_DIV_X 770
#define CLK_RIGHT_X (CLK_DIV_X + 16)
#define CLK_RIGHT_W (SCREEN_W - NAV_BTN_W - CLK_RIGHT_X)
// Left column split: clock top 42%, description bottom 58%
// Moving clock higher gives the desc zone more room for the forecast paragraph
#define CLK_CONTENT_H (SCREEN_H - STATUSBAR_H - 26)
#define CLK_SPLIT_Y (STATUSBAR_H + (CLK_CONTENT_H * 36 / 100))
// Right panel: taller sensor cards with a visible gap before weather card
#define CLK_SENSOR_LABEL_Y (STATUSBAR_H + 12)
#define CLK_SENSOR_CARD_Y (CLK_SENSOR_LABEL_Y + 14)
#define CLK_SENSOR_CARD_H 80 // tall enough for font_28 value
#define CLK_WX_CARD_Y (CLK_SENSOR_CARD_Y + CLK_SENSOR_CARD_H + 14) // visible gap
#define CLK_WX_CARD_H (SCREEN_H - CLK_WX_CARD_Y - 26)
// Weather card internals — tighter hero, more grid space
#define WX_IP 12
#define WX_TEMP_Y_REL 8
#define WX_FEELS_HDR_Y_REL 10
#define WX_FEELS_VAL_Y_REL 28
#define WX_DIV1_REL 58
#define WX_GRID_TOP_REL 66
// ── Outlook icon strip dimensions ─────────────────────────────────────────────
#define OUTLOOK_SLOTS 5
#define OUTLOOK_ICON_W 80
#define OUTLOOK_ICON_H 70
#define OUTLOOK_SLOT_W ((CLK_DIV_X - NAV_BTN_W - PAD*2) / OUTLOOK_SLOTS)
static void build_clock_screen() {
lv_obj_t *scr = screens[SCREEN_CLOCK];
lv_obj_set_style_bg_color(scr, C_BG, 0);
build_statusbar(scr, "");
// ── VERTICAL DIVIDER ─────────────────────────────────────────────────────
lv_obj_t *vdiv = lv_obj_create(scr);
lv_obj_set_size(vdiv, 1, SCREEN_H - STATUSBAR_H - 20);
lv_obj_set_pos(vdiv, CLK_DIV_X, STATUSBAR_H + 10);
lv_obj_set_style_bg_color(vdiv, C_BORDER, 0);
lv_obj_set_style_bg_opa(vdiv, LV_OPA_COVER, 0);
lv_obj_set_style_border_width(vdiv, 0, 0);
lv_obj_set_style_pad_all(vdiv, 0, 0);
lv_obj_clear_flag(vdiv, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_clear_flag(vdiv, LV_OBJ_FLAG_CLICKABLE);
// ── HORIZONTAL SPLIT LINE ─────────────────────────────────────────────────
lv_obj_t *hdiv = lv_obj_create(scr);
lv_obj_set_size(hdiv, CLK_DIV_X - NAV_BTN_W - PAD*2, 1);
lv_obj_set_pos(hdiv, NAV_BTN_W + PAD, CLK_SPLIT_Y);
lv_obj_set_style_bg_color(hdiv, C_BORDER, 0);
lv_obj_set_style_bg_opa(hdiv, LV_OPA_COVER, 0);
lv_obj_set_style_border_width(hdiv, 0, 0);
lv_obj_set_style_pad_all(hdiv, 0, 0);
lv_obj_clear_flag(hdiv, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_clear_flag(hdiv, LV_OBJ_FLAG_CLICKABLE);
// =========================================================================
// CLOCK ZONE — top 55% of left column
// =========================================================================
const int CLK_ZONE_H = CLK_SPLIT_Y - STATUSBAR_H;
const int CLK_COL_CX = NAV_BTN_W + (CLK_DIV_X - NAV_BTN_W) / 2;
const int TIME_MID_Y = STATUSBAR_H + (CLK_ZONE_H * 40 / 100);
// HH:MM:SS — five labels, all font_48, positioned absolutely
// Montserrat_48 digit pair ≈ 70px, colon ≈ 18px, total ≈ 246px
const int HH_X = CLK_COL_CX - 123;
const int C1_X = HH_X + 70;
const int MM_X = C1_X + 18;
const int C2_X = MM_X + 70;
const int SS_X = C2_X + 18;
const int TY = TIME_MID_Y - 29; // top of glyph (approx half of font_48)
clk_hh = lv_label_create(scr); lv_label_set_text(clk_hh, "00");
clk_col1 = lv_label_create(scr); lv_label_set_text(clk_col1, ":");
clk_mm = lv_label_create(scr); lv_label_set_text(clk_mm, "00");
clk_col2 = lv_label_create(scr); lv_label_set_text(clk_col2, ":");
clk_ss = lv_label_create(scr); lv_label_set_text(clk_ss, "00");
lv_obj_t *time_lbls[] = { clk_hh, clk_col1, clk_mm, clk_col2, clk_ss };
lv_color_t time_cols[] = { C_TEXT, C_DIM, C_TEXT, C_DIM, C_DIM };
int time_xs[] = { HH_X, C1_X, MM_X, C2_X, SS_X };
for (int i = 0; i < 5; i++) {
lv_obj_set_style_text_font(time_lbls[i], &lv_font_montserrat_48, 0);
lv_obj_set_style_text_color(time_lbls[i], time_cols[i], 0);
lv_obj_set_pos(time_lbls[i], time_xs[i], TY);
}
// Date — centred in clock column, below time
clk_date = lv_label_create(scr);
lv_label_set_text(clk_date, "Loading...");
lv_obj_set_style_text_font(clk_date, &lv_font_montserrat_28, 0);
lv_obj_set_style_text_color(clk_date, C_TEXT, 0);
lv_obj_set_style_text_align(clk_date, LV_TEXT_ALIGN_CENTER, 0);
lv_obj_set_width(clk_date, CLK_DIV_X - NAV_BTN_W);
lv_obj_set_pos(clk_date, NAV_BTN_W, TIME_MID_Y + 38);
// Location + TZ pill
const int PILL_W = 380, PILL_H = 38;
const int PILL_X = CLK_COL_CX - PILL_W/2;
const int PILL_Y = TIME_MID_Y + 80;
lv_obj_t *pill = lv_obj_create(scr);
lv_obj_set_size(pill, PILL_W, PILL_H);
lv_obj_set_pos(pill, PILL_X, PILL_Y);
lv_obj_set_style_bg_color(pill, C_CARD, 0);
lv_obj_set_style_bg_opa(pill, LV_OPA_COVER, 0);
lv_obj_set_style_border_color(pill, C_BORDER, 0);
lv_obj_set_style_border_width(pill, 1, 0);
lv_obj_set_style_radius(pill, 8, 0);
lv_obj_set_style_pad_all(pill, 0, 0);
lv_obj_clear_flag(pill, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_clear_flag(pill, LV_OBJ_FLAG_CLICKABLE);
lv_obj_t *loc = lv_label_create(pill);
lv_label_set_text(loc, "Sydney, NSW");
lv_obj_set_style_text_font(loc, &lv_font_montserrat_20, 0);
lv_obj_set_style_text_color(loc, C_ACCENT, 0);
lv_obj_align(loc, LV_ALIGN_LEFT_MID, 14, 0);
lv_obj_t *sep = lv_label_create(pill);
lv_label_set_text(sep, "|");
lv_obj_set_style_text_font(sep, &lv_font_montserrat_20, 0);
lv_obj_set_style_text_color(sep, C_BORDER, 0);
lv_obj_align(sep, LV_ALIGN_CENTER, 0, 0);
clk_tz = lv_label_create(pill);
lv_label_set_text(clk_tz, "AEDT +11");
lv_obj_set_style_text_font(clk_tz, &lv_font_montserrat_20, 0);
lv_obj_set_style_text_color(clk_tz, C_DIM, 0);
lv_obj_align(clk_tz, LV_ALIGN_RIGHT_MID, -14, 0);
// =========================================================================
// DESCRIPTION ZONE — bottom 45% of left column
// Condition name (font_28) + two description lines (font_20)
// Full column width → plenty of room, no truncation
// =========================================================================
const int DESC_X = NAV_BTN_W + PAD;
const int DESC_W = CLK_DIV_X - NAV_BTN_W - PAD*2;
clk_wx_cond = lv_label_create(scr);
lv_label_set_text(clk_wx_cond, "—");
lv_obj_set_style_text_font(clk_wx_cond, &lv_font_montserrat_28, 0);
lv_obj_set_style_text_color(clk_wx_cond, C_ACCENT, 0);
lv_obj_set_pos(clk_wx_cond, DESC_X, CLK_SPLIT_Y + 30);
clk_wx_desc1 = lv_label_create(scr);
lv_label_set_text(clk_wx_desc1, "");
lv_obj_set_style_text_font(clk_wx_desc1, &lv_font_montserrat_20, 0);
lv_obj_set_style_text_color(clk_wx_desc1, C_DIM, 0);
lv_obj_set_width(clk_wx_desc1, DESC_W);
lv_label_set_long_mode(clk_wx_desc1, LV_LABEL_LONG_WRAP);
lv_obj_set_pos(clk_wx_desc1, DESC_X, CLK_SPLIT_Y + 66);