diff --git a/usermods/mpu6050_imu/usermod_mpu6050_imu.h b/usermods/mpu6050_imu/usermod_mpu6050_imu.h index d904fb5ed..7d6215436 100644 --- a/usermods/mpu6050_imu/usermod_mpu6050_imu.h +++ b/usermods/mpu6050_imu/usermod_mpu6050_imu.h @@ -71,11 +71,11 @@ class MPU6050Driver : public Usermod { int16_t accel_offset[3]; }; config_t config; + bool configDirty = true; // does the configuration need an update? // MPU control/status vars bool irqBound = false; // set true if we have bound the IRQ pin 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 fifoCount; // count of all bytes currently in FIFO uint8_t fifoBuffer[64]; // FIFO storage buffer @@ -141,7 +141,10 @@ class MPU6050Driver : public Usermod { um_data.u_type[8] = UMT_UINT32; } + configDirty = false; // we have now accepted the current configuration, success or not + 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; } // Check the interrupt pin if (config.interruptPin >= 0) { @@ -166,7 +169,7 @@ class MPU6050Driver : public Usermod { // load and configure the DMP DEBUGUM_PRINTLN(F("Initializing DMP...")); - devStatus = mpu.dmpInitialize(); + auto devStatus = mpu.dmpInitialize(); // set offsets (from config) 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. */ void loop() { + if (configDirty) setup(); + // if programming failed, don't try to do anything if (!config.enabled || !dmpReady || strip.isUpdating()) return; @@ -391,8 +396,8 @@ class MPU6050Driver : public Usermod { irqBound = false; } - // Just re-init - setup(); + // Re-call setup on the next loop() + configDirty = true; } return configComplete; diff --git a/wled00/data/index.js b/wled00/data/index.js index 4e5a1eb0e..447bf03a6 100644 --- a/wled00/data/index.js +++ b/wled00/data/index.js @@ -1,7 +1,7 @@ //page js var loc = false, locip, locproto = "http:"; 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 nlMode = false; var segLmax = 0; // size (in pixels) of largest selected segment @@ -1339,7 +1339,7 @@ function updateSelectedFx() if (ds.id>0) { if (segLmax==0) fx.classList.add('hide'); // none of the segments selected (hide all effects) 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'); } } @@ -1441,7 +1441,7 @@ function readState(s,command=false) populateSegments(s); var selc=0; 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; for (let i = 0; i < (s.seg||[]).length; i++) { @@ -1452,20 +1452,23 @@ function readState(s,command=false) if (s.seg[i].sel) { if (sellvl < 2) selc = i; // get first selected segment 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); hasWhite |= !!(lc & 0x02); 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); - segLmax = segLmax < sLen ? sLen : segLmax; + has2D |= w > 1 && h > 1; + if (w*h > segLmax) segLmax = w*h; } } var i=s.seg[selc]; if (sellvl == 1) { - var lc = lastinfo.leds.seglc[selc]; + let lc = lastinfo.leds.seglc[selc]; hasRGB = !!(lc & 0x01); hasWhite = !!(lc & 0x02); hasCCT = !!(lc & 0x04); + has2D = (i.stop - i.start) > 1 && (i.stopY ? (i.stopY - i.startY) : 1) > 1; } if (!i) { showToast('No Segments!', true);