Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imagine U and I #7

Merged
merged 28 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8a013e8
Initial Staging changes
aclowmclaughlin Dec 1, 2023
73fbacc
ControllerUI !
aclowmclaughlin Dec 2, 2023
cd95e68
Weird git stuff, fixed?
aclowmclaughlin Dec 2, 2023
5ef2383
Update EVT-Core
ActuallyTaylor Dec 2, 2023
4664ba1
Progressing on ControllerUI, the states and selections are set out.
aclowmclaughlin Dec 2, 2023
0725083
ControllerUI main scheme fleshed out, next thing to do is integrate i…
aclowmclaughlin Dec 2, 2023
37be8c7
Added ControllerModel class, which acts as the Model of a MVC model.
aclowmclaughlin Dec 8, 2023
090f7a4
Everything should be almost working, need to modify LCD class in EVT-…
aclowmclaughlin Dec 9, 2023
3930c1c
Initial prototype done, just needs testing.
aclowmclaughlin Dec 9, 2023
cf01a8c
Commented all methods and variables in the classes, renamed some of t…
aclowmclaughlin Dec 9, 2023
38e8819
Slight comment changes and variable name improvements
aclowmclaughlin Jan 20, 2024
06ae490
Fixed enum names to align with convention
aclowmclaughlin Jan 20, 2024
f732626
Accumulation of all the changes made during testing. The UI now is fu…
aclowmclaughlin Jan 27, 2024
09cbf75
Removed the deprecated Debounce.hpp class.
aclowmclaughlin Jan 30, 2024
797c1e1
Final changes based on suggestions from the EEs. All done!
aclowmclaughlin Feb 3, 2024
c507830
Whoopsies needed to commit the version number for EVT-core
aclowmclaughlin Feb 3, 2024
b738f6f
Updated can submodule
ActuallyTaylor Feb 3, 2024
24e948e
Applied Formatting Changes During GitHub Build
Feb 3, 2024
1b8bd4f
Requested fixed except for the CanOpen stuff.
aclowmclaughlin Feb 10, 2024
e5fb214
Applied Formatting Changes During GitHub Build
Feb 10, 2024
8f513c7
Added some helper methods to make UIController.process() more readabl…
aclowmclaughlin Feb 10, 2024
24f9add
Merge remote-tracking branch 'origin/feature/aclowmclaughlin/UI_Redes…
aclowmclaughlin Feb 10, 2024
a50a739
Applied Formatting Changes During GitHub Build
Feb 10, 2024
295d97d
added in some preliminary changes for the new canopen.
aclowmclaughlin Feb 10, 2024
4424f82
Applied Formatting Changes During GitHub Build
Feb 10, 2024
c9a3d74
little change to fix the build.
aclowmclaughlin Feb 10, 2024
b89b1a2
Apply suggestions from code review
aclowmclaughlin Feb 24, 2024
3e52f8a
Minor commenting changes, removed LED.hpp
aclowmclaughlin Feb 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion 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/ControllerUI.cpp
src/charge_controller/dev/ControllerModel.cpp
)

###############################################################################
Expand Down
14 changes: 9 additions & 5 deletions include/charge_controller/ChargeController.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#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/ControllerModel.hpp>
#include <charge_controller/dev/ControllerUI.hpp>
#include <charge_controller/dev/LCDDisplay.hpp>

namespace time = EVT::core::time;
Expand Down Expand Up @@ -63,7 +65,7 @@ class ChargeController {
FAULT
};

ChargeController(BMSManager& bms, LCDDisplay& display, IO::CAN& can, DEV::Button& startButton, IO::GPIO& statusLED);
ChargeController(BMSManager& bms, LCDDisplay& display, IO::CAN& can, DEV::Button& startButton, IO::GPIO& statusLED, ControllerUI& controllerUI, ControllerModel& controllerModel);
aclowmclaughlin marked this conversation as resolved.
Show resolved Hide resolved

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

