Skip to content

Commit 4be9ccf

Browse files
committedMay 7, 2022
Headset detection + disable speaker (except on startup!)
1 parent 2039324 commit 4be9ccf

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed
 

‎BoxDAC.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ void BoxDAC::begin() {
119119

120120
Log.info("...done");
121121

122+
uint8_t headsetDetect = readByte(ADDR_P0_SERIAL::HEADSET_DETECT);
123+
Log.info("Headset detect=%B", headsetDetect); // Always no Headset detected?! TODO
124+
if ((headsetDetect & 0b00100000) == 0b00100000) {
125+
Events.handleHeadphoneEvent(HeadphoneEvent::INSERTED);
126+
} else {
127+
Events.handleHeadphoneEvent(HeadphoneEvent::REMOVED);
128+
}
122129
//samSay("Hackiebox by Team Revvox!");
123130
}
124131
void BoxDAC::opusTest() {
@@ -778,6 +785,36 @@ void BoxDAC::initDACI2C() {
778785
send(ADDR_P1_DAC_OUT::L_VOL_TO_SPK, 128);
779786
}
780787

788+
789+
void BoxDAC::muteSpeaker(bool mute) {
790+
send(ADDR::PAGE_CONTROL, PAGE::DAC_OUT_VOL);
791+
uint8_t state = readByte(ADDR_P1_DAC_OUT::SPK_DRIVER);
792+
793+
if (mute) {
794+
state &= ~(0b00000100);
795+
} else {
796+
state |= 0b00000100;
797+
}
798+
799+
send(ADDR_P1_DAC_OUT::SPK_DRIVER, state);
800+
}
801+
void BoxDAC::muteHeadphones(bool mute) {
802+
send(ADDR::PAGE_CONTROL, PAGE::DAC_OUT_VOL);
803+
uint8_t stateL = readByte(ADDR_P1_DAC_OUT::HPL_DRIVER);
804+
uint8_t stateR = readByte(ADDR_P1_DAC_OUT::HPR_DRIVER);
805+
806+
if (mute) {
807+
stateL &= ~(0b00000100);
808+
stateR &= ~(0b00000100);
809+
} else {
810+
stateL |= 0b00000100;
811+
stateR |= 0b00000100;
812+
}
813+
814+
send(ADDR_P1_DAC_OUT::HPL_DRIVER, stateL);
815+
send(ADDR_P1_DAC_OUT::HPR_DRIVER, stateR);
816+
}
817+
781818
void BoxDAC::checkHeadphoneState() {
782819
send(ADDR::PAGE_CONTROL, PAGE::SERIAL_IO);
783820
uint8_t intrFlags = readByte(ADDR_P0_SERIAL::DAC_INTR_FLAGS);

‎BoxDAC.h

+3
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ class BoxDAC : public EnhancedThread {
117117
void logVolume();
118118
void logBeepVolume(uint8_t volume);
119119

120+
void muteSpeaker(bool mute);
121+
void muteHeadphones(bool mute);
122+
120123
void
121124
play(),
122125
pause(),

‎BoxEvents.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,13 @@ void BoxEvents::handleHeadphoneEvent(BoxDAC::HeadphoneEvent event) {
312312
switch (event){
313313
case BoxDAC::HeadphoneEvent::INSERTED:
314314
Log.info("Headphones connected");
315+
Box.boxDAC.muteSpeaker(true);
316+
Box.boxDAC.muteHeadphones(false);
315317
break;
316318
case BoxDAC::HeadphoneEvent::REMOVED:
317319
Log.info("Headphones disconnected");
320+
Box.boxDAC.muteHeadphones(true);
321+
Box.boxDAC.muteSpeaker(false);
318322
break;
319323
}
320324
}

0 commit comments

Comments
 (0)
Please sign in to comment.