1- #include " DashboardInterface.h"
21#include " SharedFirmwareTypes.h"
2+
3+ #include " DashboardInterface.h"
34#include " CANInterface.h"
45#include " VCFCANInterfaceImpl.h"
56
7+ #include " IOExpanderUtils.h"
8+
69/* Button reads */
710DashInputState_s DashboardInterface::get_dashboard_outputs ()
811{
@@ -39,4 +42,65 @@ DashInputState_s DashboardInterface::get_dashboard_stored_state()
3942void DashboardInterface::sync_dashboard_stored_state ()
4043{
4144 _dashboard_stored_state = _dashboard_outputs;
45+ }
46+
47+ void DashboardInterface::read_ioexpander () {
48+ uint16_t data = _io_expander.read (); // read data from IOExpander
49+ ControllerMode_e new_mode = ControllerMode_e::MODE_0; // default to mode 0
50+
51+ // check for value of dial
52+ if (IOExpanderUtils::getBit (data, (bool ) MCP23017Port::B, 0 )) { // NOLINT 0 is pos of bit
53+ new_mode = ControllerMode_e::MODE_0;
54+ } else if (IOExpanderUtils::getBit (data, (bool ) MCP23017Port::B, 1 )) { // NOLINT 1 is pos of bit
55+ new_mode = ControllerMode_e::MODE_1;
56+ } else if (IOExpanderUtils::getBit (data, (bool ) MCP23017Port::B, 2 )) { // NOLINT 2 is pos of bit
57+ new_mode = ControllerMode_e::MODE_2;
58+ } else if (IOExpanderUtils::getBit (data, (bool ) MCP23017Port::B, 3 )) { // NOLINT 3 is pos of bit
59+ new_mode = ControllerMode_e::MODE_3;
60+ } else if (IOExpanderUtils::getBit (data, (bool ) MCP23017Port::B, 4 )) { // NOLINT 4 is pos of bit
61+ new_mode = ControllerMode_e::MODE_4;
62+ } else if (IOExpanderUtils::getBit (data, (bool ) MCP23017Port::B, 5 )) { // NOLINT 5 is pos of bit
63+ new_mode = ControllerMode_e::MODE_5;
64+ }
65+
66+ _dashboard_outputs.dial_state = new_mode; // set new mode
67+
68+ // write to 8-seg display based on current mode
69+ switch (_dashboard_outputs.dial_state ) {
70+ case ControllerMode_e::MODE_0:
71+ {
72+ _io_expander.writePort (MCP23017Port::A, 0b00000010 ); // NOLINT 0b0000 0010 = 2
73+ break ;
74+ }
75+ case ControllerMode_e::MODE_1:
76+ {
77+ _io_expander.writePort (MCP23017Port::A, 0b01010111 ); // NOLINT 0b0101 0111 = 87
78+ break ;
79+ }
80+ case ControllerMode_e::MODE_2:
81+ {
82+ _io_expander.writePort (MCP23017Port::A, 0b00011000 ); // NOLINT 0b0001 1000 = 24
83+ break ;
84+ }
85+ case ControllerMode_e::MODE_3:
86+ {
87+ _io_expander.writePort (MCP23017Port::A, 0b00010100 ); // NOLINT 0b0001 0100 = 20
88+ break ;
89+ }
90+ case ControllerMode_e::MODE_4:
91+ {
92+ _io_expander.writePort (MCP23017Port::A, 0b01000101 ); // NOLINT 0b0100 0101 = 69
93+ break ;
94+ }
95+ case ControllerMode_e::MODE_5:
96+ {
97+ _io_expander.writePort (MCP23017Port::A, 0b00100100 ); // NOLINT 0b0010 0100 = 36
98+ break ;
99+ }
100+ default :
101+ {
102+ _io_expander.writePort (MCP23017Port::A, 0b11110000 ); // NOLINT 0b1111 0000 = 240
103+ break ;
104+ }
105+ }
42106}
0 commit comments