upgraded to lancaster 2.0.0.rc3 (core 0.1.9)
added radio.send/receive string
This commit is contained in:
parent
78f9af5bc2
commit
b4bc985068
@ -43,7 +43,7 @@ namespace radio {
|
||||
*/
|
||||
//% help=radio/send-number
|
||||
//% weight=60
|
||||
//% blockId=radio_datagram_send block="send number %MESSAGE" blockGap=8
|
||||
//% blockId=radio_datagram_send block="send number %value" blockGap=8
|
||||
void sendNumber(int value) {
|
||||
if (radioEnable() != MICROBIT_OK) return;
|
||||
uint32_t t = system_timer_current_time();
|
||||
@ -60,7 +60,7 @@ namespace radio {
|
||||
*/
|
||||
//% help=radio/send-value
|
||||
//% weight=59
|
||||
//% blockId=radio_datagram_send_value block="send|value %name|= %value"
|
||||
//% blockId=radio_datagram_send_value block="send|value %name|= %value" blockGap=8
|
||||
void sendValue(StringData* name, int value) {
|
||||
if (radioEnable() != MICROBIT_OK) return;
|
||||
|
||||
@ -81,6 +81,22 @@ namespace radio {
|
||||
uBit.radio.datagram.send(buf, 13 + len);
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcasts a number over radio to any connected micro:bit in the group.
|
||||
*/
|
||||
//% help=radio/send-string
|
||||
//% weight=58
|
||||
//% blockId=radio_datagram_send_string block="send string %msg"
|
||||
void sendString(StringData* msg) {
|
||||
if (radioEnable() != MICROBIT_OK) return;
|
||||
|
||||
ManagedString s(msg);
|
||||
if (s.length() > MICROBIT_RADIO_MAX_PACKET_SIZE)
|
||||
s = s.substring(0, MICROBIT_RADIO_MAX_PACKET_SIZE);
|
||||
|
||||
uBit.radio.datagram.send(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a value sent with `stream value` and writes it
|
||||
* to the serial stream as JSON
|
||||
@ -159,7 +175,19 @@ namespace radio {
|
||||
packet = uBit.radio.datagram.recv();
|
||||
return receivedNumberAt(0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reads the next packet as a string and returns it.
|
||||
*/
|
||||
//% blockId=radio_datagram_receive_string block="receive string" blockGap=8
|
||||
//% weight=44
|
||||
//% help=radio/receive-string
|
||||
StringData* receiveString() {
|
||||
if (radioEnable() != MICROBIT_OK) return ManagedString().leakData();
|
||||
packet = uBit.radio.datagram.recv();
|
||||
return ManagedString(packet).leakData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the received signal strength indicator (RSSI) from the packet received by ``receive number``. Not supported in simulator.
|
||||
* namespace=radio
|
||||
|
20
libs/microbit-radio/shims.d.ts
vendored
20
libs/microbit-radio/shims.d.ts
vendored
@ -10,7 +10,7 @@ declare namespace radio {
|
||||
*/
|
||||
//% help=radio/send-number
|
||||
//% weight=60
|
||||
//% blockId=radio_datagram_send block="send number %MESSAGE" blockGap=8 shim=radio::sendNumber
|
||||
//% blockId=radio_datagram_send block="send number %value" blockGap=8 shim=radio::sendNumber
|
||||
function sendNumber(value: number): void;
|
||||
|
||||
/**
|
||||
@ -21,9 +21,17 @@ declare namespace radio {
|
||||
*/
|
||||
//% help=radio/send-value
|
||||
//% weight=59
|
||||
//% blockId=radio_datagram_send_value block="send|value %name|= %value" shim=radio::sendValue
|
||||
//% blockId=radio_datagram_send_value block="send|value %name|= %value" blockGap=8 shim=radio::sendValue
|
||||
function sendValue(name: string, value: number): void;
|
||||
|
||||
/**
|
||||
* Broadcasts a number over radio to any connected micro:bit in the group.
|
||||
*/
|
||||
//% help=radio/send-string
|
||||
//% weight=58
|
||||
//% blockId=radio_datagram_send_string block="send string %msg" shim=radio::sendString
|
||||
function sendString(msg: string): void;
|
||||
|
||||
/**
|
||||
* Reads a value sent with `stream value` and writes it
|
||||
* to the serial stream as JSON
|
||||
@ -58,6 +66,14 @@ declare namespace radio {
|
||||
//% blockId=radio_datagram_receive block="receive number" blockGap=8 shim=radio::receiveNumber
|
||||
function receiveNumber(): number;
|
||||
|
||||
/**
|
||||
* Reads the next packet as a string and returns it.
|
||||
*/
|
||||
//% blockId=radio_datagram_receive_string block="receive string" blockGap=8
|
||||
//% weight=44
|
||||
//% help=radio/receive-string shim=radio::receiveString
|
||||
function receiveString(): string;
|
||||
|
||||
/**
|
||||
* Gets the received signal strength indicator (RSSI) from the packet received by ``receive number``. Not supported in simulator.
|
||||
* namespace=radio
|
||||
|
28
libs/microbit/dal.d.ts
vendored
28
libs/microbit/dal.d.ts
vendored
@ -86,7 +86,7 @@ declare const enum DAL {
|
||||
MICROBIT_DFU_HISTOGRAM_HEIGHT = 5,
|
||||
// built/yt/yotta_modules/microbit-dal/inc//bluetooth/MicroBitEventService.h
|
||||
// built/yt/yotta_modules/microbit-dal/inc//bluetooth/MicroBitIOPinService.h
|
||||
MICROBIT_IO_PIN_SERVICE_PINCOUNT = 20,
|
||||
MICROBIT_IO_PIN_SERVICE_PINCOUNT = 19,
|
||||
MICROBIT_IO_PIN_SERVICE_DATA_SIZE = 10,
|
||||
// built/yt/yotta_modules/microbit-dal/inc//bluetooth/MicroBitLEDService.h
|
||||
MICROBIT_BLE_MAXIMUM_SCROLLTEXT = 20,
|
||||
@ -208,6 +208,7 @@ declare const enum DAL {
|
||||
MMA8653_SAMPLE_RANGES = 3,
|
||||
MMA8653_SAMPLE_RATES = 8,
|
||||
MICROBIT_ACCELEROMETER_EVT_DATA_UPDATE = 1,
|
||||
MICROBIT_ACCELEROMETER_EVT_NONE = 0,
|
||||
MICROBIT_ACCELEROMETER_EVT_TILT_UP = 1,
|
||||
MICROBIT_ACCELEROMETER_EVT_TILT_DOWN = 2,
|
||||
MICROBIT_ACCELEROMETER_EVT_TILT_LEFT = 3,
|
||||
@ -229,18 +230,6 @@ declare const enum DAL {
|
||||
MICROBIT_ACCELEROMETER_GESTURE_DAMPING = 10,
|
||||
MICROBIT_ACCELEROMETER_SHAKE_DAMPING = 10,
|
||||
MICROBIT_ACCELEROMETER_SHAKE_COUNT_THRESHOLD = 4,
|
||||
GESTURE_NONE = 0,
|
||||
GESTURE_UP = 1,
|
||||
GESTURE_DOWN = 2,
|
||||
GESTURE_LEFT = 3,
|
||||
GESTURE_RIGHT = 4,
|
||||
GESTURE_FACE_UP = 5,
|
||||
GESTURE_FACE_DOWN = 6,
|
||||
GESTURE_FREEFALL = 7,
|
||||
GESTURE_3G = 8,
|
||||
GESTURE_6G = 9,
|
||||
GESTURE_8G = 10,
|
||||
GESTURE_SHAKE = 11,
|
||||
// built/yt/yotta_modules/microbit-dal/inc//drivers/MicroBitButton.h
|
||||
MICROBIT_BUTTON_EVT_DOWN = 1,
|
||||
MICROBIT_BUTTON_EVT_UP = 2,
|
||||
@ -343,14 +332,22 @@ declare const enum DAL {
|
||||
IO_STATUS_ANALOG_IN = 0x04,
|
||||
IO_STATUS_ANALOG_OUT = 0x08,
|
||||
IO_STATUS_TOUCH_IN = 0x10,
|
||||
IO_STATUS_EVENTBUS_ENABLED = 0x80,
|
||||
IO_STATUS_EVENT_ON_EDGE = 0x20,
|
||||
IO_STATUS_EVENT_PULSE_ON_EDGE = 0x40,
|
||||
MICROBIT_PIN_MAX_OUTPUT = 1023,
|
||||
MICROBIT_PIN_MAX_SERVO_RANGE = 180,
|
||||
MICROBIT_PIN_DEFAULT_SERVO_RANGE = 2000,
|
||||
MICROBIT_PIN_DEFAULT_SERVO_CENTER = 1500,
|
||||
MICROBIT_PIN_EVENT_NONE = 0,
|
||||
MICROBIT_PIN_EVENT_ON_EDGE = 1,
|
||||
MICROBIT_PIN_EVENT_ON_PULSE = 2,
|
||||
MICROBIT_PIN_EVENT_ON_TOUCH = 3,
|
||||
MICROBIT_PIN_EVT_RISE = 2,
|
||||
MICROBIT_PIN_EVT_FALL = 3,
|
||||
MICROBIT_PIN_EVT_PULSE_HI = 4,
|
||||
MICROBIT_PIN_EVT_PULSE_LO = 5,
|
||||
PIN_CAPABILITY_DIGITAL = 0x01,
|
||||
PIN_CAPABILITY_ANALOG = 0x02,
|
||||
PIN_CAPABILITY_TOUCH = 0x04,
|
||||
// built/yt/yotta_modules/microbit-dal/inc//drivers/MicroBitRadio.h
|
||||
MICROBIT_RADIO_STATUS_INITIALISED = 0x0001,
|
||||
MICROBIT_RADIO_BASE_ADDRESS = 0x75626974,
|
||||
@ -388,6 +385,7 @@ declare const enum DAL {
|
||||
MICROBIT_THERMOMETER_PERIOD = 1000,
|
||||
MICROBIT_THERMOMETER_EVT_UPDATE = 1,
|
||||
MICROBIT_THERMOMETER_ADDED_TO_IDLE = 2,
|
||||
// built/yt/yotta_modules/microbit-dal/inc//drivers/TimedInterruptIn.h
|
||||
// built/yt/yotta_modules/microbit-dal/inc//platform/yotta_cfg_mappings.h
|
||||
// built/yt/yotta_modules/microbit-dal/inc//types/ManagedString.h
|
||||
// built/yt/yotta_modules/microbit-dal/inc//types/ManagedType.h
|
||||
|
18
libs/microbit/enums.d.ts
vendored
18
libs/microbit/enums.d.ts
vendored
@ -69,42 +69,42 @@ declare namespace basic {
|
||||
* Raised when shaken
|
||||
*/
|
||||
//% block=shake
|
||||
Shake = 11, // GESTURE_SHAKE
|
||||
Shake = 11, // MICROBIT_ACCELEROMETER_EVT_SHAKE
|
||||
/**
|
||||
* Raised when the logo is upward and the screen is vertical
|
||||
*/
|
||||
//% block="logo up"
|
||||
LogoUp = 1, // GESTURE_UP
|
||||
LogoUp = 1, // MICROBIT_ACCELEROMETER_EVT_TILT_UP
|
||||
/**
|
||||
* Raised when the logo is downward and the screen is vertical
|
||||
*/
|
||||
//% block="logo down"
|
||||
LogoDown = 2, // GESTURE_DOWN
|
||||
LogoDown = 2, // MICROBIT_ACCELEROMETER_EVT_TILT_DOWN
|
||||
/**
|
||||
* Raised when the screen is pointing down and the board is horizontal
|
||||
*/
|
||||
//% block="screen up"
|
||||
ScreenUp = 5, // GESTURE_FACE_UP
|
||||
ScreenUp = 5, // MICROBIT_ACCELEROMETER_EVT_FACE_UP
|
||||
/**
|
||||
* Raised when the screen is pointing up and the board is horizontal
|
||||
*/
|
||||
//% block="screen down"
|
||||
ScreenDown = 6, // GESTURE_FACE_DOWN
|
||||
ScreenDown = 6, // MICROBIT_ACCELEROMETER_EVT_FACE_DOWN
|
||||
/**
|
||||
* Raised when the screen is pointing left
|
||||
*/
|
||||
//% block="tilt left"
|
||||
TiltLeft = 3, // GESTURE_LEFT
|
||||
TiltLeft = 3, // MICROBIT_ACCELEROMETER_EVT_TILT_LEFT
|
||||
/**
|
||||
* Raised when the screen is pointing right
|
||||
*/
|
||||
//% block="tilt right"
|
||||
TiltRight = 4, // GESTURE_RIGHT
|
||||
TiltRight = 4, // MICROBIT_ACCELEROMETER_EVT_TILT_RIGHT
|
||||
/**
|
||||
* Raised when the board is falling!
|
||||
*/
|
||||
//% block="free fall"
|
||||
FreeFall = 7, // GESTURE_FREEFALL
|
||||
FreeFall = 7, // MICROBIT_ACCELEROMETER_EVT_FREEFALL
|
||||
}
|
||||
declare namespace input {
|
||||
}
|
||||
@ -281,7 +281,5 @@ declare namespace serial {
|
||||
Int32BE = 10,
|
||||
// UInt32,
|
||||
}
|
||||
declare namespace storage {
|
||||
}
|
||||
|
||||
// Auto-generated. Do not edit. Really.
|
||||
|
@ -59,42 +59,42 @@ enum class Gesture {
|
||||
* Raised when shaken
|
||||
*/
|
||||
//% block=shake
|
||||
Shake = GESTURE_SHAKE,
|
||||
Shake = MICROBIT_ACCELEROMETER_EVT_SHAKE,
|
||||
/**
|
||||
* Raised when the logo is upward and the screen is vertical
|
||||
*/
|
||||
//% block="logo up"
|
||||
LogoUp = GESTURE_UP,
|
||||
LogoUp = MICROBIT_ACCELEROMETER_EVT_TILT_UP,
|
||||
/**
|
||||
* Raised when the logo is downward and the screen is vertical
|
||||
*/
|
||||
//% block="logo down"
|
||||
LogoDown = GESTURE_DOWN,
|
||||
LogoDown = MICROBIT_ACCELEROMETER_EVT_TILT_DOWN,
|
||||
/**
|
||||
* Raised when the screen is pointing down and the board is horizontal
|
||||
*/
|
||||
//% block="screen up"
|
||||
ScreenUp = GESTURE_FACE_UP,
|
||||
ScreenUp = MICROBIT_ACCELEROMETER_EVT_FACE_UP,
|
||||
/**
|
||||
* Raised when the screen is pointing up and the board is horizontal
|
||||
*/
|
||||
//% block="screen down"
|
||||
ScreenDown = GESTURE_FACE_DOWN,
|
||||
ScreenDown = MICROBIT_ACCELEROMETER_EVT_FACE_DOWN,
|
||||
/**
|
||||
* Raised when the screen is pointing left
|
||||
*/
|
||||
//% block="tilt left"
|
||||
TiltLeft = GESTURE_LEFT,
|
||||
TiltLeft = MICROBIT_ACCELEROMETER_EVT_TILT_LEFT,
|
||||
/**
|
||||
* Raised when the screen is pointing right
|
||||
*/
|
||||
//% block="tilt right"
|
||||
TiltRight = GESTURE_RIGHT,
|
||||
TiltRight = MICROBIT_ACCELEROMETER_EVT_TILT_RIGHT,
|
||||
/**
|
||||
* Raised when the board is falling!
|
||||
*/
|
||||
//% block="free fall"
|
||||
FreeFall = GESTURE_FREEFALL
|
||||
FreeFall = MICROBIT_ACCELEROMETER_EVT_FREEFALL
|
||||
};
|
||||
|
||||
//% color=300 weight=99
|
||||
|
@ -26,8 +26,7 @@
|
||||
"pins.ts",
|
||||
"serial.cpp",
|
||||
"serial.ts",
|
||||
"buffer.cpp",
|
||||
"storage.cpp"
|
||||
"buffer.cpp"
|
||||
],
|
||||
"public": true,
|
||||
"dependencies": {},
|
||||
|
33
libs/microbit/shims.d.ts
vendored
33
libs/microbit/shims.d.ts
vendored
@ -597,37 +597,4 @@ declare interface Buffer {
|
||||
write(dstOffset: number, src: Buffer): void;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This allows reading and writing of small blocks of data to FLASH memory.
|
||||
*/
|
||||
//% weight=10 color=#cc6600
|
||||
declare namespace storage {
|
||||
|
||||
/**
|
||||
* Writes the key and buffer pair into FLASH. This operation is rather costly as all the key/value pairs
|
||||
* have to be rewritten as well.
|
||||
*/
|
||||
//% shim=storage::putBuffer
|
||||
function putBuffer(key: string, buffer: Buffer): void;
|
||||
|
||||
/**
|
||||
* Gets the buffer at the given key if any. If no key is available, empty buffer is returned.
|
||||
*/
|
||||
//% shim=storage::getBuffer
|
||||
function getBuffer(key: string): Buffer;
|
||||
|
||||
/**
|
||||
* Removes an entry identified by the key.
|
||||
*/
|
||||
//% shim=storage::remove
|
||||
function remove(key: string): void;
|
||||
|
||||
/**
|
||||
* The number of entries in the key value store
|
||||
*/
|
||||
//% shim=storage::size
|
||||
function size(): number;
|
||||
}
|
||||
|
||||
// Auto-generated. Do not edit. Really.
|
||||
|
@ -1,43 +0,0 @@
|
||||
#include "ksbit.h"
|
||||
|
||||
/**
|
||||
* This allows reading and writing of small blocks of data to FLASH memory.
|
||||
*/
|
||||
//% weight=10 color=#cc6600
|
||||
namespace storage {
|
||||
/**
|
||||
* Writes the key and buffer pair into FLASH. This operation is rather costly as all the key/value pairs
|
||||
* have to be rewritten as well.
|
||||
*/
|
||||
//%
|
||||
void putBuffer(StringData* key, Buffer buffer) {
|
||||
uBit.storage.put(ManagedString(key), ManagedBuffer(buffer).getBytes());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the buffer at the given key if any. If no key is available, empty buffer is returned.
|
||||
*/
|
||||
//%
|
||||
Buffer getBuffer(StringData* key) {
|
||||
KeyValuePair* pv = uBit.storage.get(ManagedString(key));
|
||||
if (pv == NULL) return ManagedBuffer().leakData();
|
||||
|
||||
return ManagedBuffer(pv->value, sizeof(pv->value)).leakData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an entry identified by the key.
|
||||
*/
|
||||
//%
|
||||
void remove(StringData * key) {
|
||||
uBit.storage.remove(ManagedString(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* The number of entries in the key value store
|
||||
*/
|
||||
//%
|
||||
int size() {
|
||||
return uBit.storage.size();
|
||||
}
|
||||
}
|
@ -63,7 +63,7 @@
|
||||
"aspectRatio": 1.22
|
||||
},
|
||||
"compileService": {
|
||||
"gittag": "v0.1.8",
|
||||
"gittag": "v0.1.9",
|
||||
"serviceId": "ws"
|
||||
},
|
||||
"serial": {
|
||||
|
@ -457,6 +457,10 @@ namespace pxsim.radio {
|
||||
board().radio.datagram.send([value]);
|
||||
}
|
||||
|
||||
export function sendString(msg: string): void {
|
||||
board().radio.datagram.send(msg);
|
||||
}
|
||||
|
||||
export function writeValueToSerial(): void {
|
||||
let b = board();
|
||||
let v = b.radio.datagram.recv().data[0];
|
||||
@ -468,11 +472,23 @@ namespace pxsim.radio {
|
||||
}
|
||||
|
||||
export function receiveNumber(): number {
|
||||
return board().radio.datagram.recv().data[0];
|
||||
let buffer = board().radio.datagram.recv().data;
|
||||
if (buffer instanceof Array) return buffer[0];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
export function receiveString(): string {
|
||||
let buffer = board().radio.datagram.recv().data;
|
||||
if (typeof buffer === "string") return <string>buffer;
|
||||
return "";
|
||||
}
|
||||
|
||||
export function receivedNumberAt(index: number): number {
|
||||
return board().radio.datagram.lastReceived.data[index] || 0;
|
||||
let buffer = board().radio.datagram.recv().data;
|
||||
if (buffer instanceof Array) return buffer[index] || 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
export function receivedSignalStrength(): number {
|
||||
|
66
sim/state.ts
66
sim/state.ts
@ -56,7 +56,7 @@ namespace pxsim {
|
||||
}
|
||||
|
||||
export interface PacketBuffer {
|
||||
data: number[];
|
||||
data: number[] | string;
|
||||
rssi?: number;
|
||||
}
|
||||
|
||||
@ -77,10 +77,13 @@ namespace pxsim {
|
||||
}
|
||||
}
|
||||
|
||||
send(buffer: number[]) {
|
||||
send(buffer: number[] | string) {
|
||||
if (buffer instanceof String) buffer = buffer.slice(0, 32);
|
||||
else buffer = buffer.slice(0, 8);
|
||||
|
||||
Runtime.postMessage(<SimulatorRadioPacketMessage>{
|
||||
type: 'radiopacket',
|
||||
data: buffer.slice(0, 8)
|
||||
type: "radiopacket",
|
||||
data: buffer
|
||||
})
|
||||
}
|
||||
|
||||
@ -128,21 +131,6 @@ namespace pxsim {
|
||||
}
|
||||
}
|
||||
|
||||
export enum BasicGesture {
|
||||
GESTURE_NONE,
|
||||
GESTURE_UP,
|
||||
GESTURE_DOWN,
|
||||
GESTURE_LEFT,
|
||||
GESTURE_RIGHT,
|
||||
GESTURE_FACE_UP,
|
||||
GESTURE_FACE_DOWN,
|
||||
GESTURE_FREEFALL,
|
||||
GESTURE_3G,
|
||||
GESTURE_6G,
|
||||
GESTURE_8G,
|
||||
GESTURE_SHAKE
|
||||
};
|
||||
|
||||
interface AccelerometerSample {
|
||||
x: number;
|
||||
y: number;
|
||||
@ -196,8 +184,8 @@ namespace pxsim {
|
||||
|
||||
export class Accelerometer {
|
||||
private sigma: number = 0; // the number of ticks that the instantaneous gesture has been stable.
|
||||
private lastGesture: BasicGesture = BasicGesture.GESTURE_NONE; // the last, stable gesture recorded.
|
||||
private currentGesture: BasicGesture = BasicGesture.GESTURE_NONE; // the instantaneous, unfiltered gesture detected.
|
||||
private lastGesture: number = 0; // the last, stable gesture recorded.
|
||||
private currentGesture: number = 0 // the instantaneous, unfiltered gesture detected.
|
||||
private sample: AccelerometerSample = { x: 0, y: 0, z: -1023 }
|
||||
private shake: ShakeHistory = { x: false, y: false, z: false, count: 0, shaken: 0, timer: 0 }; // State information needed to detect shake events.
|
||||
private pitch: number;
|
||||
@ -250,7 +238,7 @@ namespace pxsim {
|
||||
*
|
||||
* @return A best guess of the current posture of the device, based on instantaneous data.
|
||||
*/
|
||||
private instantaneousPosture(): BasicGesture {
|
||||
private instantaneousPosture(): number {
|
||||
let force = this.instantaneousAccelerationSquared();
|
||||
let shakeDetected = false;
|
||||
|
||||
@ -287,42 +275,42 @@ namespace pxsim {
|
||||
}
|
||||
|
||||
if (this.shake.shaken)
|
||||
return BasicGesture.GESTURE_SHAKE;
|
||||
return DAL.MICROBIT_ACCELEROMETER_EVT_SHAKE;
|
||||
|
||||
let sq = (n: number) => n * n
|
||||
|
||||
if (force < sq(DAL.MICROBIT_ACCELEROMETER_FREEFALL_TOLERANCE))
|
||||
return BasicGesture.GESTURE_FREEFALL;
|
||||
return DAL.MICROBIT_ACCELEROMETER_EVT_FREEFALL;
|
||||
|
||||
if (force > sq(DAL.MICROBIT_ACCELEROMETER_3G_TOLERANCE))
|
||||
return BasicGesture.GESTURE_3G;
|
||||
return DAL.MICROBIT_ACCELEROMETER_EVT_3G;
|
||||
|
||||
if (force > sq(DAL.MICROBIT_ACCELEROMETER_6G_TOLERANCE))
|
||||
return BasicGesture.GESTURE_6G;
|
||||
return DAL.MICROBIT_ACCELEROMETER_EVT_6G;
|
||||
|
||||
if (force > sq(DAL.MICROBIT_ACCELEROMETER_8G_TOLERANCE))
|
||||
return BasicGesture.GESTURE_8G;
|
||||
return DAL.MICROBIT_ACCELEROMETER_EVT_8G;
|
||||
|
||||
// Determine our posture.
|
||||
if (this.getX() < (-1000 + DAL.MICROBIT_ACCELEROMETER_TILT_TOLERANCE))
|
||||
return BasicGesture.GESTURE_LEFT;
|
||||
return DAL.MICROBIT_ACCELEROMETER_EVT_TILT_LEFT;
|
||||
|
||||
if (this.getX() > (1000 - DAL.MICROBIT_ACCELEROMETER_TILT_TOLERANCE))
|
||||
return BasicGesture.GESTURE_RIGHT;
|
||||
return DAL.MICROBIT_ACCELEROMETER_EVT_TILT_RIGHT;
|
||||
|
||||
if (this.getY() < (-1000 + DAL.MICROBIT_ACCELEROMETER_TILT_TOLERANCE))
|
||||
return BasicGesture.GESTURE_DOWN;
|
||||
return DAL.MICROBIT_ACCELEROMETER_EVT_TILT_DOWN;
|
||||
|
||||
if (this.getY() > (1000 - DAL.MICROBIT_ACCELEROMETER_TILT_TOLERANCE))
|
||||
return BasicGesture.GESTURE_UP;
|
||||
return DAL.MICROBIT_ACCELEROMETER_EVT_TILT_UP;
|
||||
|
||||
if (this.getZ() < (-1000 + DAL.MICROBIT_ACCELEROMETER_TILT_TOLERANCE))
|
||||
return BasicGesture.GESTURE_FACE_UP;
|
||||
return DAL.MICROBIT_ACCELEROMETER_EVT_FACE_UP;
|
||||
|
||||
if (this.getZ() > (1000 - DAL.MICROBIT_ACCELEROMETER_TILT_TOLERANCE))
|
||||
return BasicGesture.GESTURE_FACE_DOWN;
|
||||
return DAL.MICROBIT_ACCELEROMETER_EVT_FACE_DOWN;
|
||||
|
||||
return BasicGesture.GESTURE_NONE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
updateGesture() {
|
||||
@ -578,16 +566,16 @@ namespace pxsim {
|
||||
if (!runtime || runtime.dead) return;
|
||||
|
||||
switch (msg.type || "") {
|
||||
case 'eventbus':
|
||||
case "eventbus":
|
||||
let ev = <SimulatorEventBusMessage>msg;
|
||||
this.bus.queue(ev.id, ev.eventid, ev.value);
|
||||
break;
|
||||
case 'serial':
|
||||
this.serialIn.push((<SimulatorSerialMessage>msg).data || '');
|
||||
case "serial":
|
||||
this.serialIn.push((<SimulatorSerialMessage>msg).data || "");
|
||||
break;
|
||||
case 'radiopacket':
|
||||
case "radiopacket":
|
||||
let packet = <SimulatorRadioPacketMessage>msg;
|
||||
this.radio.datagram.queue({ data: packet.data || [], rssi: packet.rssi || 0 })
|
||||
this.radio.datagram.queue({ data: packet.data, rssi: packet.rssi || 0 })
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user