summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEnricoGuccii <partyka.003@proton.me>2026-06-13 23:57:53 +0200
committerEnricoGuccii <partyka.003@proton.me>2026-06-13 23:57:53 +0200
commit998d8d170bf10d15c7724eb69c3df285df8c24ab (patch)
tree7e8a48ae39f4a2cc36e0cdf7ce20c4002b991440 /src
parent3558ddb3b597e6c49bb2529d3f4a05b7344bfd6d (diff)
added sleep mechanism
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp38
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);
}