|
@@ -7,6 +7,7 @@
|
|
|
|
|
|
#include <wiringPiI2C.h>
|
|
|
#include <stdlib.h>
|
|
|
+#include <stdint.h>
|
|
|
#include <errno.h>
|
|
|
#include <pthread.h>
|
|
|
#include <unistd.h>
|
|
@@ -15,6 +16,7 @@
|
|
|
#include "global.h"
|
|
|
#include "timer.h"
|
|
|
#include "logger.h"
|
|
|
+#include "coffee.h"
|
|
|
|
|
|
stripe_color currentColor;
|
|
|
stripe_color effectColor;
|
|
@@ -22,6 +24,7 @@ int currentWhite = 0, currentDim = 0;
|
|
|
stripe_transient_t currentTransient = TRANS_DIRECT;
|
|
|
timer stripeTimer(stripeTimerHandler);
|
|
|
int i2cfd;
|
|
|
+coffee_status_t lastState = STATE_OFF;
|
|
|
|
|
|
/**
|
|
|
* This is the handler for time based stripe effects
|
|
@@ -49,24 +52,60 @@ void *stripeThread(void *threadid) {
|
|
|
stripeTimer.stop();
|
|
|
logger(V_BASIC, "Initialized Stripe thread\n");
|
|
|
|
|
|
+ stripeOn();
|
|
|
+ stripeSetRGB(0, 0, 0);
|
|
|
stripe_color col;
|
|
|
- col.red = 255;
|
|
|
- col.green = 0;
|
|
|
- col.blue = 0;
|
|
|
- stripeEffectPulse(col);
|
|
|
- int tmp = 0, inc = 1;
|
|
|
+ //int tmp = 0, inc = 1;
|
|
|
while (1) {
|
|
|
- pause();
|
|
|
- stripeEffectHeating(tmp);
|
|
|
- logger(V_NONE, LOG_ERRORC, "Simulating %d%% percent heating\n", tmp);
|
|
|
- sleep(1);
|
|
|
- if (inc) {
|
|
|
- if (++tmp >= 100)
|
|
|
- inc = 0;
|
|
|
- } else {
|
|
|
- if (--tmp <= 0)
|
|
|
- inc = 1;
|
|
|
+ if (getState() != lastState) {
|
|
|
+ lastState = getState();
|
|
|
+ switch (lastState) {
|
|
|
+ case STATE_IDLE:
|
|
|
+ case STATE_HEATING:
|
|
|
+ case STATE_BREW:
|
|
|
+ case STATE_BREWMANUAL:
|
|
|
+ case STATE_CLEANING:
|
|
|
+ col.red = 255;
|
|
|
+ col.green = 0;
|
|
|
+ col.blue = 0;
|
|
|
+ stripeEffectPulse(col);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case STATE_INITALHEATING:
|
|
|
+ col.red = 0;
|
|
|
+ col.green = 0;
|
|
|
+ col.blue = 255;
|
|
|
+ stripeEffectPulse(col);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case STATE_ERROR:
|
|
|
+ stripeEffectDisable();
|
|
|
+ stripeSetTransient(TRANS_FAST);
|
|
|
+ stripeSetRGB(255, 0, 0);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case STATE_OFF:
|
|
|
+ usleep(50000);
|
|
|
+ stripeEffectDisable();
|
|
|
+ stripeSetTransient(TRANS_SLOW);
|
|
|
+ stripeSetRGB(0, 0, 0);
|
|
|
+ stripeSetRGB(0, 0, 0); // do it twice, else it doesn't work?! dafuq..
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
+ usleep(100000);
|
|
|
+ /*
|
|
|
+ pause();
|
|
|
+ stripeEffectHeating(tmp);
|
|
|
+ logger(V_NONE, LOG_ERRORC, "Simulating %d%% percent heating\n", tmp);
|
|
|
+ sleep(1);
|
|
|
+ if (inc) {
|
|
|
+ if (++tmp >= 100)
|
|
|
+ inc = 0;
|
|
|
+ } else {
|
|
|
+ if (--tmp <= 0)
|
|
|
+ inc = 1;
|
|
|
+ }*/
|
|
|
}
|
|
|
|
|
|
pthread_exit(NULL);
|
|
@@ -139,6 +178,8 @@ void stripeUpdate(void) {
|
|
|
}
|
|
|
|
|
|
stripeCommand(len, data);
|
|
|
+ logger(V_STRIPE, "Updated stripe to color r %d g %d b %d\n", currentColor.red,
|
|
|
+ currentColor.green, currentColor.blue);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -154,6 +195,32 @@ void stripeUpdateDim(void) {
|
|
|
stripeCommand(len, data);
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Let the stripe fade out and turn off
|
|
|
+ */
|
|
|
+void stripeFadeOut(void) {
|
|
|
+ char data[3];
|
|
|
+ int len = 3;
|
|
|
+
|
|
|
+ data[0] = STRIPE_CMD_FADEOUT;
|
|
|
+ data[1] = (currentTransient >> 8) & 0xff;
|
|
|
+ data[2] = currentTransient & 0xff;
|
|
|
+
|
|
|
+ stripeCommand(len, data);
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Stops the current fading
|
|
|
+ */
|
|
|
+void stripeFadeStop(void) {
|
|
|
+ char data[1];
|
|
|
+ int len = 1;
|
|
|
+
|
|
|
+ data[0] = STRIPE_CMD_FADESTOP;
|
|
|
+
|
|
|
+ stripeCommand(len, data);
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* Updates the color of the stripe
|
|
|
* @param red Red value (max 255)
|
|
@@ -250,6 +317,7 @@ void stripeGetWhite(int* white) {
|
|
|
*/
|
|
|
void stripeEffectDisable(void) {
|
|
|
stripeTimer.stop();
|
|
|
+ stripeFadeStop();
|
|
|
}
|
|
|
|
|
|
/**
|