More awtrix_upgrade fixes

Fixed button pins
Added button clicks
Added volume setting
This commit is contained in:
Elfish
2023-04-03 12:15:21 +02:00
parent 9494a6bbbd
commit 1c74e5f693
4 changed files with 51 additions and 20 deletions

View File

@@ -30,7 +30,12 @@ Ticker TimerTicker;
GifPlayer gif; GifPlayer gif;
CRGB leds[MATRIX_WIDTH * MATRIX_HEIGHT]; CRGB leds[MATRIX_WIDTH * MATRIX_HEIGHT];
// Awtrix Big / Ulanzi
FastLED_NeoMatrix matrix(leds, 32, 8, NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG); FastLED_NeoMatrix matrix(leds, 32, 8, NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG);
// Awtrid Midi
//FastLED_NeoMatrix matrix(leds, 8, 8, 4, 1, NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_ROWS + NEO_MATRIX_PROGRESSIVE);
// Awtrix Mini?
//FastLED_NeoMatrix(leds, 32, 8, NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG);
MatrixDisplayUi ui(&matrix); MatrixDisplayUi ui(&matrix);

View File

@@ -31,7 +31,7 @@ enum MenuState
#ifdef ULANZI #ifdef ULANZI
SoundMenu SoundMenu
#else #else
SoundMenu, SoundMenu,
VolumeMenu VolumeMenu
#endif #endif
}; };
@@ -49,10 +49,17 @@ const char *menuItems[] PROGMEM = {
"TEMP", "TEMP",
"APPS", "APPS",
"SOUND", "SOUND",
#ifndef ULANZI
"VOLUME" ,
#endif
"UPDATE"}; "UPDATE"};
int8_t menuIndex = 0; int8_t menuIndex = 0;
#ifdef ULANZI
uint8_t menuItemCount = 13; uint8_t menuItemCount = 13;
#else
uint8_t menuItemCount = 14;
#endif
const char *timeFormat[] PROGMEM = { const char *timeFormat[] PROGMEM = {
"%H:%M:%S", "%H:%M:%S",
@@ -197,6 +204,10 @@ String MenuManager_::menutext()
break; break;
} }
break; break;
#ifndef ULANZI
case VolumeMenu:
return String(VOLUME_PERCENT) + "%";
#endif
default: default:
break; break;
} }
@@ -256,9 +267,10 @@ void MenuManager_::rightButton()
break; break;
#ifndef ULANZI #ifndef ULANZI
case VolumeMenu: case VolumeMenu:
VOLUME_PERCENT = (VOLUME_PERCENT % 100) + 1; if ((VOLUME_PERCENT + 1) > 100)
VOLUME = map(VOLUME_PERCENT, 0, 100, 0, 30); VOLUME_PERCENT = 0;
PeripheryManager.setVolume(VOLUME); else
VOLUME_PERCENT++;
#endif #endif
default: default:
break; break;
@@ -322,9 +334,10 @@ void MenuManager_::leftButton()
break; break;
#ifndef ULANZI #ifndef ULANZI
case VolumeMenu: case VolumeMenu:
VOLUME_PERCENT = (VOLUME_PERCENT % 100) - 1; if ((VOLUME_PERCENT - 1) < 0)
VOLUME = map(VOLUME_PERCENT, 0, 100, 0, 30); VOLUME_PERCENT = 100;
PeripheryManager.setVolume(VOLUME); else
VOLUME_PERCENT--;
#endif #endif
default: default:
break; break;
@@ -382,7 +395,7 @@ void MenuManager_::selectButton()
case 12: case 12:
#ifndef ULANZI #ifndef ULANZI
currentState = VolumeMenu; currentState = VolumeMenu;
break; break;
#endif #endif
case 13: case 13:
if (UpdateManager.checkUpdate(true)) if (UpdateManager.checkUpdate(true))
@@ -461,12 +474,6 @@ void MenuManager_::selectButtonLong()
DisplayManager.applyAllSettings(); DisplayManager.applyAllSettings();
saveSettings(); saveSettings();
break; break;
#ifndef ULANZI
case VolumeMenu:
VOLUME = map(VOLUME_PERCENT, 0, 100, 0, 30);
saveSettings();
#endif
break;
case TimeFormatMenu: case TimeFormatMenu:
TIME_FORMAT = timeFormat[timeFormatIndex]; TIME_FORMAT = timeFormat[timeFormatIndex];
saveSettings(); saveSettings();
@@ -483,6 +490,13 @@ void MenuManager_::selectButtonLong()
DisplayManager.loadNativeApps(); DisplayManager.loadNativeApps();
saveSettings(); saveSettings();
break; break;
#ifndef ULANZI
case VolumeMenu:
VOLUME = map(VOLUME_PERCENT, 0, 100, 0, 30);
PeripheryManager.setVolume(VOLUME);
saveSettings();
break;
#endif
default: default:
break; break;
} }

View File

