reading nxt analog sensor dev type

This commit is contained in:
Peli de Halleux 2019-10-11 22:20:16 -07:00
parent 030cd46c5f
commit fe39902d10

View File

@ -285,36 +285,53 @@ void cUiUpdatePower(void)
let nonActivated = 0;
function detectDevices() {
//control.dmesg(`detect devices (${nonActivated} na)`)
const conns = analogMM.slice(AnalogOff.InConn, DAL.NUM_INPUTS)
const inDcm = analogMM.slice(AnalogOff.InDcm, DAL.NUM_INPUTS)
const inConn = analogMM.slice(AnalogOff.InConn, DAL.NUM_INPUTS)
let numChanged = 0;
const uartSensors: SensorInfo[] = [];
for (const sensorInfo of sensorInfos) {
const newConn = conns[sensorInfo.port]
const newConn = inConn[sensorInfo.port]
if (newConn == sensorInfo.connType) {
// control.dmesg(`connection unchanged ${newConn} at ${sensorInfo.port}`)
continue;
}
numChanged++
sensorInfo.connType = newConn
sensorInfo.devType = DAL.DEVICE_TYPE_NONE
if (newConn == DAL.CONN_INPUT_UART) {
sensorInfo.devType = DAL.DEVICE_TYPE_NONE;
switch (newConn) {
case DAL.CONN_INPUT_UART: {
control.dmesg(`new UART connection at ${sensorInfo.port}`)
updateUartMode(sensorInfo.port, 0);
uartSensors.push(sensorInfo);
} else if (newConn == DAL.CONN_NXT_IIC) {
control.dmesg(`new IIC connection at ${sensorInfo.port}`)
break;
}
case DAL.CONN_NXT_IIC: {
control.dmesg(`new NXT IIC connection at ${sensorInfo.port}`)
sensorInfo.devType = DAL.DEVICE_TYPE_IIC_UNKNOWN
sensorInfo.iicid = readIICID(sensorInfo.port)
control.dmesg(`IIC ID ${sensorInfo.iicid.length}`)
} else if (newConn == DAL.CONN_INPUT_DUMB) {
break;
} case DAL.CONN_NXT_DUMB: { // analog NXT sensor
control.dmesg(`new NXT analog connection at ${sensorInfo.port}`);
sensorInfo.devType = inDcm[sensorInfo.port];
control.dmesg(`NXT analog dev type ${sensorInfo.devType}`);
break;
}
case DAL.CONN_INPUT_DUMB: {
control.dmesg(`new DUMB connection at ${sensorInfo.port}`)
// TODO? for now assume touch
sensorInfo.devType = DAL.DEVICE_TYPE_TOUCH
} else if (newConn == DAL.CONN_NONE || newConn == 0) {
break;
}
case DAL.CONN_NONE:
case 0: {
//control.dmesg(`disconnect at port ${sensorInfo.port}`)
} else {
break;
}
default: {
control.dmesg(`unknown connection type: ${newConn} at ${sensorInfo.port}`)
break;
}
}