From 4e844b0722b4a7d9337a4fc64fe5cb32a3e5f904 Mon Sep 17 00:00:00 2001 From: Lars Berning <151194+laberning@users.noreply.github.com> Date: Mon, 3 May 2021 10:05:07 +0200 Subject: [PATCH] makes low level integrations less dependent on raspberry pi hardware --- app/ble/FtmsPeripheral.js | 10 ++++++---- app/gpio/GpioTimerService.js | 35 ++++++++++++++++++++--------------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/app/ble/FtmsPeripheral.js b/app/ble/FtmsPeripheral.js index bb6100c..926b870 100644 --- a/app/ble/FtmsPeripheral.js +++ b/app/ble/FtmsPeripheral.js @@ -13,14 +13,14 @@ */ import bleno from '@abandonware/bleno' import FitnessMachineService from './ftms/FitnessMachineService.js' -import DeviceInformationService from './ftms/DeviceInformationService.js' +// import DeviceInformationService from './ftms/DeviceInformationService.js' import config from '../tools/ConfigManager.js' import log from 'loglevel' function createFtmsPeripheral (controlCallback, options) { const peripheralName = options?.simulateIndoorBike ? config.ftmsBikePeripheralName : config.ftmsRowerPeripheralName const fitnessMachineService = new FitnessMachineService(options, controlPointCallback) - const deviceInformationService = new DeviceInformationService() + // const deviceInformationService = new DeviceInformationService() bleno.on('stateChange', (state) => { triggerAdvertising(state) @@ -29,7 +29,8 @@ function createFtmsPeripheral (controlCallback, options) { bleno.on('advertisingStart', (error) => { if (!error) { bleno.setServices( - [fitnessMachineService, deviceInformationService], + // [fitnessMachineService, deviceInformationService], + [fitnessMachineService], (error) => { if (error) log.error(error) }) @@ -86,7 +87,8 @@ function createFtmsPeripheral (controlCallback, options) { if (activeState === 'poweredOn') { bleno.startAdvertising( peripheralName, - [fitnessMachineService.uuid, deviceInformationService.uuid], + // [fitnessMachineService.uuid, deviceInformationService.uuid], + [fitnessMachineService.uuid], (error) => { if (error) log.error(error) } diff --git a/app/gpio/GpioTimerService.js b/app/gpio/GpioTimerService.js index 15827aa..1e1a5b5 100644 --- a/app/gpio/GpioTimerService.js +++ b/app/gpio/GpioTimerService.js @@ -23,22 +23,27 @@ export function createGpioTimerService () { } catch (err) { log.debug('need root permission to set priority of Gpio-Thread') } - // mode can be rising, falling, both - const reedSensor = new Gpio(17, 'in', 'rising') - // use hrtime for time measurement to get a higher time precision - let hrStartTime = process.hrtime() - // assumes that GPIO-Port 17 is set to pullup and reed is connected to GND - // therefore the value is 1 if the reed sensor is open - reedSensor.watch((err, value) => { - if (err) { - throw err - } - const hrDelta = process.hrtime(hrStartTime) - hrStartTime = process.hrtime() - const delta = hrDelta[0] + hrDelta[1] / 1e9 - process.send(delta) - }) + if (Gpio.accessible) { + // mode can be rising, falling, both + const reedSensor = new Gpio(17, 'in', 'rising') + // use hrtime for time measurement to get a higher time precision + let hrStartTime = process.hrtime() + + // assumes that GPIO-Port 17 is set to pullup and reed is connected to GND + // therefore the value is 1 if the reed sensor is open + reedSensor.watch((err, value) => { + if (err) { + throw err + } + const hrDelta = process.hrtime(hrStartTime) + hrStartTime = process.hrtime() + const delta = hrDelta[0] + hrDelta[1] / 1e9 + process.send(delta) + }) + } else { + log.info('reading from Gpio is not (yet) supported on this platform') + } } createGpioTimerService()