Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/devices: parsing sensor #65

Closed
wants to merge 12 commits into from
108 changes: 21 additions & 87 deletions src/consts.ts
Original file line number Diff line number Diff line change
@@ -1,90 +1,3 @@
/**
* @typedef HubType
* @property {number} UNKNOWN 0
* @property {number} WEDO2_SMART_HUB 1
* @property {number} MOVE_HUB 2
* @property {number} POWERED_UP_HUB 3
* @property {number} POWERED_UP_REMOTE 4
* @property {number} DUPLO_TRAIN_HUB 5
* @property {number} CONTROL_PLUS_HUB 6
*/
export enum HubType {
UNKNOWN = 0,
WEDO2_SMART_HUB = 1,
MOVE_HUB = 2,
HUB = 3,
REMOTE_CONTROL = 4,
DUPLO_TRAIN_BASE = 5,
TECHNIC_MEDIUM_HUB = 6
}


// tslint:disable-next-line
export const HubTypeNames = HubType;


/**
* @typedef DeviceType
* @property {number} UNKNOWN 0
* @property {number} SIMPLE_MEDIUM_LINEAR_MOTOR 1
* @property {number} TRAIN_MOTOR 2
* @property {number} LED_LIGHTS 8
* @property {number} VOLTAGE 20
* @property {number} CURRENT 21
* @property {number} PIEZO_TONE 22
* @property {number} RGB_LIGHT 23
* @property {number} WEDO2_TILT 34
* @property {number} WEDO2_DISTANCE 35
* @property {number} COLOR_DISTANCE_SENSOR 37
* @property {number} MEDIUM_LINEAR_MOTOR 38
* @property {number} MOVE_HUB_MEDIUM_LINEAR_MOTOR 39
* @property {number} BOOST_TILT 40
* @property {number} DUPLO_TRAIN_BASE_MOTOR 41
* @property {number} DUPLO_TRAIN_BASE_SPEAKER 42
* @property {number} DUPLO_TRAIN_BASE_COLOR 43
* @property {number} DUPLO_TRAIN_BASE_SPEEDOMETER 44
* @property {number} CONTROL_PLUS_LARGE_MOTOR 46
* @property {number} CONTROL_PLUS_XLARGE_MOTOR 47
* @property {number} POWERED_UP_REMOTE_BUTTON 55
* @property {number} RSSI 56
* @property {number} CONTROL_PLUS_ACCELEROMETER 58
* @property {number} CONTROL_PLUS_TILT 59
*/
export enum DeviceType {
UNKNOWN = 0,
SIMPLE_MEDIUM_LINEAR_MOTOR = 1,
TRAIN_MOTOR = 2,
LIGHT = 8,
VOLTAGE_SENSOR = 20,
CURRENT_SENSOR = 21,
PIEZO_BUZZER = 22,
HUB_LED = 23,
TILT_SENSOR = 34,
MOTION_SENSOR = 35,
COLOR_DISTANCE_SENSOR = 37,
MEDIUM_LINEAR_MOTOR = 38,
MOVE_HUB_MEDIUM_LINEAR_MOTOR = 39,
MOVE_HUB_TILT_SENSOR = 40,
DUPLO_TRAIN_BASE_MOTOR = 41,
DUPLO_TRAIN_BASE_SPEAKER = 42,
DUPLO_TRAIN_BASE_COLOR_SENSOR = 43,
DUPLO_TRAIN_BASE_SPEEDOMETER = 44,
TECHNIC_LARGE_LINEAR_MOTOR = 46,
TECHNIC_XLARGE_LINEAR_MOTOR = 47,
TECHNIC_MEDIUM_HUB_GEST_SENSOR = 54,
REMOTE_CONTROL_BUTTON = 55,
REMOTE_CONTROL_RSSI = 56,
TECHNIC_MEDIUM_HUB_ACCELEROMETER = 57,
TECHNIC_MEDIUM_HUB_GYRO_SENSOR = 58,
TECHNIC_MEDIUM_HUB_TILT_SENSOR = 59,
TECHNIC_MEDIUM_HUB_TEMPERATURE_SENSOR = 60,
}


// tslint:disable-next-line
export const DeviceTypeNames = DeviceType;


