Skip to content

Commit 134e583

Browse files
committed
fw/applib: Provide sdk music volume and sound for iOS find phone apps and others
Signed-off-by: Federico Bechini <federico.bechini@gmail.com>
1 parent c52f432 commit 134e583

10 files changed

Lines changed: 107 additions & 10 deletions

File tree

include/pbl/services/music.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void music_get_pos(uint32_t *track_pos_ms, uint32_t *track_length_ms);
6262
int32_t music_get_playback_rate_percent(void);
6363

6464
//! @return The volume percentage.
65-
uint8_t music_get_volume_percent(void);
65+
uint8_t music_service_get_volume_percent(void);
6666

6767
//! Retrieve the current playback state.
6868
MusicPlayState music_get_playback_state(void);
@@ -76,7 +76,7 @@ bool music_is_playback_state_reporting_supported(void);
7676
bool music_is_progress_reporting_supported(void);
7777

7878
//! @return True if the service supports reporting of the current volume.
79-
//! @see music_get_volume_percent
79+
//! @see music_service_get_volume_percent
8080
bool music_is_volume_reporting_supported(void);
8181

8282
//! Sends the command to the server. Commands are "unreliable", they are sent at "best effort".

sdk/include/_pkjs_message_wrapper.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@
118118
["addEventListener", "removeEventListener", "showSimpleNotificationOnPebble",
119119
"sendAppMessage", "getTimelineToken", "timelineSubscribe",
120120
"timelineUnsubscribe", "timelineSubscriptions", "getActiveWatchInfo",
121-
"getAccountToken", "getWatchToken", "appGlanceReload"].forEach(
121+
"getAccountToken", "getWatchToken", "appGlanceReload",
122+
"playSound", "playSoundById", "playDefaultRingtone", "stopSound"].forEach(
122123
function(elem, idx, arr) {
123124
if ((elem in Pebble) || ((typeof __Pebble[elem]) !== 'function')) {
124125
// This function has already been copied over or doesn't actually exist.

src/fw/applib/music_service.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* SPDX-FileCopyrightText: 2024 Google LLC */
2+
/* SPDX-License-Identifier: Apache-2.0 */
3+
4+
#include "music_service.h"
5+
#include "syscall/syscall.h"
6+
#include "pbl/services/music.h"
7+
8+
void music_volume_up(void) {
9+
sys_music_command_send(MusicCommandVolumeUp);
10+
}
11+
12+
void music_volume_down(void) {
13+
sys_music_command_send(MusicCommandVolumeDown);
14+
}
15+
16+
uint8_t music_get_volume_percent(void) {
17+
return sys_music_get_volume_percent();
18+
}

src/fw/applib/music_service.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/* SPDX-FileCopyrightText: 2024 Google LLC */
2+
/* SPDX-License-Identifier: Apache-2.0 */
3+
4+
#pragma once
5+
6+
#include <stdint.h>
7+
8+
/**
9+
* @file music_service.h
10+
* @brief Music Service for controlling mobile device volume.
11+
*/
12+
13+
/**
14+
* @addtogroup Foundation
15+
* @{
16+
* @addtogroup MusicService
17+
* @{
18+
*/
19+
20+
/**
21+
* Sends a "Volume Up" command to the mobile device.
22+
* This command is sent to the currently active media player on the phone.
23+
*/
24+
void music_volume_up(void);
25+
26+
/**
27+
* Sends a "Volume Down" command to the mobile device.
28+
* This command is sent to the currently active media player on the phone.
29+
*/
30+
void music_volume_down(void);
31+
32+
/**
33+
* Gets the current volume level of the mobile device's media player.
34+
* @return Volume as a percentage from 0 to 100, or 255 if not available.
35+
*/
36+
uint8_t music_get_volume_percent(void);
37+
38+
/**
39+
* @} // end addtogroup MusicService
40+
* @} // end addtogroup Foundation
41+
*/

src/fw/process_management/pebble_process_info.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,9 @@ typedef enum {
163163
// sdk.major:0x5 .minor:0x5f -- speaker_play_tone() now plays the exact frequency (rev 98)
164164
// sdk.major:0x5 .minor:0x60 -- Add persist_get_max_size() for runtime persist storage capacity (rev 99)
165165
// sdk.major:0x5 .minor:0x61 -- Add speaker_is_muted() for system-wide speaker mute query (rev 100)
166-
// sdk.major:0x5 .minor:0x62 -- Add backlight_service_subscribe/unsubscribe for backlight on/off events (rev 101)
167-
166+
// sdk.major:0x5 .minor:0x63 -- Music Service volume control (rev 102)
168167
#define PROCESS_INFO_CURRENT_SDK_VERSION_MAJOR 0x5
169-
#define PROCESS_INFO_CURRENT_SDK_VERSION_MINOR 0x62
168+
#define PROCESS_INFO_CURRENT_SDK_VERSION_MINOR 0x63
170169

171170
// The first SDK to ship with 2.x APIs
172171
#define PROCESS_INFO_FIRST_2X_SDK_VERSION_MAJOR 0x4

src/fw/services/music/service.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ int32_t music_get_playback_rate_percent(void) {
294294
return playback_rate_percent;
295295
}
296296

297-
uint8_t music_get_volume_percent(void) {
297+
uint8_t music_service_get_volume_percent(void) {
298298
mutex_lock_recursive(s_music_ctx.mutex);
299299
int32_t player_volume_percent = s_music_ctx.player_volume_percent;
300300
mutex_unlock_recursive(s_music_ctx.mutex);

src/fw/syscall/syscall.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,4 +305,8 @@ WatchInfoColor sys_watch_info_get_color(void);
305305
//! choice and avoid disturbing actions such as vibration if quiet time is active.
306306
//! @return True, if Quiet Time is currently active.
307307
bool sys_do_not_disturb_is_active(void);
308+
// Music control syscalls
309+
void sys_music_command_send(MusicCommand command);
310+
uint8_t sys_music_get_volume_percent(void);
311+
308312
//! @} // end addtogroup Preferences

src/fw/syscall/syscall_music.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* SPDX-FileCopyrightText: 2024 Google LLC */
2+
/* SPDX-License-Identifier: Apache-2.0 */
3+
4+
#include "pbl/services/music.h"
5+
#include "syscall/syscall_internal.h"
6+
7+
DEFINE_SYSCALL(void, sys_music_command_send, MusicCommand command) {
8+
music_command_send(command);
9+
}
10+
11+
DEFINE_SYSCALL(uint8_t, sys_music_get_volume_percent, void) {
12+
return music_service_get_volume_percent();
13+
}

tests/fw/services/test_music_endpoint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ static void prv_receive_and_assert_volume_info(bool expect_is_handled) {
115115
cl_assert_equal_i(e.type, PEBBLE_MEDIA_EVENT);
116116
cl_assert_equal_i(e.media.type, PebbleMediaEventTypeVolumeChanged);
117117

118-
cl_assert_equal_i(music_get_volume_percent(), 0x33);
118+
cl_assert_equal_i(music_service_get_volume_percent(), 0x33);
119119

120120
} else {
121121
cl_assert_equal_i(e.type, PEBBLE_NULL_EVENT);

tools/generate_native_sdk/exported_symbols.json

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"You should also make sure you are obeying our API design guidelines:",
55
"https://pebbletechnology.atlassian.net/wiki/display/DEV/SDK+API+Design+Guidelines"
66
],
7-
"revision" : "101",
7+
"revision" : "102",
88
"version" : "2.0",
99
"files": [
1010
"fw/drivers/ambient_light.h",
@@ -128,7 +128,8 @@
128128
"fw/applib/voice/dictation_session.h",
129129
"fw/applib/ui/content_indicator.h",
130130
"fw/applib/rockyjs/rocky.h",
131-
"fw/applib/unobstructed_area_service.h"
131+
"fw/applib/unobstructed_area_service.h",
132+
"fw/applib/music_service.h"
132133
],
133134
"exports": [
134135
{
@@ -851,6 +852,26 @@
851852
"name": "AppLogLevel"
852853
}
853854
]
855+
}, {
856+
"type": "group",
857+
"name": "MusicService",
858+
"exports": [
859+
{
860+
"type": "function",
861+
"name": "music_volume_up",
862+
"addedRevision": "102"
863+
},
864+
{
865+
"type": "function",
866+
"name": "music_volume_down",
867+
"addedRevision": "102"
868+
},
869+
{
870+
"type": "function",
871+
"name": "music_get_volume_percent",
872+
"addedRevision": "102"
873+
}
874+
]
854875
}, {
855876
"type": "group",
856877
"name": "Dictionary",

0 commit comments

Comments
 (0)