mirror of
https://github.com/meshcore-dev/meshcore.js.git
synced 2026-04-20 22:13:49 +00:00
add prefs toggle for auto adding or manual adding of new contacts
This commit is contained in:
parent
e6ffafc195
commit
24d330b189
3 changed files with 75 additions and 2 deletions
|
|
@ -268,6 +268,13 @@ class Connection extends EventEmitter {
|
|||
await this.sendToRadioFrame(data.toBytes());
|
||||
}
|
||||
|
||||
async sendCommandSetOtherParams(manualAddContacts) {
|
||||
const data = new BufferWriter();
|
||||
data.writeByte(Constants.CommandCodes.SetOtherParams);
|
||||
data.writeByte(manualAddContacts); // 0 or 1
|
||||
await this.sendToRadioFrame(data.toBytes());
|
||||
}
|
||||
|
||||
onFrameReceived(frame) {
|
||||
|
||||
// emit received frame
|
||||
|
|
@ -513,7 +520,8 @@ class Connection extends EventEmitter {
|
|||
publicKey: bufferReader.readBytes(32),
|
||||
advLat: bufferReader.readInt32LE(),
|
||||
advLon: bufferReader.readInt32LE(),
|
||||
reserved: bufferReader.readBytes(4),
|
||||
reserved: bufferReader.readBytes(3),
|
||||
manualAddContacts: bufferReader.readByte(),
|
||||
radioFreq: bufferReader.readUInt32LE(),
|
||||
radioBw: bufferReader.readUInt32LE(),
|
||||
radioSf: bufferReader.readByte(),
|
||||
|
|
@ -1760,6 +1768,45 @@ class Connection extends EventEmitter {
|
|||
});
|
||||
}
|
||||
|
||||
setOtherParams(manualAddContacts) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
|
||||
// resolve promise when we receive ok
|
||||
const onOk = () => {
|
||||
this.off(Constants.ResponseCodes.Ok, onOk);
|
||||
this.off(Constants.ResponseCodes.Err, onErr);
|
||||
resolve();
|
||||
}
|
||||
|
||||
// reject promise when we receive err
|
||||
const onErr = () => {
|
||||
this.off(Constants.ResponseCodes.Ok, onOk);
|
||||
this.off(Constants.ResponseCodes.Err, onErr);
|
||||
reject();
|
||||
}
|
||||
|
||||
// listen for events
|
||||
this.once(Constants.ResponseCodes.Ok, onOk);
|
||||
this.once(Constants.ResponseCodes.Err, onErr);
|
||||
|
||||
// set other params
|
||||
await this.sendCommandSetOtherParams(manualAddContacts);
|
||||
|
||||
} catch(e) {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async setAutoAddContacts() {
|
||||
return await this.setOtherParams(false);
|
||||
}
|
||||
|
||||
async setManualAddContacts() {
|
||||
return await this.setOtherParams(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default Connection;
|
||||
|
|
|
|||
|
|
@ -45,6 +45,8 @@ class Constants {
|
|||
SetChannel: 32,
|
||||
// todo sign commands
|
||||
SendTracePath: 36,
|
||||
// todo set device pin command
|
||||
SetOtherParams: 38,
|
||||
}
|
||||
|
||||
static ResponseCodes = {
|
||||
|
|
@ -68,7 +70,7 @@ class Constants {
|
|||
}
|
||||
|
||||
static PushCodes = {
|
||||
Advert: 0x80,
|
||||
Advert: 0x80, // when companion is set to auto add contacts
|
||||
PathUpdated: 0x81,
|
||||
SendConfirmed: 0x82,
|
||||
MsgWaiting: 0x83,
|
||||
|
|
@ -78,6 +80,7 @@ class Constants {
|
|||
StatusResponse: 0x87,
|
||||
LogRxData: 0x88,
|
||||
TraceData: 0x89,
|
||||
NewAdvert: 0x8A, // when companion is set to manually add contacts
|
||||
}
|
||||
|
||||
static AdvType = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue