@geastack/host 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +25 -0
- package/audio_runtime.cpp +807 -0
- package/bluetooth.cpp +125 -0
- package/geolocation.cpp +43 -0
- package/host/apps.cpp +20 -0
- package/host/audio.cpp +240 -0
- package/host/ble.cpp +239 -0
- package/host/camera.cpp +193 -0
- package/host/display.cpp +230 -0
- package/host/fetch.cpp +1060 -0
- package/host/geolocation.cpp +31 -0
- package/host/gpio.cpp +55 -0
- package/host/http.cpp +349 -0
- package/host/image.cpp +335 -0
- package/host/imu.cpp +51 -0
- package/host/input.cpp +12 -0
- package/host/media.cpp +579 -0
- package/host/memory.cpp +91 -0
- package/host/rtc.cpp +212 -0
- package/host/rtc_esp.cpp +291 -0
- package/host/tile_loader.cpp +478 -0
- package/host/timers.cpp +327 -0
- package/host/touch.cpp +25 -0
- package/host/websocket.cpp +279 -0
- package/host/wifi.cpp +99 -0
- package/include/gea/embedded-host.h +38 -0
- package/include/host/apps.h +15 -0
- package/include/host/audio.h +158 -0
- package/include/host/backends.h +455 -0
- package/include/host/battery.h +25 -0
- package/include/host/camera.h +236 -0
- package/include/host/clock.h +45 -0
- package/include/host/device_control.h +23 -0
- package/include/host/display.h +266 -0
- package/include/host/display_orientation.h +291 -0
- package/include/host/fetch.h +310 -0
- package/include/host/gpio.h +36 -0
- package/include/host/http.h +161 -0
- package/include/host/image.h +144 -0
- package/include/host/input.h +14 -0
- package/include/host/media.h +165 -0
- package/include/host/memory.h +44 -0
- package/include/host/navigator.h +283 -0
- package/include/host/notify.h +41 -0
- package/include/host/profiler.h +49 -0
- package/include/host/rtc.h +174 -0
- package/include/host/storage.h +141 -0
- package/include/host/tile_loader.h +59 -0
- package/include/host/timers.h +41 -0
- package/include/host/touch.h +20 -0
- package/include/host/websocket.h +179 -0
- package/include/host/window.h +31 -0
- package/input.cpp +68 -0
- package/package.json +27 -0
- package/services/app_state.cpp +19 -0
- package/services/battery_service.cpp +19 -0
- package/services/bluetooth_service.cpp +37 -0
- package/services/diagnostics.cpp +233 -0
- package/services/diagnostics_connection.cpp +231 -0
- package/services/diagnostics_internal.h +15 -0
- package/services/diagnostics_server.cpp +135 -0
- package/services/mirror.cpp +364 -0
- package/services/network_services.cpp +62 -0
- package/services/runtime_log.cpp +23 -0
- package/services/settings_surface.h +221 -0
- package/wifi.cpp +185 -0
package/bluetooth.cpp
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#include "ble.h"
|
|
3
|
+
|
|
4
|
+
namespace gea::framework::bluetooth {
|
|
5
|
+
|
|
6
|
+
namespace {
|
|
7
|
+
|
|
8
|
+
class NullBluetoothHidDriver final : public BluetoothHidDriver {
|
|
9
|
+
public:
|
|
10
|
+
void preinit() override {}
|
|
11
|
+
void init(const char *deviceName, std::uint16_t appearance, const char *macAddress) override
|
|
12
|
+
{
|
|
13
|
+
(void)deviceName;
|
|
14
|
+
(void)appearance;
|
|
15
|
+
(void)macAddress;
|
|
16
|
+
}
|
|
17
|
+
bool enabled() const override { return false; }
|
|
18
|
+
void setEnabled(bool enabled) override { (void)enabled; }
|
|
19
|
+
void startAdvertising() override {}
|
|
20
|
+
void stopAdvertising() override {}
|
|
21
|
+
bool connected() const override { return false; }
|
|
22
|
+
bool bound() const override { return false; }
|
|
23
|
+
std::uint8_t batteryLevel() const override { return 0; }
|
|
24
|
+
const char *mac() override { return ""; }
|
|
25
|
+
const char *deviceName() const override { return ""; }
|
|
26
|
+
void keyTap(int hidCode) override { (void)hidCode; }
|
|
27
|
+
void keyDown(int modifier, int hidCode) override
|
|
28
|
+
{
|
|
29
|
+
(void)modifier;
|
|
30
|
+
(void)hidCode;
|
|
31
|
+
}
|
|
32
|
+
void keyUp() override {}
|
|
33
|
+
void mouseMove(int dx, int dy, int buttons, int wheel) override
|
|
34
|
+
{
|
|
35
|
+
(void)dx;
|
|
36
|
+
(void)dy;
|
|
37
|
+
(void)buttons;
|
|
38
|
+
(void)wheel;
|
|
39
|
+
}
|
|
40
|
+
void mouseClick(int button) override { (void)button; }
|
|
41
|
+
void setBatteryLevel(std::uint8_t level) override { (void)level; }
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
NullBluetoothHidDriver &nullDriver()
|
|
45
|
+
{
|
|
46
|
+
static NullBluetoothHidDriver driver;
|
|
47
|
+
return driver;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
BluetoothHidDriver *&driverSlot()
|
|
51
|
+
{
|
|
52
|
+
static BluetoothHidDriver *driver = &nullDriver();
|
|
53
|
+
return driver;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
} // namespace
|
|
57
|
+
|
|
58
|
+
void BluetoothHidDevice::setDriver(BluetoothHidDriver *driver)
|
|
59
|
+
{
|
|
60
|
+
driverSlot() = driver ? driver : &nullDriver();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
BluetoothHidDriver *BluetoothHidDevice::driver()
|
|
64
|
+
{
|
|
65
|
+
return driverSlot();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
void BluetoothHidDevice::preinit() const { driver()->preinit(); }
|
|
69
|
+
|
|
70
|
+
void BluetoothHidDevice::init(const char *deviceName, std::uint16_t appearance, const char *macAddress) const
|
|
71
|
+
{
|
|
72
|
+
driver()->init(deviceName, appearance, macAddress);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
bool BluetoothHidDevice::enabled() const { return driver()->enabled(); }
|
|
76
|
+
void BluetoothHidDevice::setEnabled(bool enabled) const { driver()->setEnabled(enabled); }
|
|
77
|
+
void BluetoothHidDevice::startAdvertising() const { driver()->startAdvertising(); }
|
|
78
|
+
void BluetoothHidDevice::stopAdvertising() const { driver()->stopAdvertising(); }
|
|
79
|
+
bool BluetoothHidDevice::connected() const { return driver()->connected(); }
|
|
80
|
+
bool BluetoothHidDevice::bound() const { return driver()->bound(); }
|
|
81
|
+
std::uint8_t BluetoothHidDevice::batteryLevel() const { return driver()->batteryLevel(); }
|
|
82
|
+
const char *BluetoothHidDevice::mac() const { return driver()->mac(); }
|
|
83
|
+
const char *BluetoothHidDevice::deviceName() const { return driver()->deviceName(); }
|
|
84
|
+
void BluetoothHidDevice::keyTap(int hidCode) const { driver()->keyTap(hidCode); }
|
|
85
|
+
void BluetoothHidDevice::keyDown(int modifier, int hidCode) const { driver()->keyDown(modifier, hidCode); }
|
|
86
|
+
void BluetoothHidDevice::keyUp() const { driver()->keyUp(); }
|
|
87
|
+
void BluetoothHidDevice::mouseMove(int dx, int dy, int buttons, int wheel) const { driver()->mouseMove(dx, dy, buttons, wheel); }
|
|
88
|
+
void BluetoothHidDevice::mouseClick(int button) const { driver()->mouseClick(button); }
|
|
89
|
+
void BluetoothHidDevice::setBatteryLevel(std::uint8_t level) const { driver()->setBatteryLevel(level); }
|
|
90
|
+
void BluetoothHidDevice::midiEnable() const { driver()->midiEnable(); }
|
|
91
|
+
bool BluetoothHidDevice::midiBound() const { return driver()->midiBound(); }
|
|
92
|
+
void BluetoothHidDevice::midiSend(const std::uint8_t *packet, int length) const { driver()->midiSend(packet, length); }
|
|
93
|
+
void BluetoothHidDevice::midiStartScan() const { driver()->midiStartScan(); }
|
|
94
|
+
void BluetoothHidDevice::midiStopScan() const { driver()->midiStopScan(); }
|
|
95
|
+
bool BluetoothHidDevice::midiScanning() const { return driver()->midiScanning(); }
|
|
96
|
+
int BluetoothHidDevice::midiScanCount() const { return driver()->midiScanCount(); }
|
|
97
|
+
const char *BluetoothHidDevice::midiScanNameAt(int index) const { return driver()->midiScanNameAt(index); }
|
|
98
|
+
void BluetoothHidDevice::midiConnect(int index) const { driver()->midiConnect(index); }
|
|
99
|
+
void BluetoothHidDevice::midiDisconnect() const { driver()->midiDisconnect(); }
|
|
100
|
+
void BluetoothHidDevice::hidHostStartScan() const { driver()->hidHostStartScan(); }
|
|
101
|
+
void BluetoothHidDevice::hidHostStopScan() const { driver()->hidHostStopScan(); }
|
|
102
|
+
bool BluetoothHidDevice::hidHostScanning() const { return driver()->hidHostScanning(); }
|
|
103
|
+
int BluetoothHidDevice::hidHostScanCount() const { return driver()->hidHostScanCount(); }
|
|
104
|
+
const char *BluetoothHidDevice::hidHostScanNameAt(int index) const { return driver()->hidHostScanNameAt(index); }
|
|
105
|
+
void BluetoothHidDevice::hidHostConnect(int index) const { driver()->hidHostConnect(index); }
|
|
106
|
+
void BluetoothHidDevice::hidHostDisconnect() const { driver()->hidHostDisconnect(); }
|
|
107
|
+
bool BluetoothHidDevice::hidHostBound() const { return driver()->hidHostBound(); }
|
|
108
|
+
int BluetoothHidDevice::hidHostReportCount() const { return driver()->hidHostReportCount(); }
|
|
109
|
+
int BluetoothHidDevice::hidHostReportIdAt(int index) const { return driver()->hidHostReportIdAt(index); }
|
|
110
|
+
int BluetoothHidDevice::hidHostReportLenAt(int index) const { return driver()->hidHostReportLenAt(index); }
|
|
111
|
+
int BluetoothHidDevice::hidHostReportByteAt(int index, int byteIndex) const { return driver()->hidHostReportByteAt(index, byteIndex); }
|
|
112
|
+
void BluetoothHidDevice::hidHostClearReports() const { driver()->hidHostClearReports(); }
|
|
113
|
+
int BluetoothHidDevice::connectionCount() const { return driver()->connectionCount(); }
|
|
114
|
+
int BluetoothHidDevice::connectionKindAt(int index) const { return driver()->connectionKindAt(index); }
|
|
115
|
+
const char *BluetoothHidDevice::connectionNameAt(int index) const { return driver()->connectionNameAt(index); }
|
|
116
|
+
void BluetoothHidDevice::configSetDocument(const std::uint8_t *bytes, int length) const { driver()->configSetDocument(bytes, length); }
|
|
117
|
+
int BluetoothHidDevice::configPendingLength() const { return driver()->configPendingLength(); }
|
|
118
|
+
int BluetoothHidDevice::configPendingByteAt(int index) const { return driver()->configPendingByteAt(index); }
|
|
119
|
+
void BluetoothHidDevice::configConsumePending() const { driver()->configConsumePending(); }
|
|
120
|
+
bool BluetoothHidDevice::configPairing() const { return driver()->configPairing(); }
|
|
121
|
+
const char *BluetoothHidDevice::configPairCode() const { return driver()->configPairCode(); }
|
|
122
|
+
void BluetoothHidDevice::configDismissPairing() const { driver()->configDismissPairing(); }
|
|
123
|
+
void BluetoothHidDevice::configPushActivity(int index) const { driver()->configPushActivity(index); }
|
|
124
|
+
|
|
125
|
+
} // namespace gea::framework::bluetooth
|
package/geolocation.cpp
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#include "geolocation.h"
|
|
3
|
+
|
|
4
|
+
namespace gea::framework::geolocation {
|
|
5
|
+
|
|
6
|
+
namespace {
|
|
7
|
+
|
|
8
|
+
class NullGeolocationDriver final : public GeolocationDriver {
|
|
9
|
+
public:
|
|
10
|
+
bool init() override { return false; }
|
|
11
|
+
bool hasFix() const override { return false; }
|
|
12
|
+
GeolocationPosition currentPosition() const override { return {}; }
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
NullGeolocationDriver &nullDriver()
|
|
16
|
+
{
|
|
17
|
+
static NullGeolocationDriver driver;
|
|
18
|
+
return driver;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
GeolocationDriver *&driverSlot()
|
|
22
|
+
{
|
|
23
|
+
static GeolocationDriver *driver = &nullDriver();
|
|
24
|
+
return driver;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
} // namespace
|
|
28
|
+
|
|
29
|
+
void GeolocationAdapter::setDriver(GeolocationDriver *driver)
|
|
30
|
+
{
|
|
31
|
+
driverSlot() = driver ? driver : &nullDriver();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
GeolocationDriver *GeolocationAdapter::driver()
|
|
35
|
+
{
|
|
36
|
+
return driverSlot();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
bool GeolocationAdapter::init() const { return driver()->init(); }
|
|
40
|
+
bool GeolocationAdapter::hasFix() const { return driver()->hasFix(); }
|
|
41
|
+
GeolocationPosition GeolocationAdapter::currentPosition() const { return driver()->currentPosition(); }
|
|
42
|
+
|
|
43
|
+
} // namespace gea::framework::geolocation
|
package/host/apps.cpp
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#include <string>
|
|
3
|
+
|
|
4
|
+
#include "apps.h"
|
|
5
|
+
#include "gea/embedded-host.h"
|
|
6
|
+
|
|
7
|
+
namespace gea::framework::host {
|
|
8
|
+
|
|
9
|
+
class AppHost {
|
|
10
|
+
public:
|
|
11
|
+
static double launch(const std::string &app_id) {
|
|
12
|
+
return apps::AppManager::launch(app_id.c_str()) ? 1.0 : 0.0;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
} // namespace gea::framework::host
|
|
17
|
+
|
|
18
|
+
double gea::host::Apps::launch(const std::string &app_id) const {
|
|
19
|
+
return gea::framework::host::AppHost::launch(app_id);
|
|
20
|
+
}
|
package/host/audio.cpp
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#include "audio.h"
|
|
3
|
+
#include "gea/embedded-host.h"
|
|
4
|
+
#include "ui/document.h" // host/audio.cpp HTMLAudioElement bridge (entangled — moves to elements)
|
|
5
|
+
|
|
6
|
+
#include <cstddef>
|
|
7
|
+
#include <cstdint>
|
|
8
|
+
#include <cstring>
|
|
9
|
+
#include <utility>
|
|
10
|
+
#include <vector>
|
|
11
|
+
|
|
12
|
+
namespace gea::framework::host {
|
|
13
|
+
|
|
14
|
+
class AudioHost {
|
|
15
|
+
public:
|
|
16
|
+
static gea::platform::audio::OscillatorType oscillatorType(double value) {
|
|
17
|
+
switch (static_cast<int>(value)) {
|
|
18
|
+
case 1: return gea::platform::audio::OscillatorType::Square;
|
|
19
|
+
case 2: return gea::platform::audio::OscillatorType::Sawtooth;
|
|
20
|
+
case 3: return gea::platform::audio::OscillatorType::Triangle;
|
|
21
|
+
default: return gea::platform::audio::OscillatorType::Sine;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static gea::platform::audio::AudioContext context() {
|
|
26
|
+
return gea::platform::audio::AudioSystem::sharedContext();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static gea::platform::audio::OscillatorNode oscillator(gea::host::NativeAudioHandle oscillator) {
|
|
30
|
+
return gea::platform::audio::OscillatorNode(oscillator);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static gea::platform::audio::AudioDestinationNode destination(gea::host::NativeAudioHandle destination) {
|
|
34
|
+
return gea::platform::audio::AudioDestinationNode(destination);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
} // namespace gea::framework::host
|
|
39
|
+
|
|
40
|
+
namespace gea::framework::audio {
|
|
41
|
+
|
|
42
|
+
double AudioBackend::volume() {
|
|
43
|
+
return static_cast<double>(gea::platform::audio::AudioSystem::volume());
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
void AudioBackend::setVolume(double volume) {
|
|
47
|
+
gea::platform::audio::AudioSystem::setVolume(static_cast<int>(volume));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
} // namespace gea::framework::audio
|
|
51
|
+
|
|
52
|
+
namespace gea::host {
|
|
53
|
+
|
|
54
|
+
namespace {
|
|
55
|
+
|
|
56
|
+
std::uint16_t le16(const std::vector<std::uint8_t> &bytes, std::size_t offset) {
|
|
57
|
+
if (offset + 2 > bytes.size()) return 0;
|
|
58
|
+
return static_cast<std::uint16_t>(bytes[offset] | (static_cast<std::uint16_t>(bytes[offset + 1]) << 8));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
std::uint32_t le32(const std::vector<std::uint8_t> &bytes, std::size_t offset) {
|
|
62
|
+
if (offset + 4 > bytes.size()) return 0;
|
|
63
|
+
return static_cast<std::uint32_t>(bytes[offset]) |
|
|
64
|
+
(static_cast<std::uint32_t>(bytes[offset + 1]) << 8) |
|
|
65
|
+
(static_cast<std::uint32_t>(bytes[offset + 2]) << 16) |
|
|
66
|
+
(static_cast<std::uint32_t>(bytes[offset + 3]) << 24);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
bool tagAt(const std::vector<std::uint8_t> &bytes, std::size_t offset, const char *tag) {
|
|
70
|
+
return offset + 4 <= bytes.size() && std::memcmp(bytes.data() + offset, tag, 4) == 0;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
AudioBuffer decodePcm16Wav(const std::vector<std::uint8_t> &bytes) {
|
|
74
|
+
if (bytes.size() < 44 || !tagAt(bytes, 0, "RIFF") || !tagAt(bytes, 8, "WAVE")) return {};
|
|
75
|
+
|
|
76
|
+
int channels = 1;
|
|
77
|
+
int sampleRate = 16000;
|
|
78
|
+
std::size_t dataOffset = 0;
|
|
79
|
+
std::size_t dataBytes = 0;
|
|
80
|
+
std::uint16_t format = 0;
|
|
81
|
+
std::uint16_t bitsPerSample = 0;
|
|
82
|
+
|
|
83
|
+
std::size_t cursor = 12;
|
|
84
|
+
while (cursor + 8 <= bytes.size()) {
|
|
85
|
+
const std::uint32_t chunkSize = le32(bytes, cursor + 4);
|
|
86
|
+
const std::size_t payload = cursor + 8;
|
|
87
|
+
if (payload + chunkSize > bytes.size()) break;
|
|
88
|
+
|
|
89
|
+
if (tagAt(bytes, cursor, "fmt ") && chunkSize >= 16) {
|
|
90
|
+
format = le16(bytes, payload);
|
|
91
|
+
channels = static_cast<int>(le16(bytes, payload + 2));
|
|
92
|
+
sampleRate = static_cast<int>(le32(bytes, payload + 4));
|
|
93
|
+
bitsPerSample = le16(bytes, payload + 14);
|
|
94
|
+
} else if (tagAt(bytes, cursor, "data")) {
|
|
95
|
+
dataOffset = payload;
|
|
96
|
+
dataBytes = chunkSize;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
cursor = payload + chunkSize + (chunkSize & 1u);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (format != 1 || bitsPerSample != 16 || dataOffset == 0 || dataBytes < 2) return {};
|
|
103
|
+
if (channels <= 0) channels = 1;
|
|
104
|
+
if (sampleRate <= 0) sampleRate = 16000;
|
|
105
|
+
|
|
106
|
+
const std::size_t sampleCount = dataBytes / sizeof(std::int16_t);
|
|
107
|
+
std::vector<std::int16_t> samples(sampleCount);
|
|
108
|
+
for (std::size_t i = 0; i < sampleCount; ++i) {
|
|
109
|
+
const std::size_t off = dataOffset + i * 2;
|
|
110
|
+
samples[i] = static_cast<std::int16_t>(le16(bytes, off));
|
|
111
|
+
}
|
|
112
|
+
return AudioBuffer(std::move(samples), sampleRate, channels);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
} // namespace
|
|
116
|
+
|
|
117
|
+
AudioDestinationProperty::operator AudioDestinationNode() const {
|
|
118
|
+
return AudioDestinationNode(gea::framework::host::AudioHost::context().destination().nativeId());
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
AudioDestinationProperty::operator double() const {
|
|
122
|
+
return static_cast<double>(gea::framework::host::AudioHost::context().destination().nativeId());
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
AudioContextCurrentTimeProperty::operator double() const {
|
|
126
|
+
return gea::framework::host::AudioHost::context().currentTime();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const AudioParamValueProperty &AudioParamValueProperty::operator=(double frequency_hz) const {
|
|
130
|
+
gea::framework::host::AudioHost::oscillator(oscillatorHandle).frequency.setValue(frequency_hz);
|
|
131
|
+
return *this;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
AudioParamValueProperty::operator double() const {
|
|
135
|
+
return gea::framework::host::AudioHost::oscillator(oscillatorHandle).frequency.value();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const AudioParam &AudioParam::operator=(double frequency_hz) const {
|
|
139
|
+
gea::framework::host::AudioHost::oscillator(oscillatorHandle).frequency.setValue(frequency_hz);
|
|
140
|
+
return *this;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
void AudioParam::setValueAtTime(double frequency_hz, double start_time) const {
|
|
144
|
+
gea::framework::host::AudioHost::oscillator(oscillatorHandle).frequency.setValueAtTime(frequency_hz, start_time);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const OscillatorTypeProperty &OscillatorTypeProperty::operator=(double type) const {
|
|
148
|
+
gea::framework::host::AudioHost::oscillator(oscillatorHandle).setType(gea::framework::host::AudioHost::oscillatorType(type));
|
|
149
|
+
return *this;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const OscillatorTypeProperty &OscillatorTypeProperty::operator=(const char *type) const {
|
|
153
|
+
return (*this = detail::oscillator_type_from_name(type));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const OscillatorTypeProperty &OscillatorTypeProperty::operator=(const std::string &type) const {
|
|
157
|
+
return (*this = type.c_str());
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
void OscillatorNode::connect(AudioDestinationNode destination) const {
|
|
161
|
+
gea::framework::host::AudioHost::oscillator(nativeHandle).connect(gea::framework::host::AudioHost::destination(destination.nativeHandle));
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
void OscillatorNode::connect(AudioDestinationProperty destination) const {
|
|
165
|
+
connect(static_cast<AudioDestinationNode>(destination));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
void OscillatorNode::connect(double destinationHandle) const {
|
|
169
|
+
connect(AudioDestinationNode(destinationHandle));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
void OscillatorNode::start(double when) const {
|
|
173
|
+
gea::framework::host::AudioHost::oscillator(nativeHandle).start(when);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
void OscillatorNode::stop(double when) const {
|
|
177
|
+
gea::framework::host::AudioHost::oscillator(nativeHandle).stop(when);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
AudioDestinationNode AudioBufferSourceNode::connect(AudioDestinationNode destination) const {
|
|
181
|
+
connected = true;
|
|
182
|
+
return destination;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
AudioDestinationNode AudioBufferSourceNode::connect(AudioDestinationProperty destination) const {
|
|
186
|
+
return connect(static_cast<AudioDestinationNode>(destination));
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
AudioDestinationNode AudioBufferSourceNode::connect(double destinationHandle) const {
|
|
190
|
+
return connect(AudioDestinationNode(destinationHandle));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
void AudioBufferSourceNode::start(double when) const {
|
|
194
|
+
(void)when;
|
|
195
|
+
if (!connected || buffer.samples.empty()) return;
|
|
196
|
+
gea::platform::audio::AudioSystem::playPcm(buffer.samples.data(), buffer.samples.size(), buffer.sampleRate, buffer.channels);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
void AudioBufferSourceNode::stop(double when) const {
|
|
200
|
+
(void)when;
|
|
201
|
+
gea::platform::audio::AudioSystem::stopPlayback();
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
OscillatorNode AudioContext::createOscillator() const {
|
|
205
|
+
return OscillatorNode(gea::framework::host::AudioHost::context().createOscillator().nativeId());
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
AudioBufferSourceNode AudioContext::createBufferSource() const {
|
|
209
|
+
return AudioBufferSourceNode{};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
AudioBuffer AudioContext::decodeAudioData(const std::vector<std::uint8_t> &bytes) const {
|
|
213
|
+
return decodePcm16Wav(bytes);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
HTMLAudioElement::HTMLAudioElement(const char *src) : src_(src ? src : "") {}
|
|
217
|
+
|
|
218
|
+
HTMLAudioElement::HTMLAudioElement(const std::string &src) : src_(src) {}
|
|
219
|
+
|
|
220
|
+
HTMLAudioElement::HTMLAudioElement(const gea::embedded::ui::NodeHandle &node) : nodeId_(node.id()) {}
|
|
221
|
+
|
|
222
|
+
std::string HTMLAudioElement::src() const {
|
|
223
|
+
if (nodeId_ >= 0) return std::string(gea::embedded::ui::NodeHandle(nodeId_).getAttribute("src"));
|
|
224
|
+
return src_;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
void HTMLAudioElement::setSrc(const std::string &src) {
|
|
228
|
+
if (nodeId_ >= 0) gea::embedded::ui::NodeHandle(nodeId_).setAttribute("src", src.c_str());
|
|
229
|
+
src_ = src;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
bool HTMLAudioElement::play() const {
|
|
233
|
+
return gea::platform::audio::AudioSystem::playFile(src());
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
void HTMLAudioElement::pause() const {
|
|
237
|
+
gea::platform::audio::AudioSystem::stopPlayback();
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
} // namespace gea::host
|
package/host/ble.cpp
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#include <cstdint>
|
|
3
|
+
#include <string>
|
|
4
|
+
#include <vector>
|
|
5
|
+
|
|
6
|
+
#include "ble.h"
|
|
7
|
+
#include "gea/embedded-host.h"
|
|
8
|
+
|
|
9
|
+
namespace gea::framework::bluetooth {
|
|
10
|
+
|
|
11
|
+
class HidValue {
|
|
12
|
+
public:
|
|
13
|
+
static int from(double value) {
|
|
14
|
+
return static_cast<int>(value);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
void HidBackend::init(const std::string &device_name, double appearance, const std::string &mac_address) {
|
|
19
|
+
const char *mac_address_ptr = mac_address.empty() ? nullptr : mac_address.c_str();
|
|
20
|
+
bluetooth().hid().init(device_name.c_str(), static_cast<std::uint16_t>(appearance), mac_address_ptr);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
bool HidBackend::enabled() {
|
|
24
|
+
return bluetooth().hid().enabled();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
void HidBackend::setEnabled(bool enabled) {
|
|
28
|
+
bluetooth().hid().setEnabled(enabled);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
void HidBackend::startAdvertising() {
|
|
32
|
+
bluetooth().hid().startAdvertising();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
void HidBackend::stopAdvertising() {
|
|
36
|
+
bluetooth().hid().stopAdvertising();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
bool HidBackend::connected() {
|
|
40
|
+
return bluetooth().hid().connected();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
bool HidBackend::bound() {
|
|
44
|
+
return bluetooth().hid().bound();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
double HidBackend::batteryLevel() {
|
|
48
|
+
return static_cast<double>(bluetooth().hid().batteryLevel());
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
std::string HidBackend::mac() {
|
|
52
|
+
const char *value = bluetooth().hid().mac();
|
|
53
|
+
return value ? value : "";
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
std::string HidBackend::deviceName() {
|
|
57
|
+
const char *value = bluetooth().hid().deviceName();
|
|
58
|
+
return value ? value : "";
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
void HidBackend::keyTap(double hid_code) {
|
|
62
|
+
bluetooth().hid().keyTap(HidValue::from(hid_code));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
void HidBackend::keyDown(double modifier, double hid_code) {
|
|
66
|
+
bluetooth().hid().keyDown(HidValue::from(modifier), HidValue::from(hid_code));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
void HidBackend::keyUp() {
|
|
70
|
+
bluetooth().hid().keyUp();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
void HidBackend::mouseMove(double dx, double dy, double buttons, double wheel) {
|
|
74
|
+
bluetooth().hid().mouseMove(
|
|
75
|
+
HidValue::from(dx), HidValue::from(dy), HidValue::from(buttons), HidValue::from(wheel));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
void HidBackend::mouseClick(double button) {
|
|
79
|
+
bluetooth().hid().mouseClick(HidValue::from(button));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
void HidBackend::midiEnable() {
|
|
83
|
+
bluetooth().hid().midiEnable();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
bool HidBackend::midiBound() {
|
|
87
|
+
return bluetooth().hid().midiBound();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
void HidBackend::midiSend(const std::vector<double> &bytes) {
|
|
91
|
+
std::uint8_t packet[20]; // one BLE-MIDI packet, ATT_MTU(23)-3 notification payload
|
|
92
|
+
int n = 0;
|
|
93
|
+
for (double b : bytes) {
|
|
94
|
+
if (n >= static_cast<int>(sizeof packet)) break;
|
|
95
|
+
int v = static_cast<int>(b);
|
|
96
|
+
if (v < 0) v = 0;
|
|
97
|
+
if (v > 255) v = 255;
|
|
98
|
+
packet[n++] = static_cast<std::uint8_t>(v);
|
|
99
|
+
}
|
|
100
|
+
if (n > 0) bluetooth().hid().midiSend(packet, n);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
void HidBackend::midiStartScan() {
|
|
104
|
+
bluetooth().hid().midiStartScan();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
void HidBackend::midiStopScan() {
|
|
108
|
+
bluetooth().hid().midiStopScan();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
bool HidBackend::midiScanning() {
|
|
112
|
+
return bluetooth().hid().midiScanning();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
double HidBackend::midiScanCount() {
|
|
116
|
+
return static_cast<double>(bluetooth().hid().midiScanCount());
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
std::string HidBackend::midiScanNameAt(double index) {
|
|
120
|
+
const char *value = bluetooth().hid().midiScanNameAt(HidValue::from(index));
|
|
121
|
+
return value ? value : "";
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
void HidBackend::midiConnect(double index) {
|
|
125
|
+
bluetooth().hid().midiConnect(HidValue::from(index));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
void HidBackend::midiDisconnect() {
|
|
129
|
+
bluetooth().hid().midiDisconnect();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
void HidBackend::hidHostStartScan() {
|
|
133
|
+
bluetooth().hid().hidHostStartScan();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
void HidBackend::hidHostStopScan() {
|
|
137
|
+
bluetooth().hid().hidHostStopScan();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
bool HidBackend::hidHostScanning() {
|
|
141
|
+
return bluetooth().hid().hidHostScanning();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
double HidBackend::hidHostScanCount() {
|
|
145
|
+
return static_cast<double>(bluetooth().hid().hidHostScanCount());
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
std::string HidBackend::hidHostScanNameAt(double index) {
|
|
149
|
+
const char *value = bluetooth().hid().hidHostScanNameAt(HidValue::from(index));
|
|
150
|
+
return value ? value : "";
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
void HidBackend::hidHostConnect(double index) {
|
|
154
|
+
bluetooth().hid().hidHostConnect(HidValue::from(index));
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
void HidBackend::hidHostDisconnect() {
|
|
158
|
+
bluetooth().hid().hidHostDisconnect();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
bool HidBackend::hidHostBound() {
|
|
162
|
+
return bluetooth().hid().hidHostBound();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
double HidBackend::hidHostReportCount() {
|
|
166
|
+
return static_cast<double>(bluetooth().hid().hidHostReportCount());
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
double HidBackend::hidHostReportIdAt(double index) {
|
|
170
|
+
return static_cast<double>(bluetooth().hid().hidHostReportIdAt(HidValue::from(index)));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
double HidBackend::hidHostReportLenAt(double index) {
|
|
174
|
+
return static_cast<double>(bluetooth().hid().hidHostReportLenAt(HidValue::from(index)));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
double HidBackend::hidHostReportByteAt(double index, double byteIndex) {
|
|
178
|
+
return static_cast<double>(bluetooth().hid().hidHostReportByteAt(HidValue::from(index), HidValue::from(byteIndex)));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
void HidBackend::hidHostClearReports() {
|
|
182
|
+
bluetooth().hid().hidHostClearReports();
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
double HidBackend::connectionCount() {
|
|
186
|
+
return static_cast<double>(bluetooth().hid().connectionCount());
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
double HidBackend::connectionKindAt(double index) {
|
|
190
|
+
return static_cast<double>(bluetooth().hid().connectionKindAt(HidValue::from(index)));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
std::string HidBackend::connectionNameAt(double index) {
|
|
194
|
+
const char *value = bluetooth().hid().connectionNameAt(HidValue::from(index));
|
|
195
|
+
return value ? value : "";
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
void HidBackend::configSetDocument(const std::vector<double> &bytes) {
|
|
199
|
+
std::vector<std::uint8_t> buffer;
|
|
200
|
+
buffer.reserve(bytes.size());
|
|
201
|
+
for (double b : bytes) {
|
|
202
|
+
int v = static_cast<int>(b);
|
|
203
|
+
if (v < 0) v = 0;
|
|
204
|
+
if (v > 255) v = 255;
|
|
205
|
+
buffer.push_back(static_cast<std::uint8_t>(v));
|
|
206
|
+
}
|
|
207
|
+
bluetooth().hid().configSetDocument(buffer.data(), static_cast<int>(buffer.size()));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
double HidBackend::configPendingLength() {
|
|
211
|
+
return static_cast<double>(bluetooth().hid().configPendingLength());
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
double HidBackend::configPendingByteAt(double index) {
|
|
215
|
+
return static_cast<double>(bluetooth().hid().configPendingByteAt(HidValue::from(index)));
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
void HidBackend::configConsumePending() {
|
|
219
|
+
bluetooth().hid().configConsumePending();
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
bool HidBackend::configPairing() {
|
|
223
|
+
return bluetooth().hid().configPairing();
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
std::string HidBackend::configPairCode() {
|
|
227
|
+
const char *value = bluetooth().hid().configPairCode();
|
|
228
|
+
return value ? value : "";
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
void HidBackend::configDismissPairing() {
|
|
232
|
+
bluetooth().hid().configDismissPairing();
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
void HidBackend::configPushActivity(double index) {
|
|
236
|
+
bluetooth().hid().configPushActivity(HidValue::from(index));
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
} // namespace gea::framework::bluetooth
|