rxpoweredup
Version:
A Typescript RxJS-based library for controlling LEGO Powered UP hubs & peripherals.
257 lines (256 loc) • 14.1 kB
JavaScript
export const HUB_SERVICE_UUID = '00001623-1212-efde-1623-785feabcd123';
export const HUB_CHARACTERISTIC_UUID = '00001624-1212-efde-1623-785feabcd123';
export var MessageType;
(function (MessageType) {
MessageType[MessageType["properties"] = 1] = "properties";
MessageType[MessageType["action"] = 2] = "action";
MessageType[MessageType["attachedIO"] = 4] = "attachedIO";
MessageType[MessageType["genericError"] = 5] = "genericError";
MessageType[MessageType["portInformationRequest"] = 33] = "portInformationRequest";
MessageType[MessageType["portModeInformationRequest"] = 34] = "portModeInformationRequest";
MessageType[MessageType["portInputFormatSetupSingle"] = 65] = "portInputFormatSetupSingle";
MessageType[MessageType["portInformation"] = 67] = "portInformation";
MessageType[MessageType["portModeInformation"] = 68] = "portModeInformation";
MessageType[MessageType["portValueSingle"] = 69] = "portValueSingle";
MessageType[MessageType["portInputFormatSetupSingleHandshake"] = 71] = "portInputFormatSetupSingleHandshake";
MessageType[MessageType["virtualPortSetup"] = 97] = "virtualPortSetup";
MessageType[MessageType["portOutputCommand"] = 129] = "portOutputCommand";
MessageType[MessageType["portOutputCommandFeedback"] = 130] = "portOutputCommandFeedback";
})(MessageType || (MessageType = {}));
export var HubActionType;
(function (HubActionType) {
HubActionType[HubActionType["switchOff"] = 1] = "switchOff";
HubActionType[HubActionType["disconnect"] = 2] = "disconnect";
HubActionType[HubActionType["willSwitchOff"] = 48] = "willSwitchOff";
HubActionType[HubActionType["willDisconnect"] = 49] = "willDisconnect";
})(HubActionType || (HubActionType = {}));
export var PortModeInformationType;
(function (PortModeInformationType) {
PortModeInformationType[PortModeInformationType["name"] = 0] = "name";
PortModeInformationType[PortModeInformationType["rawRange"] = 1] = "rawRange";
PortModeInformationType[PortModeInformationType["pctRange"] = 2] = "pctRange";
PortModeInformationType[PortModeInformationType["siRange"] = 3] = "siRange";
PortModeInformationType[PortModeInformationType["symbol"] = 4] = "symbol";
PortModeInformationType[PortModeInformationType["mapping"] = 5] = "mapping";
PortModeInformationType[PortModeInformationType["motorBias"] = 7] = "motorBias";
PortModeInformationType[PortModeInformationType["capabilityBits"] = 8] = "capabilityBits";
PortModeInformationType[PortModeInformationType["valueFormat"] = 9] = "valueFormat";
})(PortModeInformationType || (PortModeInformationType = {}));
export var PortInformationRequestType;
(function (PortInformationRequestType) {
PortInformationRequestType[PortInformationRequestType["portValue"] = 0] = "portValue";
PortInformationRequestType[PortInformationRequestType["modeInfo"] = 1] = "modeInfo";
})(PortInformationRequestType || (PortInformationRequestType = {}));
export var PortInformationReplyType;
(function (PortInformationReplyType) {
PortInformationReplyType[PortInformationReplyType["modeInfo"] = 1] = "modeInfo";
})(PortInformationReplyType || (PortInformationReplyType = {}));
export var AttachIoEvent;
(function (AttachIoEvent) {
AttachIoEvent[AttachIoEvent["Detached"] = 0] = "Detached";
AttachIoEvent[AttachIoEvent["Attached"] = 1] = "Attached";
AttachIoEvent[AttachIoEvent["AttachedVirtual"] = 2] = "AttachedVirtual";
})(AttachIoEvent || (AttachIoEvent = {}));
export var IOType;
(function (IOType) {
IOType[IOType["motor"] = 1] = "motor";
IOType[IOType["systemTrainMotor"] = 2] = "systemTrainMotor";
IOType[IOType["button"] = 5] = "button";
IOType[IOType["ledLight"] = 8] = "ledLight";
IOType[IOType["voltage"] = 20] = "voltage";
IOType[IOType["current"] = 21] = "current";
IOType[IOType["piezoTone"] = 22] = "piezoTone";
IOType[IOType["rgbLight"] = 23] = "rgbLight";
IOType[IOType["externalTiltSensor"] = 34] = "externalTiltSensor";
IOType[IOType["motionSensor"] = 35] = "motionSensor";
IOType[IOType["visionSensor"] = 37] = "visionSensor";
IOType[IOType["externalMotorWithTacho"] = 38] = "externalMotorWithTacho";
IOType[IOType["internalMotorWithTacho"] = 39] = "internalMotorWithTacho";
IOType[IOType["internalTilt"] = 40] = "internalTilt";
IOType[IOType["largeTechnicMotor"] = 46] = "largeTechnicMotor";
IOType[IOType["xLargeTechnicMotor"] = 47] = "xLargeTechnicMotor";
IOType[IOType["gestureSensor"] = 54] = "gestureSensor";
IOType[IOType["handsetButtonGroup"] = 55] = "handsetButtonGroup";
IOType[IOType["accelerometerSensor"] = 57] = "accelerometerSensor";
IOType[IOType["gyroscopeSensor"] = 58] = "gyroscopeSensor";
IOType[IOType["tiltSensor"] = 59] = "tiltSensor";
IOType[IOType["temperatureSensor"] = 60] = "temperatureSensor";
IOType[IOType["mediumTechnicAngularMotor"] = 75] = "mediumTechnicAngularMotor";
IOType[IOType["largeTechnicAngularMotor"] = 76] = "largeTechnicAngularMotor";
})(IOType || (IOType = {}));
export var HubPropertyOperation;
(function (HubPropertyOperation) {
HubPropertyOperation[HubPropertyOperation["setProperty"] = 1] = "setProperty";
HubPropertyOperation[HubPropertyOperation["enableUpdates"] = 2] = "enableUpdates";
HubPropertyOperation[HubPropertyOperation["disableUpdates"] = 3] = "disableUpdates";
HubPropertyOperation[HubPropertyOperation["reset"] = 4] = "reset";
HubPropertyOperation[HubPropertyOperation["requestUpdate"] = 5] = "requestUpdate";
HubPropertyOperation[HubPropertyOperation["update"] = 6] = "update";
})(HubPropertyOperation || (HubPropertyOperation = {}));
export const MAX_NAME_SIZE = 14;
export var HubProperty;
(function (HubProperty) {
HubProperty[HubProperty["advertisingName"] = 1] = "advertisingName";
HubProperty[HubProperty["button"] = 2] = "button";
HubProperty[HubProperty["firmwareVersion"] = 3] = "firmwareVersion";
HubProperty[HubProperty["hardwareVersion"] = 4] = "hardwareVersion";
HubProperty[HubProperty["RSSI"] = 5] = "RSSI";
HubProperty[HubProperty["batteryVoltage"] = 6] = "batteryVoltage";
HubProperty[HubProperty["manufacturerName"] = 8] = "manufacturerName";
HubProperty[HubProperty["systemTypeId"] = 11] = "systemTypeId";
HubProperty[HubProperty["primaryMacAddress"] = 13] = "primaryMacAddress";
})(HubProperty || (HubProperty = {}));
export var HubType;
(function (HubType) {
HubType[HubType["WeDoHub"] = 0] = "WeDoHub";
HubType[HubType["DuploTrain"] = 1] = "DuploTrain";
HubType[HubType["BoostHub"] = 2] = "BoostHub";
HubType[HubType["TwoPortHub"] = 3] = "TwoPortHub";
HubType[HubType["TwoPortHandset"] = 4] = "TwoPortHandset";
HubType[HubType["Unknown"] = 5] = "Unknown";
HubType[HubType["FourPortHub"] = 6] = "FourPortHub";
})(HubType || (HubType = {}));
export const HUB_DEVICE_TYPE_MAP = {
[0b00000000]: HubType.WeDoHub,
[0b00100000]: HubType.DuploTrain,
[0b01000000]: HubType.BoostHub,
[0b01000001]: HubType.TwoPortHub,
[0b01000010]: HubType.TwoPortHandset,
[0b10000000]: HubType.FourPortHub,
};
export var PortModeName;
(function (PortModeName) {
PortModeName["speed"] = "SPEED";
PortModeName["position"] = "POS";
PortModeName["absolutePosition"] = "APOS";
PortModeName["power"] = "POWER";
PortModeName["color"] = "COL O";
PortModeName["rgb"] = "RGB O";
PortModeName["currentS"] = "CUR S";
PortModeName["currentL"] = "CUR L";
PortModeName["voltageS"] = "VLT S";
PortModeName["voltageL"] = "VLT L";
PortModeName["handsetRCKey"] = "RCKEY";
PortModeName["handsetKeyA"] = "KEYA";
PortModeName["handsetKeyR"] = "KEYR";
PortModeName["handsetKeyD"] = "KEYD";
PortModeName["handsetKeySD"] = "KEYSD";
PortModeName["raw"] = "RAW";
PortModeName["impact"] = "IMP";
PortModeName["load"] = "LOAD";
PortModeName["temperature"] = "TEMP";
PortModeName["gravity"] = "GRV";
PortModeName["gesture"] = "GEST";
PortModeName["lpf2Train"] = "LPF2-TRAIN";
PortModeName["lpf2MMotor"] = "LPF2-MMOTOR";
})(PortModeName || (PortModeName = {}));
export var PortModeSymbol;
(function (PortModeSymbol) {
PortModeSymbol["percent"] = "PCT";
PortModeSymbol["degree"] = "DEG";
PortModeSymbol["milliAmps"] = "mA";
PortModeSymbol["milliVolts"] = "mV";
PortModeSymbol["button"] = "btn";
PortModeSymbol["count"] = "CNT";
PortModeSymbol["generic"] = "";
PortModeSymbol["milliG"] = "mG";
})(PortModeSymbol || (PortModeSymbol = {}));
export const MOTOR_LIMITS = {
maxSpeed: 100,
minSpeed: -100,
minPower: 0,
maxPower: 100,
minRawAngle: -0x7ffffff,
maxRawAngle: 0x7ffffff,
minServoDegreesRange: 15,
maxServoDegreesRange: 360,
maxAccDecTime: 10000,
minAccDecTime: 0,
};
export var MotorServoEndState;
(function (MotorServoEndState) {
MotorServoEndState[MotorServoEndState["float"] = 0] = "float";
MotorServoEndState[MotorServoEndState["hold"] = 126] = "hold";
MotorServoEndState[MotorServoEndState["brake"] = 127] = "brake";
})(MotorServoEndState || (MotorServoEndState = {}));
export var PortOperationStartupInformation;
(function (PortOperationStartupInformation) {
PortOperationStartupInformation[PortOperationStartupInformation["bufferIfNecessary"] = 0] = "bufferIfNecessary";
PortOperationStartupInformation[PortOperationStartupInformation["executeImmediately"] = 16] = "executeImmediately";
})(PortOperationStartupInformation || (PortOperationStartupInformation = {}));
export var PortOperationCompletionInformation;
(function (PortOperationCompletionInformation) {
PortOperationCompletionInformation[PortOperationCompletionInformation["noAction"] = 0] = "noAction";
PortOperationCompletionInformation[PortOperationCompletionInformation["commandFeedback"] = 1] = "commandFeedback";
})(PortOperationCompletionInformation || (PortOperationCompletionInformation = {}));
export var MotorUseProfile;
(function (MotorUseProfile) {
MotorUseProfile[MotorUseProfile["dontUseProfiles"] = 0] = "dontUseProfiles";
MotorUseProfile[MotorUseProfile["useAccelerationProfile"] = 1] = "useAccelerationProfile";
MotorUseProfile[MotorUseProfile["useDecelerationProfile"] = 2] = "useDecelerationProfile";
MotorUseProfile[MotorUseProfile["useAccelerationAndDecelerationProfiles"] = 3] = "useAccelerationAndDecelerationProfiles";
})(MotorUseProfile || (MotorUseProfile = {}));
export var OutputSubCommand;
(function (OutputSubCommand) {
OutputSubCommand[OutputSubCommand["setAccTime"] = 5] = "setAccTime";
OutputSubCommand[OutputSubCommand["setDecTime"] = 6] = "setDecTime";
OutputSubCommand[OutputSubCommand["startSpeed"] = 7] = "startSpeed";
OutputSubCommand[OutputSubCommand["startSpeedSynchronized"] = 8] = "startSpeedSynchronized";
OutputSubCommand[OutputSubCommand["startSpeedForDegrees"] = 11] = "startSpeedForDegrees";
OutputSubCommand[OutputSubCommand["gotoAbsolutePosition"] = 13] = "gotoAbsolutePosition";
OutputSubCommand[OutputSubCommand["gotoAbsolutePositionSynchronized"] = 14] = "gotoAbsolutePositionSynchronized";
OutputSubCommand[OutputSubCommand["writeDirectModeData"] = 81] = "writeDirectModeData";
})(OutputSubCommand || (OutputSubCommand = {}));
export var PortCommandFeedbackMask;
(function (PortCommandFeedbackMask) {
PortCommandFeedbackMask[PortCommandFeedbackMask["bufferEmptyCommandInProgress"] = 1] = "bufferEmptyCommandInProgress";
PortCommandFeedbackMask[PortCommandFeedbackMask["bufferEmptyCommandCompleted"] = 2] = "bufferEmptyCommandCompleted";
PortCommandFeedbackMask[PortCommandFeedbackMask["currentCommandDiscarded"] = 4] = "currentCommandDiscarded";
PortCommandFeedbackMask[PortCommandFeedbackMask["idle"] = 8] = "idle";
PortCommandFeedbackMask[PortCommandFeedbackMask["busyOrFull"] = 16] = "busyOrFull";
PortCommandFeedbackMask[PortCommandFeedbackMask["executionError"] = 32] = "executionError";
})(PortCommandFeedbackMask || (PortCommandFeedbackMask = {}));
export var GenericErrorCode;
(function (GenericErrorCode) {
GenericErrorCode[GenericErrorCode["ACK"] = 1] = "ACK";
GenericErrorCode[GenericErrorCode["MACK"] = 2] = "MACK";
GenericErrorCode[GenericErrorCode["bufferOverflow"] = 3] = "bufferOverflow";
GenericErrorCode[GenericErrorCode["timeout"] = 4] = "timeout";
GenericErrorCode[GenericErrorCode["commandNotRecognized"] = 5] = "commandNotRecognized";
GenericErrorCode[GenericErrorCode["invalidUse"] = 6] = "invalidUse";
GenericErrorCode[GenericErrorCode["overcurrent"] = 7] = "overcurrent";
GenericErrorCode[GenericErrorCode["internalError"] = 8] = "internalError";
})(GenericErrorCode || (GenericErrorCode = {}));
export var ButtonGroupButtonId;
(function (ButtonGroupButtonId) {
ButtonGroupButtonId[ButtonGroupButtonId["None"] = 0] = "None";
ButtonGroupButtonId[ButtonGroupButtonId["Plus"] = 1] = "Plus";
ButtonGroupButtonId[ButtonGroupButtonId["Red"] = 127] = "Red";
ButtonGroupButtonId[ButtonGroupButtonId["Minus"] = 255] = "Minus";
})(ButtonGroupButtonId || (ButtonGroupButtonId = {}));
export const MOTOR_ACC_DEC_DEFAULT_PROFILE_ID = 0;
export var LogLevel;
(function (LogLevel) {
LogLevel[LogLevel["Debug"] = 0] = "Debug";
LogLevel[LogLevel["Info"] = 1] = "Info";
LogLevel[LogLevel["Warning"] = 2] = "Warning";
LogLevel[LogLevel["Error"] = 3] = "Error";
})(LogLevel || (LogLevel = {}));
export const WELL_KNOWN_PORT_MODE_IDS = {
motor: {
[PortModeName.power]: 0,
[PortModeName.position]: 2,
[PortModeName.absolutePosition]: 3,
[PortModeName.lpf2Train]: 0,
[PortModeName.lpf2MMotor]: 0,
},
voltage: 0,
tilt: 0,
temperature: 0,
rgbLightRgbColor: 1,
};
export var VirtualPortSetupCommand;
(function (VirtualPortSetupCommand) {
VirtualPortSetupCommand[VirtualPortSetupCommand["Disconnect"] = 0] = "Disconnect";
VirtualPortSetupCommand[VirtualPortSetupCommand["Connect"] = 1] = "Connect";
})(VirtualPortSetupCommand || (VirtualPortSetupCommand = {}));