From 5401635968bbc58c60146517d40ad0f125fdf8ac Mon Sep 17 00:00:00 2001 From: Tristan Krause Date: Fri, 21 Jun 2019 15:42:25 +0200 Subject: [PATCH] bitmuster angepasst --- control/src/drv/b15f.cpp | 25 +++++++++++-------------- control/src/drv/b15f.h | 13 +++++++------ control/src/ui/ui.cpp | 2 +- control/src/ui/view_monitor.cpp | 7 +++++-- 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/control/src/drv/b15f.cpp b/control/src/drv/b15f.cpp index 36a43fa..db6ccbb 100644 --- a/control/src/drv/b15f.cpp +++ b/control/src/drv/b15f.cpp @@ -135,6 +135,13 @@ void B15F::delay_us(uint16_t us) std::this_thread::sleep_for(std::chrono::microseconds(us)); } +void B15F::reverse(uint8_t& b) +{ + b = (b & 0xF0) >> 4 | (b & 0x0F) << 4; + b = (b & 0xCC) >> 2 | (b & 0x33) << 2; + b = (b & 0xAA) >> 1 | (b & 0x55) << 1; +} + // https://stackoverflow.com/a/478960 std::string B15F::exec(std::string cmd) { @@ -197,10 +204,7 @@ bool B15F::activateSelfTestMode() } bool B15F::digitalWrite0(uint8_t port) -{ - - reverse(port); - +{ uint8_t rq[] = { RQ_DIGITAL_WRITE_0, @@ -215,9 +219,6 @@ bool B15F::digitalWrite0(uint8_t port) bool B15F::digitalWrite1(uint8_t port) { - - reverse(port); - uint8_t rq[] = { RQ_DIGITAL_WRITE_1, @@ -269,6 +270,9 @@ uint8_t B15F::readDipSwitch() uint8_t aw; usart.receive(&aw, 0, sizeof(aw)); + + reverse(aw); // DIP Schalter muss invertiert werden! + return aw; } @@ -512,10 +516,3 @@ void B15F::init() std::cout << PRE << "AVR Firmware Version: " << info[0] << " um " << info[1] << " Uhr (" << info[2] << ")" << std::endl; } - -void B15F::reverse(uint8_t& b) -{ - b = (b & 0xF0) >> 4 | (b & 0x0F) << 4; - b = (b & 0xCC) >> 2 | (b & 0x33) << 2; - b = (b & 0xAA) >> 1 | (b & 0x55) << 1; -} diff --git a/control/src/drv/b15f.h b/control/src/drv/b15f.h index 8632024..7ad849e 100644 --- a/control/src/drv/b15f.h +++ b/control/src/drv/b15f.h @@ -85,6 +85,13 @@ public: * \param us Verzögerung in Microsekunden */ void delay_us(uint16_t us); + + /** + * Invertiert das Bitmuster eines Bytes + * z.B.: 10100001 --> 10000101 + * \param b Byte, das invertiert wird + */ + void reverse(uint8_t& b); /** * Führt ein Befehl auf dieser Maschine aus und liefert stdout zurück @@ -255,12 +262,6 @@ private: * \throws DriverException */ void init(void); - - /** - * Invertiert das Bitmuster eines Bytes - * z.B.: 10100001 --> 10000101 - */ - void reverse(uint8_t& b); USART usart; static B15F* instance; diff --git a/control/src/ui/ui.cpp b/control/src/ui/ui.cpp index 20c200e..0aee3ac 100644 --- a/control/src/ui/ui.cpp +++ b/control/src/ui/ui.cpp @@ -72,7 +72,7 @@ void show_info(int) { ViewInfo* view = new ViewInfo(); view->setTitle("Info"); - view->setText("Informationen zu Board 15 Famulus Edition\n\nProjektseite: https://github.com/devfix/b15f\nDokumentation: https://devfix.github.io/b15f/"); + view->setText("Informationen zu Board 15 Famulus Edition\n \nProjektseite: https://github.com/devfix/b15f/\nDokumentation: https://devfix.github.io/b15f/\n \nB15F Software entwickelt von Tristan Krause für das Hardware-Labor.\nKontakt: tristan.krause@stud.htwk-leipzig.de"); view->setLabelClose("[ Zurueck ]"); view->repaint(); diff --git a/control/src/ui/view_monitor.cpp b/control/src/ui/view_monitor.cpp index f309b6f..2d354e9 100644 --- a/control/src/ui/view_monitor.cpp +++ b/control/src/ui/view_monitor.cpp @@ -43,8 +43,11 @@ call_t ViewMonitor::keypress(int& key) std::string ViewMonitor::fancyDigitalString(uint8_t& b) { + std::string bitstring(std::bitset<8>(b).to_string()); + std::reverse(bitstring.begin(), bitstring.end()); + std::stringstream str; - str << std::bitset<8>(b).to_string(); + str << bitstring; str << " "; str << "0x" << std::setfill ('0') << std::setw(2) << std::hex << (int) b << std::dec; return str.str(); @@ -131,7 +134,7 @@ void ViewMonitor::worker() } catch(...) { - B15F::abort("yoho meine dudes"); + B15F::abort("Die Verbindung ist unterbrochen worden. Wurde ein Stecker gezogen? :D"); return; } }