BMSManager& bms;
LCDDisplay& display;
IO::CAN& can;
DEV::Button& startButton;
IO::GPIO& statusLED;
LCDDisplay& display;
ControllerUI& controllerUI;
ControllerModel& controllerModel;

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

#endif// CHARGE_CONTROLLER_H
#endif// CHARGE_CONTROLLER_HPP
9 changes: 6 additions & 3 deletions include/charge_controller/dev/BMSManager.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#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/utils/log.hpp>
#include <co_pdo.h>

//RPDO-NUM settings
// 0: RPDO number in index and total number of sub indexes.
Expand Down Expand Up @@ -396,6 +396,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,8 +469,9 @@ class BMSManager {
// Pack 2 Data
GEN_PACK_DATA(1, packs[1].data)

*/
// End of dictionary marker
CO_OBJ_DIR_ENDMARK,
CO_OBJ_DICT_ENDMARK,
};
};

Expand Down
167 changes: 167 additions & 0 deletions include/charge_controller/dev/ControllerModel.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
#ifndef CHARGE_CONTROLLER_CONTROLLERMODEL_HPP
#define CHARGE_CONTROLLER_CONTROLLERMODEL_HPP

#include <cstdint>

#define MAX_VOLTAGE 100
#define MAX_CURRENT 60

#define DEFAULT_VOLTAGE 96
#define DEFAULT_CURRENT 60

/**
* Stores values that both the LCDDisplay and the ControllerUI need to access.
* Acts as the model in a Model-View-Controller (MVC) Structure where
aclowmclaughlin marked this conversation as resolved.
Show resolved Hide resolved
* ControllerModel is the model,
* LCDDisplay is the display, and
aclowmclaughlin marked this conversation as resolved.
Show resolved Hide resolved
* ControllerUI is the controller
*/

class ControllerModel {
aclowmclaughlin marked this conversation as resolved.
Show resolved Hide resolved
aclowmclaughlin marked this conversation as resolved.
Show resolved Hide resolved

public:
/**
* default (and only) initializer for the ControllerModel class.
aclowmclaughlin marked this conversation as resolved.
Show resolved Hide resolved
*/
ControllerModel();

/**
* enum for the different pages that the LCDDisplay can display.
*/
enum Page {
MAIN = 0,
SETTINGS = 1
};

/**
* enum that represents what set of selectable items the controller is focused on.
* The value of each entry is equal to the range of the encoder
*/
enum State {
PAGE_SELECT = 0u,
SETTING_SELECT = 1u,
VOLTAGE_SELECT = 2u,
CURRENT_SELECT = 3u,
};

/**
* enum that represents which setting is selected
* Only updated when state = SETTINGSELECT
*/
enum SelectedSetting {
VOLTAGE = 0u,
CURRENT = 1u,
SAVE = 2u,
QUIT = 3u,
RESET = 4u
};

/**
* Gets the current Page that the model is in.
*
* @return the current page the model is set to
*/
Page getPage();

/**
* Gets the current State that the model is in.
*
* @return the current state the model is set to
*/
State getState();

/**
* Sets the state of the model
*
* @param[in] newState the state to set the model's state to.
*/
void setState(State newState);

/**
* Saves the unsavedVoltage and unsavedCurrent.
* (Sets savedVoltage and savedCurrent)
*/
void saveVoltageAndCurrent();

/**
* Gets the current setting the model is in: this will be the most recent setting that was selected.
*
* @return the current setting the model is in.
*/
SelectedSetting getSelectedSetting();

/**
* Sets the selected setting of the model.
*
* @param[in] newSetting the new setting that was selected.
*/
void setSelectedSetting(SelectedSetting newSetting);

/**
* Sets the unsavedVoltage
*
* @param[in] newVoltage the new value for unsavedVoltage
*/
void setUnsavedVoltage(uint16_t newVoltage);
aclowmclaughlin marked this conversation as resolved.
Show resolved Hide resolved

/**
* Sets the unsavedCurrent
*
* @param[in] newCurrent the new value for unsavedCurrent
*/
void setUnsavedCurrent(uint16_t newCurrent);

/**
* Sets the model's current page.
*
* @param[in] newPage the new page.
*/
void setPage(Page newPage);

/**
* Gets the saved voltage value for the model.
aclowmclaughlin marked this conversation as resolved.
Show resolved Hide resolved
* @return the saved voltage in the model.
*/
uint16_t getSavedVoltage();

/**
* Gets the saved current value for the model.
* @return the saved current in the model.
*/
uint16_t getSavedCurrent();

/**
* Gets the unsaved voltage value for the model.
* @return the unsaved voltage in the model.
*/
uint16_t getUnsavedVoltage();

/**
* Gets the unsaved current value for the model.
* @return the unsaved current in the model.
*/
uint16_t getUnsavedCurrent();

/**
* Returns the valid encoder range for the given state
* @param state the state that the encoder range can take
* @return the encoder range for that state
*/
uint32_t getEncoderRange(State state);

private:
/** The current state the model is in */
State state = PAGE_SELECT;
/** The current page the lcd is displaying */
Page page = MAIN;
/** The most recent selected setting that is selected (only really relevant if state = SETTINGSELECT */
SelectedSetting setting = QUIT;

uint16_t savedVoltage = DEFAULT_VOLTAGE;//TODO see about saving values between boot sequences
aclowmclaughlin marked this conversation as resolved.
Show resolved Hide resolved
uint16_t savedCurrent = DEFAULT_CURRENT;

uint16_t unsavedVoltage = DEFAULT_VOLTAGE;
uint16_t unsavedCurrent = DEFAULT_CURRENT;
};

