Skip to content

Commit

Permalink
LYRAT Mini Buttons fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pschatzmann committed Nov 2, 2024
1 parent a15d563 commit d97d627
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ class AudioDriver {
/// Provides the pin information
virtual DriverPins &pins() { return *p_pins; }

void setPins(DriverPins &pins) { p_pins = &pins; }

/// Sets the PA Power pin to active or inactive
bool setPAPower(bool enable) {
if (p_pins == nullptr) {
Expand Down Expand Up @@ -1425,14 +1427,16 @@ class AudioDriverLyratMiniClass : public AudioDriver {
bool ok = true;
if (codecCfg.input_device != ADC_INPUT_NONE){
AD_LOGI("starting ADC");
dac.setPins(this->pins());
ok = ok && adc.setConfig(codecCfg);
}

// Start DAC
if (codecCfg.output_device != DAC_OUTPUT_NONE){
AD_LOGI("starting DAC");
dac.setPins(this->pins());
ok = dac.setConfig(codecCfg);
adc.setPAPower(true);
setPAPower(true);
setVolume(DRIVER_DEFAULT_VOLUME);
}

Expand All @@ -1452,7 +1456,7 @@ class AudioDriverLyratMiniClass : public AudioDriver {
int getVolume() { return dac.getVolume(); }
bool setInputVolume(int volume) { return adc.setVolume(volume); }
int getInputVolume() { return adc.getVolume(); }
bool isInputVolumeSupported() { return true; }
bool fInputVolumeSupported() { return true; }

protected:
AudioDriverES8311Class dac;
Expand Down
22 changes: 19 additions & 3 deletions src/DriverPins.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
# define TOUCH_LIMIT 20
#endif

#ifndef LYRAT_MINI_RANGE
# define LYRAT_MINI_RANGE 5
#endif

#ifndef LYRAT_MINI_DELAY_MS
# define LYRAT_MINI_DELAY_MS 5
#endif

namespace audio_driver {

/** @file */
Expand Down Expand Up @@ -59,7 +67,7 @@ enum class PinFunction {
* @ingroup enumerations
* @ingroup audio_driver
*/
enum AudioDriverKeys {
enum AudioDriverKey {
KEY_REC = 0,
KEY_MODE,
KEY_PLAY,
Expand Down Expand Up @@ -629,10 +637,18 @@ class PinsLyratMiniClass : public DriverPins {
addPin(PinFunction::KEY, 39, PinLogic::Input, 0);
}

/// When the button is released we might get some missreadings: so we read twice
/// to guarantee a stable result
bool isKeyPressed(uint8_t key) override {
if (key > 5) return false;
int value = analogRead(39);
return inRange(value, analog_values[key]);
bool result = inRange(value, analog_values[key]);
delay(LYRAT_MINI_DELAY_MS);
int value1 = analogRead(39);
bool result1 = inRange(value, analog_values[key]);
result = result && result1;
AD_LOGD("value: %d,%d for key: %d -> %d", value1, key, result);
return result;
}

void setRange(int value) {
Expand All @@ -642,7 +658,7 @@ class PinsLyratMiniClass : public DriverPins {
protected:
// analog values for rec, mute, play, set, vol-, vol+
int analog_values[6] {2802, 2270, 1754, 1284, 827, 304};
int range = 5;
int range = LYRAT_MINI_RANGE;

bool inRange(int in, int toBe){
return in >= (toBe-range) && in <= (toBe+range);
Expand Down

0 comments on commit d97d627

Please sign in to comment.