Skip to content

Commit 42f5810

Browse files
Improve Sound (#80)
* Switch to Makuna/DFMiniMp3 and simplified USB debugging * Adapt SD-Card folder and track names * SD-Card folder description * Implement own advert functionality * Docs * Add cosmetic pause functionality * Add high_level_state parameter * Cleanup * Add emergency sound processing * New sounds & ROS startup successful * Fix new timing issue, add Mode & GPS handling * Fix ROS startup sound order and protected redundancy call of OnPlayFinished() * Fix emergencies * Restrict GPS ping to area recording mode * Fix GPS ping, add rain handling * Add randomized mowing background sounds & further GPS ping fixes * Add new and german sound files * Add soundfiles from alfakenzo * Soundfile corrections * Add Sound "IMU init failed" * Add repeatDuration * Fix rand mow sound during waiting for GPS fix * Add debug prefix string * Restructure SoundSystem from OOP to FP * Work around playFolderTrack16() * Work around non working stop() when OnPlayFinish ed() * Improved emergency handling * Change translation * Skip needless namespace * Fix emergency during flash & docked. Add/change sounds * Add VCC warning * Add volume and language control via LL buttons * Change some sounds, add collision sound for SA/SC models * Default Volume * No "Bida bida" on stop-button * Squashed commit of the following: commit 1d40d64 Author: Jörg Ebeling <[email protected]> Date: Fri Sep 29 21:05:32 2023 +0200 Fit indentation commit be7b9e3 Author: Jörg Ebeling <[email protected]> Date: Thu Sep 28 23:09:22 2023 +0200 Better var names commit 9fb76f6 Author: Jörg Ebeling <[email protected]> Date: Thu Sep 28 00:21:02 2023 +0200 Process UIBoard available * Fix missing soundsystem.cpp for 0_13_X * Current measurements on 3.3V line * Implemented SD-Card type/format detection (old/new) and old SD-Card format support * Fix missing -DENABLE_SOUND_MODULE * Add DFPIS5V compile flag * PR cleanup * PR cleanup * Stick to previous DFP lib 1.2.2 * Removed or replaced problematic sound files * Merge branch 'main' * Merge branch 'feature/nv-config' * Merged 'nv_config' PR and integrated LL/HL config packet * Fix CI * Fix volume down announcement * Add "ROS stopped" announcement * Update ci.yaml * Update ci.yaml * Update ci.yaml * Add 0.13.x resistor comment, update button description, update some minor info * Fix SD-Card detection tampering by volume change * DFP lib version bump * Cut-off Pin-11 (IO2) recommendation for DFPlayer-Clones * Add forgotten readme img * Add new 'JL AB23A799755' clone * Add new 'JL AB23A799755' clone * PlayMowSounds only if ROS is running as well as some minor (comment) changes * Minor code corrections * Align HighLevel States and SubStates with ROS * Simple HighLevelState class for easier handling of HighLevel-Mode and SubMode * Tiny code adaptions and HighLevelState class usage * Add Docking advert and randomized background, move Darth-Vader background sound from mowing to docking * Add Docking advert and background as well as some minor code adaptions * Code review * Prepare background-sound option and small code corrections * Transitional config packet & background sound option * Merge main * Restructure sound in OtherCore as well as Autoplay Detection * Restructured sound track naming and handling * LL/HL logic handling cleanup * Add new DFPlayer clone, adapt some description * Fix comment * Enable sound module @ HW 0.13.x --------- Co-authored-by: Clemens Elflein <[email protected]>
1 parent c9d557b commit 42f5810

File tree

102 files changed

+1151
-245
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+1151
-245
lines changed
Lines changed: 92 additions & 0 deletions

Firmware/LowLevel/include/debug.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Created by Apehaenger on 02/02/23.
2+
//
3+
// This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
4+
//
5+
// Feel free to use the design in your private/educational projects, but don't try to sell the design or products based on it without getting my consent first.
6+
//
7+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
8+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
10+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
11+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
12+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
13+
// SOFTWARE.
14+
//
15+
//
16+
#ifndef _DEBUG_H_
17+
#define _DEBUG_H_
18+
19+
// Define to stream debugging messages via USB
20+
//#define USB_DEBUG
21+
22+
#ifdef USB_DEBUG
23+
24+
#define DEBUG_SERIAL Serial
25+
// #define DfMiniMp3Debug DEBUG_SERIAL // Also output DFPlayer IN/OUT cmd data
26+
27+
// Some bloody simple debug macros which superfluous '#ifdef USB_DEBUG' ...
28+
#define DEBUG_BEGIN(b) \
29+
DEBUG_SERIAL.begin(b); \
30+
while (!DEBUG_SERIAL);
31+
#define DEBUG_PRINTLN(str) DEBUG_SERIAL.println(str)
32+
#define DEBUG_PRINTF(fmt, ...) \
33+
do { \
34+
DEBUG_SERIAL.printf(fmt, ##__VA_ARGS__); \
35+
} while (0)
36+
#define PRINTF_BINARY_PATTERN_INT8 "%c%c%c%c%c%c%c%c"
37+
#define PRINTF_BYTE_TO_BINARY_INT8(i) \
38+
(((i) & 0x80ll) ? '1' : '0'), (((i) & 0x40ll) ? '1' : '0'), (((i) & 0x20ll) ? '1' : '0'), (((i) & 0x10ll) ? '1' : '0'), \
39+
(((i) & 0x08ll) ? '1' : '0'), (((i) & 0x04ll) ? '1' : '0'), (((i) & 0x02ll) ? '1' : '0'), (((i) & 0x01ll) ? '1' : '0')
40+
41+
#else
42+
43+
#define DEBUG_BEGIN(b)
44+
#define DEBUG_PRINTLN(str)
45+
#define DEBUG_PRINTF(fmt, ...)
46+
#define PRINTF_BINARY_PATTERN_INT8
47+
#define PRINTF_BYTE_TO_BINARY_INT8(i)
48+
#endif
49+
50+
#endif // _DEBUG_H_

Firmware/LowLevel/include/soundsystem.h

Lines changed: 74 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -17,53 +17,84 @@
1717
#ifndef _SOUND_SYSTEM_H_
1818
#define _SOUND_SYSTEM_H_
1919

20-
//#include <Arduino.h>
20+
#include <Arduino.h>
2121
#include <stdint.h>
22-
#include <list>
23-
24-
#include <pins.h>
25-
#include <DFPlayerMini_Fast.h>
26-
#include <soundsystem.h>
27-
28-
29-
#define BUFFERSIZE 100
30-
31-
32-
class MP3Sound
33-
{
34-
35-
36-
37-
38-
public:
39-
40-
int16_t anzSoundfiles; // number of files stored on the SD-card
41-
bool playing;
42-
43-
MP3Sound();
4422

45-
bool begin(); // init serial stream and soundmodule, anzsoundOnSD : maximum number of available soundfiles on the SD-card
46-
47-
void playSound(int soundNr); // play soundfile number. This method writes soundfile nr in a list, the method processSounds() (has to run in loop) will play
48-
// the sounds according to the list
49-
50-
void playSoundAdHoc(int soundNr); // play soundfile number immediately whithout waiting until the end of sound
51-
52-
void setvolume(int vol); // scales loudness from 0 to 100 %
53-
54-
int sounds2play(); // returns the number if sounds to play in the list
55-
56-
int processSounds(); // play all sounds from the list. This method has to be calles cyclic, e.g. every second.
23+
#include <list>
24+
#include <map>
25+
#include <string>
5726

58-
59-
private:
60-
std::list <int> active_sounds;
61-
bool sound_available;
62-
27+
#include "datatypes.h"
6328

64-
29+
namespace soundSystem {
6530

31+
enum class TrackType {
32+
BACKGROUND = 1, // Background tracks are stored in folder mp3 and get interrupted/aborted by higher priority sound like advert
33+
ADVERT, // Advert tracks are stored in language specific folder, i.e. "01" US or "49" German, and interrupt/stop background sounds
34+
};
35+
struct CardSources {
36+
bool origin : 1; // This sound track is available on origin SD-Card
37+
bool improve_sound : 1; // Available since ImproveSound PR
38+
};
39+
struct TrackFlags {
40+
bool repeat : 1; // Repeat this track. This flag is limited to background sounds!
41+
bool stop_background : 1; // Stop replaying of a current running background track after this sound got played
42+
};
43+
struct TrackDef {
44+
uint16_t num; // SD-Card's track number
45+
TrackType type;
46+
CardSources card_sources;
47+
TrackFlags track_flags;
48+
unsigned long pauseAfter = 0; // Cosmetic pause in ms, after advert track got played, before the next sound get processed from queue.
49+
int32_t repeatDuration = 180000; // How long (ms) to repeat a background sound. Default to 180 sec. noise pollution (i.e. VdS 2300)
6650
};
6751

68-
69-
#endif // _SOUND_SYSTEM_H_ HEADER_FILE
52+
// For better reading, let's use track macro names with the detailed track definition
53+
// clang-format off
54+
#define SOUND_TRACK_BGD_OM_BOOT TrackDef{ 2, TrackType::BACKGROUND, CardSources{.improve_sound=true}, TrackFlags{.repeat=true}}
55+
#define SOUND_TRACK_ADV_HI_IM_STEVE TrackDef{ 1, TrackType::ADVERT, CardSources{.origin=true, .improve_sound=true}, .pauseAfter=1500}
56+
#define SOUND_TRACK_ADV_IMU_INIT_FAILED TrackDef{19, TrackType::ADVERT, CardSources{.improve_sound=true}, .pauseAfter=500}
57+
#define SOUND_TRACK_BGD_OM_ALARM TrackDef{15, TrackType::BACKGROUND, CardSources{.improve_sound=true}, TrackFlags{.repeat=true}, .repeatDuration=20000}
58+
#define SOUND_TRACK_ADV_EMERGENCY_STOP TrackDef{ 8, TrackType::ADVERT, CardSources{.origin=true, .improve_sound=true}, TrackFlags{.stop_background=true}, .pauseAfter = 500}
59+
#define SOUND_TRACK_ADV_EMERGENCY_LIFT TrackDef{ 9, TrackType::ADVERT, CardSources{.origin=true, .improve_sound=true}, TrackFlags{.stop_background=true}, .pauseAfter = 500}
60+
#define SOUND_TRACK_ADV_EMERGENCY_ROS TrackDef{24, TrackType::ADVERT, CardSources{.improve_sound=true}, TrackFlags{.stop_background=true}, .pauseAfter = 500}
61+
#define SOUND_TRACK_ADV_EMERGENCY_CLEARED TrackDef{23, TrackType::ADVERT, CardSources{.improve_sound=true}, TrackFlags{.stop_background=true}, .pauseAfter = 500}
62+
#define SOUND_TRACK_BGD_EMERGENCY_ALARM TrackDef{ 9, TrackType::BACKGROUND, CardSources{.improve_sound=true}}
63+
#define SOUND_TRACK_ADV_OM_STARTUP_SUCCESS TrackDef{ 2, TrackType::ADVERT, CardSources{.origin=true, .improve_sound=true}, .pauseAfter = 1500}
64+
#define SOUND_TRACK_ADV_ROS_INIT TrackDef{ 3, TrackType::ADVERT, CardSources{.origin=true, .improve_sound=true}, TrackFlags{.stop_background=true}, .pauseAfter = 500}
65+
#define SOUND_TRACK_BGD_ROS_BOOT TrackDef{ 5, TrackType::BACKGROUND, CardSources{.improve_sound=true}, TrackFlags{.repeat=true}}
66+
#define SOUND_TRACK_ADV_ROS_STARTUP_SUCCESS TrackDef{16, TrackType::ADVERT, CardSources{.improve_sound=true}, TrackFlags{.stop_background=true}}
67+
#define SOUND_TRACK_ADV_ROS_STOPPED TrackDef{17, TrackType::ADVERT, CardSources{.improve_sound=true}, TrackFlags{.stop_background=true}}
68+
#define SOUND_TRACK_ADV_MAP_RECORD_START TrackDef{ 4, TrackType::ADVERT, CardSources{.origin=true, .improve_sound=true}, TrackFlags{.stop_background=true}}
69+
#define SOUND_TRACK_ADV_AUTONOMOUS_START TrackDef{12, TrackType::ADVERT, CardSources{.origin=true, .improve_sound=true}, TrackFlags{.stop_background=true}, .pauseAfter = 1500}
70+
#define SOUND_TRACK_ADV_RAIN TrackDef{10, TrackType::ADVERT, CardSources{.origin=true, .improve_sound=true}, TrackFlags{.stop_background=true}, .pauseAfter = 3000}
71+
#define SOUND_TRACK_ADV_RTKGPS_WAIT TrackDef{ 5, TrackType::ADVERT, CardSources{.origin=true, .improve_sound=true}, .pauseAfter = 1500}
72+
#define SOUND_TRACK_ADV_RTKGPS_POOR TrackDef{20, TrackType::BACKGROUND, CardSources{.improve_sound=true}}
73+
#define SOUND_TRACK_ADV_RTKGPS_MODERATE TrackDef{21, TrackType::BACKGROUND, CardSources{.improve_sound=true}}
74+
#define SOUND_TRACK_ADV_RTKGPS_GOOD TrackDef{22, TrackType::BACKGROUND, CardSources{.improve_sound=true}}
75+
#define SOUND_TRACK_BGD_MUSIC_PINK_PANTHER TrackDef{12, TrackType::BACKGROUND, CardSources{.improve_sound=true}}
76+
#define SOUND_TRACK_ADV_UP TrackDef{21, TrackType::ADVERT, CardSources{.improve_sound=true}, .pauseAfter = 100}
77+
#define SOUND_TRACK_ADV_DOWN TrackDef{20, TrackType::ADVERT, CardSources{.improve_sound=true}, .pauseAfter = 100}
78+
#define SOUND_TRACK_ADV_LANGUAGE TrackDef{22, TrackType::ADVERT, CardSources{.improve_sound=true}, .pauseAfter = 100}
79+
#define SOUND_TRACK_ADV_MOW_DONE_DOCK TrackDef{11, TrackType::ADVERT, CardSources{.improve_sound=true}, TrackFlags{.stop_background=true}, .pauseAfter = 3000}
80+
// clang-format on
81+
82+
bool begin(); // Init serial stream, soundmodule and sound_available_
83+
84+
void playSound(const TrackDef&); // Play sound trackDef. This method writes sound trackDef in a list, the method processSounds() (has to run in loop) will play the sounds according to the list
85+
void playSoundAdHoc(const TrackDef&); // Play sound track number immediately without waiting until the end of sound
86+
87+
void setDFPis5V(const bool t_dfpis5v); // Set if DFP is set to 5V Vcc
88+
void setEnableBackground(const bool); // Set if background sounds shall get played (true) or not (false)
89+
90+
void setLanguage(const iso639_1 language_p, const bool quiet = false); // Set language to the pointing ISO639-1 (2 char) language code and announce if changed and not quiet
91+
92+
void setVolume(const uint8_t t_vol); // Set volume (0-100%)
93+
uint8_t setVolumeUp(); // Scale volume up by VOLUME_STEPS and return new volume (%)
94+
uint8_t setVolumeDown(); // Scale volume down by VOLUME_STEPS and return new volume (%)
95+
96+
void applyConfig(const ll_high_level_config t_config, const bool quiet); // Apply the volume specific config options
97+
98+
void processSounds(const ll_status t_ll_state, const bool t_ros_running, const ll_high_level_state t_hl_state); // This method has to be called cyclic, e.g. every second.
99+
} // namespace soundSystem
100+
#endif // _SOUND_SYSTEM_H_ HEADER_FILE

Firmware/LowLevel/platformio.ini

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,79 +42,82 @@ board_build.f_cpu = 133000000L
4242
lib_ldf_mode = off
4343
debug_build_flags = -O0 -g -ggdb
4444

45-
build_src_filter = +<*> -<.git/> -<.svn/> -<imu/*> -<soundsystem.cpp>
45+
build_src_filter = +<*> -<.git/> -<.svn/> -<imu/*>
46+
47+
[sound]
48+
lib_deps = makuna/DFPlayer Mini Mp3 by Makuna@^1.2.3
4649

4750
[env:0_13_X]
4851
lib_ignore = JY901_SERIAL,JY901_I2C
4952
lib_deps = ${env.lib_deps}
53+
${sound.lib_deps}
5054
stm32duino/STM32duino LSM6DSO@^2.0.3
51-
powerbroker2/DFPlayerMini_Fast@^1.2.4
5255
build_src_filter = ${env.build_src_filter} +<imu/LSM6DSO/>
53-
build_flags = ${env.build_flags} -DHW_0_13_X
56+
build_flags = ${env.build_flags} -DHW_0_13_X -DENABLE_SOUND_MODULE
5457

5558
[env:0_12_X]
5659
lib_ignore = JY901_SERIAL,JY901_I2C
5760
lib_deps = ${env.lib_deps}
61+
${sound.lib_deps}
5862
stm32duino/STM32duino LSM6DSO@^2.0.3
5963
jpiat/PioSPI@^0.0.1
60-
powerbroker2/DFPlayerMini_Fast@^1.2.4
61-
build_src_filter = ${env.build_src_filter} +<imu/LSM6DSO/> +<soundsystem.cpp>
64+
build_src_filter = ${env.build_src_filter} +<imu/LSM6DSO/>
6265
build_flags = ${env.build_flags} -DHW_0_12_X -DENABLE_SOUND_MODULE
6366

6467

6568
[env:0_11_X_MPU9250]
6669
lib_ignore = JY901_SERIAL,JY901_I2C
6770
lib_deps = ${env.lib_deps}
71+
${sound.lib_deps}
6872
bolderflight/Bolder Flight Systems MPU9250@^1.0.2
69-
powerbroker2/DFPlayerMini_Fast@^1.2.4
70-
build_src_filter = ${env.build_src_filter} +<imu/MPU9250/> +<soundsystem.cpp>
73+
build_src_filter = ${env.build_src_filter} +<imu/MPU9250/>
7174
build_flags = ${env.build_flags} -DHW_0_11_X -DENABLE_SOUND_MODULE
7275

7376
[env:0_11_X_WT901]
74-
build_src_filter = ${env.build_src_filter} +<imu/WT901_I2C/> +<soundsystem.cpp>
77+
build_src_filter = ${env.build_src_filter} +<imu/WT901_I2C/>
7578
lib_ignore = JY901_SERIAL
7679
lib_deps = ${env.lib_deps}
77-
powerbroker2/DFPlayerMini_Fast@^1.2.4
80+
${sound.lib_deps}
7881
JY901_I2C
7982
build_flags = ${env.build_flags} -DWT901_I2C -DHW_0_11_X -DENABLE_SOUND_MODULE
8083

8184

8285
[env:0_10_X_MPU9250]
8386
lib_ignore = JY901_SERIAL,JY901_I2C
8487
lib_deps = ${env.lib_deps}
88+
${sound.lib_deps}
8589
bolderflight/Bolder Flight Systems MPU9250@^1.0.2
86-
powerbroker2/DFPlayerMini_Fast@^1.2.4
87-
build_src_filter = ${env.build_src_filter} +<imu/MPU9250/> +<soundsystem.cpp>
90+
build_src_filter = ${env.build_src_filter} +<imu/MPU9250/>
8891
build_flags = ${env.build_flags} -DHW_0_10_X -DENABLE_SOUND_MODULE
8992

9093
[env:0_10_X_WT901]
91-
build_src_filter = ${env.build_src_filter} +<imu/WT901_I2C/> +<soundsystem.cpp>
94+
build_src_filter = ${env.build_src_filter} +<imu/WT901_I2C/>
9295
lib_ignore = JY901_SERIAL
9396
lib_deps = ${env.lib_deps}
94-
powerbroker2/DFPlayerMini_Fast@^1.2.4
97+
${sound.lib_deps}
9598
JY901_I2C
9699
build_flags = ${env.build_flags} -DWT901_I2C -DHW_0_10_X -DENABLE_SOUND_MODULE
97100

98101

99102
[env:0_9_X_MPU9250]
100103
lib_ignore = JY901_SERIAL,JY901_I2C
101104
lib_deps = ${env.lib_deps}
105+
${sound.lib_deps}
102106
bolderflight/Bolder Flight Systems MPU9250@^1.0.2
103-
powerbroker2/DFPlayerMini_Fast@^1.2.4
104-
build_src_filter = ${env.build_src_filter} +<imu/MPU9250/> +<soundsystem.cpp>
107+
build_src_filter = ${env.build_src_filter} +<imu/MPU9250/>
105108
build_flags = ${env.build_flags} -DHW_0_9_X -DENABLE_SOUND_MODULE
106109

107110
[env:0_9_X_WT901_INSTEAD_OF_SOUND]
108111
lib_ignore = JY901_I2C
109-
build_src_filter = ${env.build_src_filter} +<imu/WT901_SERIAL/>
112+
build_src_filter = ${env.build_src_filter} +<imu/WT901_SERIAL/> -<soundsystem.cpp>
110113
lib_deps = ${env.lib_deps}
111114
JY901_SERIAL
112115
build_flags = ${env.build_flags} -DWT901_INSTEAD_OF_SOUND -DHW_0_9_X
113116

114117
[env:0_9_X_WT901]
115118
lib_ignore = JY901_I2C
116-
build_src_filter = ${env.build_src_filter} +<imu/WT901_SERIAL/> +<soundsystem.cpp>
119+
build_src_filter = ${env.build_src_filter} +<imu/WT901_SERIAL/>
117120
lib_deps = ${env.lib_deps}
121+
${sound.lib_deps}
118122
JY901_SERIAL
119-
powerbroker2/DFPlayerMini_Fast@^1.2.4
120123
build_flags = ${env.build_flags} -DWT901 -DHW_0_9_X -DENABLE_SOUND_MODULE
-18.2 KB
Binary file not shown.
157 KB
Binary file not shown.
-8.63 KB
Binary file not shown.
-9.94 KB
Binary file not shown.
-7.88 KB
Binary file not shown.
-11 KB
Binary file not shown.

0 commit comments

Comments
 (0)