Procházet zdrojové kódy

fixes and small upgrades: -fix critical crash on custom mode with pump cycle of 0. -add customizability of B channel light intensity PWM % independant from channel A -wip begin work on new more generic graphics / UI system with popups and other instantiable elements

main
David před 3 roky
rodič
revize
46fedff0f8
17 změnil soubory, kde provedl 329 přidání a 70 odebrání
  1. +4
    -1
      MK3_Firmware/include/App.h
  2. +4
    -2
      MK3_Firmware/include/DataTypes.h
  3. +0
    -5
      MK3_Firmware/include/GraphicsEngine/DayCycleDrawing.h
  4. +51
    -0
      MK3_Firmware/include/GraphicsEngine/Elements.h
  5. +1
    -0
      MK3_Firmware/include/Scenes/Scene.h
  6. +3
    -0
      MK3_Firmware/include/Scenes/TestScene.h
  7. +30
    -8
      MK3_Firmware/include/Tasks/TaskThermometer.h
  8. +2
    -1
      MK3_Firmware/include/TextContent.h
  9. +1
    -1
      MK3_Firmware/platformio.ini
  10. +50
    -21
      MK3_Firmware/src/App.cpp
  11. +5
    -3
      MK3_Firmware/src/DataTypes.cpp
  12. +16
    -0
      MK3_Firmware/src/GraphicsEngine/Elements/Elements.cpp
  13. +59
    -0
      MK3_Firmware/src/GraphicsEngine/Elements/Popup.cpp
  14. +21
    -6
      MK3_Firmware/src/Scenes/SceneCustomModeSettings.cpp
  15. +9
    -10
      MK3_Firmware/src/Scenes/SceneMainMenu.cpp
  16. +17
    -4
      MK3_Firmware/src/Scenes/TestScene.cpp
  17. +56
    -8
      MK3_Firmware/src/Tasks/TaskThermometer.cpp

+ 4
- 1
MK3_Firmware/include/App.h Zobrazit soubor

@@ -21,6 +21,7 @@
#include "GraphicsEngine/GraphicsEngine.h"
#include "GraphicsEngine/SimplexNoise.h"
#include "GraphicsEngine/SpriteArrays.h"
#include "GraphicsEngine/Elements.h"

#include "Scenes/Scene.h"
#include "Scenes/SceneMainMenu.h"
@@ -34,6 +35,7 @@
#include "Scenes/SceneThermometerCalibration.h"
#include "Scenes/SceneHeatingSettings.h"
#include "Scenes/SceneScreenSaverSettings.h"
#include "Scenes/TestScene.h"

// Commenting options
#define SERIAL_DEBUG // TODO faudrait l'implémenter car les serial debug sont par default partout...
@@ -96,7 +98,7 @@ class Application
// Intertask communication
void SendAction(uint8_t PWMChannel, float percentage, uint32_t fadetime);
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);

// *** PRIVATE METHODS ***
@@ -105,6 +107,7 @@ class Application
void Lighting();
void Heating();
void Pump();
void StopHeating();

// Booleans test
bool IsDay();


+ 4
- 2
MK3_Firmware/include/DataTypes.h Zobrazit soubor

@@ -16,7 +16,9 @@ struct BtnEvent
struct ModeParameters
{
// 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_dawn; // hour at which the night starts

@@ -29,7 +31,7 @@ struct ModeParameters
uint8_t pump_cycle_lenght; // MAXIMUM 120 (in seconds)

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 pump_cycles_per_hour, uint8_t pump_cycle_lenght);
};


+ 0
- 5
MK3_Firmware/include/GraphicsEngine/DayCycleDrawing.h Zobrazit soubor

@@ -1,5 +0,0 @@
#ifndef DAYCYCLEDRAWING_H
#define DAYCYCLEDRAWING_H


#endif

+ 51
- 0
MK3_Firmware/include/GraphicsEngine/Elements.h Zobrazit soubor

@@ -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

+ 1
- 0
MK3_Firmware/include/Scenes/Scene.h Zobrazit soubor

@@ -3,6 +3,7 @@

#include "DataTypes.h"
#include "GraphicsEngine/GraphicsEngine.h"
#include "GraphicsEngine/Elements.h"

// forward declaration. Need including App.h in each scene .c files
class Application;


+ 3
- 0
MK3_Firmware/include/Scenes/TestScene.h Zobrazit soubor

@@ -11,6 +11,9 @@ class TestScene : public Scene
void Draw(GraphicsEngine *graphics) override;
void OnButtonClic(BTN btn) override;
void Destroy() override;

private:
PopUp popup;
};

#endif

+ 30
- 8
MK3_Firmware/include/Tasks/TaskThermometer.h Zobrazit soubor

@@ -5,23 +5,45 @@
#include <Spirulerie.h>

#include "App.h"
//#include "Adafruit_Sensor.h"
//#include "DHT.h"

#define READING_DELAY 3000 //30000

// Global Variables
class Thermometer
{
public:
// Members
public:
// Methods
Thermometer();
virtual bool StartDevice();
virtual float GetTemperature();
};

