add prefs toggle for auto adding or manual adding of new contacts

This commit is contained in:
liamcottle 2025-04-13 13:43:52 +12:00
parent e6ffafc195
commit 24d330b189
3 changed files with 75 additions and 2 deletions

View file

@ -122,6 +122,12 @@
<button @click="sendTrace" class="border border-gray-500 px-2 bg-gray-100 hover:bg-gray-200 rounded">
SendTrace
</button>
<button @click="setAutoAddContacts" class="border border-gray-500 px-2 bg-gray-100 hover:bg-gray-200 rounded">
setAutoAddContacts
</button>
<button @click="setManualAddContacts" class="border border-gray-500 px-2 bg-gray-100 hover:bg-gray-200 rounded">
setManualAddContacts
</button>
</div>
</div>
@ -274,6 +280,7 @@
},
async loadSelfInfo() {
this.selfInfo = await this.connection.getSelfInfo();
console.log(this.selfInfo);
},
async loadContacts() {
this.contacts = await this.connection.getContacts();
@ -647,6 +654,22 @@
}
},
async setAutoAddContacts() {
try {
await this.connection.setAutoAddContacts();
} catch(e) {
console.log(e);
alert("failed to set auto add contacts");
}
},
async setManualAddContacts() {
try {
await this.connection.setManualAddContacts();
} catch(e) {
console.log(e);
alert("failed to set manual add contacts");
}
},
showCommandLine(contact) {
// hide cli if clicked same contact

View file

@ -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;

View file

@ -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 = {