Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertGawron committed Dec 19, 2024
1 parent 5379544 commit c8c1616
Show file tree
Hide file tree
Showing 47 changed files with 527 additions and 481 deletions.
2 changes: 1 addition & 1 deletion DevOps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ make test

## Run static analysis

make static
cd /workspace/build && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_CXX_STANDARD=17 .. && make static

# Run code coverage

Expand Down
26 changes: 11 additions & 15 deletions Software/STM32F103RBTx/Application/BusinessLogic/Inc/HmiFactory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,35 +86,31 @@ namespace BusinessLogic
*/
bool tick() override;

bool addDataSource(Device::IMeasurementRecorder &recorder) override;

private:
/**
* @brief Instance of HMI implementation using the MUI library.
*
* Note: While directly exposing the use of the MUI library in the header file is not ideal, it is
* necessary here due to design constraints.
*/
HmiMui hmi;
HmiMeasurementModel hmiMeasurementModel;

/**
* @brief Display driver used by the HMI system.
*/
Device::Display display;

/**
* @brief Display brightness regulator for managing screen brightness.
*/
Device::DisplayBrightnessRegulator brightnessRegulator;

/**
* @brief Keyboard driver used for input in the HMI system.
*/
Device::Keyboard keyboard;

/**
* @brief Display brightness regulator for managing screen brightness.
* @brief Instance of HMI implementation using the MUI library.
*
* Note: While directly exposing the use of the MUI library in the header file is not ideal, it is
* necessary here due to design constraints.
*/
Device::DisplayBrightnessRegulator brightnessRegulator;

HmiMeasurementModel hmiMeasurementModel;

// Device::IMeasurementRecorder &recorder;
HmiMui hmi;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@

