import { Device } from "./device" ; import { IDeviceInterface } from "../interfaces" ; import * as Consts from "../consts" ; class extends Device export class TechnicForceSensor extends Device { constructor ( hub , portId ) { super ( hub , portId , ModeMap , Consts . DeviceType . TECHNIC_FORCE_SENSOR ) ; } public receive ( message ) { const mode = this . _mode ; switch ( mode ) { case Mode . FORCE : const force = message [ this . isWeDo2SmartHub ? 2 : 4 ] / 10 ; event type { object } param { number } force this . notify ( "force" , { force } ) ; break ; case Mode . TOUCHED : const touched = message [ 4 ] ? true : false ; event type { object } param { boolean } touch this . notify ( "touched" , { touched } ) ; break ; case Mode . TAPPED : const tapped = message [ 4 ] ; event type { object } param { number } tapped this . notify ( "tapped" , { tapped } ) ; break ; } } } export enum Mode { FORCE = 0x00 , TOUCHED = 0x01 , TAPPED = 0x02 } export const ModeMap = { "force" : Mode . FORCE , "touched" : Mode . TOUCHED , "tapped" : Mode . TAPPED } ;