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;
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);
// 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);

View File

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

View File

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

View File

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