-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/aleemont1/esiot-23-24-assig…
…nment2 into emanuele
- Loading branch information
Showing
9 changed files
with
120 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,48 @@ | ||
#include "SleepingTask.h" | ||
|
||
SleepingTask* sleepingTaskInstance = nullptr; | ||
|
||
static void staticWakeUp() { | ||
if (sleepingTaskInstance != nullptr) { | ||
sleepingTaskInstance->wakeUp(); | ||
} | ||
} | ||
|
||
void SleepingTask::tick() | ||
{ | ||
/*TODO*/ | ||
} | ||
switch (this->getState()) | ||
{ | ||
case STARTING: | ||
this->goInSleep(); | ||
break; | ||
|
||
case ALIVE: | ||
if (pir->checkDetectedStatus()) { | ||
Serial.println("OBJECT revealed"); | ||
this->setState(OBJECT_DETECTED); | ||
} | ||
break; | ||
|
||
case OBJECT_DETECTED: | ||
this->setState(ALIVE); | ||
this->setActive(false); | ||
this->setCompleted(); | ||
break; | ||
} | ||
} | ||
|
||
void SleepingTask::goInSleep() | ||
{ | ||
set_sleep_mode(SLEEP_MODE_PWR_DOWN); | ||
sleepingTaskInstance = this; | ||
attachInterrupt(digitalPinToInterrupt(2), staticWakeUp, RISING); | ||
sei(); | ||
sleep_enable(); | ||
sleep_mode(); | ||
} | ||
|
||
void SleepingTask::wakeUp() { | ||
detachInterrupt(digitalPinToInterrupt(2)); | ||
sleep_disable(); | ||
this->setState(ALIVE); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,47 @@ | ||
#ifndef __SLEEPING_TASK__ | ||
#define __SLEEPING_TASK__ | ||
|
||
#define _MAX_TIME_BEFORE_SLEEP 10 | ||
#define _MAX_TIME_BEFORE_SLEEP 10000 /*ms*/ | ||
|
||
#include "config/config.h" | ||
#include "components/api/Pir.h" | ||
#include "components/api/LCD.h" | ||
#include "kernel/DependantTaskWithState.h" | ||
#include "avr/interrupt.h" | ||
#include "avr/sleep.h" | ||
|
||
|
||
/** | ||
* @class SleepingTask | ||
* @brief This task handle the sleeping state using the pir as sensor to detect movement and | ||
* wake up arduino | ||
* @brief This task handle the sleeping state using the pir as sensor to | ||
* detect movement and wake up arduino | ||
*/ | ||
|
||
class SleepingTask : public DependantTaskWithState | ||
class SleepingTask : public TaskWithState | ||
{ | ||
public: | ||
SleepingTask(SleepingTask *sleepingTask) : DependantTaskWithState() | ||
SleepingTask() : TaskWithState() | ||
{ | ||
Serial.println("SleepingTask created"); | ||
this->pir = new Pir(PIR_PIN); | ||
this->setState(WAITING_FOR_SOMEONE); | ||
this->lcd=new LCD(0x27, 16,2); | ||
this->init(); | ||
this->setActive(true); | ||
this->setState(STARTING); | ||
}; | ||
void tick() override; | ||
void wakeUp(); | ||
void goInSleep(); | ||
|
||
private: | ||
enum state | ||
{ | ||
WAITING_FOR_SOMEONE, | ||
GO_IN_SLEEP, | ||
WAKE_UP, | ||
STARTING, | ||
ALIVE, | ||
OBJECT_DETECTED | ||
}; | ||
Pir *pir; | ||
LCD *lcd; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters