Skip to content
This repository was archived by the owner on Aug 22, 2024. It is now read-only.

Commit 44f61be

Browse files
authored
Merge pull request #81 from n0xa/develop
Plus2/Cardputer improvements
2 parents 71acc06 + 61a3ad2 commit 44f61be

File tree

1 file changed

+57
-28
lines changed

1 file changed

+57
-28
lines changed

m5stick-nemo.ino

+57-28
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#define SMALL_TEXT 2
3737
#define TINY_TEXT 1
3838
// -=-=- FEATURES -=-=-
39-
#define M5LED
39+
#define M5LED 10
4040
#define RTC
4141
#define AXP
4242
#define ACTIVE_LOW_IR
@@ -65,11 +65,11 @@
6565
#define SMALL_TEXT 2
6666
#define TINY_TEXT 1
6767
// -=-=- FEATURES -=-=-
68-
//#define ACTIVE_LOW_IR
69-
#define M5LED
68+
#define ACTIVE_LOW_IR
69+
#define M5LED 19
7070
#define ROTATION
7171
#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.
7373
//#define SDCARD //Requires a custom-built adapter
7474
#define PWRMGMT
7575
// -=-=- ALIASES -=-=-
@@ -79,8 +79,8 @@
7979
#define M5_BUTTON_MENU 35
8080
#define M5_BUTTON_HOME 37
8181
#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
8484
#define SD_CLK_PIN 0
8585
#define SD_MISO_PIN 36
8686
#define SD_MOSI_PIN 26
@@ -97,7 +97,7 @@
9797
#define SMALL_TEXT 1
9898
#define TINY_TEXT 1
9999
// -=-=- FEATURES -=-=-
100-
#define M5LED
100+
#define M5LED 10
101101
#define RTC
102102
#define AXP
103103
#define ROTATION
@@ -132,17 +132,21 @@
132132
#define DISP M5Cardputer.Display
133133
#define IRLED 44
134134
#define BACKLIGHT 38
135+
#define MINBRIGHT 165
135136
#define SPEAKER M5Cardputer.Speaker
136137
#define BITMAP M5Cardputer.Display.drawBmp(NEMOMatrix, 97338)
137138
#define SD_CLK_PIN 40
138139
#define SD_MISO_PIN 39
139140
#define SD_MOSI_PIN 14
140141
#define SD_CS_PIN 12
141142
#define VBAT_PIN 10
143+
#define M5LED_ON LOW
144+
#define M5LED_OFF HIGH
142145
#endif
143146

144147
// -=-=-=-=-=- 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
146150
// RTC - Real-time clock exposed as M5.Rtc
147151
// AXP - AXP192 Power Management exposed as M5.Axp
148152
// PWRMGMT - StickC+2 Power Management exposed as M5.Power
@@ -154,6 +158,8 @@
154158
// SDCARD - Device has an SD Card Reader attached
155159
// SONG - Play melody or beep on startup
156160
// 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
157163

158164
/// SWITCHER ///
159165
// Proc codes
@@ -405,11 +411,13 @@ int screen_dim_time = 30;
405411
int screen_dim_current = 0;
406412

407413
void screenBrightness(int bright){
414+
Serial.printf("Brightness: %d\n", bright);
408415
#if defined(AXP)
409416
M5.Axp.ScreenBreath(bright);
410417
#endif
411418
#if defined(BACKLIGHT)
412-
analogWrite(BACKLIGHT, 205 + (bright/2));
419+
int bl = MINBRIGHT + round(((255 - MINBRIGHT) * bright / 100));
420+
analogWrite(BACKLIGHT, bl);
413421
#endif
414422
}
415423