#endif//CHARGE_CONTROLLER_CONTROLLERMODEL_HPP
57 changes: 57 additions & 0 deletions include/charge_controller/dev/ControllerUI.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#ifndef CONTROLLERUI_HPP
#define CONTROLLERUI_HPP

#include <EVT/dev/Encoder.hpp>
#include <EVT/dev/button.hpp>
#include <EVT/utils/log.hpp>
#include <charge_controller/dev/ControllerModel.hpp>
#include <charge_controller/dev/LCDDisplay.hpp>

//TODO check the encoder documentation for the debounce time
#define DEBOUNCE_TIME 500
aclowmclaughlin marked this conversation as resolved.
Show resolved Hide resolved

namespace DEV = EVT::core::DEV;

/**
* Handles the encoder inputs for the Charge Controller.
* Acts as the controller in a Model-View-Controller (MVC) Structure where
aclowmclaughlin marked this conversation as resolved.
Show resolved Hide resolved
* ControllerModel is the model,
* LCDDisplay is the display, and
* ControllerUI is the controller
*/

class ControllerUI {
aclowmclaughlin marked this conversation as resolved.
Show resolved Hide resolved
aclowmclaughlin marked this conversation as resolved.
Show resolved Hide resolved
public:
/**
* Constructor for the ControllerUI class
*
* @param[in] encoder The encoder object
* @param[in] encoderButton the button on the encoder
* @param[in] display the LCDDisplay that the ControllerUI controls
* @param[in] model the ControllerModel that stores values from the ControllerUI
*/
ControllerUI(DEV::Encoder& encoder, DEV::Button& encoderButton, LCDDisplay& display, ControllerModel& model);

/**
* Processes user input, updates appropriate values, and calls display.display() to update the view
*/
void process();

private:
/** Reference to the model object */
ControllerModel& model;
/** Reference to the encoder */
DEV::Encoder& encoder;
/** Reference to the encoder's button */
DEV::Button& encoderButton;
/** Reference to the display driver so it can update */
LCDDisplay& display;

/**
* Internal method that sets the model's state and also updates the encoder range and position to align with the state.
aclowmclaughlin marked this conversation as resolved.
Show resolved Hide resolved
* @param newState the new state to set the model's state to.
*/
void setModelState(ControllerModel::State newState);
};

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

This file was deleted.

Loading