/**
* @typedef Color
* @property {number} BLACK 0
Expand Down Expand Up @@ -189,3 +102,24 @@ export enum BLECharacteristic {
WEDO2_NAME_ID = "00001524-1212-efde-1523-785feabcd123", // "1524"
LPF2_ALL = "00001624-1212-efde-1623-785feabcd123"
}

export enum ValueType {
UInt8 = "UInt8",
Int8 = "Int8",
UInt16 = "UInt16",
Int16 = "Int16",
UInt32 = "UInt32",
Int32 = "Int32",
Float = "Float"
}

// tslint:disable-next-line
export const ValueBits = {
[ValueType.UInt8]: 1,
[ValueType.Int8]: 1,
[ValueType.UInt16]: 2,
[ValueType.Int16]: 2,
[ValueType.UInt32]: 4,
[ValueType.Int32]: 4,
[ValueType.Float]: 4
};
93 changes: 93 additions & 0 deletions src/devices.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { Device } from "./devices/generic/device";
export { Device };

import { ColorDistanceSensor } from "./devices/colordistancesensor";
import { CurrentSensor } from "./devices/currentsensor";
import { DuploTrainBaseColorSensor } from "./devices/duplotrainbasecolorsensor";
import { DuploTrainBaseMotor } from "./devices/duplotrainbasemotor";
import { DuploTrainBaseSpeaker } from "./devices/duplotrainbasespeaker";
import { DuploTrainBaseSpeedometer } from "./devices/duplotrainbasespeedometer";
import { HubLED } from "./devices/hubled";
import { Light } from "./devices/light";
import { MediumLinearMotor } from "./devices/mediumlinearmotor";
import { MotionSensor } from "./devices/motionsensor";
import { MoveHubMediumLinearMotor } from "./devices/movehubmediumlinearmotor";
import { MoveHubTiltSensor } from "./devices/movehubtiltsensor";
import { PiezoBuzzer } from "./devices/piezobuzzer";
import { RemoteControlButton } from "./devices/remotecontrolbutton";
import { SimpleMediumLinearMotor } from "./devices/simplemediumlinearmotor";
import { TechnicLargeLinearMotor } from "./devices/techniclargelinearmotor";
import { TechnicMediumHubAccelerometerSensor } from "./devices/technicmediumhubaccelerometersensor";
import { TechnicMediumHubGyroSensor } from "./devices/technicmediumhubgyrosensor";
import { TechnicMediumHubTiltSensor } from "./devices/technicmediumhubtiltsensor";
import { TechnicXLargeLinearMotor } from "./devices/technicxlargelinearmotor";
import { TiltSensor } from "./devices/tiltsensor";
import { TrainMotor } from "./devices/trainmotor";
import { VoltageSensor } from "./devices/voltagesensor";

export {
ColorDistanceSensor,
CurrentSensor,
DuploTrainBaseColorSensor,
DuploTrainBaseMotor,
DuploTrainBaseSpeaker,
DuploTrainBaseSpeedometer,
HubLED,
Light,
MediumLinearMotor,
MotionSensor,
MoveHubMediumLinearMotor,
MoveHubTiltSensor,
PiezoBuzzer,
RemoteControlButton,
SimpleMediumLinearMotor,
TechnicLargeLinearMotor,
TechnicMediumHubAccelerometerSensor,
TechnicMediumHubGyroSensor,
TechnicMediumHubTiltSensor,
TechnicXLargeLinearMotor,
TiltSensor,
TrainMotor,
VoltageSensor,
};

export const devices: {[type: number]: typeof Device} = {
[SimpleMediumLinearMotor.type]: SimpleMediumLinearMotor,
[TrainMotor.type]: TrainMotor,
[Light.type]: Light,
[VoltageSensor.type]: VoltageSensor,
[CurrentSensor.type]: CurrentSensor,
[PiezoBuzzer.type]: PiezoBuzzer,
[HubLED.type]: HubLED,
[TiltSensor.type]: TiltSensor,
[MotionSensor.type]: MotionSensor,
[ColorDistanceSensor.type]: ColorDistanceSensor,
[MediumLinearMotor.type]: MediumLinearMotor,
[MoveHubMediumLinearMotor.type]: MoveHubMediumLinearMotor,
[MoveHubTiltSensor.type]: MoveHubTiltSensor,
[DuploTrainBaseMotor.type]: DuploTrainBaseMotor,
[DuploTrainBaseSpeaker.type]: DuploTrainBaseSpeaker,
[DuploTrainBaseColorSensor.type]: DuploTrainBaseColorSensor,
[DuploTrainBaseSpeedometer.type]: DuploTrainBaseSpeedometer,
[TechnicLargeLinearMotor.type]: TechnicLargeLinearMotor,
[TechnicXLargeLinearMotor.type]: TechnicXLargeLinearMotor,
[RemoteControlButton.type]: RemoteControlButton,
[TechnicMediumHubAccelerometerSensor.type]: TechnicMediumHubAccelerometerSensor,
[TechnicMediumHubGyroSensor.type]: TechnicMediumHubGyroSensor,
[TechnicMediumHubTiltSensor.type]: TechnicMediumHubTiltSensor,
};

export const deviceType: {[typeName: string]: number} = {
UNKNOW: 0,
};
export const deviceTypeNames: {[typeName: number]: string } = {
0: "UNKNOW",
};

for (const type in devices) {
if (devices[+type]) {
const device = devices[+type];
deviceType[device.typeName] = device.type;
deviceTypeNames[device.type] = device.typeName;
}
}
Comment on lines +80 to +93
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they are no longer enum and I think it is not very good.

Loading