@@ -429,7 +437,7 @@ void screen_dim_proc() {
429437
if(screen_dim_time > 0){
430438
if (screen_dim_dimmed == false) {
431439
if (uptime() == screen_dim_current || (uptime() + 1) == screen_dim_current || (uptime() + 2) == screen_dim_current) {
432-
screenBrightness(10);
440+
screenBrightness(0);
433441
screen_dim_dimmed = true;
434442
}
435443
}
@@ -748,7 +756,7 @@ void tvbgone_setup() {
748756
DISP.setTextSize(SMALL_TEXT);
749757
irsend.begin();
750758
// 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);
752760

753761
delay_ten_us(5000);
754762
if(region == NA) {
@@ -861,10 +869,7 @@ void sendAllCodes() {
861869
rawData[(k * 2) + 1] = ontime * 10;
862870
}
863871
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);
868873
bitsleft_r = 0;
869874
delay_ten_us(20500);
870875
#if defined(AXP)
@@ -910,9 +915,14 @@ void sendAllCodes() {
910915
}
911916

912917
void clock_loop() {
913-
M5.Rtc.GetBm8563Time();
914918
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
916926
delay(250);
917927
}
918928

@@ -926,8 +936,13 @@ void sendAllCodes() {
926936
}
927937

928938
void timeset_loop() {
939+
#if defined(STICK_C_PLUS2)
940+
auto dt = StickCP2.Rtc.getDateTime();
941+
cursor = dt.time.hours;
942+
#else
929943
M5.Rtc.GetBm8563Time();
930944
cursor = M5.Rtc.Hour;
945+
#endif
931946
number_drawmenu(24);
932947
while(digitalRead(M5_BUTTON_HOME) == HIGH) {
933948
if (check_next_press()) {
@@ -942,7 +957,11 @@ void sendAllCodes() {
942957
DISP.setCursor(0, 5, 1);
943958
DISP.println(TXT_SET_MIN);
944959
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
946965
number_drawmenu(60);
947966
while(digitalRead(M5_BUTTON_HOME) == HIGH) {
948967
if (check_next_press()) {
@@ -955,11 +974,15 @@ void sendAllCodes() {
955974
int minute = cursor;
956975
DISP.fillScreen(BGCOLOR);
957976
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
963986
DISP.printf("Setting Time:\n%02d:%02d:00",hour,minute);
964987
delay(2000);
965988
rstOverride = false;
@@ -1336,9 +1359,9 @@ void aj_adv(){
13361359
pAdvertising->setAdvertisementData(oAdvertisementData);
13371360
pAdvertising->start();
13381361
#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
13401363
delay(10);
1341-
digitalWrite(IRLED, M5LED_OFF); //LED OFF on Stick C Plus
1364+
digitalWrite(M5LED, M5LED_OFF); //LED OFF on Stick C Plus
13421365
#endif
13431366
}
13441367
if (check_next_press()) {
@@ -1452,9 +1475,9 @@ void wifispam_loop() {
14521475
int i = 0;
14531476
int len = 0;
14541477
#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
14561479
delay(1);
1457-
digitalWrite(IRLED, M5LED_OFF); //LED OFF on Stick C Plus
1480+
digitalWrite(M5LED, M5LED_OFF); //LED OFF on Stick C Plus
14581481
#endif
14591482
currentTime = millis();
14601483
if (currentTime - attackTime > 100) {
@@ -1804,9 +1827,11 @@ void setup() {
18041827
#if defined(CARDPUTER)
18051828
auto cfg = M5.config();
18061829
M5Cardputer.begin(cfg, true);
1807-
pinMode(38, OUTPUT); // Backlight analogWrite range ~150 - 255
18081830
#else
18091831
M5.begin();
1832+
#endif
1833+
#if defined(BACKLIGHT)
1834+
pinMode(BACKLIGHT, OUTPUT); // Backlight analogWrite range ~150 - 255
18101835
#endif
18111836
if(check_next_press()){
18121837
clearSettings();
@@ -1839,6 +1864,10 @@ void setup() {
18391864

18401865
// Pin setup
18411866
#if defined(M5LED)
1867+
pinMode(M5LED, OUTPUT);
1868+
digitalWrite(M5LED, M5LED_OFF); //LEDOFF
1869+
#endif
1870+
#if defined(IRLED)
18421871
pinMode(IRLED, OUTPUT);
18431872
digitalWrite(IRLED, M5LED_OFF); //LEDOFF
18441873
#endif

0 commit comments

Comments
 (0)