Skip to content

Commit

Permalink
Merge remote-tracking branch 'biologist/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sascha committed Dec 12, 2023
2 parents 6ce9edc + efc66af commit 3ab3886
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 34 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## DEV-branch

* 12.12.2023: Long press behaviour, execute cmd directly after longpress-time (#279), thanks to @Joe91 !
* 12.12.2023: Fix false-positive error (Audio playback timeout)
* 10.12.2023: Distribute vTaskDelay() in main loop to avoid rare audio dropouts
* 10.12.2023: Fix wrong states on PE output pins (and SD-card failure on restart) #278, thanks to @36b6fp6s !
* 09.12.2023: Fix webstream playlist abort when track fails (#276), thanks to @laszloh !
* 07.12.2023: Show RC522 firmware version at startup, same as PN5180
* 04.12.2023: fix stuttering sound with some WAV & MP3 files, thanks to @wolle !
* 04.12.2023: change trackprogress communication from websocket to http to improve stability
* 04.12.2023: Remove some convertAsciiToUtf8() #272
Expand Down
4 changes: 2 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ extra_scripts =
pre:updateSdkConfig.py
pre:processHtml.py
lib_deps =
https://github.com/schreibfaul1/ESP32-audioI2S.git#2a0ab81
https://github.com/schreibfaul1/ESP32-audioI2S.git#71b7523
https://github.com/madhephaestus/ESP32Encoder.git#9979722
https://github.com/knolleary/pubsubclient.git#2d228f2
https://github.com/peterus/ESP-FTP-Server-Lib#554959f
https://github.com/tueddy/FastLED.git#3.6.0_IRAM ;save some IRAM to compile with all features (https://github.com/FastLED/[email protected])
https://github.com/me-no-dev/ESPAsyncWebServer.git#1d46269
https://github.com/me-no-dev/AsyncTCP.git#ca8ac5f
https://github.com/bblanchon/ArduinoJson.git#7517ecb
https://github.com/bblanchon/ArduinoJson.git#3e1be98
https://github.com/pschatzmann/ESP32-A2DP.git#96d37bc
https://github.com/Arduino-IRremote/Arduino-IRremote.git#ed94895
https://github.com/kkloesener/MFRC522_I2C.git#121a27e
Expand Down
47 changes: 28 additions & 19 deletions src/AudioPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,9 @@ void AudioPlayer_Task(void *parameter) {
audio->setI2SCommFMT_LSB(true);
#endif

uint8_t settleCount = 0;
constexpr uint32_t playbackTimeout = 2000;
uint32_t playbackTimeoutStart = millis();

AudioPlayer_CurrentVolume = AudioPlayer_GetInitVolume();
audio->setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
audio->setVolume(AudioPlayer_CurrentVolume, VOLUMECURVE);
Expand Down Expand Up @@ -402,12 +404,19 @@ void AudioPlayer_Task(void *parameter) {
trackQStatus = xQueueReceive(gTrackQueue, &gPlayProperties.playlist, 0);
if (trackQStatus == pdPASS || gPlayProperties.trackFinished || trackCommand != NO_ACTION) {
if (trackQStatus == pdPASS) {
if (gPlayProperties.pausePlay) {
gPlayProperties.pausePlay = false;
}
audio->stopSong();
Log_Printf(LOGLEVEL_NOTICE, newPlaylistReceived, gPlayProperties.numberOfTracks);
Log_Printf(LOGLEVEL_DEBUG, "Free heap: %u", ESP.getFreeHeap());
playbackTimeoutStart = millis();
gPlayProperties.pausePlay = false;
gPlayProperties.repeatCurrentTrack = false;
gPlayProperties.repeatPlaylist = false;
gPlayProperties.sleepAfterCurrentTrack = false;
gPlayProperties.sleepAfterPlaylist = false;
gPlayProperties.saveLastPlayPosition = false;
gPlayProperties.playUntilTrackNumber = 0;
gPlayProperties.trackFinished = false;
gPlayProperties.playlistFinished = false;

#ifdef MQTT_ENABLE
publishMqtt(topicPlaymodeState, gPlayProperties.playMode, false);
Expand All @@ -422,7 +431,7 @@ void AudioPlayer_Task(void *parameter) {
}
if (gPlayProperties.trackFinished) {
gPlayProperties.trackFinished = false;
if (gPlayProperties.playMode == NO_PLAYLIST) {
if (gPlayProperties.playMode == NO_PLAYLIST || gPlayProperties.playlist == nullptr) {
gPlayProperties.playlistFinished = true;
continue;
}
Expand Down Expand Up @@ -827,16 +836,23 @@ void AudioPlayer_Task(void *parameter) {
}

if (audio->isRunning()) {
settleCount = 0;
playbackTimeoutStart = millis();
}

// If error occured: remove playlist from ESPuino
if (gPlayProperties.playMode != NO_PLAYLIST && gPlayProperties.playMode != BUSY && !audio->isRunning() && !gPlayProperties.pausePlay) {
if (settleCount++ == 50) { // Hack to give audio some time to settle down after playlist was generated
gPlayProperties.playlistFinished = true;
gPlayProperties.playMode = NO_PLAYLIST;
settleCount = 0;
// If error occured: move to the next track in the playlist
if (gPlayProperties.playMode != NO_PLAYLIST && gPlayProperties.playMode != BUSY) {
// we check for timeout
if (!audio->isRunning() && !gPlayProperties.pausePlay) {
if ((millis() - playbackTimeoutStart) > playbackTimeout) {
// Audio playback timed out, move on to the next
System_IndicateError();
gPlayProperties.trackFinished = true;
playbackTimeoutStart = millis();
}
}
} else {
// we are idle, update timeout so that we do not get a spurious error when launching into a playlist
playbackTimeoutStart = millis();
}
if ((System_GetOperationMode() == OPMODE_BLUETOOTH_SOURCE) && audio->isRunning()) {
// do not delay here, audio task is time critical in BT-Source mode
Expand Down Expand Up @@ -981,13 +997,6 @@ void AudioPlayer_TrackQueueDispatcher(const char *_itemToPlay, const uint32_t _l

gPlayProperties.playMode = _playMode;
gPlayProperties.numberOfTracks = strtoul(*(musicFiles - 1), NULL, 10);
// Set some default-values
gPlayProperties.repeatCurrentTrack = false;
gPlayProperties.repeatPlaylist = false;
gPlayProperties.sleepAfterCurrentTrack = false;
gPlayProperties.sleepAfterPlaylist = false;
gPlayProperties.saveLastPlayPosition = false;
gPlayProperties.playUntilTrackNumber = 0;

#ifdef PLAY_LAST_RFID_AFTER_REBOOT
// Store last RFID-tag to NVS
Expand Down
17 changes: 12 additions & 5 deletions src/Button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ void Button_DoButtonActions(void) {
gButtons[5].isPressed = false;
Cmd_Action(BUTTON_MULTI_45);
} else {
unsigned long currentTimestamp = millis();
for (uint8_t i = 0; i <= 5; i++) {
if (gButtons[i].isPressed) {
uint8_t Cmd_Short = 0;
Expand Down Expand Up @@ -305,20 +306,19 @@ void Button_DoButtonActions(void) {
break;
}

if (gButtons[i].lastReleasedTimestamp > gButtons[i].lastPressedTimestamp) {
if (gButtons[i].lastReleasedTimestamp > gButtons[i].lastPressedTimestamp) { // short action
if (gButtons[i].lastReleasedTimestamp - gButtons[i].lastPressedTimestamp < intervalToLongPress) {
Cmd_Action(Cmd_Short);
} else {
// if not volume buttons than start action after button release
if (Cmd_Long != CMD_VOLUMEUP && Cmd_Long != CMD_VOLUMEDOWN) {
// sleep-mode should only be triggered on release, otherwise it will wake it up directly again
if (Cmd_Long == CMD_SLEEPMODE) {
Cmd_Action(Cmd_Long);
}
}

gButtons[i].isPressed = false;
} else if (Cmd_Long == CMD_VOLUMEUP || Cmd_Long == CMD_VOLUMEDOWN) {
unsigned long currentTimestamp = millis();

} else if (Cmd_Long == CMD_VOLUMEUP || Cmd_Long == CMD_VOLUMEDOWN) { // volume-buttons
// only start action if intervalToLongPress has been reached
if (currentTimestamp - gButtons[i].lastPressedTimestamp > intervalToLongPress) {

Expand All @@ -332,6 +332,13 @@ void Button_DoButtonActions(void) {

gLongPressTime = remainder;
}

} else if (Cmd_Long != CMD_SLEEPMODE) { // long action, if not sleep-mode
// start action if intervalToLongPress has been reached
if ((currentTimestamp - gButtons[i].lastPressedTimestamp) > intervalToLongPress) {
gButtons[i].isPressed = false;
Cmd_Action(Cmd_Long);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Led.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ AnimationReturnType Animation_BatteryMeasurement(const bool startNewAnimation, C
LED_INDICATOR_CLEAR(LedIndicatorType::Voltage);

if (startNewAnimation) {
#ifdef MEASURE_BATTERY_VOLTAGE
#ifdef BATTERY_MEASURE_ENABLE
float batteryLevel = Battery_EstimateLevel();
#else
float batteryLevel = 1.0f;
Expand Down
21 changes: 17 additions & 4 deletions src/Port.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
extern TwoWire i2cBusTwo;

uint8_t Port_ExpanderPortsInputChannelStatus[2];
static uint8_t Port_ExpanderPortsOutputChannelStatus[2] = {255, 255}; // Stores current configuration of output-channels locally
static uint8_t Port_ExpanderPortsOutputChannelStatus[2]; // Stores current configuration of output-channels locally
void Port_ExpanderHandler(void);
uint8_t Port_ChannelToBit(const uint8_t _channel);
void Port_WriteInitMaskForOutputChannels(void);
Expand Down Expand Up @@ -192,7 +192,17 @@ void Port_WriteInitMaskForOutputChannels(void) {
const uint8_t portBaseValueBitMask = 255;
const uint8_t portsToWrite = 2;
uint8_t OutputBitMaskInOutAsPerPort[portsToWrite] = {portBaseValueBitMask, portBaseValueBitMask}; // 255 => all channels set to input; [0]: port0, [1]: port1
uint8_t OutputBitMaskLowHighAsPerPort[portsToWrite] = {0x00, 0x00}; // Bit configured as 0 for an output-channels means: logic LOW

// init status cache with values from HW
i2cBusTwo.beginTransmission(expanderI2cAddress);
i2cBusTwo.write(0x02); // Pointer to first output-register
i2cBusTwo.endTransmission(false);
i2cBusTwo.requestFrom(expanderI2cAddress, static_cast<size_t>(portsToWrite), true); // ...and read the contents
if (i2cBusTwo.available()) {
for (uint8_t i = 0; i < portsToWrite; i++) {
Port_ExpanderPortsOutputChannelStatus[i] = i2cBusTwo.read();
}
}

#ifdef GPIO_PA_EN // Set as output to enable/disable amp for loudspeaker
if (GPIO_PA_EN >= 100 && GPIO_PA_EN <= 107) {
Expand Down Expand Up @@ -230,6 +240,10 @@ void Port_WriteInitMaskForOutputChannels(void) {

// Only change port-config if necessary (at least bitmask changed from base-default for one port)
if ((OutputBitMaskInOutAsPerPort[0] != portBaseValueBitMask) || (OutputBitMaskInOutAsPerPort[1] != portBaseValueBitMask)) {
// all outputs to LOW
Port_ExpanderPortsOutputChannelStatus[0] &= OutputBitMaskInOutAsPerPort[0];
Port_ExpanderPortsOutputChannelStatus[1] &= OutputBitMaskInOutAsPerPort[1];

i2cBusTwo.beginTransmission(expanderI2cAddress);
i2cBusTwo.write(0x06); // Pointer to configuration of input/output
for (uint8_t i = 0; i < portsToWrite; i++) {
Expand All @@ -241,8 +255,7 @@ void Port_WriteInitMaskForOutputChannels(void) {
// Write low/high-config to all output-channels. Channels that are configured as input are silently/automatically ignored by PCA9555
i2cBusTwo.beginTransmission(expanderI2cAddress);
i2cBusTwo.write(0x02); // Pointer to configuration of output-channels (high/low)
i2cBusTwo.write(OutputBitMaskLowHighAsPerPort[0]); // port0
i2cBusTwo.write(OutputBitMaskLowHighAsPerPort[1]); // port1
i2cBusTwo.write(Port_ExpanderPortsOutputChannelStatus, static_cast<size_t>(portsToWrite));
i2cBusTwo.endTransmission();
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/RfidMfrc522.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ void Rfid_Init(void) {
// Init RC522 Card-Reader
#if defined(RFID_READER_TYPE_MFRC522_I2C) || defined(RFID_READER_TYPE_MFRC522_SPI)
mfrc522.PCD_Init();
delay(10);
// Get the MFRC522 firmware version, should be 0x91 or 0x92
byte firmwareVersion = mfrc522.PCD_ReadRegister(MFRC522::VersionReg);
Log_Printf(LOGLEVEL_DEBUG, "RC522 firmware version=%#lx", firmwareVersion);

mfrc522.PCD_SetAntennaGain(rfidGain);
delay(50);
Log_Println(rfidScannerReady, LOGLEVEL_DEBUG);
Expand Down
6 changes: 4 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,13 @@ void loop() {
RotaryEncoder_Cyclic();
Mqtt_Cyclic();
}

vTaskDelay(portTICK_PERIOD_MS * 1u);
AudioPlayer_Cyclic();
vTaskDelay(portTICK_PERIOD_MS * 1u);
Battery_Cyclic();
// Port_Cyclic(); // called by button (controlled via hw-timer)
Button_Cyclic();
vTaskDelay(portTICK_PERIOD_MS * 1u);
System_Cyclic();
Rfid_PreferenceLookupHandler();

Expand All @@ -272,7 +274,7 @@ void loop() {
#endif

IrReceiver_Cyclic();
vTaskDelay(portTICK_PERIOD_MS * 5u);
vTaskDelay(portTICK_PERIOD_MS * 2u);

#ifdef HALLEFFECT_SENSOR_ENABLE
gHallEffectSensor.cyclic();
Expand Down
3 changes: 2 additions & 1 deletion src/revision.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once

#include "gitrevision.h"
constexpr const char softwareRevision[] = "Software-revision: 20231204-0-szenglein";

constexpr const char softwareRevision[] = "Software-revision: 20231212-1-szenglein";

0 comments on commit 3ab3886

Please sign in to comment.