Add Controller and Updater classes for shutter control and updates
This commit is contained in:
@@ -0,0 +1,93 @@
|
|||||||
|
#include "Arduino.h"
|
||||||
|
#include "controller.h"
|
||||||
|
/*
|
||||||
|
shutterStates[n] = 0 => le volet est fermer (position basse)
|
||||||
|
shutterStates[n] = 100 => le volet est ouvert (position haute)
|
||||||
|
*/
|
||||||
|
|
||||||
|
Controller::Controller() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void Controller::initController() {
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
// créer le volet
|
||||||
|
unsigned short pinDown = 9 - (2 * i);
|
||||||
|
unsigned short pinUp = 8 - (2 * i);
|
||||||
|
|
||||||
|
Shutter shutter{pinUp, pinDown, i}; // i est le nom
|
||||||
|
|
||||||
|
pinMode(i, OUTPUT);
|
||||||
|
|
||||||
|
// stock le volet
|
||||||
|
shutters[i] = &shutter;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Permet de correctement initaliser tout les volets
|
||||||
|
openExactePercentAllShutter(100);
|
||||||
|
openExactePercentAllShutter(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Controller::openExactePercentSpecificShutter(unsigned short shutter, float percent) {
|
||||||
|
if (percent < 0)
|
||||||
|
percent = 0;
|
||||||
|
else if (percent > 100)
|
||||||
|
percent = 100;
|
||||||
|
|
||||||
|
if (shutter < 0 && shutter >= 5)
|
||||||
|
return;
|
||||||
|
|
||||||
|
float percentOpen = shutters[shutter]->percentOpen;
|
||||||
|
// si le volet est deja ouvert a son pourcentage, ne rien faire
|
||||||
|
if (percent = percentOpen)
|
||||||
|
return;
|
||||||
|
|
||||||
|
float deltaPercent = percentOpen - percent;
|
||||||
|
|
||||||
|
if (deltaPercent < 0) // on doit fermet
|
||||||
|
digitalWrite(shutters[shutter]->pinDown, 1);
|
||||||
|
else // on doit ouvrir
|
||||||
|
digitalWrite(shutters[shutter]->pinUp, 1);
|
||||||
|
|
||||||
|
// Arreter le volet au bon moment
|
||||||
|
delay((percent * 1000) / shutters[shutter]->TIMETOOPEN);
|
||||||
|
|
||||||
|
digitalWrite(shutters[shutter]->pinUp, 0);
|
||||||
|
digitalWrite(shutters[shutter]->pinDown, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Controller::openExactePercentAllShutter(float percent) {
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
openExactePercentSpecificShutter(i, percent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Controller::checkManualOpen() {
|
||||||
|
// ouvre tous les volets du salon
|
||||||
|
if (analogRead(A7) > 512) {
|
||||||
|
openExactePercentSpecificShutter(0, 100);
|
||||||
|
openExactePercentSpecificShutter(1, 100);
|
||||||
|
openExactePercentSpecificShutter(2, 100);
|
||||||
|
}
|
||||||
|
// Ferme tous les volets du salon
|
||||||
|
if (analogRead(A6) > 512) {
|
||||||
|
openExactePercentSpecificShutter(0, 0);
|
||||||
|
openExactePercentSpecificShutter(1, 0);
|
||||||
|
openExactePercentSpecificShutter(2, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ouvre tous les volets de la cuisine
|
||||||
|
if (analogRead(A3) > 512) {
|
||||||
|
openExactePercentSpecificShutter(3, 100);
|
||||||
|
openExactePercentSpecificShutter(4, 100);
|
||||||
|
}
|
||||||
|
// Ferme tous les volets du salon
|
||||||
|
if (analogRead(A2) > 512) {
|
||||||
|
openExactePercentSpecificShutter(3, 0);
|
||||||
|
openExactePercentSpecificShutter(4, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (analogRead(A1) > 512)
|
||||||
|
openExactePercentAllShutter(100);
|
||||||
|
if (analogRead(A0) > 512)
|
||||||
|
openExactePercentAllShutter(0);
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
#ifndef CONTROLER
|
||||||
|
#define CONTROLER
|
||||||
|
|
||||||
|
class Controller {
|
||||||
|
public:
|
||||||
|
Shutter* shutters[5];
|
||||||
|
|
||||||
|
Controller();
|
||||||
|
|
||||||
|
void initController(); // permet de init le state de tout les volets /!\ bouge les volets IRL
|
||||||
|
|
||||||
|
void openExactePercentSpecificShutter(unsigned short shutter, float percent); // Ouvrir un seul volet a x pourcent
|
||||||
|
void openExactePercentAllShutter(float percent); // ouvrir tous les volets a x pourcent
|
||||||
|
|
||||||
|
void checkManualOpen();
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Shutter {
|
||||||
|
public:
|
||||||
|
const unsigned short pinUp;
|
||||||
|
const unsigned short pinDown;
|
||||||
|
const unsigned short name;
|
||||||
|
const unsigned short TIMETOOPEN = 10; // en secondes
|
||||||
|
|
||||||
|
float percentOpen = 0.0f; // pourcentage d'ouverture du volet, 0: fermer | 100: ouvert
|
||||||
|
|
||||||
|
// Constructeur
|
||||||
|
Shutter(unsigned short up, unsigned short down, unsigned short n) : pinUp(up), pinDown(down), name(n) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -2,9 +2,24 @@
|
|||||||
|
|
||||||
#include "updater.h"
|
#include "updater.h"
|
||||||
#include "wifiManager.h"
|
#include "wifiManager.h"
|
||||||
|
#include "controller.h"
|
||||||
|
|
||||||
|
unsigned long lastTimeCheckUpdate;
|
||||||
|
const unsigned timeWaitRestart = 182.575 * 24 * 3600; // permet le redemarrage tous les 6mois
|
||||||
|
const unsigned timeWaitCheckUpdate = 24 * 3600; // permet la verfu des updates tous les jours
|
||||||
|
|
||||||
|
WifiManager wifiManager; // se connecte automatiquement au WiFi
|
||||||
|
Updater updater;
|
||||||
|
Controller controller;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
updater.update(); // vérifie les updates
|
||||||
|
controller.initController();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
if (millis() > timeWaitRestart) // redemarrage tout les 6mois
|
||||||
|
ESP.restart();
|
||||||
|
else if (lastTimeCheckUpdate - millis() > timeWaitCheckUpdate)
|
||||||
|
updater.update();
|
||||||
}
|
}
|
||||||
+4
-1
@@ -5,11 +5,14 @@ const int THISVERSION = 1;
|
|||||||
const char* FIRMWAREURL = "http://89.168.57.22:6543/";
|
const char* FIRMWAREURL = "http://89.168.57.22:6543/";
|
||||||
const char* VERSIONURL = "http://89.168.57.22/6543/LastVersion.txt";
|
const char* VERSIONURL = "http://89.168.57.22/6543/LastVersion.txt";
|
||||||
|
|
||||||
|
// Permet la mise a jour a distance
|
||||||
class Updater {
|
class Updater {
|
||||||
|
private:
|
||||||
|
bool checkUpdate();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Updater();
|
Updater();
|
||||||
|
|
||||||
bool checkUpdate();
|
|
||||||
void update();
|
void update();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user