Skip to content

Commit

Permalink
Merge pull request #7 from RIT-EVT/feature/aclowmclaughlin/UI_Redesign
Browse files Browse the repository at this point in the history
Imagine U and I
  • Loading branch information
aclowmclaughlin authored Feb 24, 2024
2 parents 1875063 + 3e52f8a commit 1f2bead
Show file tree
Hide file tree
Showing 17 changed files with 896 additions and 422 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ add_library(${PROJECT_NAME} STATIC)
target_sources(${PROJECT_NAME} PRIVATE
src/charge_controller/ChargeController.cpp
src/charge_controller/dev/BMSManager.cpp
src/charge_controller/dev/Debounce.cpp
src/charge_controller/dev/LCDDisplay.cpp
src/charge_controller/dev/LCDView.cpp
src/charge_controller/dev/UIController.cpp
src/charge_controller/dev/UIModel.cpp
)

###############################################################################
Expand Down
21 changes: 14 additions & 7 deletions include/charge_controller/ChargeController.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#ifndef CHARGE_CONTROLLER_H
#define CHARGE_CONTROLLER_H
#ifndef CHARGE_CONTROLLER_HPP
#define CHARGE_CONTROLLER_HPP

#include <EVT/io/CAN.hpp>
#include <EVT/io/CANopen.hpp>

#include <EVT/dev/button.hpp>
#include <EVT/io/GPIO.hpp>
#include <charge_controller/dev/BMSManager.hpp>
#include <charge_controller/dev/LCDDisplay.hpp>
#include <charge_controller/dev/LCDView.hpp>
#include <charge_controller/dev/UIController.hpp>
#include <charge_controller/dev/UIModel.hpp>

namespace time = EVT::core::time;
namespace DEV = EVT::core::DEV;
Expand All @@ -33,6 +35,8 @@ namespace DEV = EVT::core::DEV;

#define HEARBEAT_INTERVAL 1000

