Skip to content

Commit d97d627

Browse files
committed
LYRAT Mini Buttons fix
1 parent a15d563 commit d97d627

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/Driver.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ class AudioDriver {
248248
/// Provides the pin information
249249
virtual DriverPins &pins() { return *p_pins; }
250250

251+
void setPins(DriverPins &pins) { p_pins = &pins; }
252+
251253
/// Sets the PA Power pin to active or inactive
252254
bool setPAPower(bool enable) {
253255
if (p_pins == nullptr) {
@@ -1425,14 +1427,16 @@ class AudioDriverLyratMiniClass : public AudioDriver {
14251427
bool ok = true;
14261428
if (codecCfg.input_device != ADC_INPUT_NONE){
14271429
AD_LOGI("starting ADC");
1430+
dac.setPins(this->pins());
14281431
ok = ok && adc.setConfig(codecCfg);
14291432
}
14301433

14311434
// Start DAC
14321435
if (codecCfg.output_device != DAC_OUTPUT_NONE){
14331436
AD_LOGI("starting DAC");
1437+
dac.setPins(this->pins());
14341438
ok = dac.setConfig(codecCfg);
1435-
adc.setPAPower(true);
1439+
setPAPower(true);
14361440
setVolume(DRIVER_DEFAULT_VOLUME);
14371441
}
14381442

@@ -1452,7 +1456,7 @@ class AudioDriverLyratMiniClass : public AudioDriver {
14521456
int getVolume() { return dac.getVolume(); }
14531457
bool setInputVolume(int volume) { return adc.setVolume(volume); }
14541458
int getInputVolume() { return adc.getVolume(); }
1455-
bool isInputVolumeSupported() { return true; }
1459+
bool fInputVolumeSupported() { return true; }
14561460

14571461
protected:
14581462
AudioDriverES8311Class dac;

src/DriverPins.h

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010
# define TOUCH_LIMIT 20
1111
#endif
1212

13+
#ifndef LYRAT_MINI_RANGE
14+
# define LYRAT_MINI_RANGE 5
15+
#endif
16+
17+
#ifndef LYRAT_MINI_DELAY_MS
18+
# define LYRAT_MINI_DELAY_MS 5
19+
#endif
20+
1321
namespace audio_driver {
1422

1523
/** @file */
@@ -59,7 +67,7 @@ enum class PinFunction {
5967
* @ingroup enumerations
6068
* @ingroup audio_driver
6169
*/
62-
enum AudioDriverKeys {
70+
enum AudioDriverKey {
6371
KEY_REC = 0,
6472
KEY_MODE,
6573
KEY_PLAY,
@@ -629,10 +637,18 @@ class PinsLyratMiniClass : public DriverPins {
629637
addPin(PinFunction::KEY, 39, PinLogic::Input, 0);
630638
}
631639

640+
/// When the button is released we might get some missreadings: so we read twice
641+
/// to guarantee a stable result
632642
bool isKeyPressed(uint8_t key) override {
633643
if (key > 5) return false;
634644
int value = analogRead(39);
635-
return inRange(value, analog_values[key]);
645+
bool result = inRange(value, analog_values[key]);
646+
delay(LYRAT_MINI_DELAY_MS);
647+
int value1 = analogRead(39);
648+
bool result1 = inRange(value, analog_values[key]);
649+
result = result && result1;
650+
AD_LOGD("value: %d,%d for key: %d -> %d", value1, key, result);
651+
return result;
636652
}
637653

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

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

0 commit comments

Comments
 (0)