Skip to content

Commit

Permalink
feat: fixed soundsystem, fixed emergency switches for 0.10.x hardware
Browse files Browse the repository at this point in the history
  • Loading branch information
ClemensElflein committed Nov 12, 2022
1 parent 2874c6e commit 77d4dfb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Firmware/LowLevel/include/soundsystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class MP3Sound

public:

uint32_t anzSoundfiles; // number of files stored on the SD-card
int16_t anzSoundfiles; // number of files stored on the SD-card
bool playing;

MP3Sound();
Expand Down
13 changes: 7 additions & 6 deletions Firmware/LowLevel/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,25 @@ lib_ignore = JY901_SERIAL,JY901_I2C
lib_deps = ${env.lib_deps}
bolderflight/Bolder Flight Systems MPU9250@^1.0.2
powerbroker2/DFPlayerMini_Fast@^1.2.4
build_src_filter = ${env.build_src_filter} +<imu/MPU9250/>
build_flags = ${env.build_flags} -DHW_0_10_X
build_src_filter = ${env.build_src_filter} +<imu/MPU9250/> +<soundsystem.cpp>
build_flags = ${env.build_flags} -DHW_0_10_X -DENABLE_SOUND_MODULE

[env:0_10_X_WT901]
build_src_filter = ${env.build_src_filter} +<imu/WT901_I2C/>
build_src_filter = ${env.build_src_filter} +<imu/WT901_I2C/> +<soundsystem.cpp>
lib_ignore = JY901_SERIAL
lib_deps = ${env.lib_deps}
powerbroker2/DFPlayerMini_Fast@^1.2.4
JY901_I2C
build_flags =
${env.build_flags} -DWT901_I2C -DHW_0_10_X
${env.build_flags} -DWT901_I2C -DHW_0_10_X -DENABLE_SOUND_MODULE

[env:0_9_X_MPU9250]
lib_ignore = JY901_SERIAL,JY901_I2C
lib_deps = ${env.lib_deps}
bolderflight/Bolder Flight Systems MPU9250@^1.0.2
powerbroker2/DFPlayerMini_Fast@^1.2.4
build_src_filter = ${env.build_src_filter} +<imu/MPU9250/>
build_flags = ${env.build_flags} -DHW_0_9_X
build_src_filter = ${env.build_src_filter} +<imu/MPU9250/> +<soundsystem.cpp>
build_flags = ${env.build_flags} -DHW_0_9_X -DENABLE_SOUND_MODULE

[env:0_9_X_WT901_INSTEAD_OF_SOUND]
lib_ignore = JY901_I2C
Expand Down
34 changes: 13 additions & 21 deletions Firmware/LowLevel/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,15 @@ void updateEmergency()
uint8_t last_emergency = status_message.emergency_bitmask & 1;

// Mask the emergency bits. 2x Lift sensor, 2x Emergency Button
uint8_t pin_states = gpio_get_all() & (0b11001100);
bool emergency1 = gpio_get(PIN_EMERGENCY_1);
bool emergency2 = gpio_get(PIN_EMERGENCY_2);
bool emergency3 = gpio_get(PIN_EMERGENCY_3);
bool emergency4 = gpio_get(PIN_EMERGENCY_4);

uint8_t emergency_state = 0;

bool is_lifted = (~pin_states & 0b11000000) != 0;
bool stop_pressed = (~pin_states & 0b00001100) != 0;
bool is_lifted = emergency1 || emergency2;
bool stop_pressed = emergency3 || emergency4;

