-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThe_Signet.ino
More file actions
2410 lines (2140 loc) · 106 KB
/
The_Signet.ino
File metadata and controls
2410 lines (2140 loc) · 106 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
/*
===================================================================================
The Signet Morse Beacon
Version: 1.3.1
Release Date: March 15, 2026
===================================================================================
DESCRIPTION:
A covert Morse code beacon that can transmit messages via IR (invisible) or RGB
(visible) LED. Features a captive portal web interface for configuration and custom
message input. NO LOGS, NO TELEMETRY, NO BULLSHYTE.
FEATURES:
- Wi-Fi AP + Captive Portal Web UI -No APP required
- SSID: "The_Signet_XXXXXX" (XXXXXX = Last 3 bytes of MAC Address)
- RGB & IR LED
- Morse Code Playback with configurable intensity
- Adjustable Morse speed (5-20 WPM)
- 60-second idle WiFi AP timeout to conserve power
- Help(?) screen with Morse code definitions
- OTA Firmware update support with LED combination lock (v1.3.0+)
HARDWARE:
- Seeed Studios XIAO ESP32-C6 Module (other ESP32s can be used)
- WS2812B RGB LED
- IR LED
- 10 Ohm resistor
- 270 Ohm resistor
- 47k Ohm resistor
- 100k Ohm resistor
- 2N3904 NPN Transistor
- SPST switch for sleep control
- (optional) 503035 LiPo battery with built in charge/discharge protection
- See schematic for complete circuit
AUTHOR:
Created by Mike Stewart as a tool for all those fighting against Authoritarianism
and to maintain free-speech.
===================================================================================
VERSION HISTORY:
===================================================================================
v1.3.1 (March 15, 2026) - Security hardening: OTA combination lock - 4-digit code
displayed via RGB LED (Red/Green/Blue/Yellow blinks) required
before firmware upload. Rate limiting with exponential backoff,
hard lockout after 5 failed attempts, 3-minute code expiry.
OTA serial debug gated behind OTA_DEBUG preprocessor flag.
v1.3.0 (March 3, 2026) - Security hardening: OTA combination lock - 3-digit code
displayed via RGB LED (Red/Green/Blue blinks) required
before firmware upload. MAC address locking - first client
to connect gets exclusive API access until power cycle.
AP now shuts down when locked client disconnects (prevents
secondary device WiFi access). Locked MAC cleared from RAM
after AP shutdown (anti-forensics). True stateless design:
removed NVS language persistence, language modal shows on
every boot. Zero bytes persisted to flash.
v1.2.1 (February 26, 2026) - Added UI language options for UI. English (default), French,
Spanish, Russian, Traditional Chinese, Simplified Chinese, Arabic and Farsi.
*** ITU Morse code is still implemented ***
v1.2.0 (February 20, 2026) - OTA firmware updates via web UI. Settings gear icon added
to footer, opens firmware upload modal with password
protection. Dual-partition layout enables automatic rollback
on failed updates. Requires one-time USB flash from v1.1.x.
v1.1.2 (February 19, 2026) - Bugfix: TX time display now updates correctly when message
speed (WPM) is modified (Issue #24). Custom message no longer
reverts to default when selecting options before Play (Issue #25).
Fixed race condition where blue pulse and playback could both
control LED after quick power cycle (Issue #26). API now returns
proper error responses for invalid requests (Issue #27).
v1.1.1 (January 27, 2026) - UI improvements: larger help icon and 1984 footer text,
firmware version indicator, splash screen text and
improved load reliability, Harlow font title, yellow
message hints, white card titles, iOS auto-zoom fix,
IR PWM frequency increased from 200 Hz to 30 kHz
v1.1.0 (January 21, 2026) - Default message "S O S" changed to "SOS" for standard
Morse timing
v1.0.3 (January 19, 2026) - Blue pulsing LED indicates WiFi AP ready, 4 rapid blinks
confirm Web UI connection, custom color wheel picker,
hardware PWM for IR LED (improved power efficiency)
v1.0.2 (January 3, 2026) - Compact mobile-friendly UI
v1.0.1 (January 2, 2026) - Added adjustable Morse speed (WPM)
v1.0.0 (January 1, 2026) - Initial Stable Release
===================================================================================
PIN CONFIGURATION: for Seeed Studios ESP32-C6
===================================================================================
PIN_RGB D5 - WS2812B RGB LED data
PIN_IR D8 - IR LED PWM drive
PIN_SLEEP_SW D2 - Sleep switch (SPST to GND)
===================================================================================
*/
#include <Arduino.h>
#include <WiFi.h>
#include <WebServer.h>
#include <DNSServer.h>
#include <FastLED.h>
#include <ArduinoJson.h>
#include <LittleFS.h>
#include "esp_sleep.h"
#include "esp_mac.h" // esp_read_mac()
#include "driver/ledc.h" // Hardware PWM for IR LED
#include <Update.h> // OTA firmware updates
#include "esp_ota_ops.h" // OTA boot validation
// Preferences.h removed - true stateless design (no NVS usage)
#include <atomic> // Thread-safe atomic types
#include "esp_task_wdt.h" // Task watchdog timer
#include "esp_wifi.h" // MAC address locking
// Increase main loop task stack size from 8KB to 32KB
// Required for WebServer handling multiple captive portal requests (especially Android)
SET_LOOP_TASK_STACK_SIZE(32 * 1024);
// -------------------- Version Information --------------------
#define FIRMWARE_VERSION "1.3.1"
#define FIRMWARE_DATE "March 15, 2026"
// -------------------- Forward Declarations --------------------
enum Mode { DISCREET = 0, VISIBLE = 1 };
enum ColorSel { C_RED = 0, C_GREEN = 1, C_BLUE = 2, C_CUSTOM = 3 };
enum Intensity{ I_LOW = 0, I_MED = 1, I_HIGH = 2 };
// Language codes for UI localization
enum Language : uint8_t {
LANG_EN = 0, // English (default)
LANG_ES = 1, // Spanish (Español)
LANG_FR = 2, // French (Français)
LANG_RU = 3, // Russian (Русский)
LANG_ZH_CN = 4, // Simplified Chinese (简体中文)
LANG_ZH_TW = 5, // Traditional Chinese (繁體中文)
LANG_FA = 6, // Farsi/Persian (فارسی)
LANG_AR = 7 // Arabic (العربية)
};
// Language code strings for API
const char* const LANG_CODES[] = {"en", "es", "fr", "ru", "zh-CN", "zh-TW", "fa", "ar"};
const uint8_t LANG_COUNT = 8;
uint8_t rgbBrightnessFor(Intensity i);
uint8_t irDutyFor(Intensity i);
CRGB colorValue(ColorSel c);
String intensityToStr(Intensity i);
Intensity strToIntensity(const String& s);
String colorToStr(ColorSel c);
ColorSel strToColor(const String& s);
void setupIrHardwarePwm();
void morseTask(void* pv);
void sendIndex();
void sendHelpPage();
void handleState();
void handleUpdate();
void handlePlay();
void handleStop();
void handleOtaUpload();
void handleOtaComplete();
void handleOtaCode();
void handleLanguageSet();
void handleNotFound();
bool captivePortal();
void updateBluePulse();
void connectionConfirmBlink();
void goToDeepSleep();
// -------------------- Pins & Hardware --------------------
// Adjust these to match your wiring.
#define PIN_RGB D5
#define PIN_IR D8
#define NUM_PIXELS 1
// Sleep switch: SPST between D2 and GND
// CLOSED -> D2 = LOW -> run normally
// OPEN -> D2 = HIGH (INPUT_PULLUP) -> deep sleep
#define PIN_SLEEP_SW D2
// -------------------- Hardware PWM (LEDC) for IR LED --------------------
#define IR_LEDC_CHANNEL LEDC_CHANNEL_0
#define IR_LEDC_TIMER LEDC_TIMER_0
#define IR_LEDC_FREQ_HZ 30000 // 30 kHz PWM frequency
// -------------------- WiFi AP -------------------------
const char* AP_SSID_BASE = "The_Signet";
const char* AP_PASS = "";
IPAddress apIP(192,168,4,1);
IPAddress apGateway(192,168,4,1);
IPAddress apSubnet(255,255,255,0);
String apSsid; // must persist (global) so c_str() stays valid
String portalRedirectUrl; // Pre-computed redirect URL to reduce heap pressure in handlers
static String buildApSsidWithMacTail() {
uint8_t mac[6] = {0};
// Read factory-programmed MAC from eFuse
esp_read_mac(mac, ESP_MAC_WIFI_STA);
char tail[7]; // 6 hex chars + null
snprintf(tail, sizeof(tail), "%02X%02X%02X", mac[3], mac[4], mac[5]);
String base(AP_SSID_BASE);
while (base.endsWith("_")) base.remove(base.length() - 1);
return base + "_" + tail;
}
// -------------------- WiFi Idle timeout logic --------------------
const unsigned long AP_IDLE_TIMEOUT_MS = 60000; // 60 seconds (privacy: minimize SSID exposure)
unsigned long lastActivityMs = 0;
bool apRunning = false;
inline void noteActivity() { lastActivityMs = millis(); }
// -------------------- UI Connection State & Blue Pulse --------------------
volatile bool uiServed = false; // True once Web UI has been served
static uint8_t pulseState = 10; // Current brightness (10-90)
static int8_t pulseDirection = 5; // Direction and step size
static unsigned long lastPulseMs = 0;
const unsigned long PULSE_INTERVAL_MS = 30; // Update every 30ms for smooth breathing
// -------------------- Servers -----------------------------
WebServer server(80);
DNSServer dnsServer;
// Language selection: Stateless design - modal shows every boot, no NVS persistence
// -------------------- RGB via FastLED ---------------------
CRGB leds[NUM_PIXELS];
// -------------------- Hardware PWM (LEDC) for IR -----------------
void setupIrHardwarePwm() {
ledc_timer_config_t timer_conf = {
.speed_mode = LEDC_LOW_SPEED_MODE,
.duty_resolution = LEDC_TIMER_8_BIT,
.timer_num = IR_LEDC_TIMER,
.freq_hz = IR_LEDC_FREQ_HZ,
.clk_cfg = LEDC_AUTO_CLK
};
ledc_timer_config(&timer_conf);
ledc_channel_config_t channel_conf = {
.gpio_num = PIN_IR,
.speed_mode = LEDC_LOW_SPEED_MODE,
.channel = IR_LEDC_CHANNEL,
.intr_type = LEDC_INTR_DISABLE,
.timer_sel = IR_LEDC_TIMER,
.duty = 0,
.hpoint = 0
};
ledc_channel_config(&channel_conf);
}
inline void irSetDuty(uint8_t duty) {
ledc_set_duty(LEDC_LOW_SPEED_MODE, IR_LEDC_CHANNEL, duty);
ledc_update_duty(LEDC_LOW_SPEED_MODE, IR_LEDC_CHANNEL);
}
// -------------------- App State --------------------------
static SemaphoreHandle_t textMutex = nullptr;
struct AppState {
volatile Mode mode = DISCREET;
volatile ColorSel color = C_RED;
volatile Intensity intensity = I_MED;
volatile bool dazzle = false;
volatile uint8_t wpm = 10; // Words per minute (5-20 range)
volatile uint8_t customR = 255; // Custom color RGB components
volatile uint8_t customG = 0;
volatile uint8_t customB = 255; // Default: magenta
volatile uint8_t language = LANG_EN; // UI language
String text = "SOS";
std::atomic<bool> playing{false}; // Thread-safe playback state
} state;
// -------------------- Security: MAC Address Locking --------------------
// First client to make a POST request gets exclusive access until power cycle
static uint8_t lockedMac[6] = {0};
static bool macLocked = false;
// -------------------- Security: OTA Debug Gating --------------------
// Uncomment to enable OTA serial debug output (SECURITY: code printed in plaintext!)
// #define OTA_DEBUG
#ifdef OTA_DEBUG
#define OTA_LOG(fmt, ...) Serial.printf(fmt, ##__VA_ARGS__)
#define OTA_LOGLN(msg) Serial.println(msg)
#else
#define OTA_LOG(fmt, ...)
#define OTA_LOGLN(msg)
#endif
// -------------------- Security: OTA Combination Lock --------------------
// 4-digit code (1-9 each) displayed via RGB LED blinks (R, G, B, Y)
static const uint8_t OTA_CODE_LEN = 4;
static uint8_t otaCode[OTA_CODE_LEN] = {0};
static bool otaCodeValid = false;
static unsigned long otaCodeGeneratedAt = 0;
static const unsigned long OTA_CODE_TTL_MS = 180000UL; // 3 minutes
// Rate limiting / lockout
static uint8_t otaFailCount = 0;
static unsigned long otaLastFailTime = 0;
static bool otaHardLocked = false;
static unsigned long otaRetryAfterMs = 0;
static const uint8_t OTA_MAX_ATTEMPTS = 5;
static const unsigned long OTA_BACKOFF_BASE_MS = 1000UL;
String getTextCopy() {
String copy;
if (textMutex && xSemaphoreTake(textMutex, pdMS_TO_TICKS(100)) == pdTRUE) {
copy = state.text;
xSemaphoreGive(textMutex);
} else {
copy = "SOS"; // Fallback if mutex fails
}
return copy;
}
void setTextSafe(const String& newText) {
if (textMutex && xSemaphoreTake(textMutex, pdMS_TO_TICKS(100)) == pdTRUE) {
state.text = newText;
xSemaphoreGive(textMutex);
}
}
// -------------------- Brightness / Color -----------------
uint8_t rgbBrightnessFor(Intensity i) {
switch (i) {
case I_LOW: return 40;
case I_MED: return 120;
case I_HIGH: return 200;
default: return 120;
}
}
uint8_t irDutyFor(Intensity i) {
switch (i) {
case I_LOW: return 40;
case I_MED: return 120;
case I_HIGH: return 200;
default: return 128;
}
}
CRGB colorValue(ColorSel c) {
switch (c) {
case C_RED: return CRGB(128,0,0);
case C_GREEN: return CRGB(0,128,0);
case C_BLUE: return CRGB(0,0,128);
case C_CUSTOM: return CRGB(state.customR, state.customG, state.customB);
default: return CRGB(128,0,0);
}
}
// -------------------- Morse Timing (WPM-based) -------------------
// Standard "PARIS" timing: dit duration = 1200 / WPM (in ms)
// All other timings are multiples of the dit duration
uint32_t ditDuration() { uint8_t wpm = state.wpm; return 1200 / (wpm > 0 ? wpm : 1); } // Guard against div-by-zero
uint32_t dahDuration() { return 3 * ditDuration(); }
uint32_t gapIntra() { return ditDuration(); } // Between dits/dahs in same letter
uint32_t gapLetter() { return 3 * ditDuration(); } // Between letters
uint32_t gapWord() { return 7 * ditDuration(); } // Between words
// Fixed loop gap timings (not WPM-dependent)
const uint32_t LOOP_GAP = 2000;
const uint32_t VISIBLE_DAZZLE_OFF1 = 750;
const uint32_t VISIBLE_DAZZLE_OFF2 = 750;
const uint32_t VISIBLE_DAZZLE_FLASH = 500;
struct MorseEntry { char ch; const char* code; };
const MorseEntry MORSE[] = {
{'A',".-"},{'B',"-..."},{'C',"-.-."},{'D',"-.."},{'E',"."},{'F',"..-."},{'G',"--."},{'H',"...."},{'I',".."},{'J',".---"},
{'K',"-.-"},{'L',".-.."},{'M',"--"},{'N',"-."},{'O',"---"},{'P',".--."},{'Q',"--.-"},{'R',".-."},{'S',"..."},
{'T',"-"},{'U',"..-"},{'V',"...-"},{'W',".--"},{'X',"-..-"},{'Y',"-.--"},{'Z',"--.."},
{'0',"-----"},{'1',".----"},{'2',"..---"},{'3',"...--"},{'4',"....-"},{'5',"....."},{'6',"-...."},{'7',"--..."},{'8',"---.."},{'9',"----."},
{'.',".-.-.-"},{',',"--..--"},{'?',"..--.."},{'/',"-..-."},{'-',"-....-"},{'(',"-.--."},{')',"-.--.-"},{'@',".--.-."},{'=',"-...-"}
};
const size_t MORSE_LEN = sizeof(MORSE) / sizeof(MorseEntry);
const char* lookupMorse(char c) {
if (c >= 'a' && c <= 'z') c = char(c - 'a' + 'A');
for (size_t i=0; i<MORSE_LEN; i++) if (MORSE[i].ch == c) return MORSE[i].code;
return nullptr;
}
// -------------------- Prosigns ---------------------------
struct ProsignEntry { const char* tag; const char* code; };
const ProsignEntry PROSIGNS[] = {
{"KA", "-.-.-"}, // Starting signal
{"AR", ".-.-."} // End of message
};
const size_t PROSIGN_LEN = sizeof(PROSIGNS) / sizeof(ProsignEntry);
const char* lookupProsign(const String& tag) {
for (size_t i = 0; i < PROSIGN_LEN; i++) {
if (tag.equalsIgnoreCase(PROSIGNS[i].tag)) return PROSIGNS[i].code;
}
return nullptr;
}
// -------------------- LED Control -------------------------
inline void irOff() { irSetDuty(0); }
inline void irOn() { irSetDuty(irDutyFor(state.intensity)); }
void rgbOff() {
FastLED.setBrightness(0);
leds[0] = CRGB::Black;
FastLED.show();
}
void rgbOnCurrentColor() {
FastLED.setBrightness(rgbBrightnessFor(state.intensity));
leds[0] = colorValue(state.color);
FastLED.show();
}
void activeLedOn() { if (state.mode == DISCREET) irOn(); else rgbOnCurrentColor(); }
void activeLedOff() { if (state.mode == DISCREET) irOff(); else rgbOff(); }
void allOff() { irOff(); rgbOff(); }
// -------------------- Security: MAC Locking ----------------
// Get connected client's MAC address (only 1 client allowed via max_conn=1)
bool getClientMac(uint8_t* macOut) {
wifi_sta_list_t stationList;
if (esp_wifi_ap_get_sta_list(&stationList) != ESP_OK) return false;
if (stationList.num == 0) return false;
// With max_conn=1, there's only ever one client
memcpy(macOut, stationList.sta[0].mac, 6);
return true;
}
// Check if request is from locked MAC, or lock to first client
bool checkMacLock() {
uint8_t clientMac[6];
// If can't get MAC, allow (fallback for reliability)
if (!getClientMac(clientMac)) {
return true;
}
// First client - lock to their MAC
if (!macLocked) {
memcpy(lockedMac, clientMac, 6);
macLocked = true;
Serial.printf("[Security] Locked to MAC: %02X:%02X:%02X:%02X:%02X:%02X\n",
lockedMac[0], lockedMac[1], lockedMac[2],
lockedMac[3], lockedMac[4], lockedMac[5]);
return true;
}
// Check if same MAC
return memcmp(clientMac, lockedMac, 6) == 0;
}
// -------------------- Security: OTA Combination Lock -------
// Generate random 4-digit code (1-9 each)
// Note: Must be called with otaMutex held (called from handleOtaCode which acquires it)
void generateOtaCode() {
for (int i = 0; i < OTA_CODE_LEN; i++) {
otaCode[i] = (esp_random() % 9) + 1; // 1-9
}
otaCodeValid = true;
otaCodeGeneratedAt = millis();
OTA_LOG("[OTA] Generated code: %d%d%d%d\n", otaCode[0], otaCode[1], otaCode[2], otaCode[3]);
}
// Display OTA code via RGB LED blinks: Red=digit1, Green=digit2, Blue=digit3, Yellow=digit4
void displayOtaCodeOnLed(const uint8_t* code) {
// Stop any current playback
bool wasPlaying = state.playing;
state.playing = false;
delay(200);
allOff();
// Blink pattern: Red, Green, Blue, Yellow for digits 1-4
CRGB colors[OTA_CODE_LEN] = {CRGB(255,0,0), CRGB(0,255,0), CRGB(0,0,255), CRGB(255,255,0)};
for (int digit = 0; digit < OTA_CODE_LEN; digit++) {
delay(500); // Pause between digits
for (int blink = 0; blink < code[digit]; blink++) {
leds[0] = colors[digit];
FastLED.setBrightness(200);
FastLED.show();
delay(300);
leds[0] = CRGB::Black;
FastLED.show();
delay(200);
}
}
delay(300);
allOff();
// Restore playback state if needed
if (wasPlaying) state.playing = true;
}
// Verify OTA code - invalidates after successful use
// Note: Must be called with otaMutex held (called from handleOtaUpload which acquires it)
bool verifyOtaCode(uint8_t d1, uint8_t d2, uint8_t d3, uint8_t d4) {
if (!otaCodeValid) return false;
// Check TTL expiry
if ((millis() - otaCodeGeneratedAt) > OTA_CODE_TTL_MS) {
otaCodeValid = false;
memset(otaCode, 0, OTA_CODE_LEN);
OTA_LOGLN("[OTA] Code expired");
return false;
}
bool match = (d1 == otaCode[0] && d2 == otaCode[1] && d3 == otaCode[2] && d4 == otaCode[3]);
if (match) {
otaCodeValid = false; // Invalidate after successful use
OTA_LOGLN("[OTA] Code verified successfully");
} else {
OTA_LOG("[OTA] Code verification failed: got %d%d%d%d, expected %d%d%d%d\n",
d1, d2, d3, d4, otaCode[0], otaCode[1], otaCode[2], otaCode[3]);
}
return match;
}
// -------------------- Morse Task --------------------------
TaskHandle_t morseTaskHandle = nullptr;
inline void morseDelay(uint32_t ms) { vTaskDelay(pdMS_TO_TICKS(ms)); }
void playSymbol(char s) {
uint32_t onMs = (s == '.') ? ditDuration() : dahDuration();
activeLedOn();
morseDelay(onMs);
allOff();
}
void playLetter(const char* code) {
if (!code) return;
for (size_t i=0; code[i]; i++) {
if (!state.playing) {
allOff();
return;
}
playSymbol(code[i]);
if (code[i+1]) morseDelay(gapIntra());
}
}
void doDazzleGap() {
allOff();
morseDelay(VISIBLE_DAZZLE_OFF1);
uint32_t elapsed=0, step=30;
while (elapsed < VISIBLE_DAZZLE_FLASH && state.playing) {
FastLED.setBrightness(rgbBrightnessFor(state.intensity));
leds[0]=CRGB(255,0,0); FastLED.show(); morseDelay(step);
leds[0]=CRGB(0,255,0); FastLED.show(); morseDelay(step);
leds[0]=CRGB(0,0,255); FastLED.show(); morseDelay(step);
elapsed += step*3;
}
allOff();
morseDelay(VISIBLE_DAZZLE_OFF2);
}
void morseTask(void*) {
for(;;){
while (!state.playing) vTaskDelay(pdMS_TO_TICKS(50));
while (state.playing) {
String msg = getTextCopy();
if (msg.length() == 0) {
morseDelay(500); // Wait before checking again
continue;
}
for (size_t i=0; i<msg.length() && state.playing; i++) {
char c = msg[i];
// Check for prosign: <XX> syntax
if (c == '<') {
int closePos = msg.indexOf('>', i);
if (closePos > (int)i + 1 && closePos <= (int)i + 4) {
String tag = msg.substring(i + 1, closePos);
const char* code = lookupProsign(tag);
if (code) {
playLetter(code); // Play as single unit
if (!state.playing) break;
morseDelay(gapLetter());
i = closePos; // Skip past closing >
continue;
}
}
}
if (c == ' ') {
morseDelay(gapWord());
continue;
}
const char* code = lookupMorse(c);
if (code) {
playLetter(code);
if (!state.playing) break;
morseDelay(gapLetter());
}
}
if (!state.playing) break;
if (state.mode == DISCREET) {
allOff();
morseDelay(LOOP_GAP);
} else {
if (state.dazzle) doDazzleGap();
else { activeLedOff(); morseDelay(LOOP_GAP); }
}
}
allOff();
}
}
// -------------------- Web UI (+ splash via /bb.jpg) ------------------
static const char INDEX_HTML[] PROGMEM = R"====(
<!doctype html><html lang="en"><head>
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>The Signet Morse Beacon</title>
<style>
@font-face{font-family:'Harlow';src:url('/HarlowSolid.ttf') format('truetype')}
:root{--bg:#121212;--card:#1E1E1E;--text:#ECECEC;--muted:#B0B0B0;--accent:#8AB4F8;--primary:#8AB4F8}
*{box-sizing:border-box;font-family:Inter,system-ui,Segoe UI,Roboto,Arial,sans-serif;margin:0;padding:0}
body{background:var(--bg);color:var(--text)}
.wrap{max-width:420px;margin:0 auto;padding:10px}
.appbar{text-align:center;padding:12px;font-family:'Harlow',cursive;font-size:28px;font-weight:400;color:#ddd;border-bottom:1px solid #222}
.grid{display:flex;flex-direction:column;gap:10px;margin-top:10px}
.row-2{display:grid;grid-template-columns:1fr 1fr;gap:10px}
.card{background:var(--card);border:1px solid #2A2A2A;border-radius:12px;padding:12px}
.card h3{font-size:11px;font-weight:600;color:#fff;text-transform:uppercase;letter-spacing:.5px;margin-bottom:8px}
.seg{display:flex;gap:6px}
.seg button{flex:1;border:0;border-radius:8px;padding:8px 4px;background:#171717;border:1px solid #2A2A2A;color:#ddd;font-size:12px;font-weight:500;cursor:pointer}
.seg button.active{background:var(--accent);color:#000;border-color:var(--accent)}
.seg button svg{width:18px;height:18px;fill:currentColor;vertical-align:middle}
.color-row{display:flex;gap:8px;align-items:center}
.color{width:28px;height:28px;border-radius:8px;border:1px solid #2A2A2A;cursor:pointer}
.color.active{outline:2px solid var(--accent)}
.color.red{background:#f44336}.color.green{background:#4caf50}.color.blue{background:#2196f3}
.color.custom{background:linear-gradient(135deg,#f44,#ff0,#0f0,#0ff,#00f,#f0f,#f44);position:relative}
.color-picker-wrap{display:none;margin-top:8px;text-align:center}
.color-picker-wrap.visible{display:block}
#wheelCanvas{cursor:crosshair;border-radius:50%}
.dazzle-row{display:flex;align-items:center;gap:8px}
.dazzle-row span{font-size:11px;color:var(--muted)}
.switch{position:relative;width:44px;height:24px}
.switch input{display:none}
.slider{position:absolute;cursor:pointer;inset:0;background:#333;border-radius:999px;transition:.2s}
.slider:before{content:"";position:absolute;height:18px;width:18px;left:3px;bottom:3px;background:#bbb;border-radius:50%;transition:.2s}
input:checked + .slider{background:var(--accent)}
input:checked + .slider:before{transform:translateX(20px);background:#111}
.wpm-row{display:flex;align-items:center;gap:12px}
.wpm-val{font-size:22px;font-weight:700;color:var(--accent);min-width:60px}
.wpm-val small{font-size:11px;color:var(--muted);font-weight:400}
.wpm-slider{flex:1}
.wpm-slider input[type="range"]{-webkit-appearance:none;width:100%;height:6px;border-radius:3px;background:#333}
.wpm-slider input[type="range"]::-webkit-slider-thumb{-webkit-appearance:none;width:20px;height:20px;border-radius:50%;background:var(--accent);cursor:pointer;border:2px solid #222}
.wpm-slider input[type="range"]::-moz-range-thumb{width:20px;height:20px;border-radius:50%;background:var(--accent);cursor:pointer;border:2px solid #222}
.wpm-labels{display:flex;justify-content:space-between;font-size:9px;color:#666;margin-top:4px;padding:0 2px}
.wpm-icon{font-size:20px;opacity:0.7;display:flex;align-items:center}
.wpm-icon svg{width:20px;height:20px;fill:var(--muted)}
.msg-input{width:100%;min-height:72px;background:#151515;border:1px solid #2A2A2A;border-radius:10px;padding:10px;color:#eee;font-size:16px;outline:none;resize:none;font-family:inherit;line-height:1.4}
.msg-hint{font-size:13px;color:#FFD700;margin:6px 0;text-align:center}
.msg-header{display:flex;align-items:baseline}
.max-hint{font-size:10px;color:#666;font-weight:400;margin-left:6px}
.tx-time{margin-left:auto;font-size:14px;color:#8AB4F8;font-weight:400}
.btn-row{display:flex;gap:8px;margin-top:8px}
.btn-row button{flex:1;border:0;border-radius:10px;padding:10px;font-weight:700;font-size:13px;cursor:pointer}
.btn-row .play{background:#333;color:#fff;border:1px solid #333}
.btn-row .play.active{background:var(--primary);color:#000;border-color:var(--primary)}
.btn-row .stop{background:transparent;color:#fff;border:1px solid #333}
.btn-row .stop.active{background:var(--primary);color:#000;border-color:var(--primary)}
.status{text-align:center;font-size:11px;color:#666;margin-top:6px}
.footer{display:flex;align-items:center;justify-content:center;font-size:14px;color:#FFD700;font-weight:700;margin-top:10px}
.footer-text{margin:0 8px}
.settings-btn{width:28px;height:28px;border-radius:50%;background:#333;color:#ccc;border:none;font-size:16px;line-height:28px;text-align:center;cursor:pointer}
.version{text-align:center;font-size:11px;color:#666;margin-top:6px}
.help-btn{display:inline-block;width:28px;height:28px;border-radius:50%;background:#333;color:#ccc;text-decoration:none;font-size:16px;line-height:28px;text-align:center;margin-right:8px;vertical-align:middle}
#splash{position:fixed;inset:0;background:rgba(0,0,0,.92);display:flex;flex-direction:column;align-items:center;justify-content:center;z-index:9999;opacity:0;pointer-events:none;transition:opacity .3s}
#splash p{color:#888;font-size:14px;margin-top:16px;font-style:italic}
#splash.visible{opacity:1;pointer-events:auto}
#splash img{max-width:90vw;max-height:90vh;border-radius:12px;box-shadow:0 0 40px rgba(0,0,0,.7)}
.ota-modal{position:fixed;inset:0;background:rgba(0,0,0,.9);display:flex;align-items:center;justify-content:center;z-index:9998;opacity:0;pointer-events:none;transition:opacity .2s}
.ota-modal.visible{opacity:1;pointer-events:auto}
.ota-card{background:var(--card);border-radius:16px;padding:20px;width:90%;max-width:320px}
.ota-card h3{color:#fff;margin:0 0 12px;font-size:16px;text-align:center}
.ota-close{position:absolute;top:12px;right:16px;background:none;border:none;color:#888;font-size:24px;cursor:pointer}
.ota-input{width:100%;padding:14px;margin-bottom:14px;border-radius:8px;border:1px solid #333;background:#222;color:#fff;font-size:16px;box-sizing:border-box}
.ota-input[type="file"]{padding:12px;height:auto;cursor:pointer}
.ota-btn{width:100%;padding:14px;border-radius:8px;border:none;background:var(--primary);color:#000;font-weight:600;font-size:16px;cursor:pointer}
.ota-btn:disabled{background:#555;color:#888;cursor:not-allowed}
.ota-progress{width:100%;height:6px;border-radius:3px;margin:12px 0;display:none}
.ota-status{text-align:center;font-size:12px;color:#888;margin-top:8px}
.ota-version{text-align:center;font-size:11px;color:#666;margin-bottom:12px}
/* RTL Support */
[dir="rtl"]{direction:rtl;text-align:right}
[dir="rtl"] .card{text-align:right}
[dir="rtl"] .msg-input{text-align:right}
[dir="rtl"] .footer{flex-direction:row-reverse}
[dir="rtl"] .msg-header{flex-direction:row-reverse}
[dir="rtl"] .max-hint{margin-left:0;margin-right:6px}
[dir="rtl"] .tx-time{margin-left:0;margin-right:auto}
[dir="rtl"] .wpm-row{flex-direction:row-reverse}
[dir="rtl"] .dazzle-row{flex-direction:row-reverse}
[dir="rtl"] .help-btn{margin-right:0;margin-left:8px}
/* Language Selection Modal */
.lang-modal{position:fixed;inset:0;background:rgba(0,0,0,.95);display:flex;align-items:center;justify-content:center;z-index:10000;opacity:0;pointer-events:none;transition:opacity .3s}
.lang-modal.visible{opacity:1;pointer-events:auto}
.lang-card{background:var(--card);border-radius:16px;padding:24px;width:90%;max-width:320px;text-align:center}
.lang-card h2{color:#fff;font-size:18px;margin-bottom:8px}
.lang-card p{color:#888;font-size:12px;margin-bottom:20px}
.lang-grid{display:grid;grid-template-columns:1fr 1fr;gap:10px}
.lang-btn{padding:14px 8px;border-radius:10px;border:1px solid #333;background:#222;color:#fff;font-size:14px;cursor:pointer;transition:all .2s}
.lang-btn:hover{background:#333;border-color:var(--accent)}
.lang-btn.selected{background:var(--accent);color:#000;border-color:var(--accent)}
.lang-native{display:block;font-size:12px;color:#888;margin-top:2px}
.lang-btn.selected .lang-native{color:#333}
.lang-confirm{margin-top:16px;width:100%;padding:14px;border-radius:10px;border:none;background:var(--primary);color:#000;font-weight:600;font-size:16px;cursor:pointer}
.lang-confirm:disabled{background:#555;color:#888;cursor:not-allowed}
/* Settings Language Section */
.settings-lang{margin-top:16px;padding-top:16px;border-top:1px solid #333}
.settings-lang h4{color:#888;font-size:11px;text-transform:uppercase;margin-bottom:10px}
.settings-lang select{width:100%;padding:12px;border-radius:8px;border:1px solid #333;background:#222;color:#fff;font-size:14px;cursor:pointer}
</style>
</head>
<body>
<div id="splash"><img src="/bb.jpg" alt="Big Brother"><p id="splashText">Click anywhere to send him a message...</p></div>
<!-- Language Selection Modal (First Boot) -->
<div class="lang-modal" id="langModal">
<div class="lang-card">
<h2 id="langTitle">Select Language</h2>
<p id="langSubtitle">Choose your preferred language</p>
<div class="lang-grid" id="langGrid"></div>
<button class="lang-confirm" id="langConfirm" disabled>Continue</button>
</div>
</div>
<div class="appbar">The Signet</div>
<div class="wrap">
<div class="grid">
<div class="card">
<h3 class="msg-header"><span id="lblMessage">Message</span> <span class="max-hint" id="lblMaxChars">(MAX 200 Characters)</span><span class="tx-time" id="txTime"></span></h3>
<textarea class="msg-input" id="msg" placeholder="SOS" maxlength="200" rows="3"></textarea>
<div class="msg-hint" id="lblHint">A-Z 0-9 . , ? / - ( ) @ = space <KA> <AR></div>
<div class="btn-row">
<button class="play" id="play" title="Play">▶</button>
<button class="stop" id="stop" title="Stop">■</button>
</div>
<div class="status" id="status">Idle</div>
</div>
<div class="row-2">
<div class="card">
<h3 id="lblMode">Mode</h3>
<div class="seg" id="modeGroup">
<button data-mode="DISCREET" id="btnIR" title="IR/Invisible"><svg viewBox="0 0 24 24" width="18" height="18"><path fill="currentColor" d="M12 7c2.76 0 5 2.24 5 5 0 .65-.13 1.26-.36 1.83l2.92 2.92c1.51-1.26 2.7-2.89 3.43-4.75-1.73-4.39-6-7.5-11-7.5-1.4 0-2.74.25-3.98.7l2.16 2.16C10.74 7.13 11.35 7 12 7zM2 4.27l2.28 2.28.46.46A11.804 11.804 0 001 12c1.73 4.39 6 7.5 11 7.5 1.55 0 3.03-.3 4.38-.84l.42.42L19.73 22 21 20.73 3.27 3 2 4.27zM7.53 9.8l1.55 1.55c-.05.21-.08.43-.08.65 0 1.66 1.34 3 3 3 .22 0 .44-.03.65-.08l1.55 1.55c-.67.33-1.41.53-2.2.53-2.76 0-5-2.24-5-5 0-.79.2-1.53.53-2.2zm4.31-.78l3.15 3.15.02-.16c0-1.66-1.34-3-3-3l-.17.01z"/></svg></button>
<button data-mode="VISIBLE" id="btnRGB" title="RGB/Visible"><svg viewBox="0 0 24 24" width="18" height="18"><path fill="currentColor" d="M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z"/></svg></button>
</div>
</div>
<div class="card">
<h3 id="lblIntensity">Intensity</h3>
<div class="seg" id="intensityGroup">
<button data-int="LOW" id="btnLo" title="Low"><svg viewBox="0 0 24 24" width="18" height="18"><circle cx="12" cy="12" r="4" fill="currentColor"/><line x1="12" y1="2" x2="12" y2="5" stroke="currentColor" stroke-width="2"/><line x1="12" y1="19" x2="12" y2="22" stroke="currentColor" stroke-width="2"/><line x1="2" y1="12" x2="5" y2="12" stroke="currentColor" stroke-width="2"/><line x1="19" y1="12" x2="22" y2="12" stroke="currentColor" stroke-width="2"/></svg></button>
<button data-int="MED" id="btnMed" title="Medium"><svg viewBox="0 0 24 24" width="18" height="18"><circle cx="12" cy="12" r="4" fill="currentColor"/><line x1="12" y1="1" x2="12" y2="5" stroke="currentColor" stroke-width="2"/><line x1="12" y1="19" x2="12" y2="23" stroke="currentColor" stroke-width="2"/><line x1="1" y1="12" x2="5" y2="12" stroke="currentColor" stroke-width="2"/><line x1="19" y1="12" x2="23" y2="12" stroke="currentColor" stroke-width="2"/><line x1="4.22" y1="4.22" x2="6.64" y2="6.64" stroke="currentColor" stroke-width="2"/><line x1="17.36" y1="17.36" x2="19.78" y2="19.78" stroke="currentColor" stroke-width="2"/><line x1="4.22" y1="19.78" x2="6.64" y2="17.36" stroke="currentColor" stroke-width="2"/><line x1="17.36" y1="6.64" x2="19.78" y2="4.22" stroke="currentColor" stroke-width="2"/></svg></button>
<button data-int="HIGH" id="btnHi" title="High"><svg viewBox="0 0 24 24" width="18" height="18"><circle cx="12" cy="12" r="5" fill="currentColor"/><line x1="12" y1="0" x2="12" y2="5" stroke="currentColor" stroke-width="2.5"/><line x1="12" y1="19" x2="12" y2="24" stroke="currentColor" stroke-width="2.5"/><line x1="0" y1="12" x2="5" y2="12" stroke="currentColor" stroke-width="2.5"/><line x1="19" y1="12" x2="24" y2="12" stroke="currentColor" stroke-width="2.5"/><line x1="3.5" y1="3.5" x2="6.64" y2="6.64" stroke="currentColor" stroke-width="2.5"/><line x1="17.36" y1="17.36" x2="20.5" y2="20.5" stroke="currentColor" stroke-width="2.5"/><line x1="3.5" y1="20.5" x2="6.64" y2="17.36" stroke="currentColor" stroke-width="2.5"/><line x1="17.36" y1="6.64" x2="20.5" y2="3.5" stroke="currentColor" stroke-width="2.5"/></svg></button>
</div>
</div>
</div>
<div class="row-2">
<div class="card" id="colorCard">
<h3 id="lblColor">Color</h3>
<div class="color-row" id="colorGroup">
<div class="color red" data-color="RED"></div>
<div class="color green" data-color="GREEN"></div>
<div class="color blue" data-color="BLUE"></div>
<div class="color custom" data-color="CUSTOM" id="customSwatch"></div>
</div>
<div class="color-picker-wrap" id="pickerWrap">
<canvas id="wheelCanvas" width="80" height="80"></canvas>
</div>
</div>
<div class="card" id="dazzleCard">
<h3 id="lblDazzle">Dazzle</h3>
<div class="dazzle-row">
<label class="switch"><input type="checkbox" id="dazzle"><span class="slider"></span></label>
</div>
</div>
</div>
<div class="card">
<div class="wpm-row">
<span class="wpm-icon">🐢</span>
<div class="wpm-slider">
<input type="range" id="wpm" min="5" max="20" step="5" value="10">
</div>
<span class="wpm-icon">🐇</span>
</div>
<div class="wpm-val" style="text-align:center;margin-top:8px"><span id="wpmDisplay">10</span> <small>WPM</small></div>
</div>
</div>
<div class="footer"><a href="/help" class="help-btn">?</a><span class="footer-text" id="footerText">1984 was not an instruction manual</span><button class="settings-btn" id="settingsBtn">⚙</button></div>
<div class="version" id="version"></div>
</div>
<!-- OTA Modal -->
<div class="ota-modal" id="otaModal">
<div class="ota-card">
<h3 id="otaTitle">Firmware Update</h3>
<div class="ota-version"><span id="otaCurrent">Current</span>: v<span id="otaVersion">-</span></div>
<input type="file" id="otaFile" accept=".bin" style="position:absolute;opacity:0;width:1px;height:1px">
<label for="otaFile" class="ota-btn" id="otaChooseLabel" style="display:block;text-align:center;background:#333;color:#fff;margin-bottom:14px;cursor:pointer">Choose .bin File</label>
<div id="otaFileName" style="text-align:center;font-size:12px;color:#888;margin-bottom:14px">No file selected</div>
<button class="ota-btn" id="otaGetCode" style="background:#1a5f2a;margin-bottom:10px">Get Code</button>
<div id="otaCodeSection" style="display:none;margin-bottom:14px">
<div style="color:#8AB4F8;margin-bottom:8px;text-align:center;font-size:13px">Enter LED code:</div>
<div style="display:flex;gap:8px;justify-content:center">
<input type="number" id="otaD1" min="1" max="9" style="width:45px;height:45px;text-align:center;font-size:22px;border-radius:6px;border:2px solid #ff4444;background:#331111;color:#ff6666">
<input type="number" id="otaD2" min="1" max="9" style="width:45px;height:45px;text-align:center;font-size:22px;border-radius:6px;border:2px solid #44ff44;background:#113311;color:#66ff66">
<input type="number" id="otaD3" min="1" max="9" style="width:45px;height:45px;text-align:center;font-size:22px;border-radius:6px;border:2px solid #4444ff;background:#111133;color:#6666ff">
<input type="number" id="otaD4" min="1" max="9" style="width:45px;height:45px;text-align:center;font-size:22px;border-radius:6px;border:2px solid #ffff44;background:#333311;color:#ffff66">
</div>
<div style="color:#888;font-size:11px;margin-top:6px;text-align:center">Watch LED: Red, Green, Blue, Yellow blinks</div>
</div>
<button class="ota-btn" id="otaUpload">Upload Firmware</button>
<progress class="ota-progress" id="otaProgress" value="0" max="100"></progress>
<div class="ota-status" id="otaStatus"></div>
<div class="settings-lang">
<h4 id="lblLanguage">Language</h4>
<select id="langSelect"></select>
</div>
<button class="ota-btn" id="otaClose" style="margin-top:12px;background:#333;color:#fff">Close</button>
</div>
</div>
<!-- Android Browser Dialog -->
<div class="ota-modal" id="androidDialog">
<div class="ota-card">
<h3 id="androidTitle">Open in Browser</h3>
<p id="androidDesc" style="font-size:13px;color:#ccc;text-align:center;margin-bottom:16px">Android requires a full browser for firmware updates. Copy the link and open it in Chrome.</p>
<button class="ota-btn" id="copyLinkBtn">Copy Link</button>
<div id="copyStatus" style="text-align:center;font-size:12px;color:#888;margin-top:8px"></div>
<button class="ota-btn" id="androidClose" style="margin-top:12px;background:#333;color:#fff">Close</button>
</div>
</div>
<script>
const SPLASH_KEY = 'signet_splash_seen';
const LANG_KEY = 'signet_lang';
const MORSE={A:'.-',B:'-...',C:'-.-.',D:'-..',E:'.',F:'..-.',G:'--.',H:'....',I:'..',J:'.---',K:'-.-',L:'.-..',M:'--',N:'-.',O:'---',P:'.--.',Q:'--.-',R:'.-.',S:'...',T:'-',U:'..-',V:'...-',W:'.--',X:'-..-',Y:'-.--',Z:'--..',0:'-----',1:'.----',2:'..---',3:'...--',4:'....-',5:'.....',6:'-....',7:'--...',8:'---..',9:'----.','.':'.-.-.-',',':'--..--','?':'..--..','/':'-..-.','-':'-....-','(':'-.--.',')':'-.--.-','@':'.--.-.','=':'-...-'};
const PROSIGNS={KA:'-.-.-',AR:'.-.-.'};
// Translations for all supported languages
const LANG = {
en: { name:'English', native:'English', dir:'ltr',
splash:'Click anywhere to send him a message...',
message:'Message', maxChars:'(MAX 200 Characters)', hint:'A-Z 0-9 . , ? / - ( ) @ = space <KA> <AR>',
idle:'Idle', playing:'Playing\u2026',
mode:'Mode', intensity:'Intensity', color:'Color', dazzle:'Dazzle',
footer:'1984 was not an instruction manual', firmware:'Firmware',
fwUpdate:'Firmware Update', current:'Current', chooseBin:'Choose .bin File', noFile:'No file selected',
uploadFw:'Upload Firmware', uploading:'Uploading...', success:'Success! Rebooting...', updateFailed:'Update failed',
netError:'Network error', selectBin:'Select a .bin file', errBin:'Error: Select a .bin file',
openBrowser:'Open in Browser', androidDesc:'Android requires a full browser for firmware updates. Copy the link and open it in Chrome.',
copyLink:'Copy Link', copied:'Copied! Open Chrome and paste.', copyFailed:'Copy failed. Type: 192.168.4.1', close:'Close',
language:'Language', selectLang:'Select Language', chooseLang:'Choose your preferred language', continue:'Continue'
},
es: { name:'Spanish', native:'Espa\u00F1ol', dir:'ltr',
splash:'Haz clic en cualquier lugar para enviarle un mensaje...',
message:'Mensaje', maxChars:'(M\u00C1X 200 Caracteres)', hint:'A-Z 0-9 . , ? / - ( ) @ = espacio <KA> <AR>',
idle:'Inactivo', playing:'Reproduciendo\u2026',
mode:'Modo', intensity:'Intensidad', color:'Color', dazzle:'Destello',
footer:'1984 no era un manual de instrucciones', firmware:'Firmware',
fwUpdate:'Actualizar Firmware', current:'Actual', chooseBin:'Elegir archivo .bin', noFile:'Ning\u00FAn archivo seleccionado',
uploadFw:'Subir Firmware', uploading:'Subiendo...', success:'\u00A1\u00C9xito! Reiniciando...', updateFailed:'Actualizaci\u00F3n fallida',
netError:'Error de red', selectBin:'Selecciona un archivo .bin', errBin:'Error: Selecciona un archivo .bin',
openBrowser:'Abrir en Navegador', androidDesc:'Android requiere un navegador completo para actualizaciones. Copia el enlace y \u00E1brelo en Chrome.',
copyLink:'Copiar Enlace', copied:'\u00A1Copiado! Abre Chrome y pega.', copyFailed:'Copia fallida. Escribe: 192.168.4.1', close:'Cerrar',
language:'Idioma', selectLang:'Seleccionar Idioma', chooseLang:'Elige tu idioma preferido', continue:'Continuar'
},
fr: { name:'French', native:'Fran\u00E7ais', dir:'ltr',
splash:'Cliquez n\'importe o\u00F9 pour lui envoyer un message...',
message:'Message', maxChars:'(MAX 200 Caract\u00E8res)', hint:'A-Z 0-9 . , ? / - ( ) @ = espace <KA> <AR>',
idle:'Inactif', playing:'Lecture\u2026',
mode:'Mode', intensity:'Intensit\u00E9', color:'Couleur', dazzle:'\u00C9blouir',
footer:'1984 n\'\u00E9tait pas un manuel d\'instructions', firmware:'Firmware',
fwUpdate:'Mise \u00E0 jour Firmware', current:'Actuel', chooseBin:'Choisir fichier .bin', noFile:'Aucun fichier s\u00E9lectionn\u00E9',
uploadFw:'T\u00E9l\u00E9verser Firmware', uploading:'T\u00E9l\u00E9versement...', success:'Succ\u00E8s! Red\u00E9marrage...', updateFailed:'\u00C9chec de mise \u00E0 jour',
netError:'Erreur r\u00E9seau', selectBin:'S\u00E9lectionnez un fichier .bin', errBin:'Erreur: S\u00E9lectionnez un fichier .bin',
openBrowser:'Ouvrir dans Navigateur', androidDesc:'Android n\u00E9cessite un navigateur complet pour les mises \u00E0 jour. Copiez le lien et ouvrez-le dans Chrome.',
copyLink:'Copier Lien', copied:'Copi\u00E9! Ouvrez Chrome et collez.', copyFailed:'\u00C9chec de copie. Tapez: 192.168.4.1', close:'Fermer',
language:'Langue', selectLang:'S\u00E9lectionner Langue', chooseLang:'Choisissez votre langue pr\u00E9f\u00E9r\u00E9e', continue:'Continuer'
},
ru: { name:'Russian', native:'\u0420\u0443\u0441\u0441\u043A\u0438\u0439', dir:'ltr',
splash:'\u041D\u0430\u0436\u043C\u0438\u0442\u0435 \u0432 \u043B\u044E\u0431\u043E\u043C \u043C\u0435\u0441\u0442\u0435, \u0447\u0442\u043E\u0431\u044B \u043E\u0442\u043F\u0440\u0430\u0432\u0438\u0442\u044C \u0435\u043C\u0443 \u0441\u043E\u043E\u0431\u0449\u0435\u043D\u0438\u0435...',
message:'\u0421\u043E\u043E\u0431\u0449\u0435\u043D\u0438\u0435', maxChars:'(\u041C\u0410\u041A\u0421 200 \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432)', hint:'A-Z 0-9 . , ? / - ( ) @ = \u043F\u0440\u043E\u0431\u0435\u043B <KA> <AR>',
idle:'\u041E\u0436\u0438\u0434\u0430\u043D\u0438\u0435', playing:'\u0412\u043E\u0441\u043F\u0440\u043E\u0438\u0437\u0432\u0435\u0434\u0435\u043D\u0438\u0435\u2026',
mode:'\u0420\u0435\u0436\u0438\u043C', intensity:'\u0418\u043D\u0442\u0435\u043D\u0441.', color:'\u0426\u0432\u0435\u0442', dazzle:'\u0412\u0441\u043F\u044B\u0448\u043A\u0430',
footer:'1984 \u043D\u0435 \u0431\u044B\u043B \u0438\u043D\u0441\u0442\u0440\u0443\u043A\u0446\u0438\u0435\u0439', firmware:'\u041F\u0440\u043E\u0448\u0438\u0432\u043A\u0430',
fwUpdate:'\u041E\u0431\u043D\u043E\u0432\u043B\u0435\u043D\u0438\u0435 \u043F\u0440\u043E\u0448\u0438\u0432\u043A\u0438', current:'\u0422\u0435\u043A\u0443\u0449\u0430\u044F', chooseBin:'\u0412\u044B\u0431\u0440\u0430\u0442\u044C .bin', noFile:'\u0424\u0430\u0439\u043B \u043D\u0435 \u0432\u044B\u0431\u0440\u0430\u043D',
uploadFw:'\u0417\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044C', uploading:'\u0417\u0430\u0433\u0440\u0443\u0437\u043A\u0430...', success:'\u0423\u0441\u043F\u0435\u0445! \u041F\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u043A\u0430...', updateFailed:'\u041E\u0448\u0438\u0431\u043A\u0430 \u043E\u0431\u043D\u043E\u0432\u043B\u0435\u043D\u0438\u044F',
netError:'\u041E\u0448\u0438\u0431\u043A\u0430 \u0441\u0435\u0442\u0438', selectBin:'\u0412\u044B\u0431\u0435\u0440\u0438\u0442\u0435 .bin', errBin:'\u041E\u0448\u0438\u0431\u043A\u0430: \u0412\u044B\u0431\u0435\u0440\u0438\u0442\u0435 .bin',
openBrowser:'\u041E\u0442\u043A\u0440\u044B\u0442\u044C \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435', androidDesc:'Android \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043F\u043E\u043B\u043D\u044B\u0439 \u0431\u0440\u0430\u0443\u0437\u0435\u0440. \u0421\u043A\u043E\u043F\u0438\u0440\u0443\u0439\u0442\u0435 \u0441\u0441\u044B\u043B\u043A\u0443 \u0438 \u043E\u0442\u043A\u0440\u043E\u0439\u0442\u0435 \u0432 Chrome.',
copyLink:'\u041A\u043E\u043F\u0438\u0440\u043E\u0432\u0430\u0442\u044C', copied:'\u0421\u043A\u043E\u043F\u0438\u0440\u043E\u0432\u0430\u043D\u043E! \u041E\u0442\u043A\u0440\u043E\u0439\u0442\u0435 Chrome.', copyFailed:'\u041E\u0448\u0438\u0431\u043A\u0430. \u0412\u0432\u0435\u0434\u0438\u0442\u0435: 192.168.4.1', close:'\u0417\u0430\u043A\u0440\u044B\u0442\u044C',
language:'\u042F\u0437\u044B\u043A', selectLang:'\u0412\u044B\u0431\u0440\u0430\u0442\u044C \u044F\u0437\u044B\u043A', chooseLang:'\u0412\u044B\u0431\u0435\u0440\u0438\u0442\u0435 \u043F\u0440\u0435\u0434\u043F\u043E\u0447\u0438\u0442\u0430\u0435\u043C\u044B\u0439 \u044F\u0437\u044B\u043A', continue:'\u041F\u0440\u043E\u0434\u043E\u043B\u0436\u0438\u0442\u044C'
},
'zh-CN': { name:'Simplified Chinese', native:'\u7B80\u4F53\u4E2D\u6587', dir:'ltr',
splash:'\u70B9\u51FB\u4EFB\u610F\u4F4D\u7F6E\u7ED9\u4ED6\u53D1\u9001\u6D88\u606F...',
message:'\u6D88\u606F', maxChars:'(\u6700\u591A200\u5B57\u7B26)', hint:'A-Z 0-9 . , ? / - ( ) @ = \u7A7A\u683C <KA> <AR>',
idle:'\u7A7A\u95F2', playing:'\u64AD\u653E\u4E2D\u2026',
mode:'\u6A21\u5F0F', intensity:'\u5F3A\u5EA6', color:'\u989C\u8272', dazzle:'\u95EA\u70C1',
footer:'1984\u4E0D\u662F\u64CD\u4F5C\u624B\u518C', firmware:'\u56FA\u4EF6',
fwUpdate:'\u56FA\u4EF6\u66F4\u65B0', current:'\u5F53\u524D', chooseBin:'\u9009\u62E9.bin\u6587\u4EF6', noFile:'\u672A\u9009\u62E9\u6587\u4EF6',
uploadFw:'\u4E0A\u4F20\u56FA\u4EF6', uploading:'\u4E0A\u4F20\u4E2D...', success:'\u6210\u529F\uFF01\u91CD\u542F\u4E2D...', updateFailed:'\u66F4\u65B0\u5931\u8D25',
netError:'\u7F51\u7EDC\u9519\u8BEF', selectBin:'\u8BF7\u9009\u62E9.bin\u6587\u4EF6', errBin:'\u9519\u8BEF\uFF1A\u8BF7\u9009\u62E9.bin\u6587\u4EF6',
openBrowser:'\u5728\u6D4F\u89C8\u5668\u4E2D\u6253\u5F00', androidDesc:'Android\u9700\u8981\u5B8C\u6574\u6D4F\u89C8\u5668\u8FDB\u884C\u56FA\u4EF6\u66F4\u65B0\u3002\u590D\u5236\u94FE\u63A5\u5E76\u5728Chrome\u4E2D\u6253\u5F00\u3002',
copyLink:'\u590D\u5236\u94FE\u63A5', copied:'\u5DF2\u590D\u5236\uFF01\u5728Chrome\u4E2D\u7C98\u8D34\u3002', copyFailed:'\u590D\u5236\u5931\u8D25\u3002\u8F93\u5165\uFF1A192.168.4.1', close:'\u5173\u95ED',
language:'\u8BED\u8A00', selectLang:'\u9009\u62E9\u8BED\u8A00', chooseLang:'\u9009\u62E9\u60A8\u7684\u9996\u9009\u8BED\u8A00', continue:'\u7EE7\u7EED'
},
'zh-TW': { name:'Traditional Chinese', native:'\u7E41\u9AD4\u4E2D\u6587', dir:'ltr',
splash:'\u9EDE\u64CA\u4EFB\u610F\u4F4D\u7F6E\u7D66\u4ED6\u767C\u9001\u8A0A\u606F...',
message:'\u8A0A\u606F', maxChars:'(\u6700\u591A200\u5B57\u5143)', hint:'A-Z 0-9 . , ? / - ( ) @ = \u7A7A\u683C <KA> <AR>',
idle:'\u9592\u7F6E', playing:'\u64AD\u653E\u4E2D\u2026',
mode:'\u6A21\u5F0F', intensity:'\u5F37\u5EA6', color:'\u984F\u8272', dazzle:'\u9583\u720D',
footer:'1984\u4E0D\u662F\u64CD\u4F5C\u624B\u518A', firmware:'\u97CC\u9AD4',
fwUpdate:'\u97CC\u9AD4\u66F4\u65B0', current:'\u76EE\u524D', chooseBin:'\u9078\u64C7.bin\u6A94\u6848', noFile:'\u672A\u9078\u64C7\u6A94\u6848',
uploadFw:'\u4E0A\u50B3\u97CC\u9AD4', uploading:'\u4E0A\u50B3\u4E2D...', success:'\u6210\u529F\uFF01\u91CD\u555F\u4E2D...', updateFailed:'\u66F4\u65B0\u5931\u6557',
netError:'\u7DB2\u8DEF\u932F\u8AA4', selectBin:'\u8ACB\u9078\u64C7.bin\u6A94\u6848', errBin:'\u932F\u8AA4\uFF1A\u8ACB\u9078\u64C7.bin\u6A94\u6848',
openBrowser:'\u5728\u700F\u89BD\u5668\u4E2D\u958B\u555F', androidDesc:'Android\u9700\u8981\u5B8C\u6574\u700F\u89BD\u5668\u9032\u884C\u97CC\u9AD4\u66F4\u65B0\u3002\u8907\u88FD\u9023\u7D50\u4E26\u5728Chrome\u4E2D\u958B\u555F\u3002',
copyLink:'\u8907\u88FD\u9023\u7D50', copied:'\u5DF2\u8907\u88FD\uFF01\u5728Chrome\u4E2D\u8CBB\u4E0A\u3002', copyFailed:'\u8907\u88FD\u5931\u6557\u3002\u8F38\u5165\uFF1A192.168.4.1', close:'\u95DC\u9589',
language:'\u8A9E\u8A00', selectLang:'\u9078\u64C7\u8A9E\u8A00', chooseLang:'\u9078\u64C7\u60A8\u7684\u9996\u9078\u8A9E\u8A00', continue:'\u7E7C\u7E8C'
},
fa: { name:'Farsi', native:'\u0641\u0627\u0631\u0633\u06CC', dir:'rtl',
splash:'\u0628\u0631\u0627\u06CC \u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u0628\u0647 \u0627\u0648\u060C \u0647\u0631 \u062C\u0627\u06CC\u06CC \u06A9\u0644\u06CC\u06A9 \u06A9\u0646\u06CC\u062F...',
message:'\u067E\u06CC\u0627\u0645', maxChars:'(\u062D\u062F\u0627\u06A9\u062B\u0631 \u06F2\u06F0\u06F0 \u06A9\u0627\u0631\u0627\u06A9\u062A\u0631)', hint:'A-Z 0-9 . , ? / - ( ) @ = \u0641\u0627\u0635\u0644\u0647 <KA> <AR>',
idle:'\u0622\u0645\u0627\u062F\u0647', playing:'\u062F\u0631 \u062D\u0627\u0644 \u067E\u062E\u0634\u2026',
mode:'\u062D\u0627\u0644\u062A', intensity:'\u0634\u062F\u062A', color:'\u0631\u0646\u06AF', dazzle:'\u062F\u0631\u062E\u0634\u0634',
footer:'\u06F1\u06F9\u06F8\u06F4 \u06CC\u06A9 \u06A9\u062A\u0627\u0628 \u0631\u0627\u0647\u0646\u0645\u0627 \u0646\u0628\u0648\u062F', firmware:'\u0641\u0631\u06CC\u0645\u0648\u0631',
fwUpdate:'\u0628\u0631\u0648\u0632\u0631\u0633\u0627\u0646\u06CC \u0641\u0631\u06CC\u0645\u0648\u0631', current:'\u0641\u0639\u0644\u06CC', chooseBin:'\u0627\u0646\u062A\u062E\u0627\u0628 \u0641\u0627\u06CC\u0644 .bin', noFile:'\u0641\u0627\u06CC\u0644\u06CC \u0627\u0646\u062A\u062E\u0627\u0628 \u0646\u0634\u062F\u0647',
uploadFw:'\u0628\u0627\u0631\u06AF\u0630\u0627\u0631\u06CC', uploading:'\u062F\u0631 \u062D\u0627\u0644 \u0628\u0627\u0631\u06AF\u0630\u0627\u0631\u06CC...', success:'\u0645\u0648\u0641\u0642! \u0631\u0627\u0647\u200C\u0627\u0646\u062F\u0627\u0632\u06CC \u0645\u062C\u062F\u062F...', updateFailed:'\u0628\u0631\u0648\u0632\u0631\u0633\u0627\u0646\u06CC \u0646\u0627\u0645\u0648\u0641\u0642',
netError:'\u062E\u0637\u0627\u06CC \u0634\u0628\u06A9\u0647', selectBin:'\u06CC\u06A9 \u0641\u0627\u06CC\u0644 .bin \u0627\u0646\u062A\u062E\u0627\u0628 \u06A9\u0646\u06CC\u062F', errBin:'\u062E\u0637\u0627: \u0641\u0627\u06CC\u0644 .bin \u0627\u0646\u062A\u062E\u0627\u0628 \u06A9\u0646\u06CC\u062F',
openBrowser:'\u0628\u0627\u0632 \u06A9\u0631\u062F\u0646 \u062F\u0631 \u0645\u0631\u0648\u0631\u06AF\u0631', androidDesc:'\u0627\u0646\u062F\u0631\u0648\u06CC\u062F \u0628\u0647 \u0645\u0631\u0648\u0631\u06AF\u0631 \u06A9\u0627\u0645\u0644 \u0646\u06CC\u0627\u0632 \u062F\u0627\u0631\u062F. \u0644\u06CC\u0646\u06A9 \u0631\u0627 \u06A9\u067E\u06CC \u06A9\u0646\u06CC\u062F \u0648 \u062F\u0631 Chrome \u0628\u0627\u0632 \u06A9\u0646\u06CC\u062F.',
copyLink:'\u06A9\u067E\u06CC \u0644\u06CC\u0646\u06A9', copied:'\u06A9\u067E\u06CC \u0634\u062F! Chrome \u0631\u0627 \u0628\u0627\u0632 \u06A9\u0646\u06CC\u062F.', copyFailed:'\u06A9\u067E\u06CC \u0646\u0634\u062F. \u062A\u0627\u06CC\u067E \u06A9\u0646\u06CC\u062F: 192.168.4.1', close:'\u0628\u0633\u062A\u0646',
language:'\u0632\u0628\u0627\u0646', selectLang:'\u0627\u0646\u062A\u062E\u0627\u0628 \u0632\u0628\u0627\u0646', chooseLang:'\u0632\u0628\u0627\u0646 \u0645\u0648\u0631\u062F \u0646\u0638\u0631 \u062E\u0648\u062F \u0631\u0627 \u0627\u0646\u062A\u062E\u0627\u0628 \u06A9\u0646\u06CC\u062F', continue:'\u0627\u062F\u0627\u0645\u0647'
},
ar: { name:'Arabic', native:'\u0627\u0644\u0639\u0631\u0628\u064A\u0629', dir:'rtl',
splash:'\u0627\u0646\u0642\u0631 \u0641\u064A \u0623\u064A \u0645\u0643\u0627\u0646 \u0644\u0625\u0631\u0633\u0627\u0644 \u0631\u0633\u0627\u0644\u0629 \u0625\u0644\u064A\u0647...',
message:'\u0631\u0633\u0627\u0644\u0629', maxChars:'(\u0623\u0642\u0635\u0649 \u0662\u0660\u0660 \u062D\u0631\u0641)', hint:'A-Z 0-9 . , ? / - ( ) @ = \u0645\u0633\u0627\u0641\u0629 <KA> <AR>',
idle:'\u062E\u0627\u0645\u0644', playing:'\u062C\u0627\u0631\u064A \u0627\u0644\u062A\u0634\u063A\u064A\u0644\u2026',
mode:'\u0627\u0644\u0648\u0636\u0639', intensity:'\u0627\u0644\u0634\u062F\u0629', color:'\u0627\u0644\u0644\u0648\u0646', dazzle:'\u0648\u0645\u064A\u0636',
footer:'\u0661\u0669\u0668\u0664 \u0644\u0645 \u064A\u0643\u0646 \u062F\u0644\u064A\u0644 \u062A\u0639\u0644\u064A\u0645\u0627\u062A', firmware:'\u0628\u0631\u0646\u0627\u0645\u062C \u062B\u0627\u0628\u062A',
fwUpdate:'\u062A\u062D\u062F\u064A\u062B \u0627\u0644\u0628\u0631\u0646\u0627\u0645\u062C', current:'\u0627\u0644\u062D\u0627\u0644\u064A', chooseBin:'\u0627\u062E\u062A\u0631 \u0645\u0644\u0641 .bin', noFile:'\u0644\u0645 \u064A\u062A\u0645 \u0627\u062E\u062A\u064A\u0627\u0631 \u0645\u0644\u0641',
uploadFw:'\u0631\u0641\u0639 \u0627\u0644\u0628\u0631\u0646\u0627\u0645\u062C', uploading:'\u062C\u0627\u0631\u064A \u0627\u0644\u0631\u0641\u0639...', success:'\u0646\u062C\u0627\u062D! \u0625\u0639\u0627\u062F\u0629 \u0627\u0644\u062A\u0634\u063A\u064A\u0644...', updateFailed:'\u0641\u0634\u0644 \u0627\u0644\u062A\u062D\u062F\u064A\u062B',
netError:'\u062E\u0637\u0623 \u0641\u064A \u0627\u0644\u0634\u0628\u0643\u0629', selectBin:'\u0627\u062E\u062A\u0631 \u0645\u0644\u0641 .bin', errBin:'\u062E\u0637\u0623: \u0627\u062E\u062A\u0631 \u0645\u0644\u0641 .bin',
openBrowser:'\u0641\u062A\u062D \u0641\u064A \u0627\u0644\u0645\u062A\u0635\u0641\u062D', androidDesc:'\u064A\u062A\u0637\u0644\u0628 \u0623\u0646\u062F\u0631\u0648\u064A\u062F \u0645\u062A\u0635\u0641\u062D\u0627\u064B \u0643\u0627\u0645\u0644\u0627\u064B. \u0627\u0646\u0633\u062E \u0627\u0644\u0631\u0627\u0628\u0637 \u0648\u0627\u0641\u062A\u062D\u0647 \u0641\u064A Chrome.',
copyLink:'\u0646\u0633\u062E \u0627\u0644\u0631\u0627\u0628\u0637', copied:'\u062A\u0645 \u0627\u0644\u0646\u0633\u062E! \u0627\u0641\u062A\u062D Chrome.', copyFailed:'\u0641\u0634\u0644 \u0627\u0644\u0646\u0633\u062E. \u0627\u0643\u062A\u0628: 192.168.4.1', close:'\u0625\u063A\u0644\u0627\u0642',
language:'\u0627\u0644\u0644\u063A\u0629', selectLang:'\u0627\u062E\u062A\u064A\u0627\u0631 \u0627\u0644\u0644\u063A\u0629', chooseLang:'\u0627\u062E\u062A\u0631 \u0644\u063A\u062A\u0643 \u0627\u0644\u0645\u0641\u0636\u0644\u0629', continue:'\u0645\u062A\u0627\u0628\u0639\u0629'
}
};
const LANG_ORDER = ['en','es','fr','ru','zh-CN','zh-TW','fa','ar'];
let currentLang = 'en';
function applyLanguage(code) {
const L = LANG[code];
if (!L) return;
currentLang = code;
document.documentElement.lang = code;
document.documentElement.dir = L.dir;
// Splash
const splashText = document.getElementById('splashText');
if (splashText) splashText.textContent = L.splash;
// Main UI
const setText = (id, text) => { const el = document.getElementById(id); if (el) el.textContent = text; };
setText('lblMessage', L.message);
setText('lblMaxChars', L.maxChars);
setText('lblHint', L.hint);
setText('lblMode', L.mode);
setText('lblIntensity', L.intensity);
setText('lblColor', L.color);
setText('lblDazzle', L.dazzle);
setText('footerText', L.footer);
// OTA Modal
setText('otaTitle', L.fwUpdate);
setText('otaCurrent', L.current);
setText('otaChooseLabel', L.chooseBin);
setText('otaUpload', L.uploadFw);