@@ -21,6 +21,7 @@ | |||||
#include "GraphicsEngine/GraphicsEngine.h" | #include "GraphicsEngine/GraphicsEngine.h" | ||||
#include "GraphicsEngine/SimplexNoise.h" | #include "GraphicsEngine/SimplexNoise.h" | ||||
#include "GraphicsEngine/SpriteArrays.h" | #include "GraphicsEngine/SpriteArrays.h" | ||||
#include "GraphicsEngine/Elements.h" | |||||
#include "Scenes/Scene.h" | #include "Scenes/Scene.h" | ||||
#include "Scenes/SceneMainMenu.h" | #include "Scenes/SceneMainMenu.h" | ||||
@@ -34,6 +35,7 @@ | |||||
#include "Scenes/SceneThermometerCalibration.h" | #include "Scenes/SceneThermometerCalibration.h" | ||||
#include "Scenes/SceneHeatingSettings.h" | #include "Scenes/SceneHeatingSettings.h" | ||||
#include "Scenes/SceneScreenSaverSettings.h" | #include "Scenes/SceneScreenSaverSettings.h" | ||||
#include "Scenes/TestScene.h" | |||||
// Commenting options | // Commenting options | ||||
#define SERIAL_DEBUG // TODO faudrait l'implémenter car les serial debug sont par default partout... | #define SERIAL_DEBUG // TODO faudrait l'implémenter car les serial debug sont par default partout... | ||||
@@ -96,7 +98,7 @@ class Application | |||||
// Intertask communication | // Intertask communication | ||||
void SendAction(uint8_t PWMChannel, float percentage, uint32_t fadetime); | void SendAction(uint8_t PWMChannel, float percentage, uint32_t fadetime); | ||||
void PlayMelody(Melodies melody); | void PlayMelody(Melodies melody); | ||||
void ChangeLight(uint8_t percentage, uint32_t fade_time); | |||||
void ChangeLight(uint8_t percentage_A, uint8_t percentage_C, uint32_t fade_time); | |||||
void ChangePump(uint8_t percentage, uint32_t fadetime); | void ChangePump(uint8_t percentage, uint32_t fadetime); | ||||
// *** PRIVATE METHODS *** | // *** PRIVATE METHODS *** | ||||
@@ -105,6 +107,7 @@ class Application | |||||
void Lighting(); | void Lighting(); | ||||
void Heating(); | void Heating(); | ||||
void Pump(); | void Pump(); | ||||
void StopHeating(); | |||||
// Booleans test | // Booleans test | ||||
bool IsDay(); | bool IsDay(); | ||||
@@ -16,7 +16,9 @@ struct BtnEvent | |||||
struct ModeParameters | struct ModeParameters | ||||
{ | { | ||||
// Lighting data | // Lighting data | ||||
uint8_t light_max; // max day light in percentage 0-100% | |||||
uint8_t light_max_A; // max day light in percentage 0-100% (channel A) | |||||
uint8_t light_max_B; // max day light for channel C | |||||
uint8_t hour_dusk; // hour at which the day starts | uint8_t hour_dusk; // hour at which the day starts | ||||
uint8_t hour_dawn; // hour at which the night starts | uint8_t hour_dawn; // hour at which the night starts | ||||
@@ -29,7 +31,7 @@ struct ModeParameters | |||||
uint8_t pump_cycle_lenght; // MAXIMUM 120 (in seconds) | uint8_t pump_cycle_lenght; // MAXIMUM 120 (in seconds) | ||||
ModeParameters(); | ModeParameters(); | ||||
ModeParameters(uint8_t light_max, uint8_t hour_dusk, uint8_t hour_dawn, | |||||
ModeParameters(uint8_t light_max_A, uint8_t light_max_C, uint8_t hour_dusk, uint8_t hour_dawn, | |||||
uint8_t temperature_day, uint8_t temperature_night, | uint8_t temperature_day, uint8_t temperature_night, | ||||
uint8_t pump_cycles_per_hour, uint8_t pump_cycle_lenght); | uint8_t pump_cycles_per_hour, uint8_t pump_cycle_lenght); | ||||
}; | }; | ||||
@@ -1,5 +0,0 @@ | |||||
#ifndef DAYCYCLEDRAWING_H | |||||
#define DAYCYCLEDRAWING_H | |||||
#endif |
@@ -0,0 +1,51 @@ | |||||
#ifndef ELEMENTS_H | |||||
#define ELEMENTS_H | |||||
#include "Vector2.h" | |||||
#include "GraphicsEngine.h" | |||||
/* | |||||
** Elements have properties and behaviours | |||||
** they are instantiable / destructibles dynamically in scenes | |||||
** equivalent of game objects in game engines | |||||
*/ | |||||
/* | |||||
** Base class to inherit | |||||
*/ | |||||
class Element | |||||
{ | |||||
public: | |||||
Vector2 Position; | |||||
virtual void Initialize(); | |||||
virtual void Update(); | |||||
virtual void Draw(GraphicsEngine *graphics); | |||||
}; | |||||
class PopUp : public Element | |||||
{ | |||||
public: | |||||
void Initialize() override; | |||||
void Update() override; | |||||
void Draw(GraphicsEngine *graphics) override; | |||||
void Show(bool animate); | |||||
void Hide(); | |||||
bool IsShowned(); | |||||
String Line1; | |||||
String Line2; | |||||
String Line3; | |||||
String Line4; | |||||
private: | |||||
uint16_t percentage; | |||||
uint64_t t_start; | |||||
bool is_animating = false; | |||||
uint16_t anim_speed_ms = 300; | |||||
bool show = false; | |||||
}; | |||||
#endif |
@@ -3,6 +3,7 @@ | |||||
#include "DataTypes.h" | #include "DataTypes.h" | ||||
#include "GraphicsEngine/GraphicsEngine.h" | #include "GraphicsEngine/GraphicsEngine.h" | ||||
#include "GraphicsEngine/Elements.h" | |||||
// forward declaration. Need including App.h in each scene .c files | // forward declaration. Need including App.h in each scene .c files | ||||
class Application; | class Application; | ||||
@@ -11,6 +11,9 @@ class TestScene : public Scene | |||||
void Draw(GraphicsEngine *graphics) override; | void Draw(GraphicsEngine *graphics) override; | ||||
void OnButtonClic(BTN btn) override; | void OnButtonClic(BTN btn) override; | ||||
void Destroy() override; | void Destroy() override; | ||||
private: | |||||
PopUp popup; | |||||
}; | }; | ||||
#endif | #endif |
@@ -5,23 +5,45 @@ | |||||
#include <Spirulerie.h> | #include <Spirulerie.h> | ||||
#include "App.h" | #include "App.h" | ||||
//#include "Adafruit_Sensor.h" | |||||
//#include "DHT.h" | |||||
#define READING_DELAY 3000 //30000 | #define READING_DELAY 3000 //30000 | ||||
// Global Variables | |||||
class Thermometer | class Thermometer | ||||
{ | { | ||||
public: | |||||
// Members | |||||
public: | |||||
// Methods | |||||
Thermometer(); | |||||
virtual bool StartDevice(); | |||||
virtual float GetTemperature(); | |||||
}; | |||||
class DS18B20Sensor : Thermometer | |||||
{ | |||||
protected: | |||||
OneWire oneWire; | OneWire oneWire; | ||||
DallasTemperature DS18B20; | DallasTemperature DS18B20; | ||||
DeviceAddress adress; | DeviceAddress adress; | ||||
// Methods | |||||
Thermometer(); | |||||
bool StartDevice(); | |||||
float GetTemperature(); | |||||
public: | |||||
DS18B20Sensor(); | |||||
bool StartDevice() override; | |||||
float GetTemperature() override; | |||||
}; | |||||
/* | |||||
class AM2302Sensor : Thermometer | |||||
{ | |||||
protected: | |||||
DHT DHTSensor; | |||||
public: | |||||
AM2302Sensor(); | |||||
bool StartDevice() override; | |||||
float GetTemperature() override; | |||||
}; | }; | ||||
*/ | |||||
// Functions | // Functions | ||||
TaskHandle_t InitThermometer(); // entry point | TaskHandle_t InitThermometer(); // entry point | ||||
@@ -55,7 +55,8 @@ namespace TextContent | |||||
const char text_mode_custom_FR[] PROGMEM = "personnalisé"; | const char text_mode_custom_FR[] PROGMEM = "personnalisé"; | ||||
// **** MODE CUSTOMISATION | // **** MODE CUSTOMISATION | ||||
const char text_custom_mode_title_light_FR[] PROGMEM = "lumière"; | |||||
const char text_custom_mode_title_light_A_FR[] PROGMEM = "lumière 1"; | |||||
const char text_custom_mode_title_light_B_FR[] PROGMEM = "lumière 2"; | |||||
const char text_custom_mode_title_day_FR[] PROGMEM = "journée"; | const char text_custom_mode_title_day_FR[] PROGMEM = "journée"; | ||||
const char text_custom_mode_title_temperature_FR[] PROGMEM = "température"; | const char text_custom_mode_title_temperature_FR[] PROGMEM = "température"; | ||||
const char text_custom_mode_title_pump_FR[] PROGMEM = "pompe"; | const char text_custom_mode_title_pump_FR[] PROGMEM = "pompe"; | ||||
@@ -15,4 +15,4 @@ framework = arduino | |||||
board_build.partitions = no_ota.csv | board_build.partitions = no_ota.csv | ||||
monitor_speed = 115200 | monitor_speed = 115200 | ||||
upload_speed = 115200 | upload_speed = 115200 | ||||
lib_deps = david-spirulerie/La Spirulerie @ ^0.0.2 | |||||
lib_deps = david-spirulerie/La Spirulerie @ ^0.0.2 |
@@ -9,7 +9,7 @@ Application::Application() | |||||
singleton = this; | singleton = this; | ||||
m_mode_normal = ModeParameters(); | m_mode_normal = ModeParameters(); | ||||
m_mode_hibernation = ModeParameters(10, 21, 7, 22, 20, 10, 45); | |||||
m_mode_hibernation = ModeParameters(10, 5, 21, 7, 22, 20, 10, 45); | |||||
} | } | ||||
void Application::Init() | void Application::Init() | ||||
@@ -74,7 +74,7 @@ void Application::Update() | |||||
parameters = m_mode_normal; | parameters = m_mode_normal; | ||||
else if (mode == 2) | else if (mode == 2) | ||||
parameters = DataSaveLoad::ReadCustomMode(); | parameters = DataSaveLoad::ReadCustomMode(); | ||||
Serial.printf("NEW MODE luminosity: %d\n", parameters.light_max); | |||||
Serial.printf("NEW MODE luminosity: %d\n", parameters.light_max_A); | |||||
modeNeedsRefresh = false; | modeNeedsRefresh = false; | ||||
} | } | ||||
@@ -169,26 +169,39 @@ void Application::LoadScene(Scene *scene) | |||||
void Application::Lighting() | void Application::Lighting() | ||||
{ | { | ||||
uint8_t light_value = 0; | |||||
uint8_t light_value_A = 0; | |||||
uint8_t light_value_B = 0; | |||||
tmElements_t current_time = TimeSystem::GetTime(); | tmElements_t current_time = TimeSystem::GetTime(); | ||||
if (current_time.Hour > parameters.hour_dawn | if (current_time.Hour > parameters.hour_dawn | ||||
&& current_time.Hour < parameters.hour_dusk) | && current_time.Hour < parameters.hour_dusk) | ||||
{ | { | ||||
// TODO could be refactored more elegantly and with a smoother gradient | // TODO could be refactored more elegantly and with a smoother gradient | ||||
light_value = parameters.light_max; | |||||
light_value_A = parameters.light_max_A; | |||||
if (current_time.Hour - parameters.hour_dawn == 0) | if (current_time.Hour - parameters.hour_dawn == 0) | ||||
light_value = parameters.light_max / 3; | |||||
light_value_A = parameters.light_max_A / 3; | |||||
else if (current_time.Hour - parameters.hour_dusk == 1) | else if (current_time.Hour - parameters.hour_dusk == 1) | ||||
light_value = parameters.light_max / 2; | |||||
light_value_A = parameters.light_max_A / 2; | |||||
if (parameters.hour_dawn - current_time.Hour == 0) | if (parameters.hour_dawn - current_time.Hour == 0) | ||||
light_value = parameters.light_max / 3; | |||||
light_value_A = parameters.light_max_A / 3; | |||||
else if (parameters.hour_dusk - current_time.Hour == 1) | else if (parameters.hour_dusk - current_time.Hour == 1) | ||||
light_value = parameters.light_max / 2; | |||||
light_value_A = parameters.light_max_A / 2; | |||||
// TODO could be refactored more elegantly and with a smoother gradient | |||||
light_value_B = parameters.light_max_B; | |||||
if (current_time.Hour - parameters.hour_dawn == 0) | |||||
light_value_B = parameters.light_max_B / 3; | |||||
else if (current_time.Hour - parameters.hour_dusk == 1) | |||||
light_value_B = parameters.light_max_B / 2; | |||||
if (parameters.hour_dawn - current_time.Hour == 0) | |||||
light_value_B = parameters.light_max_B / 3; | |||||
else if (parameters.hour_dusk - current_time.Hour == 1) | |||||
light_value_B = parameters.light_max_B / 2; | |||||
} | } | ||||
ChangeLight(light_value, 1500); | |||||
ChangeLight(light_value_A, light_value_B, 1500); | |||||
} | } | ||||
void Application::Heating() | void Application::Heating() | ||||
@@ -214,26 +227,34 @@ void Application::Heating() | |||||
if (temperature == -1) | if (temperature == -1) | ||||
{ | { | ||||
// Do not turn on the heating if the thermometer is not working | // Do not turn on the heating if the thermometer is not working | ||||
SendAction(PWMC_C, 0, 1000); | |||||
StopHeating(); | |||||
return; | return; | ||||
} | } | ||||
uint8_t pourcentage_chauffage = DataSaveLoad::ReadCurrentHeatingPercentage(); | |||||
if (IsDay()) | if (IsDay()) | ||||
{ | { | ||||
if (temperature < parameters.temperature_day) | if (temperature < parameters.temperature_day) | ||||
SendAction(PWMC_C, MAX_PERCENTAGE_HEATER, 1000); | |||||
SendAction(PWMC_C, pourcentage_chauffage, 1000); | |||||
else | else | ||||
SendAction(PWMC_C, 0, 1000); | |||||
StopHeating(); | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
if (temperature < parameters.temperature_night) | if (temperature < parameters.temperature_night) | ||||
SendAction(PWMC_C, MAX_PERCENTAGE_HEATER, 0); | |||||
SendAction(PWMC_C, pourcentage_chauffage, 0); | |||||
else | else | ||||
SendAction(PWMC_C, 0, 1000); | |||||
StopHeating(); | |||||
} | } | ||||
} | } | ||||
void Application::StopHeating() | |||||
{ | |||||
SendAction(PWMC_C, 0, 1000); | |||||
} | |||||
void Application::Pump() | void Application::Pump() | ||||
{ | { | ||||
tmElements_t time; | tmElements_t time; | ||||
@@ -241,6 +262,12 @@ void Application::Pump() | |||||
float cycle_time_minutes; | float cycle_time_minutes; | ||||
uint8_t cycle_current_minute; | uint8_t cycle_current_minute; | ||||
if (parameters.pump_cycles_per_hour == 0) | |||||
{ | |||||
ChangePump(0, 600); | |||||
return; | |||||
} | |||||
time = TimeSystem::GetTime(); | time = TimeSystem::GetTime(); | ||||
cycle_delay = 60 / parameters.pump_cycles_per_hour; | cycle_delay = 60 / parameters.pump_cycles_per_hour; | ||||
cycle_time_minutes = parameters.pump_cycle_lenght / 60; | cycle_time_minutes = parameters.pump_cycle_lenght / 60; | ||||
@@ -302,17 +329,19 @@ void Application::PlayMelody(Melodies melody) | |||||
xQueueSend(audioQueue, &melody, 0); | xQueueSend(audioQueue, &melody, 0); | ||||
} | } | ||||
void Application::ChangeLight(uint8_t percentage, uint32_t fade_time) | |||||
void Application::ChangeLight(uint8_t percentage_A, uint8_t percentage_C, uint32_t fade_time) | |||||
{ | { | ||||
if (percentage > 100) | |||||
percentage = 100; | |||||
if (percentage_A > 100) | |||||
percentage_A = 100; | |||||
if (percentage_C > 100) | |||||
percentage_C = 100; | |||||
if (m_current_light_level != percentage) | |||||
if (m_current_light_level != percentage_A) | |||||
{ | { | ||||
SendAction(PWMC_A, percentage, fade_time); // Warm White LED | |||||
SendAction(PWMC_B, percentage * 0.7f, fade_time); // Red LED (heats more -> decrease pwm) | |||||
SendAction(PWMC_A, percentage_A, fade_time); // Warm White LED | |||||
SendAction(PWMC_B, percentage_C, fade_time); // Red LED (heats more -> decrease pwm) | |||||
} | } | ||||
m_current_light_level = percentage; | |||||
m_current_light_level = percentage_A; | |||||
} | } | ||||
void Application::ChangePump(uint8_t percentage, uint32_t fade_time) | void Application::ChangePump(uint8_t percentage, uint32_t fade_time) | ||||
@@ -2,7 +2,8 @@ | |||||
ModeParameters::ModeParameters() | ModeParameters::ModeParameters() | ||||
{ | { | ||||
this->light_max = 31; | |||||
this->light_max_A = 31; | |||||
this->light_max_B = 15; | |||||
this->hour_dusk = 23; | this->hour_dusk = 23; | ||||
this->hour_dawn = 5; | this->hour_dawn = 5; | ||||
this->temperature_day = 35; | this->temperature_day = 35; | ||||
@@ -12,11 +13,12 @@ ModeParameters::ModeParameters() | |||||
} | } | ||||
ModeParameters::ModeParameters( | ModeParameters::ModeParameters( | ||||
uint8_t light_max, uint8_t hour_dusk, uint8_t hour_dawn, | |||||
uint8_t light_max_A, uint8_t light_max_B, uint8_t hour_dusk, uint8_t hour_dawn, | |||||
uint8_t temperature_day, uint8_t temperature_night, | uint8_t temperature_day, uint8_t temperature_night, | ||||
uint8_t pump_cycles_per_hour, uint8_t pump_cycle_lenght) | uint8_t pump_cycles_per_hour, uint8_t pump_cycle_lenght) | ||||
{ | { | ||||
this->light_max = light_max; | |||||
this->light_max_A = light_max_A; | |||||
this->light_max_B = light_max_B; | |||||
this->hour_dusk = hour_dusk; | this->hour_dusk = hour_dusk; | ||||
this->hour_dawn = hour_dawn; | this->hour_dawn = hour_dawn; | ||||
this->temperature_day = temperature_day; | this->temperature_day = temperature_day; | ||||
@@ -0,0 +1,16 @@ | |||||
#include "GraphicsEngine/Elements.h" | |||||
void Element::Initialize() | |||||
{ | |||||
} | |||||
void Element::Update() | |||||
{ | |||||
} | |||||
void Element::Draw(GraphicsEngine *graphics) | |||||
{ | |||||
} |
@@ -0,0 +1,59 @@ | |||||
#include "GraphicsEngine/Elements.h" | |||||
void PopUp::Initialize() | |||||
{ | |||||
} | |||||
void PopUp::Update() | |||||
{ | |||||
if (!show) | |||||
return; | |||||
uint16_t milli_count = millis() - t_start; | |||||
if (milli_count >= anim_speed_ms) | |||||
is_animating = false; | |||||
percentage = ((float)milli_count / (float)anim_speed_ms) * 100; | |||||
} | |||||
void PopUp::Draw(GraphicsEngine *graphics) | |||||
{ | |||||
if (!show) | |||||
return; | |||||
if (is_animating) | |||||
{ | |||||
uint16_t val = 100 - percentage; | |||||
graphics->Screen.fillRoundRect(12 + val / 4, 12 + val / 4, WIN_WIDTH - 24 - val / 2, WIN_HEIGHT - 24 - val / 2, 8, SPIRULERIE_LIGHT); | |||||
graphics->Screen.drawRoundRect(12 + val / 4, 12 + val / 4, WIN_WIDTH - 24 - val / 2, WIN_HEIGHT - 24 - val / 2, 8, SPIRULERIE_BLUE); | |||||
return; | |||||
} | |||||
graphics->Screen.fillRoundRect(12, 12, WIN_WIDTH - 24, WIN_HEIGHT - 24, 8, SPIRULERIE_LIGHT); | |||||
graphics->Screen.drawRoundRect(12, 12, WIN_WIDTH - 24, WIN_HEIGHT - 24, 8, SPIRULERIE_BLUE); | |||||
graphics->Screen.drawRoundRect(13, 13, WIN_WIDTH - 26, WIN_HEIGHT - 26, 6, SPIRULERIE_BLUE); | |||||
graphics->Screen.drawString(Line1, WIN_WIDTH / 2, WIN_HEIGHT / 2 - 42); | |||||
graphics->Screen.drawString(Line2, WIN_WIDTH / 2, WIN_HEIGHT / 2 - 20); | |||||
graphics->Screen.drawString(Line3, WIN_WIDTH / 2, WIN_HEIGHT / 2 + 2); | |||||
graphics->Screen.drawString(Line4, WIN_WIDTH / 2, WIN_HEIGHT / 2 + 24); | |||||
} | |||||
void PopUp::Show(bool animate) | |||||
{ | |||||
show = true; | |||||
is_animating = animate; | |||||
t_start = millis(); | |||||
} | |||||
void PopUp::Hide() | |||||
{ | |||||
show = false; | |||||
is_animating = false; | |||||
} | |||||
bool PopUp::IsShowned() | |||||
{ | |||||
return (show); | |||||
} |
@@ -1,7 +1,7 @@ | |||||
#include "Scenes/SceneCustomModeSettings.h" | #include "Scenes/SceneCustomModeSettings.h" | ||||
#include "App.h" | #include "App.h" | ||||
enum PARAMS { LUMIERE_MAX, HOUR_START, HOUR_END, T_DAY, T_NIGHT, PUMP_CYCLE_PER_HOUR, PUMP_CYCLE_LENGHT }; | |||||
enum PARAMS { LUMIERE_MAX_A, LUMIERE_MAX_B, HOUR_START, HOUR_END, T_DAY, T_NIGHT, PUMP_CYCLE_PER_HOUR, PUMP_CYCLE_LENGHT }; | |||||
void SceneCustomModeSettings::Initialize() | void SceneCustomModeSettings::Initialize() | ||||
{ | { | ||||
@@ -9,7 +9,7 @@ void SceneCustomModeSettings::Initialize() | |||||
Scene::Initialize(); | Scene::Initialize(); | ||||
m_custom_mode = DataSaveLoad::ReadCustomMode(); | m_custom_mode = DataSaveLoad::ReadCustomMode(); | ||||
m_selection = (float)(100.0f / MAX_PERCENTAGE_LIGHT) * m_custom_mode.light_max; | |||||
m_selection = (float)(100.0f / MAX_PERCENTAGE_LIGHT) * m_custom_mode.light_max_A; | |||||
app->Graphics.LoadFont("Comfortaa_16", SPIRULERIE_BLUE, SPIRULERIE_LIGHT); | app->Graphics.LoadFont("Comfortaa_16", SPIRULERIE_BLUE, SPIRULERIE_LIGHT); | ||||
app->Graphics.Screen.setTextDatum(TC_DATUM); | app->Graphics.Screen.setTextDatum(TC_DATUM); | ||||
@@ -21,13 +21,23 @@ void SceneCustomModeSettings::Update() | |||||
switch (m_progress) | switch (m_progress) | ||||
{ | { | ||||
case PARAMS::LUMIERE_MAX: | |||||
case PARAMS::LUMIERE_MAX_A: | |||||
if (m_selection > 100) | if (m_selection > 100) | ||||
m_selection = 0; | m_selection = 0; | ||||
if (m_selection < 0) | if (m_selection < 0) | ||||
m_selection = 100; | m_selection = 100; | ||||
m_title_text = TextContent::text_custom_mode_title_light_FR; | |||||
m_title_text = TextContent::text_custom_mode_title_light_A_FR; | |||||
m_helper_text = TextContent::text_custom_mode_light_max_FR; | |||||
m_selection_text = (String)m_selection + " %"; | |||||
break; | |||||
case PARAMS::LUMIERE_MAX_B: | |||||
if (m_selection > 100) | |||||
m_selection = 0; | |||||
if (m_selection < 0) | |||||
m_selection = 100; | |||||
m_title_text = TextContent::text_custom_mode_title_light_B_FR; | |||||
m_helper_text = TextContent::text_custom_mode_light_max_FR; | m_helper_text = TextContent::text_custom_mode_light_max_FR; | ||||
m_selection_text = (String)m_selection + " %"; | m_selection_text = (String)m_selection + " %"; | ||||
break; | break; | ||||
@@ -132,9 +142,14 @@ void SceneCustomModeSettings::OnButtonClic(BTN btn) | |||||
case BTN::MIDDLE: | case BTN::MIDDLE: | ||||
// get to next option | // get to next option | ||||
m_progress++; | m_progress++; | ||||
if (m_progress == PARAMS::HOUR_START) | |||||
if (m_progress == PARAMS::LUMIERE_MAX_B) | |||||
{ | |||||
m_custom_mode.light_max_A = m_selection*MAX_PERCENTAGE_LIGHT/100; | |||||
m_selection = (float)(100.0f / MAX_PERCENTAGE_LIGHT) * m_custom_mode.light_max_B; | |||||
} | |||||
else if (m_progress == PARAMS::HOUR_START) | |||||
{ | { | ||||
m_custom_mode.light_max = m_selection*MAX_PERCENTAGE_LIGHT/100; | |||||
m_custom_mode.light_max_B = m_selection*MAX_PERCENTAGE_LIGHT/100; | |||||
m_selection = m_custom_mode.hour_dawn; | m_selection = m_custom_mode.hour_dawn; | ||||
} | } | ||||
else if (m_progress == PARAMS::HOUR_END) | else if (m_progress == PARAMS::HOUR_END) | ||||
@@ -24,21 +24,17 @@ void SceneMainMenu::Draw(GraphicsEngine *graphics) | |||||
// clear screen | // clear screen | ||||
graphics->DrawScreen(SPIRULERIE_GREY); | graphics->DrawScreen(SPIRULERIE_GREY); | ||||
// Show the time | |||||
// draw sky and sun / stars | |||||
DrawDayNightCycle(hour(), app->parameters.hour_dawn, app->parameters.hour_dusk); | DrawDayNightCycle(hour(), app->parameters.hour_dawn, app->parameters.hour_dusk); | ||||
// Render a separator | |||||
//graphics->Screen.drawFastHLine(32, 64, 96, SPIRULERIE_LIGHT); | |||||
// draw green bottom half | |||||
graphics->Screen.fillRect(0, 64, 160, 64, SPIRULERIE_GREEN); | graphics->Screen.fillRect(0, 64, 160, 64, SPIRULERIE_GREEN); | ||||
// Show the current temperature | |||||
// show the current temperature | |||||
DrawTemperature(24, 80, app->GetCurrentTemperature()); | DrawTemperature(24, 80, app->GetCurrentTemperature()); | ||||
//if (app->heatNominal) | //if (app->heatNominal) | ||||
// graphics->DrawImage(Sprites::chauffage_32_32, 18, 80, 32, 32); // trop moche | // graphics->DrawImage(Sprites::chauffage_32_32, 18, 80, 32, 32); // trop moche | ||||
// draw possible moves out of screen | |||||
// draw possible moves out of the screen | |||||
graphics->DrawRightArrow(); | graphics->DrawRightArrow(); | ||||
Scene::Draw(graphics); | Scene::Draw(graphics); | ||||
@@ -49,7 +45,7 @@ void SceneMainMenu::OnButtonClic(BTN btn) | |||||
switch (btn) | switch (btn) | ||||
{ | { | ||||
case BTN::LEFT: | case BTN::LEFT: | ||||
//app->LoadScene(new SceneLoadingScreen()); | |||||
//app->LoadScene(new TestScene()); | |||||
break; | break; | ||||
case BTN::MIDDLE: | case BTN::MIDDLE: | ||||
break; | break; | ||||
@@ -71,9 +67,10 @@ void SceneMainMenu::Destroy() | |||||
void SceneMainMenu::DrawDayNightCycle(uint8_t hour, uint8_t dawn, uint8_t dusk) | void SceneMainMenu::DrawDayNightCycle(uint8_t hour, uint8_t dawn, uint8_t dusk) | ||||
{ | { | ||||
// check boundaries | |||||
// check if night | |||||
if (hour < dawn || hour >= dusk) | if (hour < dawn || hour >= dusk) | ||||
{ | { | ||||
// draw the night sky | |||||
app->Graphics.Screen.fillRect(0, 0, 160, 64, SPIRULERIE_GREY); | app->Graphics.Screen.fillRect(0, 0, 160, 64, SPIRULERIE_GREY); | ||||
for (int i = 0; i < 32; i++) | for (int i = 0; i < 32; i++) | ||||
{ | { | ||||
@@ -84,11 +81,13 @@ void SceneMainMenu::DrawDayNightCycle(uint8_t hour, uint8_t dawn, uint8_t dusk) | |||||
x = (x + 1) / 2.0f * 160.0f; | x = (x + 1) / 2.0f * 160.0f; | ||||
y = (y + 1) / 2.0f * 64.0f; | y = (y + 1) / 2.0f * 64.0f; | ||||
// draw a star | |||||
app->Graphics.Screen.drawPixel(x, y, SPIRULERIE_LIGHT); | app->Graphics.Screen.drawPixel(x, y, SPIRULERIE_LIGHT); | ||||
} | } | ||||
return; | return; | ||||
} | } | ||||
// draw blue sky | |||||
app->Graphics.Screen.fillRect(0, 0, 160, 64, SPIRULERIE_BLUE); | app->Graphics.Screen.fillRect(0, 0, 160, 64, SPIRULERIE_BLUE); | ||||
uint8_t num_day_hours = dusk - dawn; | uint8_t num_day_hours = dusk - dawn; | ||||
@@ -9,6 +9,14 @@ void TestScene::Initialize() | |||||
{ | { | ||||
Serial.printf("<== scene TestScene ==>\n"); | Serial.printf("<== scene TestScene ==>\n"); | ||||
Scene::Initialize(); | Scene::Initialize(); | ||||
popup.Initialize(); | |||||
popup.Line1 = "Title!"; | |||||
popup.Line2 = "ceci est popup !"; | |||||
popup.Line3 = "ligne 3"; | |||||
popup.Line4 = "[OK]"; | |||||
app->Graphics.LoadFont("Comfortaa_16", SPIRULERIE_GREY, SPIRULERIE_LIGHT); | |||||
} | } | ||||
void TestScene::Update() | void TestScene::Update() | ||||
@@ -18,14 +26,14 @@ void TestScene::Update() | |||||
pos.X = (WIN_WIDTH / 2) + noisyX - 8; | pos.X = (WIN_WIDTH / 2) + noisyX - 8; | ||||
pos.Y = (WIN_HEIGHT / 2) + noisyY - 8; | pos.Y = (WIN_HEIGHT / 2) + noisyY - 8; | ||||
popup.Update(); | |||||
Scene::Update(); | Scene::Update(); | ||||
} | } | ||||
void TestScene::Draw(GraphicsEngine *graphics) | void TestScene::Draw(GraphicsEngine *graphics) | ||||
{ | { | ||||
graphics->DrawScreen(SPIRULERIE_LIGHT); | graphics->DrawScreen(SPIRULERIE_LIGHT); | ||||
//graphics->Screen.fillRoundRect(pos.X, pos.Y, 16, 16, 8, SPIRULERIE_GREEN); | |||||
float current_millis = millis() / 2000.0f; | float current_millis = millis() / 2000.0f; | ||||
int x = 5; | int x = 5; | ||||
@@ -41,14 +49,19 @@ void TestScene::Draw(GraphicsEngine *graphics) | |||||
static int y = 0; | static int y = 0; | ||||
y--; | y--; | ||||
//graphics->DrawImage(pixel_noir, 0, y, 450, 510); | |||||
popup.Draw(graphics); | |||||
Scene::Draw(graphics); | Scene::Draw(graphics); | ||||
} | } | ||||
void TestScene::OnButtonClic(BTN btn) | void TestScene::OnButtonClic(BTN btn) | ||||
{ | { | ||||
Application::singleton->LoadScene(new SceneMainMenu()); | |||||
if (popup.IsShowned()) | |||||
popup.Hide(); | |||||
else | |||||
popup.Show(true); | |||||
Scene::OnButtonClic(btn); | Scene::OnButtonClic(btn); | ||||
} | } | ||||
@@ -18,7 +18,7 @@ void ThermometerTask(void *parameter) | |||||
{ | { | ||||
QueueHandle_t temperatureQueue = Application::singleton->temperatureQueue; | QueueHandle_t temperatureQueue = Application::singleton->temperatureQueue; | ||||
QueueHandle_t TSensorActiveQueue = Application::singleton->TSensorActiveQueue; | QueueHandle_t TSensorActiveQueue = Application::singleton->TSensorActiveQueue; | ||||
Thermometer thermometer; | |||||
DS18B20Sensor DS18B20Temp; | |||||
// we should fill the queue with at least an error value. Not the undefined default | // we should fill the queue with at least an error value. Not the undefined default | ||||
float init_temp = -1; | float init_temp = -1; | ||||
@@ -28,8 +28,12 @@ void ThermometerTask(void *parameter) | |||||
delay(1000); | delay(1000); | ||||
// Start the thermometer and try again if there is an error | // Start the thermometer and try again if there is an error | ||||
while (!thermometer.StartDevice()) | |||||
for (size_t i = 0; i < 10; i++) | |||||
{ | |||||
if(DS18B20Temp.StartDevice()) | |||||
break; | |||||
delay(400); | delay(400); | ||||
} | |||||
// Wait a bit between initialization and first reading | // Wait a bit between initialization and first reading | ||||
delay(5000); | delay(5000); | ||||
@@ -45,9 +49,9 @@ void ThermometerTask(void *parameter) | |||||
if (canCheckTemperature) | if (canCheckTemperature) | ||||
{ | { | ||||
// Check Temperature | // Check Temperature | ||||
tempC = thermometer.GetTemperature(); | |||||
tempC = DS18B20Temp.GetTemperature(); | |||||
if (tempC == -1) | if (tempC == -1) | ||||
thermometer.StartDevice(); | |||||
DS18B20Temp.StartDevice(); | |||||
if (tempC < -1) | if (tempC < -1) | ||||
tempC = -1; // sometime gets -127 for some reason | tempC = -1; // sometime gets -127 for some reason | ||||
@@ -64,12 +68,21 @@ void ThermometerTask(void *parameter) | |||||
Thermometer::Thermometer() | Thermometer::Thermometer() | ||||
{ | { | ||||
} | |||||
// ------------------------------ | |||||
// ---------- DS18B20 ----------- | |||||
// ------------------------------ | |||||
DS18B20Sensor::DS18B20Sensor() | |||||
{ | |||||
oneWire = OneWire(PIN_DS18B20); | oneWire = OneWire(PIN_DS18B20); | ||||
delay(200); | delay(200); | ||||
DS18B20 = DallasTemperature(&oneWire); | DS18B20 = DallasTemperature(&oneWire); | ||||
} | } | ||||
bool Thermometer::StartDevice() | |||||
bool DS18B20Sensor::StartDevice() | |||||
{ | { | ||||
DS18B20.begin(); | DS18B20.begin(); | ||||
delay(500); | delay(500); | ||||
@@ -78,11 +91,11 @@ bool Thermometer::StartDevice() | |||||
Serial.printf("error in starting up DS18B20..\n"); | Serial.printf("error in starting up DS18B20..\n"); | ||||
return (false); | return (false); | ||||
} | } | ||||
Serial.printf("=> DS18B20 started OK !\n"); | |||||
Serial.printf("=> DS18B20 started OK ! Adress: %u\n", adress); | |||||
return (true); | return (true); | ||||
} | } | ||||
float Thermometer::GetTemperature() | |||||
float DS18B20Sensor::GetTemperature() | |||||
{ | { | ||||
if (DS18B20.requestTemperaturesByAddress(adress)) | if (DS18B20.requestTemperaturesByAddress(adress)) | ||||
{ | { | ||||
@@ -93,4 +106,39 @@ float Thermometer::GetTemperature() | |||||
} | } | ||||
Serial.printf("Error getting adress temperature...\n"); | Serial.printf("Error getting adress temperature...\n"); | ||||
return (-1); | return (-1); | ||||
} | |||||
} | |||||
// ------------------------------ | |||||
// ---------- AM2302 ------------ | |||||
// ------------------------------ | |||||
/* | |||||
AM2302Sensor::AM2302Sensor() : DHTSensor(PIN_DS18B20, DHT22) | |||||
{ | |||||
} | |||||
bool AM2302Sensor::StartDevice() | |||||
{ | |||||
DHTSensor.begin(); | |||||
delay(3000); | |||||
if (isnan(DHTSensor.readTemperature())) | |||||
{ | |||||
Serial.printf("error in starting up AM2302..\n"); | |||||
return (false); | |||||
} | |||||
Serial.printf("=> AM2302 started OK !\n"); | |||||
return (true); | |||||
} | |||||
float AM2302Sensor::GetTemperature() | |||||
{ | |||||
float tempC = DHTSensor.readTemperature(); | |||||
if(!isnan(tempC)) | |||||
{ | |||||
Serial.printf("AM2302 Value : %0.2f\n", tempC); | |||||
return (tempC); | |||||
} | |||||
Serial.printf("Error reading AM2302...\n"); | |||||
return (-1); | |||||
} | |||||
*/ |