From 8d2420e1c292008eadc6736d3015f80203fbcdc2 Mon Sep 17 00:00:00 2001 From: Arghya Biswas Date: Wed, 8 Oct 2025 23:07:27 +0530 Subject: [PATCH] fix motor on off issue on reset Signed-off-by: Arghya Biswas --- Script/doubleSwitch.py | 17 +++++++++++++---- Script/pinDescription.py | 14 +++++++------- Script/singleSwitch.py | 14 +++++++++++--- config.yaml | 2 +- 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/Script/doubleSwitch.py b/Script/doubleSwitch.py index bfabd10..c3dfb95 100644 --- a/Script/doubleSwitch.py +++ b/Script/doubleSwitch.py @@ -28,6 +28,7 @@ ResetTrigger = False isConfigReadNeed = True cycleIndexPosMiddle = False +countComplete = False lastButtonState = HIGH debounceDelay = 5000 @@ -186,6 +187,7 @@ def doubleSwitchLoop(model: str): global buttonState global ResetTrigger global lastDebounceTime + global countComplete rtn = LOOP_RTN_TYPE_ERROR switchModel = None @@ -205,18 +207,21 @@ def doubleSwitchLoop(model: str): # Reading the gpio pin for the switchs if gpio.digitalRead(MICRO_SWITCH_S1_NC_PIN) and gpio.digitalRead(MICRO_SWITCH_S2_NO_PIN): currentPosition = POSITION_LEFT - lcd.write("Position Left ", row = ROW_NO_2) print("Position Left") + if not countComplete: + lcd.write("Position Left ", row = ROW_NO_2) if gpio.digitalRead(MICRO_SWITCH_S1_NO_PIN) and gpio.digitalRead(MICRO_SWITCH_S2_NO_PIN): currentPosition = POSITION_MIDDLE - lcd.write("Position Middle", row = ROW_NO_2) print("Position Middle") + if not countComplete: + lcd.write("Position Middle", row = ROW_NO_2) if gpio.digitalRead(MICRO_SWITCH_S1_NO_PIN) and gpio.digitalRead(MICRO_SWITCH_S2_NC_PIN): currentPosition = POSITION_RIGHT - lcd.write("Position Right ", row = ROW_NO_2) print("Position Right") + if not countComplete: + lcd.write("Position Right ", row = ROW_NO_2) print("S1_NO:", gpio.digitalRead(MICRO_SWITCH_S1_NO_PIN), end="\t") print("S1_NC:", gpio.digitalRead(MICRO_SWITCH_S1_NC_PIN), end="\t") @@ -270,9 +275,10 @@ def doubleSwitchLoop(model: str): gpio.digitalWrite(ON_BOARD_LED_PIN, HIGH) gpio.digitalWrite(MOTOR_ON_OFF_PIN, LOW) setMotorControlStatus(LOW) - lcd.write("Count Finished!", row = ROW_NO_3, padding = True) + lcd.write("Count Finished!", row = ROW_NO_2, padding = True) print("Count Finished!") cycleCounter = 0 + countComplete = True # Reset button debounce logic ResetBtnReading = gpio.digitalRead(RESET_PUSH_SWITCH_PIN) @@ -298,10 +304,13 @@ def doubleSwitchLoop(model: str): gpio.digitalWrite(ON_BOARD_LED_PIN, LOW) setCycleCount(cycleCounter) ResetTrigger = False + countComplete = False time.sleep(2) lcd.write(" "*LCD_MODULE_NO_OF_COLUMN, row = ROW_NO_3) time.sleep(1) printCountValue(row = ROW_NO_3, currentCount = cycleCounter, totalCount = TotalCounter) + gpio.digitalWrite(MOTOR_ON_OFF_PIN, HIGH) + setMotorControlStatus(HIGH) # Return the loop status return rtn, switchModel diff --git a/Script/pinDescription.py b/Script/pinDescription.py index 6bf853c..ddd0534 100644 --- a/Script/pinDescription.py +++ b/Script/pinDescription.py @@ -3,17 +3,17 @@ MICRO_SWITCH_S2_NO_PIN = 33 MICRO_SWITCH_S2_NC_PIN = 35 -POSITION_LEFT_LED_PIN = 11 -POSITION_MIDDLE_LED_PIN = 13 -POSITION_RIGHT_LED_PIN = 15 +POSITION_LEFT_LED_PIN = 13 +POSITION_MIDDLE_LED_PIN = 11 +POSITION_RIGHT_LED_PIN = 7 -RESET_PUSH_SWITCH_PIN = 37 +RESET_PUSH_SWITCH_PIN = 38 MOTOR_ON_OFF_PIN = 32 -ON_BOARD_LED_PIN = 36 +ON_BOARD_LED_PIN = 15 -GPIO_3V3_1_PIN = 38 -GPIO_3V3_2_PIN = 40 +GPIO_3V3_1_PIN = 36 +GPIO_3V3_2_PIN = 37 LCD_MODULE_ADDRESS = 0x27 diff --git a/Script/singleSwitch.py b/Script/singleSwitch.py index 1445f59..8a1e8bb 100644 --- a/Script/singleSwitch.py +++ b/Script/singleSwitch.py @@ -28,6 +28,7 @@ ResetTrigger = False isConfigReadNeed = True cycleIndexPosMiddle = False +countComplete = False lastButtonState = HIGH debounceDelay = 5000 @@ -166,6 +167,7 @@ def singleSwitchLoop(model: str): global buttonState global ResetTrigger global lastDebounceTime + global countComplete rtn = LOOP_RTN_TYPE_ERROR switchModel = None @@ -184,13 +186,15 @@ def singleSwitchLoop(model: str): # Reading the gpio pin for the switchs if gpio.digitalRead(MICRO_SWITCH_S1_NC_PIN): currentPosition = POSITION_LEFT - lcd.write("Position Left ", row = ROW_NO_2) print("Position Left") + if not countComplete: + lcd.write("Position Left ", row = ROW_NO_2) if gpio.digitalRead(MICRO_SWITCH_S1_NO_PIN): currentPosition = POSITION_MIDDLE - lcd.write("Position Middle", row = ROW_NO_2) print("Position Middle") + if not countComplete: + lcd.write("Position Middle", row = ROW_NO_2) print("S1_NO:", gpio.digitalRead(MICRO_SWITCH_S1_NO_PIN), end="\t") print("S1_NC:", gpio.digitalRead(MICRO_SWITCH_S1_NC_PIN)) @@ -236,9 +240,10 @@ def singleSwitchLoop(model: str): gpio.digitalWrite(ON_BOARD_LED_PIN, HIGH) gpio.digitalWrite(MOTOR_ON_OFF_PIN, LOW) setMotorControlStatus(LOW) - lcd.write("Count Finished!", row = ROW_NO_3, padding = True) + lcd.write("Count Finished!", row = ROW_NO_2, padding = True) print("Count Finished!") cycleCounter = 0 + countComplete = True # Reset button debounce logic ResetBtnReading = gpio.digitalRead(RESET_PUSH_SWITCH_PIN) @@ -264,10 +269,13 @@ def singleSwitchLoop(model: str): gpio.digitalWrite(ON_BOARD_LED_PIN, LOW) setCycleCount(cycleCounter) ResetTrigger = False + countComplete = False time.sleep(2) lcd.write(" "*LCD_MODULE_NO_OF_COLUMN, row = ROW_NO_3) time.sleep(1) printCountValue(row = ROW_NO_3, currentCount = cycleCounter, totalCount = TotalCounter) + gpio.digitalWrite(MOTOR_ON_OFF_PIN, HIGH) + setMotorControlStatus(HIGH) # Return the loop status return rtn, switchModel diff --git a/config.yaml b/config.yaml index 7d75f56..4ed8978 100644 --- a/config.yaml +++ b/config.yaml @@ -1,2 +1,2 @@ -appVersion: 1.9.1.1017 +appVersion: 1.9.2.1018 maxCount : 7500000