diff --git a/code/espurna/ir.ino b/code/espurna/ir.ino index e57b45d0..deba94ee 100644 --- a/code/espurna/ir.ino +++ b/code/espurna/ir.ino @@ -23,12 +23,13 @@ unsigned long _ir_last_toggle = 0; void _irProcessCode(unsigned long code, unsigned char type) { // Check valid code - unsigned long last_code = 0; - unsigned long last_time = 0; + static unsigned long last_code = 0; + static unsigned long last_time = 0; if (code == 0xFFFFFFFF) return; if (type == 0xFF) return; if ((last_code == code) && (millis() - last_time < IR_DEBOUNCE)) return; last_code = code; + last_time = millis(); DEBUG_MSG_P(PSTR("[IR] Received 0x%08X (%d)\n"), code, type); #if IR_BUTTON_SET > 0 diff --git a/code/espurna/pwm.c b/code/espurna/pwm.c index ee18814d..b925da8e 100644 --- a/code/espurna/pwm.c +++ b/code/espurna/pwm.c @@ -19,27 +19,29 @@ /* Set the following three defines to your needs */ #ifndef SDK_PWM_PERIOD_COMPAT_MODE - #define SDK_PWM_PERIOD_COMPAT_MODE 0 +#define SDK_PWM_PERIOD_COMPAT_MODE 0 #endif + #ifndef PWM_MAX_CHANNELS - #define PWM_MAX_CHANNELS 8 +#define PWM_MAX_CHANNELS 8 #endif -#define PWM_DEBUG 0 -#define PWM_USE_NMI 1 + +#define PWM_DEBUG 0 +#define PWM_USE_NMI 1 /* no user servicable parts beyond this point */ -#define PWM_MAX_TICKS 0x7fffff +#define PWM_MAX_TICKS 0x7fffff #if SDK_PWM_PERIOD_COMPAT_MODE -#define PWM_PERIOD_TO_TICKS(x) (x * 0.2) -#define PWM_DUTY_TO_TICKS(x) (x * 5) -#define PWM_MAX_DUTY (PWM_MAX_TICKS * 0.2) -#define PWM_MAX_PERIOD (PWM_MAX_TICKS * 5) +#define PWM_PERIOD_TO_TICKS(x) (x * 0.2) +#define PWM_DUTY_TO_TICKS(x) (x * 5) +#define PWM_MAX_DUTY (PWM_MAX_TICKS * 0.2) +#define PWM_MAX_PERIOD (PWM_MAX_TICKS * 5) #else -#define PWM_PERIOD_TO_TICKS(x) (x) -#define PWM_DUTY_TO_TICKS(x) (x) -#define PWM_MAX_DUTY PWM_MAX_TICKS -#define PWM_MAX_PERIOD PWM_MAX_TICKS +#define PWM_PERIOD_TO_TICKS(x) (x) +#define PWM_DUTY_TO_TICKS(x) (x) +#define PWM_MAX_DUTY PWM_MAX_TICKS +#define PWM_MAX_PERIOD PWM_MAX_TICKS #endif #include @@ -48,8 +50,8 @@ #include "libs/pwm.h" // from SDK hw_timer.c -#define TIMER1_DIVIDE_BY_16 0x0004 -#define TIMER1_ENABLE_TIMER 0x0080 +#define TIMER1_DIVIDE_BY_16 0x0004 +#define TIMER1_ENABLE_TIMER 0x0080 struct pwm_phase { uint32_t ticks; ///< delay until next phase, in 200ns units @@ -400,7 +402,7 @@ pwm_start(void) void ICACHE_FLASH_ATTR pwm_set_duty(uint32_t duty, uint8_t channel) { - if (channel > PWM_MAX_CHANNELS) + if (channel >= PWM_MAX_CHANNELS) return; if (duty > PWM_MAX_DUTY) @@ -412,7 +414,7 @@ pwm_set_duty(uint32_t duty, uint8_t channel) uint32_t ICACHE_FLASH_ATTR pwm_get_duty(uint8_t channel) { - if (channel > PWM_MAX_CHANNELS) + if (channel >= PWM_MAX_CHANNELS) return 0; return pwm_duty[channel]; } diff --git a/code/extra_scripts.py b/code/extra_scripts.py index c4946f25..de37bd31 100644 --- a/code/extra_scripts.py +++ b/code/extra_scripts.py @@ -4,11 +4,7 @@ from __future__ import print_function import os import sys from subprocess import call - import click -from platformio import util - -import distutils.spawn Import("env", "projenv") diff --git a/code/gulpfile.js b/code/gulpfile.js index e7a0c9b3..d4089e61 100644 --- a/code/gulpfile.js +++ b/code/gulpfile.js @@ -72,8 +72,8 @@ var toHeader = function(name, debug) { output += '#define ' + safename + '_len ' + source.contents.length + '\n'; output += 'const uint8_t ' + safename + '[] PROGMEM = {'; for (var i=0; i 0) output += ','; - if (0 === (i % 20)) output += '\n'; + if (i > 0) { output += ',' }; + if (0 === (i % 20)) { output += '\n' }; output += '0x' + ('00' + source.contents[i].toString(16)).slice(-2); } output += '\n};'; diff --git a/code/ota.py b/code/ota.py index 7e8d9f00..0cd6a12c 100755 --- a/code/ota.py +++ b/code/ota.py @@ -39,6 +39,8 @@ def on_service_state_change(zeroconf, service_type, name, state_change): Callback that adds discovered devices to "devices" list """ + global discover_last + if state_change is ServiceStateChange.Added: discover_last = time.time() info = zeroconf.get_service_info(service_type, name) @@ -146,7 +148,6 @@ def get_board_by_mac(mac): """ Returns the required data to flash a given board """ - hostname = hostname.lower() for device in devices: if device.get('mac', '').lower() == mac: board = {}