class DS18B20Sensor : Thermometer
{
protected:
OneWire oneWire;
DallasTemperature DS18B20;
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
TaskHandle_t InitThermometer(); // entry point


+ 2
- 1
MK3_Firmware/include/TextContent.h Zobrazit soubor

@@ -55,7 +55,8 @@ namespace TextContent
const char text_mode_custom_FR[] PROGMEM = "personnalisé";

// **** 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_temperature_FR[] PROGMEM = "température";
const char text_custom_mode_title_pump_FR[] PROGMEM = "pompe";


+ 1
- 1
MK3_Firmware/platformio.ini Zobrazit soubor

@@ -15,4 +15,4 @@ framework = arduino
board_build.partitions = no_ota.csv
monitor_speed = 115200
upload_speed = 115200
lib_deps = david-spirulerie/La Spirulerie @ ^0.0.2
lib_deps = david-spirulerie/La Spirulerie @ ^0.0.2

+ 50
- 21
MK3_Firmware/src/App.cpp Zobrazit soubor

@@ -9,7 +9,7 @@ Application::Application()
singleton = this;

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()
@@ -74,7 +74,7 @@ void Application::Update()
parameters = m_mode_normal;
else if (mode == 2)
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;
}

@@ -169,26 +169,39 @@ void Application::LoadScene(Scene *scene)

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();

if (current_time.Hour > parameters.hour_dawn
&& current_time.Hour < parameters.hour_dusk)
{
// 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)
light_value = parameters.light_max / 3;
light_value_A = parameters.light_max_A / 3;
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)
light_value = parameters.light_max / 3;
light_value_A = parameters.light_max_A / 3;
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()
@@ -214,26 +227,34 @@ void Application::Heating()
if (temperature == -1)
{
// Do not turn on the heating if the thermometer is not working
SendAction(PWMC_C, 0, 1000);
StopHeating();
return;
}


uint8_t pourcentage_chauffage = DataSaveLoad::ReadCurrentHeatingPercentage();
if (IsDay())
{
if (temperature < parameters.temperature_day)
SendAction(PWMC_C, MAX_PERCENTAGE_HEATER, 1000);
SendAction(PWMC_C, pourcentage_chauffage, 1000);
else
SendAction(PWMC_C, 0, 1000);
StopHeating();
}
else
{
if (temperature < parameters.temperature_night)
SendAction(PWMC_C, MAX_PERCENTAGE_HEATER, 0);
SendAction(PWMC_C, pourcentage_chauffage, 0);
else
SendAction(PWMC_C, 0, 1000);
StopHeating();
}
}

void Application::StopHeating()
{
SendAction(PWMC_C, 0, 1000);
}

void Application::Pump()
{
tmElements_t time;
@@ -241,6 +262,12 @@ void Application::Pump()
float cycle_time_minutes;
uint8_t cycle_current_minute;

if (parameters.pump_cycles_per_hour == 0)
{
ChangePump(0, 600);
return;
}

time = TimeSystem::GetTime();
cycle_delay = 60 / parameters.pump_cycles_per_hour;
cycle_time_minutes = parameters.pump_cycle_lenght / 60;
@@ -302,17 +329,19 @@ void Application::PlayMelody(Melodies melody)
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)


+ 5
- 3
MK3_Firmware/src/DataTypes.cpp Zobrazit soubor

@@ -2,7 +2,8 @@

ModeParameters::ModeParameters()
{
this->light_max = 31;
this->light_max_A = 31;
this->light_max_B = 15;
this->hour_dusk = 23;
this->hour_dawn = 5;
this->temperature_day = 35;
@@ -12,11 +13,12 @@ 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 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_dawn = hour_dawn;
this->temperature_day = temperature_day;


+ 16
- 0
MK3_Firmware/src/GraphicsEngine/Elements/Elements.cpp Zobrazit soubor

@@ -0,0 +1,16 @@
#include "GraphicsEngine/Elements.h"

void Element::Initialize()
{
}

void Element::Update()
{
}

void Element::Draw(GraphicsEngine *graphics)
{

}

+ 59
- 0
MK3_Firmware/src/GraphicsEngine/Elements/Popup.cpp Zobrazit soubor

@@ -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);
}

+ 21
- 6
MK3_Firmware/src/Scenes/SceneCustomModeSettings.cpp Zobrazit soubor

@@ -1,7 +1,7 @@
#include "Scenes/SceneCustomModeSettings.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()
{
@@ -9,7 +9,7 @@ void SceneCustomModeSettings::Initialize()
Scene::Initialize();

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.Screen.setTextDatum(TC_DATUM);
@@ -21,13 +21,23 @@ void SceneCustomModeSettings::Update()

switch (m_progress)
{
case PARAMS::LUMIERE_MAX:
case PARAMS::LUMIERE_MAX_A:
if (m_selection > 100)
m_selection = 0;
if (m_selection < 0)
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_selection_text = (String)m_selection + " %";
break;
@@ -132,9 +142,14 @@ void SceneCustomModeSettings::OnButtonClic(BTN btn)
case BTN::MIDDLE:
// get to next option
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;
}
else if (m_progress == PARAMS::HOUR_END)


+ 9
- 10
MK3_Firmware/src/Scenes/SceneMainMenu.cpp Zobrazit soubor

@@ -24,21 +24,17 @@ void SceneMainMenu::Draw(GraphicsEngine *graphics)
// clear screen
graphics->DrawScreen(SPIRULERIE_GREY);

// Show the time
// draw sky and sun / stars
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);

