Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes in mode change for color sensor #1025

Merged
merged 13 commits into from
Jul 18, 2023
Prev Previous commit
Next Next commit
Update color.ts
  • Loading branch information
THEb0nny committed Jul 15, 2023
commit 5b89c45cff4862b6a700be6251e626c93e9086d2
12 changes: 9 additions & 3 deletions libs/color-sensor/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,19 @@ namespace sensors {
setMode(m: ColorSensorMode) {
// don't change threshold after initialization
if (m != this.mode && this.isActive()) { // If the new mode is different from what was set for the sensor
/*
let maxModeRange = 0;
if (m == ColorSensorMode.RefRaw || m == ColorSensorMode.RgbRaw) maxModeRange = 1023;
else if (m == ColorSensorMode.Color) maxModeRange = 7;
else maxModeRange = 100; // ReflectedLightIntensity or AmbientLightIntensity
*/
//const previousValue = this.mode == ColorSensorMode.RgbRaw ? this._queryArr()[0] : this._query(); // Before changing the mode, remember what the value was
this._setMode(m); // Change mode
//const startChangeTime = control.millis();
//const startModeChangeTime = control.millis();
pause(MODE_SWITCH_DELAY);
pauseUntil(() => (this.getStatus() == 8 && (this.mode == ColorSensorMode.RgbRaw ? this._queryArr()[0] : this._query()) < 1024)); // Pause until mode change
pauseUntil(() => (this.getStatus() == 8 && (this.mode == ColorSensorMode.RgbRaw ? this._queryArr()[0] : this._query()) <= 1023)); // Pause until mode change
/*
const modeChangeTime = control.millis() - startChangeTime;
const modeChangeTime = control.millis() - startModeChangeTime;
control.dmesg(`Previous value ${previousValue} before mode change on port ${this._port}`);
control.dmesg(`Value ${this.mode == ColorSensorMode.RgbRaw ? this._queryArr()[0] : this._query()} after mode change in port ${this._port}`);
control.dmesg(`Time at mode change ${modeChangeTime} msec in port ${this._port}`);
Expand Down