makes low level integrations less dependent on raspberry pi hardware
This commit is contained in:
parent
4a6f8d9cc1
commit
4e844b0722
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in New Issue