diff --git a/src/main.cpp b/src/main.cpp index 49c0c47..98d7f99 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,9 +21,9 @@ void setup() { analogWriteResolution(PWM_RESOLUTION); #ifdef ARDUINO_ARCH_ESP8266 - analogWriteFreq(PWM_FREQUENCY); + analogWriteFreq(std::min(PWM_FREQUENCY, PWM_MAX_FREQUENCY)); #else - analogWriteFrequency(PWM_FREQUENCY); + analogWriteFrequency(std::min(PWM_FREQUENCY, PWM_MAX_FREQUENCY)); #endif ApplicationInstance.begin(); diff --git a/src/sys_constants.h b/src/sys_constants.h index 9cb9155..7d45001 100644 --- a/src/sys_constants.h +++ b/src/sys_constants.h @@ -24,6 +24,12 @@ #define PWM_FREQUENCY (22000u) #define PWM_MAX_VALUE ((uint16_t)((1u << PWM_RESOLUTION) - 1)) +#ifdef ARDUINO_ARCH_ESP32 +#define PWM_MAX_FREQUENCY (40000000ul / (1u << PWM_RESOLUTION)) +#else +#define PWM_MAX_FREQUENCY (60000ul) +#endif + #define NTP_UPDATE_INTERVAL (24ul * 3600 * 1000) #define GAMMA (2.2f) diff --git a/www/src/props.js b/www/src/props.js index 8723cd2..fce6fd5 100644 --- a/www/src/props.js +++ b/www/src/props.js @@ -1,4 +1,5 @@ import {PacketType} from "./cmd.js"; +import {PWM_MAX_VALUE, TEMPERATURE_MAX_VALUE} from "./sys_constants.js"; /**@type {PropertiesConfig} */ export const PropertyConfig = [{ @@ -9,14 +10,14 @@ export const PropertyConfig = [{ {key: "showTemperature", type: "skip"}, {key: "power", title: "Power", type: "trigger", kind: "Boolean", cmd: PacketType.POWER}, - {key: "brightness", title: "Brightness", type: "wheel", limit: 16383, kind: "Uint16", cmd: PacketType.BRIGHTNESS}, + {key: "brightness", title: "Brightness", type: "wheel", limit: PWM_MAX_VALUE, kind: "Uint16", cmd: PacketType.BRIGHTNESS}, {key: "color", title: "Color", type: "color", kind: "Uint32", cmd: PacketType.COLOR, visibleIf: "rgbMode"}, {key: "calibration", title: "Calibration", type: "color", kind: "Uint32", cmd: PacketType.CALIBRATION, visibleIf: "rgbMode"}, { - key: "colorTemperature", title: "Color Temperature", type: "wheel", limit: 32767, kind: "Uint16", cmd: PacketType.TEMPERATURE, - anchor: 16383, anchorAmount: 0.02, anchored: true, visibleIf: "cctMode", + key: "colorTemperature", title: "Color Temperature", type: "wheel", limit: TEMPERATURE_MAX_VALUE, kind: "Uint16", cmd: PacketType.TEMPERATURE, + anchor: TEMPERATURE_MAX_VALUE / 2, anchorAmount: 0.02, anchored: true, visibleIf: "cctMode", displayConverter: function (value) { const percent = value / this.limit * 100; let converted; @@ -29,14 +30,14 @@ export const PropertyConfig = [{ let [int, fraction] = converted.toFixed(1).split("."); if (converted > 0) int = `+${int}`; - if(int === "-0") int = "0"; + if (int === "-0") int = "0"; return fraction === "0" ? int : [int, `.${fraction}`]; } }, { - key: "colorTemperatureRgb", title: "Color Temperature", type: "wheel", limit: 32767, kind: "Uint16", cmd: PacketType.TEMPERATURE, + key: "colorTemperatureRgb", title: "Color Temperature", type: "wheel", limit: TEMPERATURE_MAX_VALUE, kind: "Uint16", cmd: PacketType.TEMPERATURE, visibleIf: "rgbMode", displayConverter: function (value) { const {sysConfig: {ledMinTemperature, ledMaxTemperature}} = window.__app.app.config @@ -50,7 +51,7 @@ export const PropertyConfig = [{ }, { key: "night_mode", section: "Night Mode", collapse: true, props: [ {key: "nightMode.enabled", title: "Enabled", type: "trigger", kind: "Boolean", cmd: PacketType.NIGHT_MODE_ENABLED}, - {key: "nightMode.brightness", title: "Brightness", type: "wheel", limit: 16383, kind: "Uint16", cmd: PacketType.NIGHT_MODE_BRIGHTNESS}, + {key: "nightMode.brightness", title: "Brightness", type: "wheel", limit: PWM_MAX_VALUE, kind: "Uint16", cmd: PacketType.NIGHT_MODE_BRIGHTNESS}, {key: "nightMode.startTime", title: "Start Time", type: "time", kind: "Uint32", cmd: PacketType.NIGHT_MODE_START}, {key: "nightMode.endTime", title: "End Time", type: "time", kind: "Uint32", cmd: PacketType.NIGHT_MODE_END}, {key: "nightMode.switchInterval", title: "Switch Interval", type: "time", kind: "Uint16", cmd: PacketType.NIGHT_MODE_INTERVAL}, diff --git a/www/src/sys_constants.js b/www/src/sys_constants.js new file mode 100644 index 0000000..f8d93ae --- /dev/null +++ b/www/src/sys_constants.js @@ -0,0 +1,3 @@ +export const PWM_RESOLUTION = 14; +export const PWM_MAX_VALUE = (2 ** PWM_RESOLUTION - 1); +export const TEMPERATURE_MAX_VALUE = PWM_MAX_VALUE * 2; \ No newline at end of file