added long press to turn off:
This commit is contained in:
parent
1c9398681d
commit
712d1bac78
@ -58,7 +58,7 @@ void Controls_loop(void *pvParameters){
|
|||||||
if(CONTROLS_DEBUG){
|
if(CONTROLS_DEBUG){
|
||||||
Serial.printf("Key: %d\n", duration);
|
Serial.printf("Key: %d\n", duration);
|
||||||
}
|
}
|
||||||
Controls_send_event(Key);
|
Controls_send_event({Key, (int)duration});
|
||||||
}else{
|
}else{
|
||||||
if(CONTROLS_DEBUG){
|
if(CONTROLS_DEBUG){
|
||||||
Serial.println("Too short");
|
Serial.println("Too short");
|
||||||
@ -92,7 +92,7 @@ void Controls_loop(void *pvParameters){
|
|||||||
if(CONTROLS_DEBUG){
|
if(CONTROLS_DEBUG){
|
||||||
Serial.println("Dir A");
|
Serial.println("Dir A");
|
||||||
}
|
}
|
||||||
Controls_send_event(Counterclockwise);
|
Controls_send_event({Counterclockwise, NULL});
|
||||||
}else if(
|
}else if(
|
||||||
pinChanges[base + 0] == PIN_B &&
|
pinChanges[base + 0] == PIN_B &&
|
||||||
pinChanges[base + 1] == PIN_A &&
|
pinChanges[base + 1] == PIN_A &&
|
||||||
@ -103,7 +103,7 @@ void Controls_loop(void *pvParameters){
|
|||||||
if(CONTROLS_DEBUG){
|
if(CONTROLS_DEBUG){
|
||||||
Serial.println("Dir B");
|
Serial.println("Dir B");
|
||||||
}
|
}
|
||||||
Controls_send_event(Clockwise);
|
Controls_send_event({Clockwise, NULL});
|
||||||
}else{
|
}else{
|
||||||
if(CONTROLS_DEBUG){
|
if(CONTROLS_DEBUG){
|
||||||
Serial.println("Unknown direction");
|
Serial.println("Unknown direction");
|
||||||
@ -136,5 +136,5 @@ void Controls_setup(){
|
|||||||
|
|
||||||
|
|
||||||
TaskHandle_t taskControls = NULL;
|
TaskHandle_t taskControls = NULL;
|
||||||
xTaskCreate(Controls_loop, "Controls_loop", 1000, NULL, tskIDLE_PRIORITY, &taskControls);
|
xTaskCreate(Controls_loop, "Controls_loop", 2048, NULL, tskIDLE_PRIORITY, &taskControls);
|
||||||
}
|
}
|
||||||
@ -6,16 +6,22 @@
|
|||||||
#define PIN_B 3
|
#define PIN_B 3
|
||||||
#define PIN_KEY 4
|
#define PIN_KEY 4
|
||||||
|
|
||||||
#define KEY_DURATION_MS 120
|
#define KEY_DURATION_MS 150
|
||||||
|
|
||||||
#define CONTROLS_DEBUG false
|
#define CONTROLS_DEBUG false
|
||||||
|
|
||||||
enum ControlEvent {
|
|
||||||
|
enum ControlEventType {
|
||||||
Clockwise,
|
Clockwise,
|
||||||
Counterclockwise,
|
Counterclockwise,
|
||||||
Key
|
Key
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ControlEvent {
|
||||||
|
ControlEventType type;
|
||||||
|
int data;
|
||||||
|
};
|
||||||
|
|
||||||
typedef void (* ControlsCallback)( ControlEvent ) ;
|
typedef void (* ControlsCallback)( ControlEvent ) ;
|
||||||
|
|
||||||
void Controls_setup();
|
void Controls_setup();
|
||||||
|
|||||||
@ -3,21 +3,17 @@
|
|||||||
|
|
||||||
|
|
||||||
CRGB colorTable[] = {
|
CRGB colorTable[] = {
|
||||||
CRGB(255, 243, 218),
|
// CRGB(255, 100, 4),
|
||||||
CRGB(255, 250, 237),
|
// CRGB(255, 128, 4),
|
||||||
CRGB(255, 255, 255),
|
// CRGB(255, 100, 32),
|
||||||
CRGB(250, 233, 213),
|
// CRGB(255, 128, 32),
|
||||||
CRGB::Red,
|
CRGB::White,
|
||||||
CRGB::Blue,
|
CRGB(255, 142, 32), // "warm wit"
|
||||||
CRGB::Green,
|
|
||||||
CRGB::Purple,
|
|
||||||
CRGB::Turquoise,
|
|
||||||
CRGB::Yellow,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Hanglamp::Hanglamp(){
|
Hanglamp::Hanglamp(){
|
||||||
|
turnOn();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hanglamp::setup(){
|
void Hanglamp::setup(){
|
||||||
@ -57,8 +53,8 @@ void Hanglamp::adjustBrightness(int add){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Hanglamp::controlsCallback(ControlEvent event){
|
void Hanglamp::controlsCallback(ControlEvent event){
|
||||||
Serial.printf("ControlEvent: %d\n", event);
|
Serial.printf("ControlEventType: %d\n", event);
|
||||||
switch(event){
|
switch(event.type){
|
||||||
case Clockwise:
|
case Clockwise:
|
||||||
adjustBrightness(4);
|
adjustBrightness(4);
|
||||||
break;
|
break;
|
||||||
@ -66,11 +62,51 @@ void Hanglamp::controlsCallback(ControlEvent event){
|
|||||||
adjustBrightness(-4);
|
adjustBrightness(-4);
|
||||||
break;
|
break;
|
||||||
case Key:
|
case Key:
|
||||||
nextColor();
|
Serial.printf("key press %d\n", event.data);
|
||||||
|
|
||||||
|
if(!isOn()){
|
||||||
|
turnOn();
|
||||||
|
}else{
|
||||||
|
auto msDuration = event.data/1000;
|
||||||
|
|
||||||
|
Serial.printf("msDuration %d\n", msDuration);
|
||||||
|
if(msDuration > 800){
|
||||||
|
turnOff();
|
||||||
|
}else{
|
||||||
|
nextColor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hanglamp::status(CRGB color){
|
void Hanglamp::status(CRGB color){
|
||||||
Led_status(color);
|
Led_status(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Hanglamp::setOn(bool on){
|
||||||
|
Serial.printf("Hanglamp::setOn(%d -> %d)\n", this->on, on);
|
||||||
|
this->on = on;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Hanglamp::isOn(){
|
||||||
|
return this->on;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Hanglamp::turnOn(){
|
||||||
|
if(!this->on){
|
||||||
|
FastLED.setBrightness(this->brightness);
|
||||||
|
FastLED.show();
|
||||||
|
this->setOn(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Hanglamp::turnOff(){
|
||||||
|
if(this->on){
|
||||||
|
FastLED.setBrightness(0);
|
||||||
|
FastLED.show();
|
||||||
|
this->setOn(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@ -16,9 +16,15 @@ class Hanglamp {
|
|||||||
void status(CRGB color);
|
void status(CRGB color);
|
||||||
void setColor(CRGB color);
|
void setColor(CRGB color);
|
||||||
|
|
||||||
|
bool isOn();
|
||||||
|
void turnOn();
|
||||||
|
void turnOff();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char colorIndex = 0;
|
char colorIndex = 0;
|
||||||
int brightness = 128;
|
int brightness = 128;
|
||||||
|
bool on = false;
|
||||||
|
void setOn(bool on);
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -1,3 +1,4 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|
||||||
@ -5,6 +6,8 @@
|
|||||||
|
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user