Compare commits

...

2 Commits

Author SHA1 Message Date
interfisch a0960eb5c6 add find end mode for buttons on startup 2022-03-02 19:58:23 +01:00
interfisch 6cd5c9c9e0 change sense opaque values 2022-03-02 18:36:10 +01:00
2 changed files with 53 additions and 21 deletions

View File

@ -9,7 +9,7 @@
; https://docs.platformio.org/page/projectconf.html ; https://docs.platformio.org/page/projectconf.html
[env:d1_mini] [env:d1_mini]
platform = espressif8266 platform = espressif8266 @ 2.6.3
board = d1_mini board = d1_mini
framework = arduino framework = arduino

View File

@ -29,12 +29,15 @@ HomieNode blind2Node("blindr", "Blind Right", "blind"); //paramters: topic, $nam
#define BUTTON_DEBOUNCE 200 #define BUTTON_DEBOUNCE 200
#define PIN_BUTTON1 D5 #define PIN_BUTTON1 D5
#define PIN_BUTTON2 D6 #define PIN_BUTTON2 D6
#define BUTTON_TIME_HOLD_FIND_END 5000
struct button{ struct button{
uint8_t pin; uint8_t pin;
unsigned long last_time_read=0; unsigned long last_time_read=0;
bool down=false; bool down=false;
bool changed=false; bool changed=false;
bool manual_drive_direction=false; bool manual_drive_direction=false;
unsigned long millisup=0;
unsigned long millisdown=0;
}; };
button button1; button button1;
button button2; button button2;
@ -207,8 +210,8 @@ void setup() {
blind1.sense_clear_lower=40; blind1.sense_clear_lower=40;
blind1.sense_clear_upper=150; blind1.sense_clear_upper=150;
blind1.sense_opaque_lower=280; blind1.sense_opaque_lower=280;
blind1.sense_opaque_upper=800; blind1.sense_opaque_upper=890;
blind1.sense_end_lower=850; blind1.sense_end_lower=900;
blind1.sense_end_upper=1024; blind1.sense_end_upper=1024;
blind1.speedfactorLow=28.7; blind1.speedfactorLow=28.7;
blind1.speedfactorHigh=25.3; blind1.speedfactorHigh=25.3;
@ -226,8 +229,8 @@ void setup() {
blind2.sense_clear_lower=40; blind2.sense_clear_lower=40;
blind2.sense_clear_upper=150; blind2.sense_clear_upper=150;
blind2.sense_opaque_lower=280; blind2.sense_opaque_lower=280;
blind2.sense_opaque_upper=800; blind2.sense_opaque_upper=890;
blind2.sense_end_lower=850; blind2.sense_end_lower=900;
blind2.sense_end_upper=1024; blind2.sense_end_upper=1024;
blind2.speedfactorLow=27.6; blind2.speedfactorLow=27.6;
blind2.speedfactorHigh=23.5; blind2.speedfactorHigh=23.5;
@ -414,35 +417,61 @@ void classifySensorValue(blindmodel &blind) {
void checkButton(button &btn) { void checkButton(button &btn) {
btn.changed=false; btn.changed=false;
if (millis() > btn.last_time_read + BUTTON_DEBOUNCE) { if (millis() > btn.last_time_read + BUTTON_DEBOUNCE) {
bool new_pin_button_down=!digitalRead(btn.pin); bool new_pin_button_down=!digitalRead(btn.pin);
if (btn.down != new_pin_button_down) { //changed if (btn.down != new_pin_button_down) { //changed
btn.down = new_pin_button_down; //update btn.down = new_pin_button_down; //update
btn.changed=true; btn.changed=true;
btn.last_time_read=millis(); //delay next check if (btn.down) { //remember time when button was pressed or released
btn.millisdown=millis();
}else{
btn.millisup=millis();
} }
} }
btn.last_time_read=millis(); //delay next check
}
} }
void manualMoveHandler(button &btn, blindmodel &blind) void manualMoveHandler(button &btn, blindmodel &blind)
{ {
if (btn.changed) { if (btn.changed) {
if (blind.error==ERRORCODE_UNDEFINED_POSITION) {
if (!btn.down && (btn.millisup-btn.millisdown)>BUTTON_TIME_HOLD_FIND_END) { //changed to released
blind.mode = MODE_FIND_END;
blind.mode_find_end_state=0; //reset mode find state
blind.position_last_classchange=blind.position; //otherwise error trips immediately
blind.error=0; //reset
Serial.println("Reset and find end triggered");
}
}else{ //not undefined error
if (btn.down) { //changed to pressed if (btn.down) { //changed to pressed
blind.mode=MODE_MANUAL; blind.mode=MODE_MANUAL;
if (btn.manual_drive_direction) { //drive up if (btn.manual_drive_direction) { //drive up
//M1.setmotor( _CW, 100); //M1.setmotor( _CW, 100);
blind.speed=-100; blind.speed=-100;
//Serial.print("CW PWM: "); Serial.println("CW manual ");
}else{ //drive down }else{ //drive down
blind.speed=100; blind.speed=100;
//Serial.print("CCW PWM: "); Serial.println("CCW manual ");
} }
btn.manual_drive_direction=!btn.manual_drive_direction; //switch direction every new press btn.manual_drive_direction=!btn.manual_drive_direction; //switch direction every new press
}else{ //changed to released }else{ //changed to released
//Serial.println("Motor STOP"); //Serial.println("Motor STOP");
blind.mode=MODE_IDLE; blind.mode=MODE_IDLE;
blind.speed=0; blind.speed=0;
} }
} }
}
} }
void readSensor(blindmodel &blind, int value, HomieNode &node) void readSensor(blindmodel &blind, int value, HomieNode &node)
@ -746,6 +775,9 @@ String modeNumToString(uint8_t modenum){
case MODE_ERROR: case MODE_ERROR:
return "MODE_ERROR"; return "MODE_ERROR";
break; break;
case MODE_MANUAL:
return "MODE_MANUAL";
break;
} }
return "UNDEF"; return "UNDEF";
} }