ref #77 : add MT protocols to ggwave.js + new API for setting freqStart

This commit is contained in:
Georgi Gerganov
2022-09-10 17:57:37 +03:00
parent d2f79fc845
commit d02960259b
7 changed files with 46 additions and 3 deletions

View File

@@ -33,6 +33,7 @@ Here is a list of possible applications of **ggwave** with a few examples:
- **Serverless, one-to-many broadcast**
- [wave-share](https://github.com/ggerganov/wave-share) - file sharing through sound
- **Internet of Things**
- [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
- [r2t2](https://github.com/ggerganov/ggwave/tree/master/examples/r2t2) - Transmit data with the PC speaker
- [buttons](https://github.com/ggerganov/ggwave/tree/master/examples/buttons) - Record and send commands via [Talking buttons](https://github.com/ggerganov/ggwave/discussions/27)
- **Audio QR codes**

View File

@@ -23,6 +23,9 @@ EMSCRIPTEN_BINDINGS(ggwave) {
.value("GGWAVE_PROTOCOL_DT_NORMAL", GGWAVE_PROTOCOL_DT_NORMAL)
.value("GGWAVE_PROTOCOL_DT_FAST", GGWAVE_PROTOCOL_DT_FAST)
.value("GGWAVE_PROTOCOL_DT_FASTEST", GGWAVE_PROTOCOL_DT_FASTEST)
.value("GGWAVE_PROTOCOL_MT_NORMAL", GGWAVE_PROTOCOL_MT_NORMAL)
.value("GGWAVE_PROTOCOL_MT_FAST", GGWAVE_PROTOCOL_MT_FAST)
.value("GGWAVE_PROTOCOL_MT_FASTEST", GGWAVE_PROTOCOL_MT_FASTEST)
.value("GGWAVE_PROTOCOL_CUSTOM_0", GGWAVE_PROTOCOL_CUSTOM_0)
.value("GGWAVE_PROTOCOL_CUSTOM_1", GGWAVE_PROTOCOL_CUSTOM_1)
@@ -113,4 +116,16 @@ EMSCRIPTEN_BINDINGS(ggwave) {
int state) {
ggwave_txToggleProtocol(protocolId, state);
}));
emscripten::function("rxProtocolSetFreqStart", emscripten::optional_override(
[](ggwave_ProtocolId protocolId,
int freqStart) {
ggwave_rxProtocolSetFreqStart(protocolId, freqStart);
}));
emscripten::function("txProtocolSetFreqStart", emscripten::optional_override(
[](ggwave_ProtocolId protocolId,
int freqStart) {
ggwave_txProtocolSetFreqStart(protocolId, freqStart);
}));
}

File diff suppressed because one or more lines are too long

View File

@@ -96,6 +96,9 @@
if (!context) {
context = new AudioContext({sampleRate: 48000});
// If you applied a shift on the transmitter side, you need to apply the same shift on the receiver side:
//ggwave.rxProtocolSetFreqStart(ggwave.ProtocolId.GGWAVE_PROTOCOL_MT_FASTEST, 24 + 48);
parameters = ggwave.getDefaultParameters();
parameters.payloadLength = kPayloadLength;
parameters.samplesPerFrame = 1024;

View File

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

View File

@@ -330,6 +330,16 @@ extern "C" {
ggwave_ProtocolId protocolId,
int state);
// Set freqStart for an Rx protocol
GGWAVE_API void ggwave_rxProtocolSetFreqStart(
ggwave_ProtocolId protocolId,
int freqStart);
// Set freqStart for a Tx protocol
GGWAVE_API void ggwave_txProtocolSetFreqStart(
ggwave_ProtocolId protocolId,
int freqStart);
#ifdef __cplusplus
}

View File

@@ -204,6 +204,20 @@ void ggwave_txToggleProtocol(
GGWave::Protocols::tx().toggle(protocolId, state != 0);
}
extern "C"
void ggwave_rxProtocolSetFreqStart(
ggwave_ProtocolId protocolId,
int freqStart) {
GGWave::Protocols::rx()[protocolId].freqStart = freqStart;
}
extern "C"
void ggwave_txProtocolSetFreqStart(
ggwave_ProtocolId protocolId,
int freqStart) {
GGWave::Protocols::tx()[protocolId].freqStart = freqStart;
}
//
// C++ implementation
//