@@ -30,8 +30,8 @@
// Pinouts für das WEMOS_D1_MINI32-Environment // Pinouts für das WEMOS_D1_MINI32-Environment
#define LDR_PIN A0 #define LDR_PIN A0
#define BUTTON_UP_PIN D0 #define BUTTON_UP_PIN D0
#define BUTTON_DOWN_PIN D4 #define BUTTON_DOWN_PIN D8
#define BUTTON_SELECT_PIN D8 #define BUTTON_SELECT_PIN D4
#define DFPLAYER_RX D7 #define DFPLAYER_RX D7
#define DFPLAYER_TX D5 #define DFPLAYER_TX D5
#define I2C_SCL_PIN D1 #define I2C_SCL_PIN D1
@@ -42,6 +42,7 @@
Adafruit_SHT31 sht31; Adafruit_SHT31 sht31;
#else #else
Adafruit_BME280 bme280; Adafruit_BME280 bme280;
TwoWire I2Cbme280 = TwoWire(0);
#endif #endif
EasyButton button_left(BUTTON_UP_PIN); EasyButton button_left(BUTTON_UP_PIN);
@@ -90,6 +91,7 @@ PeripheryManager_ &PeripheryManager = PeripheryManager.getInstance();
void left_button_pressed() void left_button_pressed()
{ {
PeripheryManager.playFromFile(DFMINI_MP3_CLICK);
if (AP_MODE) if (AP_MODE)
{ {
--MATRIX_LAYOUT; --MATRIX_LAYOUT;
@@ -107,6 +109,7 @@ void left_button_pressed()
void right_button_pressed() void right_button_pressed()
{ {
PeripheryManager.playFromFile(DFMINI_MP3_CLICK);
if (AP_MODE) if (AP_MODE)
{ {
++MATRIX_LAYOUT; ++MATRIX_LAYOUT;
@@ -124,18 +127,21 @@ void right_button_pressed()
void select_button_pressed() void select_button_pressed()
{ {
PeripheryManager.playFromFile(DFMINI_MP3_CLICK);
DisplayManager.selectButton(); DisplayManager.selectButton();
MenuManager.selectButton(); MenuManager.selectButton();
} }
void select_button_pressed_long() void select_button_pressed_long()
{ {
PeripheryManager.playFromFile(DFMINI_MP3_CLICK);
DisplayManager.selectButtonLong(); DisplayManager.selectButtonLong();
MenuManager.selectButtonLong(); MenuManager.selectButtonLong();
} }
void select_button_tripple() void select_button_tripple()
{ {
PeripheryManager.playFromFile(DFMINI_MP3_CLICK_ON);
if (MATRIX_OFF) if (MATRIX_OFF)
{ {
DisplayManager.MatrixState(true); DisplayManager.MatrixState(true);
@@ -187,7 +193,9 @@ void PeripheryManager_::stopSound()
#ifndef ULANZI #ifndef ULANZI
void PeripheryManager_::setVolume(uint8_t vol) void PeripheryManager_::setVolume(uint8_t vol)
{ {
uint8_t curVolume = dfmp3.getVolume(); // need to read volume in order to work. Donno why! :(
dfmp3.setVolume(vol); dfmp3.setVolume(vol);
delay(50);
} }
#endif #endif
@@ -243,7 +251,7 @@ void PeripheryManager_::setup()
digitalWrite(BUZZER_PIN, LOW); digitalWrite(BUZZER_PIN, LOW);
#else #else
dfmp3.begin(); dfmp3.begin();
delay(50); delay(100);
setVolume(VOLUME); setVolume(VOLUME);
#endif #endif
button_left.begin(); button_left.begin();
@@ -254,11 +262,13 @@ void PeripheryManager_::setup()
button_select.onPressed(select_button_pressed); button_select.onPressed(select_button_pressed);
button_select.onPressedFor(1000, select_button_pressed_long); button_select.onPressedFor(1000, select_button_pressed_long);
button_select.onSequence(2, 300, select_button_tripple); button_select.onSequence(2, 300, select_button_tripple);
Wire.begin(I2C_SDA_PIN, I2C_SCL_PIN);
#ifdef ULANZI #ifdef ULANZI
Wire.begin(I2C_SDA_PIN, I2C_SCL_PIN);
sht31.begin(0x44); sht31.begin(0x44);
#else #else
bme280.begin(); I2Cbme280.begin(I2C_SDA_PIN, I2C_SCL_PIN);
bme280.begin(0x76, &I2Cbme280);
dfmp3.begin(); dfmp3.begin();
#endif #endif
photocell.setPhotocellPositionOnGround(false); photocell.setPhotocellPositionOnGround(false);
@@ -267,7 +277,6 @@ void PeripheryManager_::setup()
void PeripheryManager_::tick() void PeripheryManager_::tick()
{ {
MQTTManager.sendButton(0, button_left.read()); MQTTManager.sendButton(0, button_left.read());
MQTTManager.sendButton(1, button_select.read()); MQTTManager.sendButton(1, button_select.read());
MQTTManager.sendButton(2, button_right.read()); MQTTManager.sendButton(2, button_right.read());

View File

@@ -7,6 +7,9 @@
#define DFMINI_MP3_BOOT "1" #define DFMINI_MP3_BOOT "1"
#define DFMINI_MP3_ALARM "2" #define DFMINI_MP3_ALARM "2"
#define DFMINI_MP3_TIMER "2" #define DFMINI_MP3_TIMER "2"
#define DFMINI_MP3_CLICK "5"
#define DFMINI_MP3_CLICK_ON "3"
#define DFMINI_MP3_ENTER "4"
#endif #endif
class PeripheryManager_ class PeripheryManager_