Added setSyncDelta method to the library
This commit is contained in:
@@ -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.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.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.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.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.
|
- `RCVD.rawWrite(Uint8Array command) -> Promise` - accept a write command shaped as byte data in Uint8Array and resolve on successful write operation.
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"version": "0.0.3",
|
"version": "0.0.4",
|
||||||
"name": "RCVD",
|
"name": "RCVD",
|
||||||
"description": "Casio BLE-enabled watches time synchronization app",
|
"description": "Casio BLE-enabled watches time synchronization app",
|
||||||
"type": "certified",
|
"type": "certified",
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ RCVD = (function(nav) {
|
|||||||
}),
|
}),
|
||||||
watchModel = '',
|
watchModel = '',
|
||||||
localgatt = null, //local GATT reference for disconnection
|
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(),
|
TD = new TextDecoder(),
|
||||||
ids = s => `26eb00${s}-b012-49a8-b1f8-394fb2032b0f`,
|
ids = s => `26eb00${s}-b012-49a8-b1f8-394fb2032b0f`,
|
||||||
scanids = ['00001804-0000-1000-8000-00805f9b34fb', ids('0d')],
|
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
|
plgen = k => [...Array(6)].map((a,i)=>[k,i]), //property list generator
|
||||||
cyclePresyncProperties = _ => new Promise((res, rej) => {
|
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)
|
if(watchModel.indexOf('OCW') > 5)
|
||||||
slist = [[30,0],[30,1]]
|
slist = [[30,0],[30,1]]
|
||||||
else if(watchModel.indexOf('B2100') > 5 || watchModel.indexOf('B001') > 5 || watchModel.indexOf('DW-B5600') > 5 )
|
else if(watchModel.indexOf('B2100') > 5 || watchModel.indexOf('B001') > 5 || watchModel.indexOf('DW-B5600') > 5 )
|
||||||
@@ -122,10 +123,10 @@ RCVD = (function(nav) {
|
|||||||
getModel: _ => watchModel,
|
getModel: _ => watchModel,
|
||||||
rawRead: execReadCmd,
|
rawRead: execReadCmd,
|
||||||
rawWrite: execWriteCmd,
|
rawWrite: execWriteCmd,
|
||||||
|
setSyncDelta: val => {syncDelta = +val; if(isNaN(syncDelta)) syncDelta = 500},
|
||||||
sync: dObj => new Promise((res, rej) => {
|
sync: dObj => new Promise((res, rej) => {
|
||||||
cyclePresyncProperties().then(_ => {
|
cyclePresyncProperties().then(_ => {
|
||||||
//set to the next second to make up for latency
|
var d = dObj || new Date(Date.now() + syncDelta), year = d.getFullYear()
|
||||||
var d = dObj || new Date(Date.now() + 500), year = d.getFullYear()
|
|
||||||
execWriteCmd(Uint8Array.from([
|
execWriteCmd(Uint8Array.from([
|
||||||
9,
|
9,
|
||||||
year&255, year>>>8,
|
year&255, year>>>8,
|
||||||
|
|||||||
Reference in New Issue
Block a user