screen with digitalClok, boxProgress, circleProgess. Lot of trials and errors in build
I have added digitalTime (digitalClock1), textArea (T_DATE_DISPLAY),,BoxProgress (tankLevelA), CircleProgress (valveOpenA), and button (buttonWithIcon1). Please find the code and the errors of the last trial (please note I have wandered through lots of modifications in vain, I must be doing something fundamentally wrong):
ERROR::
Please see Reply due to excess characters
main.c please see the 2nd. reply due to number of charaters
model.hpp
#ifndef MODEL_HPP
#define MODEL_HPP
#include <touchgfx/hal/Types.hpp>
#include <touchgfx/Model.hpp>
class Model : public touchgfx::Model
{
public:
Model();
void tick() override;
// Demo mode methods
float getTankLevel() const { return tankLevel; }
float getValvePosition() const { return valvePosition; }
bool isDemoModeActive() const { return true; }
protected:
// Demo mode variables
float tankLevel;
float valvePosition;
bool tankIncreasing;
bool valveIncreasing;
void updateDemoData();
};
#endif // MODEL_HPPmodel.cpp
#include "gui/model/Model.hpp"
#include "stm32h7xx_hal.h"
#include <stdio.h>
extern RTC_HandleTypeDef hrtc;
extern RTC_TimeTypeDef sTime;
extern RTC_DateTypeDef sDate;
Model::Model() :
tankLevel(0.0f), valvePosition(0.0f),
tankIncreasing(true), valveIncreasing(true)
{
}
void Model::updateDemoData()
{
// Tank: oscillate between 0 and 100
const float tankStep = 0.5f;
if (tankIncreasing) {
tankLevel += tankStep;
if (tankLevel >= 100.0f) {
tankLevel = 100.0f;
tankIncreasing = false;
}
} else {
tankLevel -= tankStep;
if (tankLevel <= 0.0f) {
tankLevel = 0.0f;
tankIncreasing = true;
}
}
// Valve: oscillate between 0 and 100
const float valveStep = 0.3f;
if (valveIncreasing) {
valvePosition += valveStep;
if (valvePosition >= 100.0f) {
valvePosition = 100.0f;
valveIncreasing = false;
}
} else {
valvePosition -= valveStep;
if (valvePosition <= 0.0f) {
valvePosition = 0.0f;
valveIncreasing = true;
}
}
}
void Model::tick()
{
// Update RTC
HAL_RTC_GetTime(&hrtc, &sTime, FORMAT_BCD);
HAL_RTC_GetDate(&hrtc, &sDate, FORMAT_BCD);
// Debug output
static int tickCount = 0;
if (tickCount++ % 60 == 0) {
printf("Tick: %d, RTC: %02d:%02d:%02d\n", tickCount, sTime.Hours, sTime.Minutes, sTime.Seconds);
printf("Demo: Tank=%.1f%%, Valve=%.1f%%\n", tankLevel, valvePosition);
}
updateDemoData();
}screen1presenter.hpp
#ifndef SCREEN1PRESENTER_HPP
#define SCREEN1PRESENTER_HPP
#include <mvp/Presenter.hpp>
#include <touchgfx/ModelListener.hpp>
#include <cstdint>
// Forward declaration
class Screen1View;
class Screen1Presenter : public touchgfx::Presenter, public touchgfx::ModelListener
{
public:
explicit Screen1Presenter(Screen1View& v);
// REQUIRED BY FRAMEWORK
virtual void bind(touchgfx::Model* model) override {}
virtual void activate();
virtual void deactivate();
// Custom methods for our UI updates
void updateTime(uint8_t hour, uint8_t minute, uint8_t second);
void updateDate(uint8_t day, uint8_t month, uint16_t year);
void updateTankLevel(float level);
void updateValvePosition(float position);
private:
Screen1View& view;
};
#endif // SCREEN1PRESENTER_HPPscreen1presenter.cpp
#ifndef SCREEN1PRESENTER_HPP
#define SCREEN1PRESENTER_HPP
#include <mvp/Presenter.hpp>
#include <touchgfx/ModelListener.hpp>
#include <cstdint>
// Forward declaration
class Screen1View;
class Screen1Presenter : public touchgfx::Presenter, public touchgfx::ModelListener
{
public:
explicit Screen1Presenter(Screen1View& v);
// REQUIRED BY FRAMEWORK
virtual void bind(touchgfx::Model* model) override {}
virtual void activate();
virtual void deactivate();
// Custom methods for our UI updates
void updateTime(uint8_t hour, uint8_t minute, uint8_t second);
void updateDate(uint8_t day, uint8_t month, uint16_t year);
void updateTankLevel(float level);
void updateValvePosition(float position);
private:
Screen1View& view;
};
#endif // SCREEN1PRESENTER_HPPscreen1view.hpp
#ifndef SCREEN1VIEW_HPP
#define SCREEN1VIEW_HPP
#include <gui_generated/screen1_screen/Screen1ViewBase.hpp>
#include <gui/screen1_screen/Screen1Presenter.hpp>
#include <cstdint>
class Screen1View : public Screen1ViewBase
{
public:
Screen1View();
virtual ~Screen1View() {}
virtual void setupScreen();
virtual void tearDownScreen();
void updateTime(uint8_t hour, uint8_t minute, uint8_t second);
void updateDate(uint8_t day, uint8_t month, uint16_t year);
void updateTankLevel(float level);
void updateValvePosition(float position);
protected:
int tank_minValue, tank_maxValue;
int valve_minValue, valve_maxValue;
};
#endif // SCREEN1VIEW_HPPscreen1view.cpp
#include "gui/screen1_screen/Screen1View.hpp"
Screen1View::Screen1View()
{
}
void Screen1View::setupScreen()
{
Screen1ViewBase::setupScreen();
tankLevelA.getRange(tank_minValue, tank_maxValue);
valveOpenA.getRange(valve_minValue, valve_maxValue);
}
void Screen1View::tearDownScreen()
{
Screen1ViewBase::tearDownScreen();
}
void Screen1View::updateTime(uint8_t hour, uint8_t minute, uint8_t second)
{
digitalClock1.setTime24Hour(hour, minute, second);
}
void Screen1View::updateDate(uint8_t day, uint8_t month, uint16_t year)
{
// Update date widget if you have one
}
void Screen1View::updateTankLevel(float level)
{
int scaledValue = tank_minValue + (int)((level / 100.0f) * (tank_maxValue - tank_minValue));
tankLevelA.setValue(scaledValue);
}
void Screen1View::updateValvePosition(float position)
{
int scaledValue = valve_minValue + (int)((position / 100.0f) * (valve_maxValue - valve_minValue));
valveOpenA.setValue(scaledValue);
}modelListener.hpp
#ifndef MODELLISTENER_HPP
#define MODELLISTENER_HPP
#include <gui/model/Model.hpp>
class ModelListener
{
public:
ModelListener() : model(0) {}
virtual ~ModelListener() {}
void bind(Model* m)
{
model = m;
}
protected:
Model* model;
};
#endif // MODELLISTENER_HPP
