]> www.infradead.org Git - users/dwmw2/esp32-pool.git/commitdiff
Make encoder direction a parameter
authorDavid Woodhouse <dwmw@amazon.co.uk>
Mon, 31 Mar 2025 08:43:38 +0000 (09:43 +0100)
committerDavid Woodhouse <dwmw@amazon.co.uk>
Mon, 31 Mar 2025 08:43:38 +0000 (09:43 +0100)
.... and then realise that of course the *board* is the same way round for
all of mine (prototype and in-the-wall); it's just that the motor is
different. So I didn't need it after all.

blind.yaml
landing-blind-1.yaml [new file with mode: 0644]
landing-blind-3.yaml

index b8285b46ea5d9376d6b0960b5fdfc2e12e5ad057..de84fcc529358dd440addf2826dd6ab7b756f3ca 100644 (file)
@@ -241,6 +241,9 @@ button:
     name: Home
     id: home
     on_press:
+      - logger.log:
+          level: INFO
+          format: "Blind rehome"
       - lambda: |
           id(motor).set_max_speed(${max_speed}/2);
           id(motor).set_target(id(motor)->current_position - 2.5 * ${encoder_closed_pos} * ${motor_direction});
@@ -391,8 +394,9 @@ sensor:
           }
           if (delta < 2 && delta > -2)
             return {};
+          delta *= ${encoder_direction};
           id(encoder_tracking_)[0] = curr;
-          id(encoder_tracking_)[1] -= delta;
+          id(encoder_tracking_)[1] += delta;
           if (id(encoder_tracking_)[1] < id(sensored_home_pos)) {
              ESP_LOGI("home", "Adjusted to %d", id(encoder_tracking_)[1]);
              id(sensored_home_pos) = id(encoder_tracking_)[1];
@@ -400,10 +404,10 @@ sensor:
           ESP_LOGD("angle", "Old %d new %d delta %d now %d home %d", id(encoder_tracking_)[0], curr, delta,
             id(encoder_tracking_)[1] + delta, id(sensored_home_pos));
 
-          if (delta < -100 && id(pd_blinds)->current_operation != COVER_OPERATION_CLOSING) {
+          if (delta 100 && id(pd_blinds)->current_operation != COVER_OPERATION_CLOSING) {
              id(pd_blinds)->current_operation= COVER_OPERATION_CLOSING;
              ESP_LOGI("cover", "closing");
-          } else if (delta 100 && id(pd_blinds)->current_operation != COVER_OPERATION_OPENING) {
+          } else if (delta < -100 && id(pd_blinds)->current_operation != COVER_OPERATION_OPENING) {
              id(pd_blinds)->current_operation = COVER_OPERATION_OPENING;
              ESP_LOGI("cover", "opening");
           }
diff --git a/landing-blind-1.yaml b/landing-blind-1.yaml
new file mode 100644 (file)
index 0000000..65bba3b
--- /dev/null
@@ -0,0 +1,17 @@
+substitutions:
+  name: "landing-blind-1"
+  encoder_closed_pos: "22500" # full blinds length (in encoder counts) !! CHANGE TO SUIT YOUR SETUP !!
+  encoder_direction: "-1" # Which way is towards 'closed'?
+  motor_direction: "-1" # w.r.t. encoder
+  microsteps: "2"
+  run_current: "100m"
+  max_speed: "800"
+  stallguard_threshold: "60"
+  pd_voltage: "15"
+
+packages:
+  blind: !include blind.yaml
+
+
+logger:
+  level: DEBUG
index 4755082cb87332765c484c9ecbb7b4e67cae879e..6a24539f67413d85bce6081100831ea3c0e74fe0 100644 (file)
@@ -2,7 +2,8 @@
 substitutions:
   name: "landing-blind-3"
   encoder_closed_pos: "230000" # full blinds length (in encoder counts) !! CHANGE TO SUIT YOUR SETUP !!
-  motor_direction: "1"
+  encoder_direction: "-1" # Which way is towards 'closed'?
+  motor_direction: "1" # w.r.t. encoder
   microsteps: "2"
   run_current: "100m"
   max_speed: "800"