Skip to content

Commit

Permalink
Implement inc/dec volume with ears (defective)
Browse files Browse the repository at this point in the history
  • Loading branch information
SciLor committed Jul 8, 2020
1 parent dd4b514 commit bec39d4
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
41 changes: 41 additions & 0 deletions BoxDAC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,4 +416,45 @@ uint8_t BoxDAC::readByte(ADDR_P1_DAC_OUT source_register) {
}
uint8_t BoxDAC::readByte(ADDR_P3_MCLK source_register) {
return readByte((uint8_t)source_register);
}

bool BoxDAC::increaseVolume() {
if (current_volume < VOL_MAX) {
current_volume += VOL_STEP;
setVolume(current_volume);
beepRaw(0x278A, 0x79BD, 0x000140); //16kHz
//beepMidi(78,50,true);
return true;
} else {
beepRaw(0x30F9, 0x763F, 0x000140); //16kHz
delay(50);
beepRaw(0x30F9, 0x763F, 0x000140); //16kHz
//beepMidi(84,50,true);
Log.info("Maximum volume %X reached.", current_volume);
}
return false;
}
bool BoxDAC::decreaseVolume() {
if (current_volume > VOL_MIN) {
current_volume -= VOL_STEP;
setVolume(current_volume);
beepRaw(0x18F5, 0x7D87, 0x000140); //16kHz
//beepMidi(70, 50, true);
return true;
} else {
beepRaw(0x0F0A, 0x7F1A, 0x000140); //16kHz
delay(50);
beepRaw(0x0F0A, 0x7F1A, 0x000140); //16kHz
//beepMidi(62, 50, true);
Log.info("Minimal volume %X reached.", current_volume);
}
return false;
}

void BoxDAC::setVolume(uint8_t volume) {
send(ADDR::PAGE_CONTROL, PAGE::SERIAL_IO);
send(ADDR_P0_SERIAL::DAC_VOL_L_CTRL, volume);
send(ADDR_P0_SERIAL::DAC_VOL_R_CTRL, volume);
Log.info("Set volume to %X", volume);
while ((readByte(ADDR_P0_SERIAL::DAC_FLAG_REG) & 0b00010001) != 0b00010001) { }
}
10 changes: 10 additions & 0 deletions BoxDAC.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ class BoxDAC : public EnhancedThread {
const int wavelength = (2*sampleRate / frequency); // half wavelength of square wave
int16_t sample[2] { amplitude, amplitude }; // current sample value
int count = 0;

const static uint8_t VOL_MIN = 0x0A;
const static uint8_t VOL_MAX = 0xB0;
uint8_t VOL_STEP = 0x06;
uint8_t current_volume = VOL_MIN;
bool increaseVolume();
bool decreaseVolume();

void setVolume(uint8_t volume);


private:
enum class PAGE {
Expand Down
4 changes: 2 additions & 2 deletions BoxEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ void BoxEvents::handleEarEvent(BoxButtonEars::EarButton earId, BoxButtonEars::Pr
if (pressType == BoxButtonEars::PressedType::PRESS) {
if (pressLength == BoxButtonEars::PressedTime::SHORT) {
if (earId == BoxButtonEars::EarButton::BIG) {

Box.boxDAC.increaseVolume();
} else if (earId == BoxButtonEars::EarButton::SMALL) {

Box.boxDAC.decreaseVolume();
} else if (earId == BoxButtonEars::EarButton::BOTH) {

}
Expand Down

0 comments on commit bec39d4

Please sign in to comment.