Skip to content

Commit aa0e305

Browse files
committed
pbio/drv/sound: add default volume config option
Add a default volume configuration option for each platform that supports sound. The EV3 speaker can be quite loud, so we don't want it to default to 100%.
1 parent 1c4fe54 commit aa0e305

File tree

4 files changed

+4
-1
lines changed

4 files changed

+4
-1
lines changed

lib/pbio/platform/ev3/pbdrvconfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272

7373
#define PBDRV_CONFIG_SOUND (1)
7474
#define PBDRV_CONFIG_SOUND_EV3 (1)
75+
#define PBDRV_CONFIG_SOUND_DEFAULT_VOLUME 75
7576

7677
#define PBDRV_CONFIG_UART (1)
7778
#define PBDRV_CONFIG_UART_DEBUG_FIRST_PORT (1)

lib/pbio/platform/nxt/pbdrvconfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#define PBDRV_CONFIG_RESET_NXT (1)
4343

4444
#define PBDRV_CONFIG_SOUND (1)
45+
#define PBDRV_CONFIG_SOUND_DEFAULT_VOLUME 100
4546
#define PBDRV_CONFIG_SOUND_SAMPLED (1)
4647
#define PBDRV_CONFIG_SOUND_BEEP_SAMPLED (1)
4748
#define PBDRV_CONFIG_SOUND_NXT (1)

lib/pbio/platform/prime_hub/pbdrvconfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
#define PBDRV_CONFIG_RESISTOR_LADDER_NUM_DEV (2)
105105

106106
#define PBDRV_CONFIG_SOUND (1)
107+
#define PBDRV_CONFIG_SOUND_DEFAULT_VOLUME 100
107108
#define PBDRV_CONFIG_SOUND_SAMPLED (1)
108109
#define PBDRV_CONFIG_SOUND_BEEP_SAMPLED (1)
109110
#define PBDRV_CONFIG_SOUND_STM32_HAL_DAC (1)

pybricks/common/pb_type_speaker.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static mp_obj_t pb_type_Speaker_make_new(const mp_obj_type_t *type, size_t n_arg
7979

8080
// REVISIT: If a user creates two Speaker instances, this will reset the volume settings for both.
8181
// If done only once per singleton, however, altered volume settings would be persisted between program runs.
82-
self->volume = 100;
82+
self->volume = PBDRV_CONFIG_SOUND_DEFAULT_VOLUME;
8383
self->sample_attenuator = INT16_MAX;
8484

8585
return MP_OBJ_FROM_PTR(self);

0 commit comments

Comments
 (0)