diff --git a/libs/core/dal.d.ts b/libs/core/dal.d.ts index a01cd452..bf9e6fdd 100644 --- a/libs/core/dal.d.ts +++ b/libs/core/dal.d.ts @@ -2,6 +2,7 @@ declare const enum DAL { // built/dockermake/pxtapp/ev3const.h NUM_INPUTS = 4, + NUM_OUTPUTS = 4, LCD_WIDTH = 178, LCD_HEIGHT = 128, NUM_BUTTONS = 6, @@ -45,6 +46,7 @@ declare const enum DAL { CONN_OUTPUT_TACHO = 125, CONN_NONE = 126, CONN_ERROR = 127, + opProgramStart = 0x03, opOutputGetType = 0xA0, opOutputSetType = 0xA1, opOutputReset = 0xA2, diff --git a/libs/core/ev3const.h b/libs/core/ev3const.h index 2a424a29..6c222ff3 100644 --- a/libs/core/ev3const.h +++ b/libs/core/ev3const.h @@ -2,6 +2,7 @@ #define __PXT_EV3CONST_H #define NUM_INPUTS 4 +#define NUM_OUTPUTS 4 #define LCD_WIDTH 178 #define LCD_HEIGHT 128 #define NUM_BUTTONS 6 @@ -52,6 +53,7 @@ #define CONN_NONE 126 #define CONN_ERROR 127 +#define opProgramStart 0x03 #define opOutputGetType 0xA0 #define opOutputSetType 0xA1 #define opOutputReset 0xA2 diff --git a/libs/core/output.cpp b/libs/core/output.cpp index dde7d9bd..bc08bd13 100644 --- a/libs/core/output.cpp +++ b/libs/core/output.cpp @@ -1,5 +1,5 @@ #include "pxt.h" -#include "ev3.h" +#include "ev3const.h" namespace output { @@ -12,18 +12,11 @@ Buffer createBuffer(int size) { return mkBuffer(NULL, size); } -extern "C" int WriteToPWMDevice(char *bytes, int num_bytes); - -//% -void writePWM(Buffer buf) { - WriteToPWMDevice((char *)buf->data, buf->length); -} } namespace pxt { void target_init() { - OutputInit(); } } diff --git a/libs/core/output.ts b/libs/core/output.ts index 5213658c..19f5ac93 100644 --- a/libs/core/output.ts +++ b/libs/core/output.ts @@ -13,8 +13,34 @@ enum OutputType { } namespace output { - //% shim=output::writePWM - function writePWM(buf: Buffer): void { } + let pwmMM: MMap + let motorMM: MMap + + const enum MotorDataOff { + TachoCounts = 0, // int32 + Speed = 4, // int8 + Padding = 5, // int8[3] + TachoSensor = 8, // int32 + Size = 12 + } + + function init() { + if (pwmMM) return + pwmMM = control.mmap("/dev/lms_pwm", 0, 0) + if (!pwmMM) control.fail("no PWM file") + motorMM = control.mmap("/dev/lms_motor", MotorDataOff.Size * DAL.NUM_OUTPUTS, 0) + + stop(Output.ALL) + + let buf = output.createBuffer(1) + buf[0] = DAL.opProgramStart + writePWM(buf) + } + + function writePWM(buf: Buffer): void { + init() + pwmMM.write(buf) + } function mkCmd(out: Output, cmd: number, addSize: number) { let b = createBuffer(2 + addSize) diff --git a/libs/core/pxt.json b/libs/core/pxt.json index b7d3e261..50e20cee 100644 --- a/libs/core/pxt.json +++ b/libs/core/pxt.json @@ -30,11 +30,9 @@ "testFiles": [ "test.ts" ], - "npmDependencies": { - "ev3api-bin": "1.1.0" - }, + "npmDependencies": {}, "public": true, "dependencies": { "base": "file:../base" } -} +} \ No newline at end of file