// Show the current temperature
// show the current temperature
DrawTemperature(24, 80, app->GetCurrentTemperature());

//if (app->heatNominal)
// 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();

Scene::Draw(graphics);
@@ -49,7 +45,7 @@ void SceneMainMenu::OnButtonClic(BTN btn)
switch (btn)
{
case BTN::LEFT:
//app->LoadScene(new SceneLoadingScreen());
//app->LoadScene(new TestScene());
break;
case BTN::MIDDLE:
break;
@@ -71,9 +67,10 @@ void SceneMainMenu::Destroy()

void SceneMainMenu::DrawDayNightCycle(uint8_t hour, uint8_t dawn, uint8_t dusk)
{
// check boundaries
// check if night
if (hour < dawn || hour >= dusk)
{
// draw the night sky
app->Graphics.Screen.fillRect(0, 0, 160, 64, SPIRULERIE_GREY);
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;
y = (y + 1) / 2.0f * 64.0f;

// draw a star
app->Graphics.Screen.drawPixel(x, y, SPIRULERIE_LIGHT);
}
return;
}

// draw blue sky
app->Graphics.Screen.fillRect(0, 0, 160, 64, SPIRULERIE_BLUE);

uint8_t num_day_hours = dusk - dawn;


+ 17
- 4
MK3_Firmware/src/Scenes/TestScene.cpp Zobrazit soubor

@@ -9,6 +9,14 @@ void TestScene::Initialize()
{
Serial.printf("<== scene TestScene ==>\n");
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()
@@ -18,14 +26,14 @@ void TestScene::Update()

pos.X = (WIN_WIDTH / 2) + noisyX - 8;
pos.Y = (WIN_HEIGHT / 2) + noisyY - 8;

popup.Update();
Scene::Update();
}

void TestScene::Draw(GraphicsEngine *graphics)
{
graphics->DrawScreen(SPIRULERIE_LIGHT);
//graphics->Screen.fillRoundRect(pos.X, pos.Y, 16, 16, 8, SPIRULERIE_GREEN);

float current_millis = millis() / 2000.0f;
int x = 5;
@@ -41,14 +49,19 @@ void TestScene::Draw(GraphicsEngine *graphics)

static int y = 0;
y--;
//graphics->DrawImage(pixel_noir, 0, y, 450, 510);


popup.Draw(graphics);
Scene::Draw(graphics);
}

void TestScene::OnButtonClic(BTN btn)
{
Application::singleton->LoadScene(new SceneMainMenu());
if (popup.IsShowned())
popup.Hide();
else
popup.Show(true);

Scene::OnButtonClic(btn);
}



+ 56
- 8
MK3_Firmware/src/Tasks/TaskThermometer.cpp Zobrazit soubor

@@ -18,7 +18,7 @@ void ThermometerTask(void *parameter)
{
QueueHandle_t temperatureQueue = Application::singleton->temperatureQueue;
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
float init_temp = -1;
@@ -28,8 +28,12 @@ void ThermometerTask(void *parameter)
delay(1000);

// 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);
}

// Wait a bit between initialization and first reading
delay(5000);
@@ -45,9 +49,9 @@ void ThermometerTask(void *parameter)
if (canCheckTemperature)
{
// Check Temperature
tempC = thermometer.GetTemperature();
tempC = DS18B20Temp.GetTemperature();
if (tempC == -1)
thermometer.StartDevice();
DS18B20Temp.StartDevice();

if (tempC < -1)
tempC = -1; // sometime gets -127 for some reason
@@ -64,12 +68,21 @@ void ThermometerTask(void *parameter)

Thermometer::Thermometer()
{

}

// ------------------------------
// ---------- DS18B20 -----------
// ------------------------------

DS18B20Sensor::DS18B20Sensor()
{
oneWire = OneWire(PIN_DS18B20);
delay(200);
DS18B20 = DallasTemperature(&oneWire);
}

bool Thermometer::StartDevice()
bool DS18B20Sensor::StartDevice()
{
DS18B20.begin();
delay(500);
@@ -78,11 +91,11 @@ bool Thermometer::StartDevice()
Serial.printf("error in starting up DS18B20..\n");
return (false);
}
Serial.printf("=> DS18B20 started OK !\n");
Serial.printf("=> DS18B20 started OK ! Adress: %u\n", adress);
return (true);
}

float Thermometer::GetTemperature()
float DS18B20Sensor::GetTemperature()
{
if (DS18B20.requestTemperaturesByAddress(adress))
{
@@ -93,4 +106,39 @@ float Thermometer::GetTemperature()
}
Serial.printf("Error getting adress temperature...\n");
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);
}
*/

Načítá se…
Zrušit
Uložit