As a quick follow up, this works!
var last_wheel_event_time = 0, actual_wheel_event_time; var last_cumulative_wheel_revolutions = 0, cumulative_wheel_revolutions; var delta_revolutions, delta_event_time; var wheel_circumference = 2340; var delta_time_in_ms; function OnNotify(event) { //console.log("-> "+(event.target.value.getUint8(0, true)>>> 0).toString(2)); //characteristics flags cumulative_wheel_revolutions = event.target.value.getUint32(1, true); actual_wheel_event_time = event.target.value.getUint16(5, true); console.log("Cumulative wheel Revolutions: "+ cumulative_wheel_revolutions); console.log("Last Wheel Event time: "+ actual_wheel_event_time + " ms"); delta_revolutions = cumulative_wheel_revolutions - last_cumulative_wheel_revolutions; //console.log("-> "+event.target.value.getUint16(7, true)); //crank //console.log("-> "+event.target.value.getUint16(9, true)); //crank if (actual_wheel_event_time >= last_wheel_event_time) { delta_event_time = actual_wheel_event_time - last_wheel_event_time; } else { delta_event_time = 65536 - last_wheel_event_time + actual_wheel_event_time; } delta_time_in_ms =(delta_event_time / 1.024); console.log(delta_event_time); console.log("delta_time_in_ms:" + delta_time_in_ms); last_wheel_event_time = actual_wheel_event_time; last_cumulative_wheel_revolutions = cumulative_wheel_revolutions; } var gatt; NRF.requestDevice({ timeout:20000, filters: [{ namePrefix: 'Wahoo' }] }).then(function(device) { console.log(device); return device.gatt.connect(); }).then(function(g) { gatt = g; return gatt.getPrimaryService("1816"); }).then(function(service) { //console.log("Service:" + service); return service.getCharacteristic("0x2A5B"); }).then(function(characteristic) { characteristic.on('characteristicvaluechanged', OnNotify); return characteristic.startNotifications(); }).then(function() { console.log("Done!"); // Then call gatt.disconnect(); if/when you want to disconnect });
Thanks a lot, J
@Joost started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
As a quick follow up, this works!
Thanks a lot, J