3 #include "AudioConfig.h"
4 #include "AudioTools/AudioLibs/I2SCodecStream.h"
5 #include "AudioTools/CoreAudio/AudioActions.h"
21 AudioBoardAction(AudioBoard &
board, AudioDriverKey key) {
23 this->p_board = &
board;
27 int id()
override {
return key | 0x400; }
28 bool readValue()
override {
return p_board->isKeyPressed(key); }
44 bool begin()
override {
return I2SCodecStream::begin(); }
62 void addAction(AudioDriverKey key,
void (*action)(
bool,
int,
void *),
63 void *ref =
nullptr) {
64 AudioBoardAction *abo =
new AudioBoardAction(
board(), key);
65 abo->actionOn = action;
66 abo->ref = (ref ==
nullptr) ?
this : ref;
73 void addAction(AudioDriverKey key,
void (*actionOn)(
bool,
int,
void *),
74 void (*actionOff)(
bool,
int,
void *),
75 void *ref =
nullptr) {
77 AudioBoardAction *abo =
new AudioBoardAction(
board(), key);
78 abo->actionOn = actionOn;
79 abo->actionOn = actionOff;
80 abo->ref = (ref ==
nullptr) ?
this : ref;
92 void addAction(
int pin,
void (*action)(
bool,
int,
void *),
93 void *ref =
nullptr) {
97 actions.
add(pin, action, activeLogic, ref ==
nullptr ?
this : ref);
109 void addAction(
int pin,
void (*action)(
bool,
int,
void *),
110 AudioActions::ActiveLogic activeLogic,
void *ref =
nullptr) {
112 actions.
add(pin, action, activeLogic, ref ==
nullptr ?
this : ref);
127 float new_volume = current_volume + inc;
128 LOGI(
"incrementVolume: %f -> %f", current_volume, new_volume);
159 self->active = !
self->active;
160 self->setActive(self->active);
171 self->setActive(self->active);
180 self->active =
false;
181 self->setActive(self->active);
191 if (self->pinHeadphoneDetect() >= 0) {
194 if (self->headphoneIsConnected != isConnected) {
195 self->headphoneIsConnected = isConnected;
198 bool powerActive = !isConnected;
199 LOGW(
"Headphone jack has been %s",
200 isConnected ?
"inserted" :
"removed");
201 self->setSpeakerActive(powerActive);
222 return getPinID(PinFunction::HEADPHONE_DETECT);
308 return headphoneGpioPin > 0 ? !
digitalRead(headphoneGpioPin) :
false;
320 int sd_cs = getSdCsPin();
322 if (input_mode != -1 && (input_mode != sd_cs || !cfg.sd_active)) {
323 LOGD(
"actionInputMode")
332 int sd_cs = getSdCsPin();
335 if ((vol_up != -1 && vol_down != -1) &&
336 (!cfg.sd_active || (vol_down != sd_cs && vol_up != sd_cs))) {
337 LOGD(
"actionVolumeDown")
339 LOGD(
"actionVolumeUp")
342 LOGW(
"Volume Buttons ignored because of conflict: %d ",
pinVolumeDown());
350 if (head_phone != -1 && (
getPinID(PinFunction::KEY, 6) != head_phone)) {
352 AudioActions::ActiveChange,
this);
369 action_increment_value = value;
372 float actionVolumeIncrementValue() {
return action_increment_value; }
374 bool isKeyPressed(
int key) {
375 if (!
board())
return false;
376 return board().isKeyPressed(key);
380 AudioActions actions;
381 bool headphoneIsConnected =
false;
383 float action_increment_value = 0.02;
386 static GpioPin sd_cs = -2;
388 if (sd_cs != -2)
return sd_cs;
390 auto sd_opt =
getPins().getSPIPins(PinFunction::SD);
392 sd_cs = sd_opt.value().cs;
395 LOGI(
"No sd defined -> sd_active=false")
396 cfg.sd_active = false;
404 auto opt =
board().getPins().getPin(pin);
405 PinLogic logic = PinLogic::Input;
406 if (opt) logic = opt.value().pin_logic;
408 case PinLogic::Input:
409 case PinLogic::InputActiveLow:
410 return AudioActions::ActiveLow;
411 case PinLogic::InputActiveHigh:
412 return AudioActions::ActiveHigh;
413 case PinLogic::InputActiveTouch:
414 return AudioActions::ActiveTouch;
416 return AudioActions::ActiveLow;
static int digitalRead(int pin)
e.g. for AudioActions
Definition: NoArduino.h:206