if (is_lifted)
{
Expand Down Expand Up @@ -171,20 +175,20 @@ void updateEmergency()
if (lift_emergency_started > 0 && (millis() - lift_emergency_started) >= LIFT_EMERGENCY_MILLIS)
{
// Emergency bit 2 (lift wheel 1)set?
if (~pin_states & 0b01000000)
if (emergency1)
emergency_state |= 0b01000;
// Emergency bit 1 (lift wheel 2)set?
if (~pin_states & 0b10000000)
if (emergency2)
emergency_state |= 0b10000;
}

if (button_emergency_started > 0 && (millis() - button_emergency_started) >= BUTTON_EMERGENCY_MILLIS)
{
// Emergency bit 2 (stop button) set?
if (~pin_states & 0b00000100)
if (emergency3)
emergency_state |= 0b00010;
// Emergency bit 1 (stop button)set?
if (~pin_states & 0b00001000)
if (emergency4)
emergency_state |= 0b00100;
}

Expand Down Expand Up @@ -462,18 +466,13 @@ void setup()

#ifdef ENABLE_SOUND_MODULE
p.neoPixelSetValue(0, 0, 255, 255, true);
delay(1000);

sound_available = my_sound.begin(NR_SOUNDFILES);
sound_available = my_sound.begin();
if (sound_available)
{
p.neoPixelSetValue(0, 0, 0, 255, true);
my_sound.setvolume(10);
delay(100);
my_sound.setvolume(10);
delay(100);
my_sound.setvolume(100);
my_sound.playSoundAdHoc(1);
delay(6000);
p.neoPixelSetValue(0, 255, 255, 0, true);
}
else
Expand All @@ -487,13 +486,6 @@ void setup()
}
}

// Soundtest
my_sound.playSound(2);
my_sound.playSound(3);
my_sound.playSound(13);
my_sound.playSound(14);

int i = my_sound.sounds2play();

#else
sound_available = false;
Expand Down
26 changes: 13 additions & 13 deletions Firmware/LowLevel/src/soundsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
#include <soundsystem.h>


SerialPIO soundSerial(PIN_SOUND_TX, PIN_SOUND_RX, 250);

DFPlayerMini_Fast myMP3;


MP3Sound::MP3Sound()
{

Serial2.setTX(PIN_SOUND_TX);
Serial2.setRX(PIN_SOUND_RX);

this->anzSoundfiles = 0; // number of files stored on the SD-card
this->playing = false;
this->sound_available = false;
Expand All @@ -34,26 +33,27 @@ MP3Sound::MP3Sound()



bool MP3Sound::begin(int anzsoundsOnSD)
bool MP3Sound::begin()

{

// serial stream init for soundmodule
Serial2.begin(9600);
while (Serial2.available())
Serial2.read();
soundSerial.begin(9600);
soundSerial.flush();
while (soundSerial.available())
soundSerial.read();
// init soundmodule
sound_available = myMP3.begin(Serial2,true);
delay(1000);
return (sound_available);
sound_available = myMP3.begin(soundSerial,true);
this->anzSoundfiles = myMP3.numSdTracks();
return this->anzSoundfiles > 0;
}


void MP3Sound::setvolume(int vol) // scales from 0 to 100 %
{

// value of 30 is max equivalent to 100 %
int val = (int) (30 / 100.0 * vol);
int val = (int) (30.0 / 100.0 * (double)vol);
myMP3.volume(val);
delay(300);

Expand All @@ -63,7 +63,7 @@ void MP3Sound::setvolume(int vol) // scales from 0 to 100 %

void MP3Sound::playSoundAdHoc(int soundNr)
{
if(soundNr > NR_SOUNDFILES) return;
if(soundNr > anzSoundfiles) return;

myMP3.play(soundNr);
delay(1000);
Expand All @@ -75,7 +75,7 @@ void MP3Sound::playSoundAdHoc(int soundNr)

void MP3Sound::playSound(int soundNr)
{
if((soundNr > NR_SOUNDFILES) || (active_sounds.size() == BUFFERSIZE) ) return;
if((soundNr > anzSoundfiles) || (active_sounds.size() == BUFFERSIZE) ) return;

active_sounds.push_front(soundNr);

Expand Down

0 comments on commit 77d4dfb

Please sign in to comment.