diff options
| -rw-r--r-- | src/main.cpp | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/src/main.cpp b/src/main.cpp index 980029f..9d60f96 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -36,6 +36,10 @@ volatile RobotEmotion currentState = E_NEUTRAL; volatile int fatigueLevel = 0;
volatile bool isTired = false;
+
+volatile int sleepTimer = 0;
+volatile bool isSleepy = false;
+
volatile char manualMotors = '0';
volatile char manualRGB = '0';
@@ -109,17 +113,29 @@ void wifiTask(void * pvParameters) { void robotLogicTask(void * pvParameters) {
for(;;) {
+
+ if (currentState == MANUAL && manualMotors == '0') {
+ sleepTimer++;
+ } else {
+ sleepTimer = 0;
+ }
- if (currentState == MANUAL && manualMotors != '0') {
+ if (sleepTimer >= 100) {
+ isSleepy = true;
+ } else {
+ isSleepy = false;
+ }
+
+ if (currentState == MANUAL && manualMotors != '0') {
fatigueLevel++;
} else {
if (fatigueLevel > 0) fatigueLevel--;
}
- if (fatigueLevel >= 100 ) {
+ if (fatigueLevel >= 100) {
isTired = true;
} else if (fatigueLevel == 0) {
- isTired = false;
+ isTired = false;
}
vTaskDelay(100 / portTICK_PERIOD_MS);
@@ -151,6 +167,8 @@ void oledTask(void * pvParameters) { RobotEmotion lastEmotion = E_NEUTRAL;
+ bool wasSleepy = false;
+
for(;;) {
if (currentState != lastEmotion) {
lastEmotion = currentState;
@@ -171,6 +189,20 @@ void oledTask(void * pvParameters) { }
}
roboEyes.setSweat(isTired);
+
+ if (isSleepy != wasSleepy) {
+ wasSleepy = isSleepy;
+ if (isSleepy) {
+ roboEyes.setIdleMode(OFF);
+ roboEyes.setAutoblinker(OFF);
+ roboEyes.close();
+ } else {
+ roboEyes.setIdleMode(ON,2,2);
+ roboEyes.setAutoblinker(ON);
+ roboEyes.open();
+ }
+ }
+
roboEyes.update();
vTaskDelay(20 / portTICK_PERIOD_MS);
}
|