IR works
This commit is contained in:
parent
03b864c355
commit
0cc3cfee4b
@ -27,4 +27,13 @@ int allocateNotifyEvent() {
|
||||
void dmesg(String s) {
|
||||
DMESG("# %s", s->data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace serial {
|
||||
/** Send DMESG debug buffer over serial. */
|
||||
//%
|
||||
void writeDmesg() {
|
||||
pxt::dumpDmesg();
|
||||
}
|
||||
}
|
@ -27,6 +27,7 @@ const enum LMS {
|
||||
DEVICE_TYPE_MINITACHO = 8,
|
||||
DEVICE_TYPE_NEWTACHO = 9,
|
||||
DEVICE_TYPE_TOUCH = 16,
|
||||
DEVICE_TYPE_IR = 33,
|
||||
DEVICE_TYPE_THIRD_PARTY_START = 50,
|
||||
DEVICE_TYPE_THIRD_PARTY_END = 99,
|
||||
DEVICE_TYPE_IIC_UNKNOWN = 100,
|
||||
|
6
libs/core/dmesg.txt
Normal file
6
libs/core/dmesg.txt
Normal file
@ -0,0 +1,6 @@
|
||||
[ 1] runtime starting...
|
||||
[ 53] runtime started [V0.60]
|
||||
[ 55] mmap /dev/lms_analog len=5172 off=0
|
||||
[ 56] mmap /dev/lms_uart len=42744 off=0
|
||||
[ 64] Error: 7 [0]
|
||||
[ 64] PANIC 42
|
@ -80,16 +80,19 @@ namespace input.internal {
|
||||
info.connType = newConn
|
||||
info.devType = LMS.DEVICE_TYPE_NONE
|
||||
if (newConn == LMS.CONN_INPUT_UART) {
|
||||
control.dmesg(`new UART connection at ${info.port}`)
|
||||
setUartMode(info.port, 0)
|
||||
let uinfo = readUartInfo(info.port, 0)
|
||||
info.devType = uinfo[TypesOff.Type]
|
||||
control.dmesg(`UART type ${info.devType}`)
|
||||
} else if (newConn == LMS.CONN_INPUT_DUMB) {
|
||||
control.dmesg(`new DUMB connection at ${info.port}`)
|
||||
// TODO? for now assume touch
|
||||
info.devType = LMS.DEVICE_TYPE_TOUCH
|
||||
} else if (newConn == LMS.CONN_NONE) {
|
||||
// OK
|
||||
} else if (newConn == LMS.CONN_NONE || newConn == 0) {
|
||||
control.dmesg(`disconnect at ${info.port}`)
|
||||
} else {
|
||||
// ???
|
||||
control.dmesg(`unknown connection type: ${newConn} at ${info.port}`)
|
||||
}
|
||||
}
|
||||
|
||||
@ -106,12 +109,16 @@ namespace input.internal {
|
||||
|
||||
for (let info of autos) {
|
||||
if (!info.sensor && info.devType != LMS.DEVICE_TYPE_NONE) {
|
||||
let found = false
|
||||
for (let s of autoSensors) {
|
||||
if (s.getPort() == 0 && s._deviceType() == info.devType) {
|
||||
s._setPort(info.port + 1)
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
control.dmesg(`sensor not found for type=${info.devType} at ${info.port}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -133,6 +140,8 @@ namespace input.internal {
|
||||
_setPort(port: number, manual = false) {
|
||||
port = Math.clamp(0, 4, port | 0) - 1;
|
||||
if (port == this.port) return
|
||||
this.port = port
|
||||
control.dmesg(`sensor set port ${port} on devtype=${this._deviceType()}`)
|
||||
for (let i = 0; i < sensors.length; ++i) {
|
||||
if (i != this.port && sensors[i].sensor == this) {
|
||||
sensors[i] = null
|
||||
@ -190,27 +199,33 @@ namespace input.internal {
|
||||
|
||||
export class UartSensor extends Sensor {
|
||||
protected mode: number
|
||||
protected realmode: number
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
this.mode = 0
|
||||
this.realmode = -1
|
||||
}
|
||||
|
||||
protected _portUpdated() {
|
||||
this.mode = -1
|
||||
this.realmode = -1
|
||||
if (this.port > 0) {
|
||||
if (this.isManual()) {
|
||||
uartReset(this.port)
|
||||
} else {
|
||||
this.mode = 0
|
||||
this.realmode = 0
|
||||
}
|
||||
this._setMode(this.mode)
|
||||
}
|
||||
}
|
||||
|
||||
protected _setMode(m: number) {
|
||||
if (this.port < 0) return
|
||||
//control.dmesg(`_setMode p=${this.port} m: ${this.realmode} -> ${m}`)
|
||||
let v = m | 0
|
||||
if (v != this.mode) {
|
||||
this.mode = v
|
||||
if (this.port < 0) return
|
||||
if (this.realmode != this.mode) {
|
||||
this.realmode = v
|
||||
setUartMode(this.port, v)
|
||||
}
|
||||
}
|
||||
@ -226,6 +241,7 @@ namespace input.internal {
|
||||
|
||||
function uartReset(port: number) {
|
||||
if (port < 0) return
|
||||
control.dmesg(`UART reset at ${port}`)
|
||||
devcon.setNumber(NumberFormat.Int8LE, DevConOff.Connection + port, LMS.CONN_NONE)
|
||||
devcon.setNumber(NumberFormat.Int8LE, DevConOff.Type + port, 0)
|
||||
devcon.setNumber(NumberFormat.Int8LE, DevConOff.Mode + port, 0)
|
||||
@ -272,6 +288,7 @@ namespace input.internal {
|
||||
const UART_PORT_CHANGED = 1
|
||||
while (true) {
|
||||
if (port < 0) return
|
||||
control.dmesg(`UART set mode to ${mode} at ${port}`)
|
||||
devcon.setNumber(NumberFormat.Int8LE, DevConOff.Connection + port, LMS.CONN_INPUT_UART)
|
||||
devcon.setNumber(NumberFormat.Int8LE, DevConOff.Type + port, 33)
|
||||
devcon.setNumber(NumberFormat.Int8LE, DevConOff.Mode + port, mode)
|
||||
|
@ -77,6 +77,10 @@ namespace input {
|
||||
}
|
||||
}
|
||||
|
||||
_deviceType() {
|
||||
return LMS.DEVICE_TYPE_IR
|
||||
}
|
||||
|
||||
setRemoteChannel(c: IrRemoteChannel) {
|
||||
c = Math.clamp(0, 3, c | 0)
|
||||
this.channel = c
|
||||
|
@ -52,6 +52,7 @@ static struct Thread *allThreads;
|
||||
static struct Event *eventHead, *eventTail;
|
||||
static int usbFD;
|
||||
static int dmesgPtr;
|
||||
static int dmesgSerialPtr;
|
||||
static char dmesgBuf[4096];
|
||||
|
||||
struct Event {
|
||||
@ -366,9 +367,11 @@ uint32_t afterProgramPage() {
|
||||
return 0;
|
||||
}
|
||||
void dumpDmesg() {
|
||||
sendSerial("\nDMESG:\n", 8);
|
||||
sendSerial(dmesgBuf, dmesgPtr);
|
||||
sendSerial("\n\n", 2);
|
||||
auto len = dmesgPtr - dmesgSerialPtr;
|
||||
if (len == 0)
|
||||
return;
|
||||
sendSerial(dmesgBuf + dmesgSerialPtr, len);
|
||||
dmesgSerialPtr = dmesgPtr;
|
||||
}
|
||||
|
||||
int lmsPid;
|
||||
@ -458,6 +461,7 @@ void dmesgRaw(const char *buf, uint32_t len) {
|
||||
return;
|
||||
if (dmesgPtr + len > sizeof(dmesgBuf)) {
|
||||
dmesgPtr = 0;
|
||||
dmesgSerialPtr = 0;
|
||||
}
|
||||
memcpy(dmesgBuf + dmesgPtr, buf, len);
|
||||
dmesgPtr += len;
|
||||
|
6
libs/core/shims.d.ts
vendored
6
libs/core/shims.d.ts
vendored
@ -56,6 +56,12 @@ declare namespace control {
|
||||
//% shim=control::dmesg
|
||||
function dmesg(s: string): void;
|
||||
}
|
||||
declare namespace serial {
|
||||
|
||||
/** Send DMESG debug buffer over serial. */
|
||||
//% shim=serial::writeDmesg
|
||||
function writeDmesg(): void;
|
||||
}
|
||||
declare namespace input {
|
||||
|
||||
/**
|
||||
|
@ -26,12 +26,27 @@ input.buttonUp.onEvent(ButtonEvent.Click, () => {
|
||||
screen.scroll(10)
|
||||
})
|
||||
|
||||
for (let i = 0; i < 3; ++i) {
|
||||
loops.forever(() => {
|
||||
let r = Math.randomRange(0, 100)
|
||||
serial.writeValue("R", r)
|
||||
//screen.drawText(10, 10, `R=${r}`)
|
||||
loops.pause(1000)
|
||||
|
||||
let num = 0
|
||||
|
||||
input.touch.button.onEvent(ButtonEvent.Click, () => {
|
||||
screen.drawText(10, 60, "Click! " + num)
|
||||
num++
|
||||
})
|
||||
|
||||
input.ir.getRemoteCommand()
|
||||
|
||||
input.ir.button(IrRemoteButton.TopLeft).onEvent(ButtonEvent.Down, () => {
|
||||
screen.drawText(10, 60, "TOPLEFT " + num)
|
||||
num++
|
||||
})
|
||||
|
||||
input.ir.button(IrRemoteButton.TopRight).onEvent(ButtonEvent.Down, () => {
|
||||
screen.drawText(10, 60, "TOPRIGH " + num)
|
||||
num++
|
||||
})
|
||||
|
||||
loops.forever(() => {
|
||||
serial.writeDmesg()
|
||||
loops.pause(400)
|
||||
})
|
||||
loops.pause(300)
|
||||
}
|
||||
|
@ -14,6 +14,10 @@ namespace input {
|
||||
_update(prev: number, curr: number) {
|
||||
this.button.update(curr > 0)
|
||||
}
|
||||
|
||||
_deviceType() {
|
||||
return LMS.DEVICE_TYPE_TOUCH
|
||||
}
|
||||
}
|
||||
|
||||
//% whenUsed
|
||||
|
Loading…
Reference in New Issue
Block a user