Merge branch '0_15' into debug-refactor

This commit is contained in:
Blaž Kristan 2024-07-10 14:27:51 +02:00
commit 6417193986
2 changed files with 19 additions and 11 deletions

View File

@ -71,11 +71,11 @@ class MPU6050Driver : public Usermod {
int16_t accel_offset[3]; int16_t accel_offset[3];
}; };
config_t config; config_t config;
bool configDirty = true; // does the configuration need an update?
// MPU control/status vars // MPU control/status vars
bool irqBound = false; // set true if we have bound the IRQ pin bool irqBound = false; // set true if we have bound the IRQ pin
bool dmpReady = false; // set true if DMP init was successful bool dmpReady = false; // set true if DMP init was successful
uint8_t devStatus; // return status after each device operation (0 = success, !0 = error)
uint16_t packetSize; // expected DMP packet size (default is 42 bytes) uint16_t packetSize; // expected DMP packet size (default is 42 bytes)
uint16_t fifoCount; // count of all bytes currently in FIFO uint16_t fifoCount; // count of all bytes currently in FIFO
uint8_t fifoBuffer[64]; // FIFO storage buffer uint8_t fifoBuffer[64]; // FIFO storage buffer
@ -141,7 +141,10 @@ class MPU6050Driver : public Usermod {
um_data.u_type[8] = UMT_UINT32; um_data.u_type[8] = UMT_UINT32;
} }
configDirty = false; // we have now accepted the current configuration, success or not
if (!config.enabled) return; if (!config.enabled) return;
// TODO: notice if these have changed ??
if (i2c_scl<0 || i2c_sda<0) { DEBUGUM_PRINTLN(F("MPU6050: I2C is no good.")); return; } if (i2c_scl<0 || i2c_sda<0) { DEBUGUM_PRINTLN(F("MPU6050: I2C is no good.")); return; }
// Check the interrupt pin // Check the interrupt pin
if (config.interruptPin >= 0) { if (config.interruptPin >= 0) {
@ -166,7 +169,7 @@ class MPU6050Driver : public Usermod {
// load and configure the DMP // load and configure the DMP
DEBUGUM_PRINTLN(F("Initializing DMP...")); DEBUGUM_PRINTLN(F("Initializing DMP..."));
devStatus = mpu.dmpInitialize(); auto devStatus = mpu.dmpInitialize();
// set offsets (from config) // set offsets (from config)
mpu.setXGyroOffset(config.gyro_offset[0]); mpu.setXGyroOffset(config.gyro_offset[0]);
@ -225,6 +228,8 @@ class MPU6050Driver : public Usermod {
* loop() is called continuously. Here you can check for events, read sensors, etc. * loop() is called continuously. Here you can check for events, read sensors, etc.
*/ */
void loop() { void loop() {
if (configDirty) setup();
// if programming failed, don't try to do anything // if programming failed, don't try to do anything
if (!config.enabled || !dmpReady || strip.isUpdating()) return; if (!config.enabled || !dmpReady || strip.isUpdating()) return;
@ -391,8 +396,8 @@ class MPU6050Driver : public Usermod {
irqBound = false; irqBound = false;
} }
// Just re-init // Re-call setup on the next loop()
setup(); configDirty = true;
} }
return configComplete; return configComplete;

View File

@ -1,7 +1,7 @@
//page js //page js
var loc = false, locip, locproto = "http:"; var loc = false, locip, locproto = "http:";
var isOn = false, nlA = false, isLv = false, isInfo = false, isNodes = false, syncSend = false/*, syncTglRecv = true*/; var isOn = false, nlA = false, isLv = false, isInfo = false, isNodes = false, syncSend = false/*, syncTglRecv = true*/;
var hasWhite = false, hasRGB = false, hasCCT = false; var hasWhite = false, hasRGB = false, hasCCT = false, has2D = false;
var nlDur = 60, nlTar = 0; var nlDur = 60, nlTar = 0;
var nlMode = false; var nlMode = false;
var segLmax = 0; // size (in pixels) of largest selected segment var segLmax = 0; // size (in pixels) of largest selected segment
@ -1339,7 +1339,7 @@ function updateSelectedFx()
if (ds.id>0) { if (ds.id>0) {
if (segLmax==0) fx.classList.add('hide'); // none of the segments selected (hide all effects) if (segLmax==0) fx.classList.add('hide'); // none of the segments selected (hide all effects)
else { else {
if ((segLmax==1 && (!opts[3] || opts[3].indexOf("0")<0)) || (!isM && opts[3] && ((opts[3].indexOf("2")>=0 && opts[3].indexOf("1")<0)))) fx.classList.add('hide'); if ((segLmax==1 && (!opts[3] || opts[3].indexOf("0")<0)) || (!has2D && opts[3] && ((opts[3].indexOf("2")>=0 && opts[3].indexOf("1")<0)))) fx.classList.add('hide');
else fx.classList.remove('hide'); else fx.classList.remove('hide');
} }
} }
@ -1441,7 +1441,7 @@ function readState(s,command=false)
populateSegments(s); populateSegments(s);
var selc=0; var selc=0;
var sellvl=0; // 0: selc is invalid, 1: selc is mainseg, 2: selc is first selected var sellvl=0; // 0: selc is invalid, 1: selc is mainseg, 2: selc is first selected
hasRGB = hasWhite = hasCCT = false; hasRGB = hasWhite = hasCCT = has2D = false;
segLmax = 0; segLmax = 0;
for (let i = 0; i < (s.seg||[]).length; i++) for (let i = 0; i < (s.seg||[]).length; i++)
{ {
@ -1452,20 +1452,23 @@ function readState(s,command=false)
if (s.seg[i].sel) { if (s.seg[i].sel) {
if (sellvl < 2) selc = i; // get first selected segment if (sellvl < 2) selc = i; // get first selected segment
sellvl = 2; sellvl = 2;
var lc = lastinfo.leds.seglc[i]; let w = (s.seg[i].stop - s.seg[i].start);
let h = s.seg[i].stopY ? (s.seg[i].stopY - s.seg[i].startY) : 1;
let lc = lastinfo.leds.seglc[i];
hasRGB |= !!(lc & 0x01); hasRGB |= !!(lc & 0x01);
hasWhite |= !!(lc & 0x02); hasWhite |= !!(lc & 0x02);
hasCCT |= !!(lc & 0x04); hasCCT |= !!(lc & 0x04);
let sLen = (s.seg[i].stop - s.seg[i].start)*(s.seg[i].stopY?(s.seg[i].stopY - s.seg[i].startY):1); has2D |= w > 1 && h > 1;
segLmax = segLmax < sLen ? sLen : segLmax; if (w*h > segLmax) segLmax = w*h;
} }
} }
var i=s.seg[selc]; var i=s.seg[selc];
if (sellvl == 1) { if (sellvl == 1) {
var lc = lastinfo.leds.seglc[selc]; let lc = lastinfo.leds.seglc[selc];
hasRGB = !!(lc & 0x01); hasRGB = !!(lc & 0x01);
hasWhite = !!(lc & 0x02); hasWhite = !!(lc & 0x02);
hasCCT = !!(lc & 0x04); hasCCT = !!(lc & 0x04);
has2D = (i.stop - i.start) > 1 && (i.stopY ? (i.stopY - i.startY) : 1) > 1;
} }
if (!i) { if (!i) {
showToast('No Segments!', true); showToast('No Segments!', true);