namespace CC {

/**
* https://elconchargers.com/?page_id=98
* https://www.diyelectriccar.com/threads/setting-up-can-bus-for-elcon-charger.202419/
Expand All @@ -52,7 +56,6 @@ namespace DEV = EVT::core::DEV;
* Up to four Elcon PFC chargers can be on the same CAN bus with CAN IDs of E5, E7, E8 and E9.
* A 120 ohm termination resistor is required between CAN-L and CAN-H.
*/

class ChargeController {
public:
enum class ControllerStates {
Expand All @@ -63,7 +66,7 @@ class ChargeController {
FAULT
};

ChargeController(BMSManager& bms, LCDDisplay& display, IO::CAN& can, DEV::Button& startButton, IO::GPIO& statusLED);
ChargeController(BMSManager& bms, LCDView& display, IO::CAN& can, DEV::Button& startButton, IO::GPIO& statusLED, UIController& controllerUI, UIModel& controllerModel);

/**
* Initialize the submodules of the Charge Controller
Expand Down Expand Up @@ -139,10 +142,12 @@ class ChargeController {
void faultState();

BMSManager& bms;
LCDDisplay& display;
IO::CAN& can;
DEV::Button& startButton;
IO::GPIO& statusLED;
LCDView& display;
UIController& controllerUI;
UIModel& controllerModel;

uint32_t lastHeartBeat = time::millis();
uint8_t oldCount = 0;
Expand All @@ -154,4 +159,6 @@ class ChargeController {
static constexpr IO::GPIO::State RELAY_OFF = IO::GPIO::State::LOW;
};

#endif// CHARGE_CONTROLLER_H
}//namespace CC

#endif// CHARGE_CONTROLLER_HPP
36 changes: 26 additions & 10 deletions include/charge_controller/dev/BMSManager.hpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
#ifndef EXAMPLE_BMSMANAGER_HPP
#define EXAMPLE_BMSMANAGER_HPP

#include <Canopen/co_obj.h>
#include <EVT/io/CAN.hpp>
#include <EVT/io/GPIO.hpp>
#include <co_obj.h>
#include <stdint.h>

#include <Canopen/co_pdo.h>
#include <EVT/io/CANDevice.hpp>
#include <EVT/io/CANOpenMacros.hpp>
#include <EVT/utils/log.hpp>
#include <co_pdo.h>

//RPDO-NUM settings
// 0: RPDO number in index and total number of sub indexes.
// 1: The COB-ID to receive PDOs from.
// 2: transmission trigger
// 6 spaces in an array

#define GEN_PACK_RPDO_CONFIG(NUM, ID) \
{ \
.Key = CO_KEY(0x1400 + 2 * NUM, 0, CO_UNSIGNED8 | CO_OBJ_D__R_), \
Expand Down Expand Up @@ -45,7 +48,6 @@
.Type = nullptr, \
.Data = (uintptr_t) 0xFE, \
},

// RPDO(NUM) mapping, determines the PDO messages to send when TPDO(NUM) is triggered
// 0: The number of PDO messages associated with the TPDO
// 1: Link to the first PDO message
Expand Down Expand Up @@ -136,6 +138,7 @@
}, \
\
// 8 spaces in an array

#define GEN_PACK_DATA(NUM, VAR) \
{ \
.Key = CO_KEY(0x2100 + NUM, 1, CO_UNSIGNED16 | CO_OBJ___PR_), \
Expand Down Expand Up @@ -177,10 +180,11 @@
.Type = nullptr, \
.Data = (uintptr_t) &VAR.status, \
},

namespace IO = EVT::core::IO;

class BMSManager {
namespace CC {

class BMSManager : public CANDevice {
static constexpr uint32_t TOTAL_VOLTAGE_ID = 0x2101;
static constexpr uint32_t STATE_ID = 0x2102;
static constexpr uintptr_t BMS_PACK_ONE_ID = 0x20;
Expand Down Expand Up @@ -336,14 +340,21 @@ class BMSManager {
*
* @return Pointer to the start of the object dictionary
*/
CO_OBJ_T* getObjectDictionary();
CO_OBJ_T* getObjectDictionary() override;

/**
* Get the size of the object dictionary
* Get the number of elements in the object dictionary.
*
* @return Size of the object dictionary
* @return The number of elements in the object dictionary
*/
uint8_t getObjectDictionarySize();
uint8_t getNumElements() override;

/**
* Get the device's node ID
*
* @return The node ID of the can device.
*/
uint8_t getNodeID() override;

static constexpr uint8_t MAX_BMS_PACKS = 2;

Expand Down Expand Up @@ -396,6 +407,8 @@ class BMSManager {
OBJECT_DICTIONARY_SIZE = 69;

CO_OBJ_T objectDictionaryBMS[OBJECT_DICTIONARY_SIZE + 1] = {
///COMMENTED OUT UNTIL WE FIX CANOPEN
/*
// Sync ID, defaults to 0x80
{
.Key = CO_KEY(0x1005, 0, CO_UNSIGNED32 | CO_OBJ_D__R_),
Expand Down Expand Up @@ -467,9 +480,12 @@ class BMSManager {
// Pack 2 Data
GEN_PACK_DATA(1, packs[1].data)
*/
// End of dictionary marker
CO_OBJ_DIR_ENDMARK,
CO_OBJ_DICT_ENDMARK,
};
};

}//namespace CC

#endif// EXAMPLE_BMSMANAGER_HPP
38 changes: 0 additions & 38 deletions include/charge_controller/dev/Debounce.hpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,39 @@
#include <EVT/dev/LCD.hpp>
#include <EVT/io/SPI.hpp>
#include <charge_controller/dev/BMSManager.hpp>
#include <charge_controller/dev/UIModel.hpp>
#include <cstdint>
#include <cstdio>

#define UNSAVED_PREFIX_CHAR '*'
#define EDITING_PREFIX_CHAR '<'
#define SELECTED_PREFIX_CHAR '>'

namespace IO = EVT::core::IO;
namespace DEV = EVT::core::DEV;

class LCDDisplay {
namespace CC {

/**
* Outputs all the values from the ChargeController & UIModel classes to the LCD display
* Acts as the view in a Model-View-Controller (MVC) design pattern where
* UIModel is the model,
* LCDView is the view, and
* UIController is the controller.
*/
class LCDView {
public:
/**
* Initializer for the LCD Display class.
* Initializer for the LCDView class.
*
* @param[in] regSelect Register select pin
* @param[in] reset Reset pin
* @param[in] spi SPI class for communication
*/
LCDDisplay(IO::GPIO& reg_select, IO::GPIO& reset, IO::SPI& spi);
LCDView(IO::GPIO& reg_select, IO::GPIO& reset, IO::SPI& spi, UIModel& model);

/**
* Initializes the LCD driver and displays the splash image.
* Initializes the LCD driver
*/
void init();

Expand Down Expand Up @@ -54,39 +69,39 @@ class LCDDisplay {
/**
* Set the status of the battery at the given index.
* Will display in either the BM1 (BMS 1) column if index is 0
* or BM2 (BMS 2)
* or BM2 (BMS 2).
*
* @param status the status to display for the BMS at index.
* @param index the index of the bms to display too (0 - 1).
*/
void setBatteryStatus(BMSManager::BMSStatus status, uint8_t index);

/**
* Set's the display for the BMS at the given index's minimum cell voltage.
* Sets the display for the BMS at the given index's minimum cell voltage.
*
* @param cellVoltage the cell voltage to display.
* @param index the index of the bms.
*/
void setMinCellVoltage(int16_t cellVoltage, uint8_t index);

/**
* Set's the display for the BMS at the given index's maximum cell voltage.
* Sets the display for the BMS at the given index's maximum cell voltage.
*
* @param cellVoltage the cell voltage to display.
* @param index the index of the bms.
*/
void setMaxCellVoltage(int16_t cellVoltage, uint8_t index);

/**
* Set's the display for the BMS at the given index's minimum temperature.
* Sets the display for the BMS at the given index's minimum temperature.
*
* @param temp the temperature to display.
* @param index the index of the bms.
*/
void setMinTemp(int16_t temp, uint8_t index);

/**
* Set's the display for the BMS at the given index's maximum temperature.
* Sets the display for the BMS at the given index's maximum temperature.
*
* @param temp the temperature to display.
* @param index the index of the bms.
Expand All @@ -99,6 +114,11 @@ class LCDDisplay {
*/
DEV::LCD lcd;

/**
* The model reference
*/
UIModel& model;

/** The current status of the charge controller */
const char* chargeControllerStatus = "NULL";
/** The current status for battery */
Expand All @@ -109,6 +129,8 @@ class LCDDisplay {
uint16_t chargeControllerVoltage = 0;
/** The current that is being supplied */
uint16_t chargeControllerCurrent = 0;
/** The current page that the display is on */
UIModel::Page page = UIModel::Page::MAIN;

int16_t batteryMinVoltages[2] = {};
int16_t batteryMaxVoltages[2] = {};
Expand All @@ -120,22 +142,38 @@ class LCDDisplay {
const uint8_t chargePercentage = 0;

/**
* The 9 section headers to be displayed.
* The 8 section headers for the main screen
*/
static constexpr char* SECTION_TITLES[12]{
static constexpr char* MAIN_SCREEN_SECTION_TITLES[9]{
(char*) "B1 Status",
(char*) "CC Status",
(char*) "B2 Status",
(char*) "B1 Voltage",
(char*) "Charge %",
(char*) "B2 Voltage",
(char*) "B1 Min T",
(char*) "C Voltage",
(char*) "B2 Min T",
(char*) "B1 Max T",
(char*) "C Current",
(char*) "B2 Max T",
(char*) "Page 1/2"};

/**
* The 8 section headers for the setting screen
*/
static constexpr char* SETTING_SCREEN_SECTION_TITLES[9]{
(char*) "CC Status",
(char*) "Charge %",
(char*) "C Voltage",
(char*) "C Current",
(char*) "S Voltage",
(char*) "S Current",
//The next three section headers are left blank because they are selectable.
//We leave their headers blank, and write their header (save,quit,reset) in
//their 'text' section, so we are able to add a '>' in front if they are selected.
(char*) "",//Save
(char*) "",//Quit
(char*) "" //Reset
};
};

}//namespace CC

#endif// LCDDISPLAY_H
Loading

0 comments on commit 1f2bead

Please sign in to comment.