summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Baumann <derflob@derflob.de>2020-12-19 07:42:04 +0100
committerFlorian Baumann <derflob@derflob.de>2020-12-19 07:42:04 +0100
commit0055b3000b22419ba3af080f680adb6ecce0b9fd (patch)
tree857088716cbac3879658f51da9836455ec5b8523
parentca8225bd0f2c10f6f5b16169e3b96f05079616b5 (diff)
downloadRJ45EEPROMKeyHolder-master.tar.gz
RJ45EEPROMKeyHolder-master.tar.bz2
'breathing' led statusHEADmaster
-rw-r--r--include/pins.h3
-rw-r--r--src/main.cpp34
2 files changed, 30 insertions, 7 deletions
diff --git a/include/pins.h b/include/pins.h
index fee33a1..7ef47f7 100644
--- a/include/pins.h
+++ b/include/pins.h
@@ -10,7 +10,8 @@
#define LED_STATUS 32
#define LED_STATUS_PWM_CHANNEL 0
-#define LED_STATUS_DUTY_CYCLE 32
+#define LED_STATUS_DUTY_CYCLE 64
+#define LED_BREATH_SPEED 1500
#define SPI_SCK 18
#define SPI_MISO 19
diff --git a/src/main.cpp b/src/main.cpp
index d00d6ed..7117e44 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -31,6 +31,7 @@ volatile enum kh_states {
} state;
void update_led_status();
+void breath_led_status(uint32_t speed, uint32_t min_duty, uint32_t max_duty);
void update_leds_sockets();
void mqtt_callback(char* topic, byte* payload, unsigned int length);
@@ -70,7 +71,7 @@ void led_task(void *parameter)
while (1) {
update_led_status();
update_leds_sockets();
- vTaskDelay(25 / portTICK_PERIOD_MS);
+ vTaskDelay(10 / portTICK_PERIOD_MS);
}
}
@@ -80,17 +81,39 @@ void update_led_status()
case KH_SETUP:
case KH_CONNECTING_WIFI:
case KH_CONNECTING_MQTT:
- ledcWrite(LED_STATUS_PWM_CHANNEL, (millis() % 1000 < 500) ? LED_STATUS_DUTY_CYCLE : 0);
+ breath_led_status(LED_BREATH_SPEED / 5, 4, LED_STATUS_DUTY_CYCLE * 2);
+ //ledcWrite(LED_STATUS_PWM_CHANNEL, (millis() % 1000 < 500) ? LED_STATUS_DUTY_CYCLE : 0);
break;
case KH_PUBLISHING_CONFIG:
- ledcWrite(LED_STATUS_PWM_CHANNEL, (millis() % 500 < 250) ? LED_STATUS_DUTY_CYCLE : 0);
+ breath_led_status(LED_BREATH_SPEED / 3, 4, LED_STATUS_DUTY_CYCLE * 2);
+ //ledcWrite(LED_STATUS_PWM_CHANNEL, (millis() % 500 < 250) ? LED_STATUS_DUTY_CYCLE : 0);
break;
case KH_UPDATING_KEY_STATE:
- ledcWrite(LED_STATUS_PWM_CHANNEL, LED_STATUS_DUTY_CYCLE);
+ breath_led_status(LED_BREATH_SPEED, 4, LED_STATUS_DUTY_CYCLE);
+ //ledcWrite(LED_STATUS_PWM_CHANNEL, LED_STATUS_DUTY_CYCLE);
break;
case KH_ERROR:
default:
- ledcWrite(LED_STATUS_PWM_CHANNEL, (millis() % 100 < 50) ? LED_STATUS_DUTY_CYCLE : 0);
+ breath_led_status(100, 4, 255);
+ //ledcWrite(LED_STATUS_PWM_CHANNEL, (millis() % 100 < 50) ? LED_STATUS_DUTY_CYCLE : 0);
+ }
+}
+
+void breath_led_status(uint32_t speed, uint32_t min_duty, uint32_t max_duty)
+{
+ auto time = millis();
+
+ if (time / (speed * 2) % 2) {
+ ledcWrite(LED_STATUS_PWM_CHANNEL, max_duty);
+ } else {
+ uint32_t duty = (time % speed) * max_duty / speed;
+
+ if (time / speed % 2 == 0) {
+ duty = max_duty - duty;
+ }
+ if (duty < min_duty)
+ duty = min_duty;
+ ledcWrite(LED_STATUS_PWM_CHANNEL, (uint8_t)duty);
}
}
@@ -122,7 +145,6 @@ void update_leds_sockets()
digitalWrite(LED_REG_RCLK, HIGH);
delayMicroseconds(10);
digitalWrite(LED_REG_RCLK, LOW);
-
}
void update_key_status(bool send_discovery = false)