|
@@ -34,7 +34,7 @@ bool flagIgnoreRlsInt0, flagIgnoreRlsInt1;
|
|
int pinState[4] = {1, 1, 1, 0};
|
|
int pinState[4] = {1, 1, 1, 0};
|
|
|
|
|
|
//sweep counter to log every brew
|
|
//sweep counter to log every brew
|
|
-uint16_t logcycle = 0;
|
|
|
|
|
|
+uint16_t logcycle = 1;
|
|
|
|
|
|
timer Int0Timer(&halInt0TimerHandler);
|
|
timer Int0Timer(&halInt0TimerHandler);
|
|
timer Int1Timer(&halInt1TimerHandler);
|
|
timer Int1Timer(&halInt1TimerHandler);
|
|
@@ -43,6 +43,7 @@ timer idleTimer(&halIdleTimerHandler);
|
|
time_t heatingCycle[] = {0, 0};
|
|
time_t heatingCycle[] = {0, 0};
|
|
timespec flowTimestep[] = {{0,0},{0,0}};
|
|
timespec flowTimestep[] = {{0,0},{0,0}};
|
|
uint8_t flowIndex = 0;
|
|
uint8_t flowIndex = 0;
|
|
|
|
+uint16_t rotaryIndex = 0;
|
|
|
|
|
|
timespec pumpCycle[] = {{0,0},{0,0}};
|
|
timespec pumpCycle[] = {{0,0},{0,0}};
|
|
|
|
|
|
@@ -68,6 +69,9 @@ void halInit(void) {
|
|
pinMode(PIN_INT1, INPUT);
|
|
pinMode(PIN_INT1, INPUT);
|
|
pinMode(PIN_FLOW, INPUT);
|
|
pinMode(PIN_FLOW, INPUT);
|
|
pinMode(PIN_DISP, OUTPUT);
|
|
pinMode(PIN_DISP, OUTPUT);
|
|
|
|
+ pinMode(PIN_ROTARY1, INPUT);
|
|
|
|
+ pinMode(PIN_ROTARY2, INPUT);
|
|
|
|
+
|
|
|
|
|
|
idleTimer.setDivider(1200); //1 min
|
|
idleTimer.setDivider(1200); //1 min
|
|
idleCounter = 0;
|
|
idleCounter = 0;
|
|
@@ -115,6 +119,12 @@ void halInit(void) {
|
|
logger_error("Unable to setup ISRProximity: %s\n", strerror(errno));
|
|
logger_error("Unable to setup ISRProximity: %s\n", strerror(errno));
|
|
return;
|
|
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;
|
|
|
|
+ }
|
|
|
|
|
|
if (!(logcycle = sqlGetConf(CFGSweepCounter))) {
|
|
if (!(logcycle = sqlGetConf(CFGSweepCounter))) {
|
|
logger_error("hal.cpp: Couldn't read the logcycle counter from the database\n");
|
|
logger_error("hal.cpp: Couldn't read the logcycle counter from the database\n");
|
|
@@ -186,6 +196,41 @@ int halGetRelaisState(int relais) {
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ *
|
|
|
|
+ */
|
|
|
|
+void halIntRotary(void){
|
|
|
|
+ //check for the status of the other pin
|
|
|
|
+ if(digitalRead(PIN_ROTARY2)) {
|
|
|
|
+ //clockwise rotation
|
|
|
|
+ rotaryIndex = (rotaryIndex + 1) % ROTARY_RESOLUTION;
|
|
|
|
+
|
|
|
|
+ if(!(rotaryIndex % ROTARY_STEPSIZE)) {
|
|
|
|
+ logger(V_HAL, "rotary encoder CW, now at %d\n", rotaryIndex);
|
|
|
|
+ halSendSignal(SigRotCW);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ //counterclockwise rotation
|
|
|
|
+ if(rotaryIndex) rotaryIndex--;
|
|
|
|
+ else rotaryIndex = ROTARY_RESOLUTION - 1;
|
|
|
|
+
|
|
|
|
+ if(!(rotaryIndex % ROTARY_STEPSIZE)) {
|
|
|
|
+ logger(V_HAL, "rotary encoder CCW, now at %d\n", rotaryIndex);
|
|
|
|
+ halSendSignal(SigRotCCW);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ *
|
|
|
|
+ */
|
|
|
|
+uint16_t halGetRotaryIndex (void){
|
|
|
|
+ return rotaryIndex;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Interrupt routine for Int0 (Top button)
|
|
* Interrupt routine for Int0 (Top button)
|
|
*/
|
|
*/
|
|
@@ -272,13 +317,20 @@ void halInt1TimerHandler(void) {
|
|
|
|
|
|
/**
|
|
/**
|
|
* Interrupt routine for the flow sensor
|
|
* Interrupt routine for the flow sensor
|
|
- * It counts the edgdes and stores the value in flowcnt
|
|
|
|
|
|
+ * It counts the edges and stores the value in flowcnt
|
|
*/
|
|
*/
|
|
void halIntFlow(void) {
|
|
void halIntFlow(void) {
|
|
//halRelaisOff(RELAIS_POWER);
|
|
//halRelaisOff(RELAIS_POWER);
|
|
logger(V_HAL, "IntFlow triggered #%d total: %.2fml\n", flowcnt, halGetFlow());
|
|
logger(V_HAL, "IntFlow triggered #%d total: %.2fml\n", flowcnt, halGetFlow());
|
|
flowcnt++;
|
|
flowcnt++;
|
|
|
|
|
|
|
|
+ //detect a manual brewing process
|
|
|
|
+ //TODO to be able to detect a manual brewing process we need to have the following
|
|
|
|
+ //autoclear the flowcnt after certain idle time
|
|
|
|
+ //detect when the the flow is triggered but the pump is not started from software
|
|
|
|
+ //here we need to suppress the false alarms when the pump is turned off and slowly running out
|
|
|
|
+
|
|
|
|
+
|
|
//subroutine to log the flow to the database
|
|
//subroutine to log the flow to the database
|
|
timespec deltaT;
|
|
timespec deltaT;
|
|
clock_gettime(CLOCK_REALTIME, &flowTimestep[flowIndex]);
|
|
clock_gettime(CLOCK_REALTIME, &flowTimestep[flowIndex]);
|
|
@@ -415,6 +467,8 @@ void halSendSignal(HalSig val) {
|
|
case SigInt0RlsLong:
|
|
case SigInt0RlsLong:
|
|
case SigInt1Rls:
|
|
case SigInt1Rls:
|
|
case SigInt1RlsLong:
|
|
case SigInt1RlsLong:
|
|
|
|
+ case SigRotCCW:
|
|
|
|
+ case SigRotCW:
|
|
if (idle) {
|
|
if (idle) {
|
|
halLeaveIdle();
|
|
halLeaveIdle();
|
|
return;
|
|
return;
|
|
@@ -574,7 +628,7 @@ void halTerminate(event_t *event){
|
|
*/
|
|
*/
|
|
void halWriteBackCache(){
|
|
void halWriteBackCache(){
|
|
if (sqlSetConf(CFGSweepCounter, logcycle)) {
|
|
if (sqlSetConf(CFGSweepCounter, logcycle)) {
|
|
- logger_error("hall.cpp: Couldn't write logcycle to database");
|
|
|
|
|
|
+ logger_error("hal.cpp: Couldn't write logcycle to database");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
logger(V_BREW, "Writing back logcycle %d\n", logcycle);
|
|
logger(V_BREW, "Writing back logcycle %d\n", logcycle);
|