commit 9a6d2acc314908b1c6e9b9daceed2bb29d464f68
parent 760ad02672c03bfc9b13ba4c9f35a7a7363608c8
Author: Luxferre <lux@ferre>
Date: Fri, 23 Dec 2022 17:02:10 +0200
Added setSyncDelta method to the library
Diffstat:
3 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/README.md b/README.md
@@ -40,7 +40,8 @@ The [library](rcvd.js) can be used "as is" or as a building block for more advan
- `RCVD.connect() -> Promise` - connect to a watch, perform the necessary handshake operations and resolve the Promise on success;
- `RCVD.disconnect()` - disconnect from the currently connected watch's GATT server;
- `RCVD.sync(Date obj?) -> Promise` - perform time synchronization with the **optional** Date object (if it's not passed, actual current local time will be set), running all the required DST/world time setting cycles before setting the actual time;
-- `RCVD.getModel() -> String` - return the watch model name obdained during the connection process;
+- `RCVD.setSyncDelta(ms)` - update the delta value (in milliseconds) to add to the current time before synchronization to make up for the Bluetooth transmission delay (500 ms by default, can be adjusted according to your host and watch latency);
+- `RCVD.getModel() -> String` - return the watch model name obtained during the connection process;
- `RCVD.rawRead(uint8 param1, uint8 param2...) -> Promise(Uint8Array)` - accept variable number of integer parameters and execute the read command on the watch, resolving to the result in a Uint8Array value;
- `RCVD.rawWrite(Uint8Array command) -> Promise` - accept a write command shaped as byte data in Uint8Array and resolve on successful write operation.
diff --git a/manifest.webapp b/manifest.webapp
@@ -1,5 +1,5 @@
{
- "version": "0.0.3",
+ "version": "0.0.4",
"name": "RCVD",
"description": "Casio BLE-enabled watches time synchronization app",
"type": "certified",
diff --git a/rcvd.js b/rcvd.js
@@ -16,6 +16,7 @@ RCVD = (function(nav) {
}),
watchModel = '',
localgatt = null, //local GATT reference for disconnection
+ syncDelta = 500, //the delta value (in milliseconds) to make up for BLE transmission latency, 500 ms by default
TD = new TextDecoder(),
ids = s => `26eb00${s}-b012-49a8-b1f8-394fb2032b0f`,
scanids = ['00001804-0000-1000-8000-00805f9b34fb', ids('0d')],
@@ -83,7 +84,7 @@ RCVD = (function(nav) {
plgen = k => [...Array(6)].map((a,i)=>[k,i]), //property list generator
cyclePresyncProperties = _ => new Promise((res, rej) => {
- var slist = [...plgen(30),...plgen(31)]
+ var slist = [...plgen(30),...plgen(31)] //full property list for primary targets, GW-B/GMW-B models
if(watchModel.indexOf('OCW') > 5)
slist = [[30,0],[30,1]]
else if(watchModel.indexOf('B2100') > 5 || watchModel.indexOf('B001') > 5 || watchModel.indexOf('DW-B5600') > 5 )
@@ -122,10 +123,10 @@ RCVD = (function(nav) {
getModel: _ => watchModel,
rawRead: execReadCmd,
rawWrite: execWriteCmd,
+ setSyncDelta: val => {syncDelta = +val; if(isNaN(syncDelta)) syncDelta = 500},
sync: dObj => new Promise((res, rej) => {
cyclePresyncProperties().then(_ => {
- //set to the next second to make up for latency
- var d = dObj || new Date(Date.now() + 500), year = d.getFullYear()
+ var d = dObj || new Date(Date.now() + syncDelta), year = d.getFullYear()
execWriteCmd(Uint8Array.from([
9,
year&255, year>>>8,