36
36
#define SMALL_TEXT 2
37
37
#define TINY_TEXT 1
38
38
// -=-=- FEATURES -=-=-
39
- #define M5LED
39
+ #define M5LED 10
40
40
#define RTC
41
41
#define AXP
42
42
#define ACTIVE_LOW_IR
65
65
#define SMALL_TEXT 2
66
66
#define TINY_TEXT 1
67
67
// -=-=- FEATURES -=-=-
68
- // #define ACTIVE_LOW_IR
69
- #define M5LED
68
+ #define ACTIVE_LOW_IR
69
+ #define M5LED 19
70
70
#define ROTATION
71
71
#define USE_EEPROM
72
- // #define RTC //TODO: plus2 has a BM8563 RTC but the class isn't the same, needs work.
72
+ #define RTC // TODO: plus2 has a BM8563 RTC but the class isn't the same, needs work.
73
73
// #define SDCARD //Requires a custom-built adapter
74
74
#define PWRMGMT
75
75
// -=-=- ALIASES -=-=-
79
79
#define M5_BUTTON_MENU 35
80
80
#define M5_BUTTON_HOME 37
81
81
#define M5_BUTTON_RST 39
82
- // TODO: Figure out screen brightness on PLUS2 (if possible at all?) without AXP.
83
- #define BACKLIGHT 27 // best I can tell from the schematics?
82
+ # define BACKLIGHT 27
83
+ #define MINBRIGHT 190
84
84
#define SD_CLK_PIN 0
85
85
#define SD_MISO_PIN 36
86
86
#define SD_MOSI_PIN 26
97
97
#define SMALL_TEXT 1
98
98
#define TINY_TEXT 1
99
99
// -=-=- FEATURES -=-=-
100
- #define M5LED
100
+ #define M5LED 10
101
101
#define RTC
102
102
#define AXP
103
103
#define ROTATION
132
132
#define DISP M5Cardputer.Display
133
133
#define IRLED 44
134
134
#define BACKLIGHT 38
135
+ #define MINBRIGHT 165
135
136
#define SPEAKER M5Cardputer.Speaker
136
137
#define BITMAP M5Cardputer.Display.drawBmp(NEMOMatrix, 97338 )
137
138
#define SD_CLK_PIN 40
138
139
#define SD_MISO_PIN 39
139
140
#define SD_MOSI_PIN 14
140
141
#define SD_CS_PIN 12
141
142
#define VBAT_PIN 10
143
+ #define M5LED_ON LOW
144
+ #define M5LED_OFF HIGH
142
145
#endif
143
146
144
147
// -=-=-=-=-=- LIST OF CURRENTLY DEFINED FEATURES -=-=-=-=-=-
145
- // M5LED - An LED exposed as IRLED
148
+ // M5LED - A visible LED (Red) exposed on this pin number
149
+ // IRLED - An IR LED exposed on this pin number
146
150
// RTC - Real-time clock exposed as M5.Rtc
147
151
// AXP - AXP192 Power Management exposed as M5.Axp
148
152
// PWRMGMT - StickC+2 Power Management exposed as M5.Power
154
158
// SDCARD - Device has an SD Card Reader attached
155
159
// SONG - Play melody or beep on startup
156
160
// SPEAKER - Aliased to the prefix used for making noise
161
+ // BACKLIGHT - Alias to the pin used for the backlight on some models
162
+ // MINBRIGHT - The lowest number (0-255) for the backlight to show through
157
163
158
164
// / SWITCHER ///
159
165
// Proc codes
@@ -405,11 +411,13 @@ int screen_dim_time = 30;
405
411
int screen_dim_current = 0 ;
406
412
407
413
void screenBrightness (int bright){
414
+ Serial.printf (" Brightness: %d\n " , bright);
408
415
#if defined(AXP)
409
416
M5.Axp .ScreenBreath (bright);
410
417
#endif
411
418
#if defined(BACKLIGHT)
412
- analogWrite (BACKLIGHT, 205 + (bright/2 ));
419
+ int bl = MINBRIGHT + round (((255 - MINBRIGHT) * bright / 100 ));
420
+ analogWrite (BACKLIGHT, bl);
413
421
#endif
414
422
}
415
423
@@ -429,7 +437,7 @@ void screen_dim_proc() {
429
437
if (screen_dim_time > 0 ){
430
438
if (screen_dim_dimmed == false ) {
431
439
if (uptime () == screen_dim_current || (uptime () + 1 ) == screen_dim_current || (uptime () + 2 ) == screen_dim_current) {
432
- screenBrightness (10 );
440
+ screenBrightness (0 );
433
441
screen_dim_dimmed = true ;
434
442
}
435
443
}
@@ -748,7 +756,7 @@ void tvbgone_setup() {
748
756
DISP.setTextSize (SMALL_TEXT);
749
757
irsend.begin ();
750
758
// Hack: Set IRLED high to turn it off after setup. Otherwise it stays on (active low)
751
- digitalWrite (IRLED, HIGH );
759
+ digitalWrite (IRLED, M5LED_OFF );
752
760
753
761
delay_ten_us (5000 );
754
762
if (region == NA) {
@@ -861,10 +869,7 @@ void sendAllCodes() {
861
869
rawData[(k * 2 ) + 1 ] = ontime * 10 ;
862
870
}
863
871
irsend.sendRaw (rawData, (numpairs * 2 ) , freq);
864
- #if defined(ACTIVE_LOW_IR)
865
- // Set Active Low IRLED high to turn it off after each burst.
866
- digitalWrite (IRLED, HIGH);
867
- #endif
872
+ digitalWrite (IRLED, M5LED_OFF);
868
873
bitsleft_r = 0 ;
869
874
delay_ten_us (20500 );
870
875
#if defined(AXP)
@@ -910,9 +915,14 @@ void sendAllCodes() {
910
915
}
911
916
912
917
void clock_loop () {
913
- M5.Rtc .GetBm8563Time ();
914
918
DISP.setCursor (40 , 40 , 2 );
915
- DISP.printf (" %02d:%02d:%02d\n " , M5.Rtc .Hour , M5.Rtc .Minute , M5.Rtc .Second );
919
+ #if defined(STICK_C_PLUS2)
920
+ auto dt = StickCP2.Rtc .getDateTime ();
921
+ DISP.printf (" %02d:%02d:%02d\n " , dt.time .hours , dt.time .minutes , dt.time .seconds );
922
+ #else
923
+ M5.Rtc .GetBm8563Time ();
924
+ DISP.printf (" %02d:%02d:%02d\n " , M5.Rtc .Hour , M5.Rtc .Minute , M5.Rtc .Second );
925
+ #endif
916
926
delay (250 );
917
927
}
918
928
@@ -926,8 +936,13 @@ void sendAllCodes() {
926
936
}
927
937
928
938
void timeset_loop () {
939
+ #if defined(STICK_C_PLUS2)
940
+ auto dt = StickCP2.Rtc .getDateTime ();
941
+ cursor = dt.time .hours ;
942
+ #else
929
943
M5.Rtc .GetBm8563Time ();
930
944
cursor = M5.Rtc .Hour ;
945
+ #endif
931
946
number_drawmenu (24 );
932
947
while (digitalRead (M5_BUTTON_HOME) == HIGH) {
933
948
if (check_next_press ()) {
@@ -942,7 +957,11 @@ void sendAllCodes() {
942
957
DISP.setCursor (0 , 5 , 1 );
943
958
DISP.println (TXT_SET_MIN);
944
959
delay (2000 );
945
- cursor = M5.Rtc .Minute ;
960
+ #if defined(STICK_C_PLUS2)
961
+ cursor = dt.time .minutes ;
962
+ #else
963
+ cursor = M5.Rtc .Minute ;
964
+ #endif
946
965
number_drawmenu (60 );
947
966
while (digitalRead (M5_BUTTON_HOME) == HIGH) {
948
967
if (check_next_press ()) {
@@ -955,11 +974,15 @@ void sendAllCodes() {
955
974
int minute = cursor;
956
975
DISP.fillScreen (BGCOLOR);
957
976
DISP.setCursor (0 , 5 , 1 );
958
- RTC_TimeTypeDef TimeStruct;
959
- TimeStruct.Hours = hour;
960
- TimeStruct.Minutes = minute;
961
- TimeStruct.Seconds = 0 ;
962
- M5.Rtc .SetTime (&TimeStruct);
977
+ #if defined(STICK_C_PLUS2)
978
+ StickCP2.Rtc .setDateTime ( { { dt.date .year , dt.date .month , dt.date .date }, { hour, minute, 0 } } );
979
+ #else
980
+ RTC_TimeTypeDef TimeStruct;
981
+ TimeStruct.Hours = hour;
982
+ TimeStruct.Minutes = minute;
983
+ TimeStruct.Seconds = 0 ;
984
+ M5.Rtc .SetTime (&TimeStruct);
985
+ #endif
963
986
DISP.printf (" Setting Time:\n %02d:%02d:00" ,hour,minute);
964
987
delay (2000 );
965
988
rstOverride = false ;
@@ -1336,9 +1359,9 @@ void aj_adv(){
1336
1359
pAdvertising->setAdvertisementData (oAdvertisementData);
1337
1360
pAdvertising->start ();
1338
1361
#if defined(M5LED)
1339
- digitalWrite (IRLED , M5LED_ON); // LED ON on Stick C Plus
1362
+ digitalWrite (M5LED , M5LED_ON); // LED ON on Stick C Plus
1340
1363
delay (10 );
1341
- digitalWrite (IRLED , M5LED_OFF); // LED OFF on Stick C Plus
1364
+ digitalWrite (M5LED , M5LED_OFF); // LED OFF on Stick C Plus
1342
1365
#endif
1343
1366
}
1344
1367
if (check_next_press ()) {
@@ -1452,9 +1475,9 @@ void wifispam_loop() {
1452
1475
int i = 0 ;
1453
1476
int len = 0 ;
1454
1477
#if defined(M5LED)
1455
- digitalWrite (IRLED , M5LED_ON); // LED ON on Stick C Plus
1478
+ digitalWrite (M5LED , M5LED_ON); // LED ON on Stick C Plus
1456
1479
delay (1 );
1457
- digitalWrite (IRLED , M5LED_OFF); // LED OFF on Stick C Plus
1480
+ digitalWrite (M5LED , M5LED_OFF); // LED OFF on Stick C Plus
1458
1481
#endif
1459
1482
currentTime = millis ();
1460
1483
if (currentTime - attackTime > 100 ) {
@@ -1804,9 +1827,11 @@ void setup() {
1804
1827
#if defined(CARDPUTER)
1805
1828
auto cfg = M5.config ();
1806
1829
M5Cardputer.begin (cfg, true );
1807
- pinMode (38 , OUTPUT); // Backlight analogWrite range ~150 - 255
1808
1830
#else
1809
1831
M5.begin ();
1832
+ #endif
1833
+ #if defined(BACKLIGHT)
1834
+ pinMode (BACKLIGHT, OUTPUT); // Backlight analogWrite range ~150 - 255
1810
1835
#endif
1811
1836
if (check_next_press ()){
1812
1837
clearSettings ();
@@ -1839,6 +1864,10 @@ void setup() {
1839
1864
1840
1865
// Pin setup
1841
1866
#if defined(M5LED)
1867
+ pinMode (M5LED, OUTPUT);
1868
+ digitalWrite (M5LED, M5LED_OFF); // LEDOFF
1869
+ #endif
1870
+ #if defined(IRLED)
1842
1871
pinMode (IRLED, OUTPUT);
1843
1872
digitalWrite (IRLED, M5LED_OFF); // LEDOFF
1844
1873
#endif
0 commit comments