Compare commits
No commits in common. "a0960eb5c694ad8490a07c44bca9415c21b61ac5" and "a981a1f1aeeb69a3f851a0363fe10543bc53e75e" have entirely different histories.
a0960eb5c6
...
a981a1f1ae
|
@ -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 @ 2.6.3
|
platform = espressif8266
|
||||||
board = d1_mini
|
board = d1_mini
|
||||||
framework = arduino
|
framework = arduino
|
||||||
|
|
||||||
|
|
46
src/main.cpp
46
src/main.cpp
|
@ -29,15 +29,12 @@ 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;
|
||||||
|
@ -210,8 +207,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=890;
|
blind1.sense_opaque_upper=800;
|
||||||
blind1.sense_end_lower=900;
|
blind1.sense_end_lower=850;
|
||||||
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;
|
||||||
|
@ -229,8 +226,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=890;
|
blind2.sense_opaque_upper=800;
|
||||||
blind2.sense_end_lower=900;
|
blind2.sense_end_lower=850;
|
||||||
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;
|
||||||
|
@ -417,61 +414,35 @@ 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;
|
||||||
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
|
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.println("CW manual ");
|
//Serial.print("CW PWM: ");
|
||||||
}else{ //drive down
|
}else{ //drive down
|
||||||
blind.speed=100;
|
blind.speed=100;
|
||||||
Serial.println("CCW manual ");
|
//Serial.print("CCW PWM: ");
|
||||||
}
|
}
|
||||||
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)
|
||||||
|
@ -775,9 +746,6 @@ 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";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue