Quellcode durchsuchen

fixed problem of rotaryinterrupt triggers when the pump was running, no the rotary encoder is not tracking the position of the knob anymore!

Sebastian vor 6 Jahren
Ursprung
Commit
c4ddc9d38f
3 geänderte Dateien mit 10 neuen und 19 gelöschten Zeilen
  1. 1 1
      CoffeeCode/buildno
  2. 9 17
      CoffeeCode/hal.cpp
  3. 0 1
      CoffeeCode/hal.h

+ 1 - 1
CoffeeCode/buildno

@@ -1 +1 @@
-291
+293

+ 9 - 17
CoffeeCode/hal.cpp

@@ -43,7 +43,7 @@ timer idleTimer(&halIdleTimerHandler);
 time_t heatingCycle[] = {0, 0};
 timespec flowTimestep[] = {{0,0},{0,0}};
 uint8_t flowIndex = 0;
-uint16_t rotaryIndex = 0;
+int16_t tickCounter = 0;
 
 timespec pumpCycle[] = {{0,0},{0,0}};
 
@@ -119,8 +119,6 @@ void halInit(void) {
 		logger_error("Unable to setup ISRProximity: %s\n", strerror(errno));
 		return;
 	}
-	//there are some issues with the serial port so interrupts get triggered without an external source and the program
-	//crashes
 	if (wiringPiISR(PIN_ROTARY1, INT_EDGE_RISING, &halIntRotary) < 0) {
 		logger_error("Unable to setup ISRRotary2: %s\n", strerror(errno));
 		return;
@@ -203,33 +201,27 @@ void halIntRotary(void){
 	//check for the status of the other pin
 	if(digitalRead(PIN_ROTARY2)) {
 		//clockwise rotation
-		rotaryIndex = (rotaryIndex + 1) % ROTARY_RESOLUTION;
+		tickCounter++;
 
-		if(!(rotaryIndex % ROTARY_STEPSIZE)) {
-			logger(V_HAL, "rotary encoder CW, now at %d\n", rotaryIndex);
+		if(!(tickCounter % ROTARY_STEPSIZE)) {
+			logger(V_HAL, "rotary encoder CW");
 			halSendSignal(SigRotCW);
+			tickCounter = 0;
 		}
 	}
 	else {
 		//counterclockwise rotation
-		if(rotaryIndex) rotaryIndex--;
-		else rotaryIndex = ROTARY_RESOLUTION - 1;
+		tickCounter--;
 
-		if(!(rotaryIndex % ROTARY_STEPSIZE)) {
-			logger(V_HAL, "rotary encoder CCW, now at %d\n", rotaryIndex);
+		if(!(abs(tickCounter) % ROTARY_STEPSIZE)) {
+			logger(V_HAL, "rotary encoder CCW");
 			halSendSignal(SigRotCCW);
+			tickCounter = 0;
 		}
 	}
 
 }
 
-/**
- *
- */
-uint16_t halGetRotaryIndex (void){
-	return rotaryIndex;
-}
-
 
 /**
  * Interrupt routine for Int0 (Top button)

+ 0 - 1
CoffeeCode/hal.h

@@ -76,7 +76,6 @@ void halRelaisOff(int relais);
 void halRelaisSet(int relais, int state);
 int halGetRelaisState(int relais);
 void halIntRotary(void);
-uint16_t halGetRotaryIndex (void);
 void halInt0(void);
 void halInt1(void);
 void halIntFlow(void);