Skip to content

Commit d029602

Browse files
committed
ref #77 : add MT protocols to ggwave.js + new API for setting freqStart
1 parent d2f79fc commit d029602

File tree

7 files changed

+46
-3
lines changed

7 files changed

+46
-3
lines changed

README-tmpl.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Here is a list of possible applications of **ggwave** with a few examples:
3333
- **Serverless, one-to-many broadcast**
3434
- [wave-share](https://github.com/ggerganov/wave-share) - file sharing through sound
3535
- **Internet of Things**
36+
- [esp32-rx](https://github.com/ggerganov/ggwave/tree/master/examples/esp32-rx), [arduino-rx](https://github.com/ggerganov/ggwave/tree/master/examples/arduino-rx), [rp2040-rx](https://github.com/ggerganov/ggwave/tree/master/examples/rp2040-rx), [arduino-tx](https://github.com/ggerganov/ggwave/tree/master/examples/arduino-tx) - Sand and receive sound data on microcontrollers
3637
- [r2t2](https://github.com/ggerganov/ggwave/tree/master/examples/r2t2) - Transmit data with the PC speaker
3738
- [buttons](https://github.com/ggerganov/ggwave/tree/master/examples/buttons) - Record and send commands via [Talking buttons](https://github.com/ggerganov/ggwave/discussions/27)
3839
- **Audio QR codes**

bindings/javascript/emscripten.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ EMSCRIPTEN_BINDINGS(ggwave) {
2323
.value("GGWAVE_PROTOCOL_DT_NORMAL", GGWAVE_PROTOCOL_DT_NORMAL)
2424
.value("GGWAVE_PROTOCOL_DT_FAST", GGWAVE_PROTOCOL_DT_FAST)
2525
.value("GGWAVE_PROTOCOL_DT_FASTEST", GGWAVE_PROTOCOL_DT_FASTEST)
26+
.value("GGWAVE_PROTOCOL_MT_NORMAL", GGWAVE_PROTOCOL_MT_NORMAL)
27+
.value("GGWAVE_PROTOCOL_MT_FAST", GGWAVE_PROTOCOL_MT_FAST)
28+
.value("GGWAVE_PROTOCOL_MT_FASTEST", GGWAVE_PROTOCOL_MT_FASTEST)
2629

2730
.value("GGWAVE_PROTOCOL_CUSTOM_0", GGWAVE_PROTOCOL_CUSTOM_0)
2831
.value("GGWAVE_PROTOCOL_CUSTOM_1", GGWAVE_PROTOCOL_CUSTOM_1)
@@ -113,4 +116,16 @@ EMSCRIPTEN_BINDINGS(ggwave) {
113116
int state) {
114117
ggwave_txToggleProtocol(protocolId, state);
115118
}));
119+
120+
emscripten::function("rxProtocolSetFreqStart", emscripten::optional_override(
121+
[](ggwave_ProtocolId protocolId,
122+
int freqStart) {
123+
ggwave_rxProtocolSetFreqStart(protocolId, freqStart);
124+
}));
125+
126+
emscripten::function("txProtocolSetFreqStart", emscripten::optional_override(
127+
[](ggwave_ProtocolId protocolId,
128+
int freqStart) {
129+
ggwave_txProtocolSetFreqStart(protocolId, freqStart);
130+
}));
116131
}

bindings/javascript/ggwave.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/arduino-rx-web/index-tmpl.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@
9696
if (!context) {
9797
context = new AudioContext({sampleRate: 48000});
9898

99+
// If you applied a shift on the transmitter side, you need to apply the same shift on the receiver side:
100+
//ggwave.rxProtocolSetFreqStart(ggwave.ProtocolId.GGWAVE_PROTOCOL_MT_FASTEST, 24 + 48);
101+
99102
parameters = ggwave.getDefaultParameters();
100103
parameters.payloadLength = kPayloadLength;
101104
parameters.samplesPerFrame = 1024;

examples/ggwave-js/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
set(TARGET ggwave-js)
22

3-
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/index-tmpl.html ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TARGET}/index.html @ONLY)
4-
configure_file(${CMAKE_SOURCE_DIR}/bindings/javascript/ggwave.js ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TARGET}/ggwave.js COPYONLY)
3+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/index-tmpl.html ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TARGET}/index.html @ONLY)
4+
configure_file(${CMAKE_SOURCE_DIR}/bindings/javascript/ggwave.js ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TARGET}/ggwave.js COPYONLY)

include/ggwave/ggwave.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,16 @@ extern "C" {
330330
ggwave_ProtocolId protocolId,
331331
int state);
332332

333+
// Set freqStart for an Rx protocol
334+
GGWAVE_API void ggwave_rxProtocolSetFreqStart(
335+
ggwave_ProtocolId protocolId,
336+
int freqStart);
337+
338+
// Set freqStart for a Tx protocol
339+
GGWAVE_API void ggwave_txProtocolSetFreqStart(
340+
ggwave_ProtocolId protocolId,
341+
int freqStart);
342+
333343
#ifdef __cplusplus
334344
}
335345

src/ggwave.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,20 @@ void ggwave_txToggleProtocol(
204204
GGWave::Protocols::tx().toggle(protocolId, state != 0);
205205
}
206206

207+
extern "C"
208+
void ggwave_rxProtocolSetFreqStart(
209+
ggwave_ProtocolId protocolId,
210+
int freqStart) {
211+
GGWave::Protocols::rx()[protocolId].freqStart = freqStart;
212+
}
213+
214+
extern "C"
215+
void ggwave_txProtocolSetFreqStart(
216+
ggwave_ProtocolId protocolId,
217+
int freqStart) {
218+
GGWave::Protocols::tx()[protocolId].freqStart = freqStart;
219+
}
220+
207221
//
208222
// C++ implementation
209223
//

0 commit comments

Comments
 (0)