import { Device } from "./device" ; import { IDeviceInterface } from "../interfaces" ; import * as Consts from "../consts" ; import { calculateRamp , mapSpeed } from "../utils" ; class extends Device export class BasicMotor extends Device { constructor ( hub , portId , modeMap , type = Consts . DeviceType . UNKNOWN ) { super ( hub , portId , modeMap , type ) ; } method param { number } power returns { Promise } public setPower ( power , interrupt = true ) { if ( interrupt ) { this . cancelEventTimer ( ) ; } return this . writeDirect ( 0x00 , Buffer . from ( [ mapSpeed ( power ) ] ) ) ; } method param { number } fromPower param { number } toPower param { number } time returns { Promise } public rampPower ( fromPower , toPower , time ) { this . cancelEventTimer ( ) ; return new Promise ( ( resolve ) => { calculateRamp ( this , fromPower , toPower , time ) . on ( "changePower" , ( power ) => { this . setPower ( power , false ) ; } ) . on ( "finished" , resolve ) ; } ) ; } method returns { Promise } public stop ( ) { this . cancelEventTimer ( ) ; return this . setPower ( 0 ) ; } method returns { Promise } public brake ( ) { this . cancelEventTimer ( ) ; return this . setPower ( Consts . BrakingStyle . BRAKE ) ; } }