16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-21 19:29:19 +02:00

serial port input device configuration, additional control commands and minor control logic tweaks

This commit is contained in:
tmj-fstate
2018-02-10 19:53:21 +01:00
parent e9c4714780
commit 0c880f3d4e
16 changed files with 1437 additions and 897 deletions

49
uart.h
View File

@@ -39,53 +39,30 @@ public:
// methods
uart_input();
~uart_input();
void poll();
bool
init() { return recall_bindings(); }
bool
recall_bindings();
void
poll();
private:
// types
enum input_type_t
{
toggle,
impulse,
impulse_r,
impulse_r_on,
impulse_r_off
toggle, // two commands, each mapped to one state; press event on state change
impulse, // one command; press event when set, release when cleared
value // one command; press event, value of specified byte passed as param1
};
std::array<std::tuple<size_t, user_command, input_type_t>, 23> input_bits =
{
std::make_tuple(1, user_command::linebreakertoggle, impulse_r_off),
std::make_tuple(2, user_command::linebreakertoggle, impulse_r_on),
std::make_tuple(3, user_command::motoroverloadrelayreset, impulse),
std::make_tuple(5, user_command::converteroverloadrelayreset, impulse),
std::make_tuple(6, user_command::motorconnectorsopen, toggle),
std::make_tuple(7, user_command::alerteracknowledge, impulse_r),
std::make_tuple(9, user_command::convertertoggle, toggle),
std::make_tuple(10, user_command::compressortoggle, toggle),
std::make_tuple(11, user_command::sandboxactivate, impulse),
std::make_tuple(12, user_command::heatingtoggle, toggle),
std::make_tuple(15, user_command::motoroverloadrelaythresholdtoggle, toggle),
std::make_tuple(16, user_command::pantographtogglefront, toggle),
std::make_tuple(17, user_command::pantographtogglerear, toggle),
std::make_tuple(18, user_command::wheelspinbrakeactivate, impulse),
std::make_tuple(19, user_command::headlightsdimtoggle, toggle),
std::make_tuple(20, user_command::interiorlightdimtoggle, toggle),
std::make_tuple(21, user_command::independentbrakebailoff, impulse),
std::make_tuple(22, user_command::hornhighactivate, impulse),
std::make_tuple(23, user_command::hornlowactivate, impulse),
std::make_tuple(24, user_command::batterytoggle, toggle),
std::make_tuple(25, user_command::headlighttoggleleft, toggle),
std::make_tuple(26, user_command::headlighttoggleupper, toggle),
std::make_tuple(27, user_command::headlighttoggleright, toggle)
};
using input_pin_t = std::tuple<std::size_t, input_type_t, user_command, user_command>;
using inputpin_sequence = std::vector<input_pin_t>;
// members
sp_port *port = nullptr;
inputpin_sequence m_inputbindings;
command_relay relay;
std::array<uint8_t, 16> old_packet;
std::array<std::uint8_t, 16> old_packet; // TBD, TODO: replace with vector of configurable size?
std::chrono::time_point<std::chrono::high_resolution_clock> last_update;
conf_t conf;
bool data_pending = false;