minimal calibration sequence update
This commit is contained in:
11
index.js
11
index.js
@@ -279,10 +279,13 @@ io.on('connection', async (socket) => {
|
|||||||
|
|
||||||
// Update calibration status in database based on device's actual state
|
// Update calibration status in database based on device's actual state
|
||||||
if (data.port && typeof data.calibrated === 'boolean') {
|
if (data.port && typeof data.calibrated === 'boolean') {
|
||||||
const result = await pool.query(
|
// When the device declares itself uncalibrated, also clear await_calib so
|
||||||
"update peripherals set calibrated=$1 where device_id=$2 and peripheral_number=$3 returning id, user_id",
|
// any stale pending-calibration state is gone. The device is already connected
|
||||||
[data.calibrated, rows[0].device_id, data.port]
|
// via socket, so the next calib_start from the agenda job will land correctly.
|
||||||
);
|
const updateQuery = data.calibrated
|
||||||
|
? "update peripherals set calibrated=TRUE where device_id=$1 and peripheral_number=$2 returning id, user_id"
|
||||||
|
: "update peripherals set calibrated=FALSE, await_calib=FALSE where device_id=$1 and peripheral_number=$2 returning id, user_id";
|
||||||
|
const result = await pool.query(updateQuery, [rows[0].device_id, data.port]);
|
||||||
console.log(`Updated port ${data.port} calibrated status to ${data.calibrated}`);
|
console.log(`Updated port ${data.port} calibrated status to ${data.calibrated}`);
|
||||||
|
|
||||||
// Notify user app of calibration status change
|
// Notify user app of calibration status change
|
||||||
|
|||||||
Reference in New Issue
Block a user