namespace BusinessLogic
{

class HmiMeasurementModel
{
public:
HmiMeasurementModel(Device::IMeasurementReader &reader);
explicit HmiMeasurementModel(Device::IMeasurementReader &reader);

HmiMeasurementModel() = delete;

Expand All @@ -35,8 +34,9 @@ namespace BusinessLogic
*/
HmiMeasurementModel &operator=(const HmiMeasurementModel &) = delete;

int dummyGetData();
[[nodiscard]] std::uint32_t getLatestMeasurement(Device::MeasurementDeviceId source) const;

private:
Device::IMeasurementReader &reader;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ namespace BusinessLogic
bool tick() override;

private:
HmiMeasurementModel &hmiMeasurementModel;

Device::IDisplay &display; /**< Reference to the display interface. */
Device::IDisplayBrightnessRegulator &displayBrightnessRegulator; /**< Reference to the display brightness regulator. */
Device::IKeyboard &keyboard; /**< Reference to the keyboard interface. */

MUIU8G2 mui; /**< Instance of the MUIU8G2 library for managing the GUI. */

HmiMeasurementModel &hmiMeasurementModel;
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef HmiMuiHandlers_h
#define HmiMuiHandlers_h

#include "BusinessLogic/Inc/HmiMeasurementModel.hpp"
#include "Device/Interfaces/IDisplay.hpp"

#include "MUIU8g2.h"

#include <cstdint>

namespace BusinessLogic
{
// Those are raw C functions, that needs to have signature based on what MUI lib requires.
std::uint8_t device1_printLastReading(mui_t *muiHandler, std::uint8_t muiMessage);
std::uint8_t device2_printLastReading(mui_t *muiHandler, std::uint8_t muiMessage);
std::uint8_t device3_printLastReading(mui_t *muiHandler, std::uint8_t muiMessage);
std::uint8_t device4_printLastReading(mui_t *muiHandler, std::uint8_t muiMessage);
std::uint8_t device5_printLastReading(mui_t *muiHandler, std::uint8_t muiMessage);

bool registerMuiToItsObjects(mui_t *ui, Device::IDisplay *display, BusinessLogic::HmiMeasurementModel *model);

}

#endif // HmiMuiHandlers_h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "Device/Inc/WiFiMeasurementRecorder.hpp"
#include "Device/Inc/SdCardMeasurementRecorder.hpp"
#include "Device/Inc/CacheMeasurementRecorder.hpp"
#include "Device/Inc/CacheMeasurementRecorder.hpp"
#include "Driver/Interfaces/IUartDriver.hpp"
#include "Driver/Interfaces/ISdCardDriver.hpp"

Expand Down Expand Up @@ -74,13 +73,13 @@ namespace BusinessLogic
// bool registerStoresToHmi(IHmiFactory &coordinator);

private:
Device::CacheMeasurementRecorder &cacheRecorder;

/** @brief WiFi measurement recorder used for storing measurements via WiFi. */
Device::WiFiMeasurementRecorder wifiRecorder;

/** @brief SD card measurement recorder used for storing measurements on an SD card. */
Device::SdCardMeasurementRecorder sdCardRecorder;

Device::CacheMeasurementRecorder &cacheRecorder;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ namespace BusinessLogic
* @return True if the update operation was successful; false otherwise.
*/
virtual bool tick() = 0;

virtual bool addDataSource(Device::IMeasurementRecorder &recorder) = 0;
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "BusinessLogic/Interfaces/IPlatformFactory.hpp"
#include "BusinessLogic/Inc/HmiFactory.hpp"
#include "BusinessLogic/Inc/HmiMui.hpp"
#include "Device/Interfaces/IMeasurementReader.hpp"
#include "Device/Inc/Keyboard.hpp"
#include "Device/Inc/DisplayBrightnessRegulator.hpp"

Expand Down Expand Up @@ -35,10 +36,4 @@ namespace BusinessLogic
{
return hmi.tick();
}

bool HmiFactory::addDataSource(Device::IMeasurementRecorder &recorder)
{
return true;
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@


#include "BusinessLogic/Inc/HmiMeasurementModel.hpp"
#include "Device/Interfaces/IMeasurementReader.hpp"
#include "Device/Inc/MeasurementDeviceId.hpp"

#include <cstdint>

namespace BusinessLogic
{
Expand All @@ -9,8 +13,8 @@ namespace BusinessLogic
{
}

int HmiMeasurementModel::dummyGetData()
std::uint32_t HmiMeasurementModel::getLatestMeasurement(Device::MeasurementDeviceId source) const
{
return reader.getDataDummy();
return reader.getLatestMeasurement(source);
}
}
47 changes: 7 additions & 40 deletions Software/STM32F103RBTx/Application/BusinessLogic/Src/HmiMui.cpp
Original file line number Diff line number Diff line change
@@ -1,48 +1,16 @@
#include "BusinessLogic/Inc/HmiMui.hpp"

#include "Device/Inc/KeyboardKeyActionState.hpp"
#include "BusinessLogic/Inc/HmiMuiHandlers.hpp"
#include "BusinessLogic/Inc/HmiMeasurementModel.hpp"
#include "Device/Interfaces/IDisplay.hpp"
#include "Device/Interfaces/IDisplayBrightnessRegulator.hpp"
#include "Device/Interfaces/IKeyboard.hpp"

#include "Device/Inc/KeyboardKeyActionState.hpp"
#include "Driver/Inc/KeyboardKeyIdentifier.hpp"

#include "mui.h"
#include "u8g2.h"
#include "u8x8.h"
#include "mui_u8g2.h"

#include "stdio.h"

char myLabel[10];

// hacks!!!!
Device::IDisplay *_display;
BusinessLogic::HmiMeasurementModel *model;

// Define a custom MUIF handler for dynamic labels
uint8_t mui_dynamic_label_handler(mui_t *ui, uint8_t msg)
{
if (msg == MUIF_MSG_DRAW)
{
_display->setCursor(mui_get_x(ui), mui_get_y(ui));
//_display->getU8x8()->print(stop_watch_timer);

sprintf(myLabel, "%d", model->dummyGetData());

_display->drawUTF8(mui_get_x(ui), mui_get_y(ui), myLabel);
// _display->getU8g2().print(".");
// u8g2.print((stop_watch_timer/10)%100);
}

// if (msg == MUIF_MSG_DRAW)
{
printf("hello %d\n", msg);
// const char *label = get_device_value(ui->arg); /* Fetch dynamic content based on index */
// u8g2_DrawStr(ui->u8g2, ui->x, ui->y, label);
}
return 0;
}
namespace BusinessLogic
{

Expand All @@ -60,7 +28,7 @@ namespace BusinessLogic
MUIF_BUTTON("BG", mui_u8g2_btn_goto_wm_fi), /* assume a callback to go to a given form */
// {"DL", mui_dynamic_label_handler}, /* Custom handler for dynamic labels */
// MUIF_LABEL(mui_u8g2_draw_text)
MUIF_RO("CT", mui_dynamic_label_handler),
MUIF_RO("CT", device1_printLastReading),

// Add more UI elements or callbacks as needed
};
Expand Down Expand Up @@ -120,8 +88,6 @@ namespace BusinessLogic

bool HmiMui::initialize()
{
_display = &display;
model = &hmiMeasurementModel;
/*
volatile int x = 0;
// display.initialize();
Expand All @@ -143,9 +109,10 @@ namespace BusinessLogic
{
display.begin();

sprintf(myLabel, "hello");

mui.begin(display, fds_data, muif_list, sizeof(muif_list) / sizeof(muif_t));

registerMuiToItsObjects(mui.getMUI(), &display, &hmiMeasurementModel);

mui.gotoForm(/* form_id= */ 1, /* initial_cursor_position= */ 0);
display.firstPage();
display.setCursor(0, 0);
Expand Down
Loading

0 comments on commit c8c1616

Please sign in to comment.