From eec2dd0db6e3f0b507380f4f2101b6e952dbb341 Mon Sep 17 00:00:00 2001 From: Tristan Krause Date: Thu, 27 Jun 2019 16:19:47 +0200 Subject: [PATCH] docu --- control/src/cli.cpp | 2 +- control/src/cli.cpp.orig | 120 ++++++++++++ control/src/drv/b15f.cpp | 22 +-- control/src/drv/b15f.cpp.orig | 90 +++++---- control/src/drv/b15f.h | 2 +- control/src/drv/b15f.h.orig | 51 +++-- control/src/drv/requests.h.orig | 57 ------ docs/html/annotated.html | 2 +- docs/html/b15f_8cpp_source.html | 60 +++--- docs/html/b15f_8h_source.html | 65 +++---- docs/html/classB15F-members.html | 20 +- docs/html/classB15F.html | 174 ++++++++++-------- docs/html/classDot-members.html | 2 +- docs/html/classDot.html | 2 +- docs/html/classDriverException-members.html | 2 +- docs/html/classDriverException.html | 2 +- docs/html/classPlottyFile-members.html | 2 +- docs/html/classPlottyFile.html | 2 +- docs/html/classTimeoutException-members.html | 2 +- docs/html/classTimeoutException.html | 2 +- docs/html/classUSART-members.html | 2 +- docs/html/classUSART.html | 2 +- docs/html/classUSARTException-members.html | 2 +- docs/html/classUSARTException.html | 2 +- docs/html/classView-members.html | 2 +- docs/html/classView.html | 2 +- docs/html/classViewInfo-members.html | 2 +- docs/html/classViewInfo.html | 2 +- docs/html/classViewMonitor-members.html | 2 +- docs/html/classViewMonitor.html | 2 +- docs/html/classViewPromt-members.html | 2 +- docs/html/classViewPromt.html | 2 +- docs/html/classViewSelection-members.html | 2 +- docs/html/classViewSelection.html | 2 +- docs/html/classes.html | 2 +- docs/html/cli_8cpp_source.html | 6 +- .../dir_1788f8309b1a812dcb800a185471cf6c.html | 2 +- .../dir_587c94d866dbb2f408f78cf41f9b2f8d.html | 2 +- docs/html/dot_8cpp_source.html | 2 +- docs/html/dot_8h_source.html | 2 +- docs/html/driverexception_8h_source.html | 2 +- docs/html/files.html | 2 +- docs/html/functions.html | 20 +- docs/html/functions_func.html | 20 +- docs/html/functions_vars.html | 2 +- docs/html/hierarchy.html | 2 +- docs/html/index.html | 2 +- docs/html/plottyfile_8cpp_source.html | 2 +- docs/html/plottyfile_8h_source.html | 2 +- docs/html/requests_8h_source.html | 2 +- docs/html/search/all_0.js | 6 +- docs/html/search/all_3.js | 4 +- docs/html/search/all_9.js | 2 +- docs/html/search/all_b.js | 6 +- docs/html/search/functions_0.js | 6 +- docs/html/search/functions_2.js | 4 +- docs/html/search/functions_7.js | 2 +- docs/html/search/functions_9.js | 6 +- docs/html/timeoutexception_8h_source.html | 2 +- docs/html/ui_8cpp_source.html | 16 +- docs/html/ui_8h_source.html | 2 +- docs/html/usart_8cpp_source.html | 2 +- docs/html/usart_8h_source.html | 2 +- docs/html/usartexception_8h_source.html | 2 +- docs/html/view_8cpp_source.html | 2 +- docs/html/view_8h_source.html | 2 +- docs/html/view__info_8cpp_source.html | 2 +- docs/html/view__info_8h_source.html | 2 +- docs/html/view__monitor_8cpp_source.html | 10 +- docs/html/view__monitor_8h_source.html | 2 +- docs/html/view__promt_8cpp_source.html | 2 +- docs/html/view__promt_8h_source.html | 2 +- docs/html/view__selection_8cpp_source.html | 2 +- docs/html/view__selection_8h_source.html | 2 +- 74 files changed, 503 insertions(+), 368 deletions(-) create mode 100644 control/src/cli.cpp.orig delete mode 100644 control/src/drv/requests.h.orig diff --git a/control/src/cli.cpp b/control/src/cli.cpp index bbab408..5652dc0 100644 --- a/control/src/cli.cpp +++ b/control/src/cli.cpp @@ -100,7 +100,7 @@ void init() // set view context View::setWinContext(newwin(WIN_HEIGHT, WIN_WIDTH, 0, 0)); - + // set graphical error handler B15F::setAbortHandler(&abort_handler); } diff --git a/control/src/cli.cpp.orig b/control/src/cli.cpp.orig new file mode 100644 index 0000000..bbab408 --- /dev/null +++ b/control/src/cli.cpp.orig @@ -0,0 +1,120 @@ +//#define B15F_CLI_DEBUG + +#include +#include // sudo apt-get install libncurses5-dev +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "drv/b15f.h" +#include "ui/ui.h" +#include "ui/view_selection.h" +#include "ui/view_info.h" +#include "ui/view_monitor.h" +#include "ui/view_promt.h" + +constexpr uint8_t WIN_WIDTH = 80; +constexpr uint8_t WIN_HEIGHT = 24; + +volatile int win_changed_cooldown = 0; +volatile bool t_refresh_active = false; + +void signal_handler(int signal) +{ + if(signal == SIGWINCH) + { + win_changed_cooldown = 10; // 100ms + + if (!t_refresh_active) + { + if(t_refresh.joinable()) + t_refresh.join(); + t_refresh_active = true; + t_refresh = std::thread([]() + { + + while(win_changed_cooldown--) + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + + t_refresh_active = false; + + if(win_stack.size()) + win_stack.back()->repaint(); + + }); + } + + } + else if(signal == SIGINT) + { + cleanup(); + std::cout << "SIGINT - Abbruch." << std::endl; + exit(EXIT_FAILURE); + } +} + +void abort_handler(std::exception& ex) +{ + ViewInfo* view = new ViewInfo(); + view->setTitle("Fehler"); + std::string msg(ex.what()); + msg += "\n\nBeende in 5 Sekunden."; + view->setText(msg.c_str()); + view->setLabelClose(""); + view->repaint(); + + std::this_thread::sleep_for(std::chrono::milliseconds(5000)); + + cleanup(); + std::cerr << std::endl << "*** EXCEPTION ***" << std::endl << ex.what() << std::endl; + exit(EXIT_FAILURE); +} + +void init() +{ + // init b15 driver + B15F::getInstance(); +#ifndef B15F_CLI_DEBUG + std::cout << std::endl << "Starte in 3s ..." << std::endl; + sleep(3); +#endif + + // init all ncurses stuff + initscr(); + start_color(); + curs_set(0); // 0: invisible, 1: normal, 2: very visible + clear(); + noecho(); + cbreak(); // Line buffering disabled. pass on everything + mousemask(ALL_MOUSE_EVENTS, NULL); + + // connect signals to handler + signal(SIGWINCH, signal_handler); + signal(SIGINT, signal_handler); + + // set view context + View::setWinContext(newwin(WIN_HEIGHT, WIN_WIDTH, 0, 0)); + + // set graphical error handler + B15F::setAbortHandler(&abort_handler); +} + + +int main() +{ + init(); + + int exit_code = EXIT_SUCCESS; + + show_main(0); + + cleanup(); + + return exit_code; +} diff --git a/control/src/drv/b15f.cpp b/control/src/drv/b15f.cpp index f7deca9..c96ae52 100644 --- a/control/src/drv/b15f.cpp +++ b/control/src/drv/b15f.cpp @@ -195,7 +195,7 @@ void B15F::activateSelfTestMode() { RQ_SELF_TEST }; - + assertRequestLength(rq, RQ_SELF_TEST); usart.transmit(&rq[0], 0, sizeof(rq)); @@ -211,7 +211,7 @@ void B15F::digitalWrite0(uint8_t port) RQ_DIGITAL_WRITE_0, port }; - + assertRequestLength(rq, RQ_DIGITAL_WRITE_0); usart.transmit(&rq[0], 0, sizeof(rq)); @@ -227,7 +227,7 @@ void B15F::digitalWrite1(uint8_t port) RQ_DIGITAL_WRITE_1, port }; - + assertRequestLength(rq, RQ_DIGITAL_WRITE_1); usart.transmit(&rq[0], 0, sizeof(rq)); @@ -243,7 +243,7 @@ uint8_t B15F::digitalRead0() { RQ_DIGITAL_READ_0 }; - + assertRequestLength(rq, RQ_DIGITAL_READ_0); usart.transmit(&rq[0], 0, sizeof(rq)); @@ -259,7 +259,7 @@ uint8_t B15F::digitalRead1() { RQ_DIGITAL_READ_1 }; - + assertRequestLength(rq, RQ_DIGITAL_READ_1); usart.transmit(&rq[0], 0, sizeof(rq)); @@ -275,7 +275,7 @@ uint8_t B15F::readDipSwitch() { RQ_READ_DIP_SWITCH }; - + assertRequestLength(rq, RQ_READ_DIP_SWITCH); usart.transmit(&rq[0], 0, sizeof(rq)); @@ -295,7 +295,7 @@ void B15F::analogWrite0(uint16_t value) static_cast(value & 0xFF), static_cast(value >> 8) }; - + assertRequestLength(rq, RQ_ANALOG_WRITE_0); usart.transmit(&rq[0], 0, sizeof(rq)); @@ -312,7 +312,7 @@ void B15F::analogWrite1(uint16_t value) static_cast(value & 0xFF), static_cast(value >> 8) }; - + assertRequestLength(rq, RQ_ANALOG_WRITE_1); usart.transmit(&rq[0], 0, sizeof(rq)); @@ -345,7 +345,7 @@ uint16_t B15F::analogRead(uint8_t channel) } void B15F::analogSequence(uint8_t channel_a, uint16_t *buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t *buffer_b, - uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count) + uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count) { // prepare pointers buffer_a += offset_a; @@ -593,7 +593,7 @@ void B15F::setServoPosition(uint16_t pos) static_cast(pos & 0xFF), static_cast(pos >> 8) }; - + assertRequestLength(rq, RQ_SERVO_SET_POS); usart.transmit(&rq[0], 0, sizeof(rq)); @@ -625,7 +625,7 @@ void B15F::init() // normal PC serial interface std::string device = exec("bash -c 'ls /dev/ttyUSB* 2> /dev/null'"); #endif - + while (device.find(' ') != std::string::npos || device.find('\n') != std::string::npos || device.find('\t') != std::string::npos) device.pop_back(); diff --git a/control/src/drv/b15f.cpp.orig b/control/src/drv/b15f.cpp.orig index 8ca3da1..f7deca9 100644 --- a/control/src/drv/b15f.cpp.orig +++ b/control/src/drv/b15f.cpp.orig @@ -171,7 +171,6 @@ void B15F::abort(std::exception &ex) errorhandler(ex); else { - std::cerr << "NOTICE: B15F::errorhandler not set" << std::endl; std::cout << ex.what() << std::endl; throw DriverException(ex.what()); } @@ -190,45 +189,51 @@ void B15F::setAbortHandler(errorhandler_t func) * Steuerbefehle für B15 * *************************/ -bool B15F::activateSelfTestMode() +void B15F::activateSelfTestMode() { uint8_t rq[] = { RQ_SELF_TEST }; + + assertRequestLength(rq, RQ_SELF_TEST); usart.transmit(&rq[0], 0, sizeof(rq)); uint8_t aw; usart.receive(&aw, 0, sizeof(aw)); - return aw == MSG_OK; + assertCode(aw, MSG_OK); } -bool B15F::digitalWrite0(uint8_t port) +void B15F::digitalWrite0(uint8_t port) { uint8_t rq[] = { RQ_DIGITAL_WRITE_0, port }; + + assertRequestLength(rq, RQ_DIGITAL_WRITE_0); usart.transmit(&rq[0], 0, sizeof(rq)); uint8_t aw; usart.receive(&aw, 0, sizeof(aw)); - return aw == MSG_OK; + assertCode(aw, MSG_OK); } -bool B15F::digitalWrite1(uint8_t port) +void B15F::digitalWrite1(uint8_t port) { uint8_t rq[] = { RQ_DIGITAL_WRITE_1, port }; + + assertRequestLength(rq, RQ_DIGITAL_WRITE_1); usart.transmit(&rq[0], 0, sizeof(rq)); uint8_t aw; usart.receive(&aw, 0, sizeof(aw)); - return aw == MSG_OK; + assertCode(aw, MSG_OK); } uint8_t B15F::digitalRead0() @@ -238,6 +243,8 @@ uint8_t B15F::digitalRead0() { RQ_DIGITAL_READ_0 }; + + assertRequestLength(rq, RQ_DIGITAL_READ_0); usart.transmit(&rq[0], 0, sizeof(rq)); uint8_t aw; @@ -252,6 +259,8 @@ uint8_t B15F::digitalRead1() { RQ_DIGITAL_READ_1 }; + + assertRequestLength(rq, RQ_DIGITAL_READ_1); usart.transmit(&rq[0], 0, sizeof(rq)); uint8_t aw; @@ -266,6 +275,8 @@ uint8_t B15F::readDipSwitch() { RQ_READ_DIP_SWITCH }; + + assertRequestLength(rq, RQ_READ_DIP_SWITCH); usart.transmit(&rq[0], 0, sizeof(rq)); uint8_t aw; @@ -276,7 +287,7 @@ uint8_t B15F::readDipSwitch() return aw; } -bool B15F::analogWrite0(uint16_t value) +void B15F::analogWrite0(uint16_t value) { uint8_t rq[] = { @@ -284,14 +295,16 @@ bool B15F::analogWrite0(uint16_t value) static_cast(value & 0xFF), static_cast(value >> 8) }; + + assertRequestLength(rq, RQ_ANALOG_WRITE_0); usart.transmit(&rq[0], 0, sizeof(rq)); uint8_t aw; usart.receive(&aw, 0, sizeof(aw)); - return aw == MSG_OK; + assertCode(aw, MSG_OK); } -bool B15F::analogWrite1(uint16_t value) +void B15F::analogWrite1(uint16_t value) { uint8_t rq[] = { @@ -299,11 +312,13 @@ bool B15F::analogWrite1(uint16_t value) static_cast(value & 0xFF), static_cast(value >> 8) }; + + assertRequestLength(rq, RQ_ANALOG_WRITE_1); usart.transmit(&rq[0], 0, sizeof(rq)); uint8_t aw; usart.receive(&aw, 0, sizeof(aw)); - return aw == MSG_OK; + assertCode(aw, MSG_OK); } uint16_t B15F::analogRead(uint8_t channel) @@ -318,6 +333,7 @@ uint16_t B15F::analogRead(uint8_t channel) channel }; + assertRequestLength(rq, RQ_ANALOG_READ); usart.transmit(&rq[0], 0, sizeof(rq)); uint16_t aw; @@ -328,8 +344,7 @@ uint16_t B15F::analogRead(uint8_t channel) return aw; } -void -B15F::analogSequence(uint8_t channel_a, uint16_t *buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t *buffer_b, +void B15F::analogSequence(uint8_t channel_a, uint16_t *buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t *buffer_b, uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count) { // prepare pointers @@ -351,6 +366,7 @@ B15F::analogSequence(uint8_t channel_a, uint16_t *buffer_a, uint32_t offset_a, u static_cast(count >> 8) }; + assertRequestLength(rq, RQ_ADC_DAC_STROKE); usart.transmit(&rq[0], 0, sizeof(rq)); for (uint16_t i = 0; i < count; i++) @@ -382,8 +398,7 @@ B15F::analogSequence(uint8_t channel_a, uint16_t *buffer_a, uint32_t offset_a, u uint8_t aw; usart.receive(&aw, 0, sizeof(aw)); - if(aw != MSG_OK) - abort("Sequenz unterbrochen"); + assertCode(aw, MSG_OK); } uint8_t B15F::pwmSetFrequency(uint32_t freq) @@ -399,6 +414,7 @@ uint8_t B15F::pwmSetFrequency(uint32_t freq) static_cast((freq >> 24) & 0xFF) }; + assertRequestLength(rq, RQ_PWM_SET_FREQ); usart.transmit(&rq[0], 0, sizeof(rq)); uint8_t aw; @@ -406,7 +422,7 @@ uint8_t B15F::pwmSetFrequency(uint32_t freq) return aw; } -bool B15F::pwmSetValue(uint8_t value) +void B15F::pwmSetValue(uint8_t value) { usart.clearInputBuffer(); @@ -416,14 +432,15 @@ bool B15F::pwmSetValue(uint8_t value) value }; + assertRequestLength(rq, RQ_PWM_SET_VALUE); usart.transmit(&rq[0], 0, sizeof(rq)); uint8_t aw; usart.receive(&aw, 0, sizeof(aw)); - return aw == MSG_OK; + assertCode(aw, MSG_OK); } -bool B15F::setMem8(volatile uint8_t* adr, uint8_t val) +void B15F::setMem8(volatile uint8_t* adr, uint8_t val) { usart.clearInputBuffer(); @@ -435,11 +452,12 @@ bool B15F::setMem8(volatile uint8_t* adr, uint8_t val) val }; + assertRequestLength(rq, RQ_SET_MEM_8); usart.transmit(&rq[0], 0, sizeof(rq)); uint8_t aw; usart.receive(&aw, 0, sizeof(aw)); - return aw == val; + assertCode(aw, MSG_OK); } uint8_t B15F::getMem8(volatile uint8_t* adr) @@ -453,6 +471,7 @@ uint8_t B15F::getMem8(volatile uint8_t* adr) static_cast(reinterpret_cast(adr) >> 8) }; + assertRequestLength(rq, RQ_GET_MEM_8); usart.transmit(&rq[0], 0, sizeof(rq)); uint8_t aw; @@ -460,7 +479,7 @@ uint8_t B15F::getMem8(volatile uint8_t* adr) return aw; } -bool B15F::setMem16(volatile uint16_t* adr, uint16_t val) +void B15F::setMem16(volatile uint16_t* adr, uint16_t val) { usart.clearInputBuffer(); @@ -473,11 +492,12 @@ bool B15F::setMem16(volatile uint16_t* adr, uint16_t val) static_cast(val >> 8) }; + assertRequestLength(rq, RQ_SET_MEM_16); usart.transmit(&rq[0], 0, sizeof(rq)); uint16_t aw; usart.receive(reinterpret_cast(&aw), 0, sizeof(aw)); - return aw == val; + assertCode(aw, MSG_OK); } uint16_t B15F::getMem16(volatile uint16_t* adr) @@ -491,6 +511,7 @@ uint16_t B15F::getMem16(volatile uint16_t* adr) static_cast(reinterpret_cast(adr) >> 8) }; + assertRequestLength(rq, RQ_GET_MEM_16); usart.transmit(&rq[0], 0, sizeof(rq)); uint16_t aw; @@ -498,9 +519,9 @@ uint16_t B15F::getMem16(volatile uint16_t* adr) return aw; } -bool B15F::setRegister(volatile uint8_t* adr, uint8_t val) +void B15F::setRegister(volatile uint8_t* adr, uint8_t val) { - return setMem8(adr, val); + setMem8(adr, val); } uint8_t B15F::getRegister(volatile uint8_t* adr) @@ -517,6 +538,7 @@ uint16_t* B15F::getInterruptCounterOffset() RQ_COUNTER_OFFSET }; + assertRequestLength(rq, RQ_COUNTER_OFFSET); usart.transmit(&rq[0], 0, sizeof(rq)); uint16_t aw; @@ -533,6 +555,7 @@ void B15F::setServoEnabled(void) RQ_SERVO_ENABLE }; + assertRequestLength(rq, RQ_SERVO_ENABLE); usart.transmit(&rq[0], 0, sizeof(rq)); uint8_t aw; @@ -549,6 +572,7 @@ void B15F::setServoDisabled(void) RQ_SERVO_DISABLE }; + assertRequestLength(rq, RQ_SERVO_DISABLE); usart.transmit(&rq[0], 0, sizeof(rq)); uint8_t aw; @@ -560,7 +584,7 @@ void B15F::setServoPosition(uint16_t pos) { if(pos > 19000) throw DriverException("Impulslänge ist zu lang: " + std::to_string(pos)); - + usart.clearInputBuffer(); uint8_t rq[] = @@ -569,7 +593,8 @@ void B15F::setServoPosition(uint16_t pos) static_cast(pos & 0xFF), static_cast(pos >> 8) }; - + + assertRequestLength(rq, RQ_SERVO_SET_POS); usart.transmit(&rq[0], 0, sizeof(rq)); uint8_t aw; @@ -593,7 +618,14 @@ B15F::B15F() void B15F::init() { - std::string device = exec("bash -c 'ls /dev/ttyUSB*'"); +#ifdef __arm__ + // Raspberry Pi serial interface + std::string device = exec("bash -c 'ls /dev/ttyAMA* 2> /dev/null'"); +#else + // normal PC serial interface + std::string device = exec("bash -c 'ls /dev/ttyUSB* 2> /dev/null'"); +#endif + while (device.find(' ') != std::string::npos || device.find('\n') != std::string::npos || device.find('\t') != std::string::npos) device.pop_back(); @@ -635,9 +667,3 @@ void B15F::init() std::cout << PRE << "AVR Firmware Version: " << info[0] << " um " << info[1] << " Uhr (" << info[2] << ")" << std::endl; } - -void B15F::assertCode(uint8_t& code, uint8_t expectation) const -{ - if(code != expectation) - throw DriverException("Ungültige Antwort erhalten: " + std::to_string((int) code) + " (erwartet: " + std::to_string((int) expectation) + ")"); -} diff --git a/control/src/drv/b15f.h b/control/src/drv/b15f.h index 65110cf..9b6a98c 100644 --- a/control/src/drv/b15f.h +++ b/control/src/drv/b15f.h @@ -335,7 +335,7 @@ private: if(code != static_cast(expectation)) throw DriverException("Ungültige Antwort erhalten: " + std::to_string((int) code) + " (erwartet: " + std::to_string((int) expectation) + ")"); } - + /** * Wirft eine Exception, falls die Request die falsche Länge hat. * \throws DriverException diff --git a/control/src/drv/b15f.h.orig b/control/src/drv/b15f.h.orig index 6e16d1c..65110cf 100644 --- a/control/src/drv/b15f.h.orig +++ b/control/src/drv/b15f.h.orig @@ -130,21 +130,21 @@ public: * WICHTIG: Es darf dabei nichts an den Klemmen angeschlossen sein! * \throws DriverException */ - bool activateSelfTestMode(void); + void activateSelfTestMode(void); /** * Setzt den Wert des digitalen Ausgabeports 0 * \param port Wert für gesamten Port * \throws DriverException */ - bool digitalWrite0(uint8_t); + void digitalWrite0(uint8_t); /** * Setzt den Wert des digitalen Ausgabeports 1 * \param port Wert für gesamten Port * \throws DriverException */ - bool digitalWrite1(uint8_t); + void digitalWrite1(uint8_t); /** * Liest den Wert des digitalen Eingabeports 0 @@ -172,14 +172,14 @@ public: * \param port 10-Bit Wert * \throws DriverException */ - bool analogWrite0(uint16_t port); + void analogWrite0(uint16_t port); /** * Setzt den Wert des Digital-Analog-Converters (DAC / DAU) 1 * \param port 10-Bit Wert * \throws DriverException */ - bool analogWrite1(uint16_t port); + void analogWrite1(uint16_t port); /** * Liest den Wert des Analog-Digital-Converters (ADC / ADU) @@ -221,7 +221,7 @@ public: * \param value PWM Wert [0..TOP] * \throws DriverException */ - bool pwmSetValue(uint8_t value); + void pwmSetValue(uint8_t value); /** * Setzt direkt den Wert einer MCU Speicherzelle der Größe 8 Bit. @@ -231,7 +231,7 @@ public: * \param val Neuer Wert für die Zelle * \return true, falls Vorgang erfolgreich */ - bool setMem8(volatile uint8_t* adr, uint8_t val); + void setMem8(volatile uint8_t* adr, uint8_t val); /** * Liefert den Wert einer MCU Speicherzelle der Größe 8 Bit. @@ -247,9 +247,9 @@ public: * *Wichtig:* bei einer falschen Adresse kann das Board 15 ernsthaften Schaden nehmen! * \param adr Speicheradresse * \param val Neuer Wert für die Zelle - * \return true, falls Vorgang erfolgreich + * \throws DriverException */ - bool setMem16(volatile uint16_t* adr, uint16_t val); + void setMem16(volatile uint16_t* adr, uint16_t val); /** * Liefert den Wert einer MCU Speicherzelle der Größe 16 Bit. @@ -264,9 +264,9 @@ public: * *Wichtig:* bei einer falschen Adresse kann das Board 15 ernsthaften Schaden nehmen! * \param adr Speicheradresse * \param val Neuer Wert für das Register - * \return true, falls Vorgang erfolgreich + * \throws DriverException */ - bool setRegister(volatile uint8_t* adr, uint8_t val); + void setRegister(volatile uint8_t* adr, uint8_t val); /** * Diese Funktion ist ein Alias für getMem8(). @@ -280,20 +280,23 @@ public: * \return Adresse (in der MCU) */ uint16_t* getInterruptCounterOffset(void); - + /** * Aktiviert das Servo Signal an PB2 und Initialisiert es mit 1,5ms Pulselänge. + * \throws DriverException */ void setServoEnabled(void); - + /** * Deaktiviert das Servo Signal an PB2. + * \throws DriverException */ void setServoDisabled(void); - + /** * Setzt die Pulselänge des Servo Signals und damit die Position. * \param pos Pulselänge des Signals in Mikrosekunden + * \throws DriverException */ void setServoPosition(uint16_t pos); @@ -321,12 +324,28 @@ private: * \throws DriverException */ void init(void); - + /** * Wirft eine Exception, falls der Code ungleich dem erwarteten Wert ist. * \throws DriverException */ - void assertCode(uint8_t& code, uint8_t expectation) const; + template + void assertCode(CodeType& code, ExpectationType expectation) const + { + if(code != static_cast(expectation)) + throw DriverException("Ungültige Antwort erhalten: " + std::to_string((int) code) + " (erwartet: " + std::to_string((int) expectation) + ")"); + } + + /** + * Wirft eine Exception, falls die Request die falsche Länge hat. + * \throws DriverException + */ + template + void assertRequestLength(uint8_t (&)[RequestLength], uint8_t rq_num) + { + if(RequestLength != rq_len[rq_num]) + throw DriverException("Ungültige Request Länge: " + std::to_string(RequestLength) + " (erwartet: " + std::to_string(rq_len[rq_num]) + ")"); + } USART usart; //!< USART Instanz für serielle Verbindung static B15F* instance; //!< private Instanz für Singleton diff --git a/control/src/drv/requests.h.orig b/control/src/drv/requests.h.orig deleted file mode 100644 index e436dcf..0000000 --- a/control/src/drv/requests.h.orig +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef REQUESTS_H -#define REQUESTS_H - -constexpr static uint8_t RQ_DISCARD = 0; -constexpr static uint8_t RQ_TEST = 1; -constexpr static uint8_t RQ_INFO = 2; -constexpr static uint8_t RQ_INT_TEST = 3; -constexpr static uint8_t RQ_SELF_TEST = 4; -constexpr static uint8_t RQ_DIGITAL_WRITE_0 = 5; -constexpr static uint8_t RQ_DIGITAL_WRITE_1 = 6; -constexpr static uint8_t RQ_DIGITAL_READ_0 = 7; -constexpr static uint8_t RQ_DIGITAL_READ_1 = 8; -constexpr static uint8_t RQ_READ_DIP_SWITCH = 9; -constexpr static uint8_t RQ_ANALOG_WRITE_0 = 10; -constexpr static uint8_t RQ_ANALOG_WRITE_1 = 11; -constexpr static uint8_t RQ_ANALOG_READ = 12; -constexpr static uint8_t RQ_ADC_DAC_STROKE = 13; -constexpr static uint8_t RQ_PWM_SET_FREQ = 14; -constexpr static uint8_t RQ_PWM_SET_VALUE = 15; -constexpr static uint8_t RQ_SET_MEM_8 = 16; -constexpr static uint8_t RQ_GET_MEM_8 = 17; -constexpr static uint8_t RQ_SET_MEM_16 = 18; -constexpr static uint8_t RQ_GET_MEM_16 = 19; -constexpr static uint8_t RQ_COUNTER_OFFSET = 20; -constexpr static uint8_t RQ_SERVO_ENABLE = 21; -constexpr static uint8_t RQ_SERVO_DISABLE = 22; -constexpr static uint8_t RQ_SERVO_SET_POS = 23; - -uint8_t const rq_len[] = -{ - 1 /* RQ_DISCARD */, - 1 /* RQ_TEST */ + 1 /* test byte */, - 1 /* RQ_INFO */, - 1 /* RQ_INT_TEST */ + 1 /* test int high low */ + 1 /* test int high high */, - 1 /* RQ_SELF_TEST */, - 1 /* RQ_DIGITAL_WRITE_0 */ + 1 /* port value */, - 1 /* RQ_DIGITAL_WRITE_1 */ + 1 /* port value */, - 1 /* RQ_DIGITAL_READ_0 */, - 1 /* RQ_DIGITAL_READ_1 */, - 1 /* RQ_READ_DIP_SWITCH */, - 1 /* RQ_ANALOG_WRITE_0 */ + 1 /* test int high low */ + 1 /* test int high high */, - 1 /* RQ_ANALOG_WRITE_1 */ + 1 /* test int high low */ + 1 /* test int high high */, - 1 /* RQ_ANALOG_READ */ + 1 /* adc channel */, - 1 /* RQ_ADC_DAC_STROKE */ + 1 /* channel a */ + 1 /* channel b */ + 1 /* start low */ + 1 /* start high */ + 1 /* delta low */ + 1 /* delta high */ + 1 /* count low */ + 1 /* count high */, - 1 /* RQ_PWM_SET_FREQ */ + 1 /* freq low low */ + 1 /* freq low high */ + 1 /* freq high low */ + 1 /* freq high high */, - 1 /* RQ_PWM_SET_VALUE */ + 1 /* pwm value */, - 1 /* RQ_SET_MEM_8 */ + 1 /* memory address low */ + 1 /* memory address high */ + 1 /* memory value (8-bit) */, - 1 /* RQ_GET_MEM_8 */ + 1 /* memory address low */ + 1 /* memory address high */, - 1 /* RQ_SET_MEM_16 */ + 1 /* memory address low */ + 1 /* memory address high */ + 1 /* memory value low */ + 1 /* memory value high */, - 1 /* RQ_GET_MEM_16 */ + 1 /* memory address low */ + 1 /* memory address high */, - 1 /* RQ_COUNTER_OFFSET */, - 1 /* RQ_SERVO_ENABLE */, - 1 /* RQ_SERVO_DISABLE */, - 1 /* RQ_SERVO_SET_POS */ + 1 /* pulse length low */ + 1 /* pulse length high */, -}; - -#endif // REQUESTS_H diff --git a/docs/html/annotated.html b/docs/html/annotated.html index ec87ddf..b918d7a 100644 --- a/docs/html/annotated.html +++ b/docs/html/annotated.html @@ -85,7 +85,7 @@ $(function() { diff --git a/docs/html/b15f_8cpp_source.html b/docs/html/b15f_8cpp_source.html index 7f920f8..f5b5929 100644 --- a/docs/html/b15f_8cpp_source.html +++ b/docs/html/b15f_8cpp_source.html @@ -70,18 +70,22 @@ $(function() {
b15f.cpp
-
1 #include "b15f.h"
2 
3 B15F *B15F::instance = nullptr;
4 errorhandler_t B15F::errorhandler = nullptr;
5 
6 
7 /*************************************
8  * Grundfunktionen des B15F Treibers *
9  *************************************/
10 
12 {
13  if (!instance)
14  instance = new B15F();
15 
16  return *instance;
17 }
18 
19 void B15F::reconnect()
20 {
21  uint8_t tries = RECONNECT_TRIES;
22  while (tries--)
23  {
25  discard();
26 
27  if (testConnection())
28  return;
29  }
30 
31  abort("Verbindung kann nicht repariert werden");
32 }
33 
34 void B15F::discard(void)
35 {
36  try
37  {
38  uint8_t rq[] =
39  {
40  RQ_DISCARD
41  };
42 
43  usart.clearOutputBuffer();
44  for (uint8_t i = 0; i < 16; i++)
45  {
46  usart.transmit(&rq[0], 0, sizeof(rq)); // sende discard Befehl (verwerfe input)
47  delay_ms(4);
48  }
49  usart.clearInputBuffer();
50  }
51  catch (std::exception &ex)
52  {
53  abort(ex);
54  }
55 }
56 
58 {
59  // erzeuge zufälliges Byte
60  srand(time(NULL));
61  uint8_t dummy = rand() % 256;
62 
63  uint8_t rq[] =
64  {
65  RQ_TEST,
66  dummy
67  };
68  usart.transmit(&rq[0], 0, sizeof(rq));
69 
70  uint8_t aw[2];
71  usart.receive(&aw[0], 0, sizeof(aw));
72 
73  return aw[0] == MSG_OK && aw[1] == dummy;
74 }
75 
76 bool B15F::testIntConv()
77 {
78  srand(time(NULL));
79  uint16_t dummy = rand() % (0xFFFF / 3);
80 
81  uint8_t rq[] =
82  {
83  RQ_INT_TEST,
84  static_cast<uint8_t >(dummy & 0xFF),
85  static_cast<uint8_t >(dummy >> 8)
86  };
87  usart.transmit(&rq[0], 0, sizeof(rq));
88 
89  uint16_t aw;
90  usart.receive(reinterpret_cast<uint8_t *>(&aw), 0, sizeof(aw));
91 
92  return aw == dummy * 3;
93 }
94 
95 
96 std::vector<std::string> B15F::getBoardInfo(void)
97 {
98  std::vector<std::string> info;
99 
100  uint8_t rq[] =
101  {
102  RQ_INFO
103  };
104  usart.transmit(&rq[0], 0, sizeof(rq));
105 
106  uint8_t n;
107  usart.receive(&n, 0, sizeof(n));
108  while (n--)
109  {
110  uint8_t len;
111  usart.receive(&len, 0, sizeof(len));
112 
113  char str[len + 1];
114  str[len] = '\0';
115  usart.receive(reinterpret_cast<uint8_t *>(&str[0]), 0, len);
116 
117  info.push_back(std::string(str));
118  }
119 
120  uint8_t aw;
121  usart.receive(&aw, 0, sizeof(aw));
122  if (aw != MSG_OK)
123  abort("Board Info fehlerhalft: code " + std::to_string((int) aw));
124 
125  return info;
126 }
127 
128 void B15F::delay_ms(uint16_t ms)
129 {
130  std::this_thread::sleep_for(std::chrono::milliseconds(ms));
131 }
132 
133 void B15F::delay_us(uint16_t us)
134 {
135  std::this_thread::sleep_for(std::chrono::microseconds(us));
136 }
137 
138 void B15F::reverse(uint8_t& b)
139 {
140  b = (b & 0xF0) >> 4 | (b & 0x0F) << 4;
141  b = (b & 0xCC) >> 2 | (b & 0x33) << 2;
142  b = (b & 0xAA) >> 1 | (b & 0x55) << 1;
143 }
144 
145 // https://stackoverflow.com/a/478960
146 std::string B15F::exec(std::string cmd)
147 {
148  std::array<char, 128> buffer;
149  std::string result;
150  std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd.c_str(), "r"), pclose);
151  if (!pipe)
152  {
153  throw std::runtime_error("popen() failed!");
154  }
155  while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr)
156  {
157  result += buffer.data();
158  }
159  return result;
160 }
161 
162 void B15F::abort(std::string msg)
163 {
164  DriverException ex(msg);
165  abort(ex);
166 }
167 
168 void B15F::abort(std::exception &ex)
169 {
170  if (errorhandler)
171  errorhandler(ex);
172  else
173  {
174  std::cerr << "NOTICE: B15F::errorhandler not set" << std::endl;
175  std::cout << ex.what() << std::endl;
176  throw DriverException(ex.what());
177  }
178 }
179 
180 void B15F::setAbortHandler(errorhandler_t func)
181 {
182  errorhandler = func;
183 }
184 
185 /*************************************/
186 
187 
188 
189 /*************************
190  * Steuerbefehle für B15 *
191  *************************/
192 
194 {
195  uint8_t rq[] =
196  {
197  RQ_SELF_TEST
198  };
199  usart.transmit(&rq[0], 0, sizeof(rq));
200 
201  uint8_t aw;
202  usart.receive(&aw, 0, sizeof(aw));
203  return aw == MSG_OK;
204 }
205 
206 bool B15F::digitalWrite0(uint8_t port)
207 {
208  uint8_t rq[] =
209  {
210  RQ_DIGITAL_WRITE_0,
211  port
212  };
213  usart.transmit(&rq[0], 0, sizeof(rq));
214 
215  uint8_t aw;
216  usart.receive(&aw, 0, sizeof(aw));
217  return aw == MSG_OK;
218 }
219 
220 bool B15F::digitalWrite1(uint8_t port)
221 {
222  uint8_t rq[] =
223  {
224  RQ_DIGITAL_WRITE_1,
225  port
226  };
227  usart.transmit(&rq[0], 0, sizeof(rq));
228 
229  uint8_t aw;
230  usart.receive(&aw, 0, sizeof(aw));
231  return aw == MSG_OK;
232 }
233 
234 uint8_t B15F::digitalRead0()
235 {
236  usart.clearInputBuffer();
237  uint8_t rq[] =
238  {
239  RQ_DIGITAL_READ_0
240  };
241  usart.transmit(&rq[0], 0, sizeof(rq));
242 
243  uint8_t aw;
244  usart.receive(&aw, 0, sizeof(aw));
245  return aw;
246 }
247 
248 uint8_t B15F::digitalRead1()
249 {
250  usart.clearInputBuffer();
251  uint8_t rq[] =
252  {
253  RQ_DIGITAL_READ_1
254  };
255  usart.transmit(&rq[0], 0, sizeof(rq));
256 
257  uint8_t aw;
258  usart.receive(&aw, 0, sizeof(aw));
259  return aw;
260 }
261 
262 uint8_t B15F::readDipSwitch()
263 {
264  usart.clearInputBuffer();
265  uint8_t rq[] =
266  {
267  RQ_READ_DIP_SWITCH
268  };
269  usart.transmit(&rq[0], 0, sizeof(rq));
270 
271  uint8_t aw;
272  usart.receive(&aw, 0, sizeof(aw));
273 
274  reverse(aw); // DIP Schalter muss invertiert werden!
275 
276  return aw;
277 }
278 
279 bool B15F::analogWrite0(uint16_t value)
280 {
281  uint8_t rq[] =
282  {
283  RQ_ANALOG_WRITE_0,
284  static_cast<uint8_t >(value & 0xFF),
285  static_cast<uint8_t >(value >> 8)
286  };
287  usart.transmit(&rq[0], 0, sizeof(rq));
288 
289  uint8_t aw;
290  usart.receive(&aw, 0, sizeof(aw));
291  return aw == MSG_OK;
292 }
293 
294 bool B15F::analogWrite1(uint16_t value)
295 {
296  uint8_t rq[] =
297  {
298  RQ_ANALOG_WRITE_1,
299  static_cast<uint8_t >(value & 0xFF),
300  static_cast<uint8_t >(value >> 8)
301  };
302  usart.transmit(&rq[0], 0, sizeof(rq));
303 
304  uint8_t aw;
305  usart.receive(&aw, 0, sizeof(aw));
306  return aw == MSG_OK;
307 }
308 
309 uint16_t B15F::analogRead(uint8_t channel)
310 {
311  usart.clearInputBuffer();
312  if (channel > 7)
313  abort("Bad ADC channel: " + std::to_string(channel));
314 
315  uint8_t rq[] =
316  {
317  RQ_ANALOG_READ,
318  channel
319  };
320 
321  usart.transmit(&rq[0], 0, sizeof(rq));
322 
323  uint16_t aw;
324  usart.receive(reinterpret_cast<uint8_t *>(&aw), 0, sizeof(aw));
325 
326  if (aw > 1023)
327  abort("Bad ADC data detected (1)");
328  return aw;
329 }
330 
331 void
332 B15F::analogSequence(uint8_t channel_a, uint16_t *buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t *buffer_b,
333  uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count)
334 {
335  // prepare pointers
336  buffer_a += offset_a;
337  buffer_b += offset_b;
338 
339 
340  usart.clearInputBuffer();
341  uint8_t rq[] =
342  {
343  RQ_ADC_DAC_STROKE,
344  channel_a,
345  channel_b,
346  static_cast<uint8_t >(start & 0xFF),
347  static_cast<uint8_t >(start >> 8),
348  static_cast<uint8_t >(delta & 0xFF),
349  static_cast<uint8_t >(delta >> 8),
350  static_cast<uint8_t >(count & 0xFF),
351  static_cast<uint8_t >(count >> 8)
352  };
353 
354  usart.transmit(&rq[0], 0, sizeof(rq));
355 
356  for (uint16_t i = 0; i < count; i++)
357  {
358  if (buffer_a)
359  {
360  usart.receive(reinterpret_cast<uint8_t *>(&buffer_a[i]), 0, 2);
361 
362  if (buffer_a[i] > 1023) // check for broken usart connection
363  abort("Bad ADC data detected (2)");
364  }
365  else
366  {
367  usart.drop(2);
368  }
369 
370  if (buffer_b)
371  {
372  usart.receive(reinterpret_cast<uint8_t *>(&buffer_b[i]), 0, 2);
373 
374  if (buffer_b[i] > 1023) // check for broken usart connection
375  abort("Bad ADC data detected (3)");
376  }
377  else
378  {
379  usart.drop(2);
380  }
381  }
382 
383  uint8_t aw;
384  usart.receive(&aw, 0, sizeof(aw));
385  if(aw != MSG_OK)
386  abort("Sequenz unterbrochen");
387 }
388 
389 uint8_t B15F::pwmSetFrequency(uint32_t freq)
390 {
391  usart.clearInputBuffer();
392 
393  uint8_t rq[] =
394  {
395  RQ_PWM_SET_FREQ,
396  static_cast<uint8_t>((freq >> 0) & 0xFF),
397  static_cast<uint8_t>((freq >> 8) & 0xFF),
398  static_cast<uint8_t>((freq >> 16) & 0xFF),
399  static_cast<uint8_t>((freq >> 24) & 0xFF)
400  };
401 
402  usart.transmit(&rq[0], 0, sizeof(rq));
403 
404  uint8_t aw;
405  usart.receive(&aw, 0, sizeof(aw));
406  return aw;
407 }
408 
409 bool B15F::pwmSetValue(uint8_t value)
410 {
411  usart.clearInputBuffer();
412 
413  uint8_t rq[] =
414  {
415  RQ_PWM_SET_VALUE,
416  value
417  };
418 
419  usart.transmit(&rq[0], 0, sizeof(rq));
420 
421  uint8_t aw;
422  usart.receive(&aw, 0, sizeof(aw));
423  return aw == MSG_OK;
424 }
425 
426 bool B15F::setMem8(volatile uint8_t* adr, uint8_t val)
427 {
428  usart.clearInputBuffer();
429 
430  uint8_t rq[] =
431  {
432  RQ_SET_MEM_8,
433  static_cast<uint8_t >(reinterpret_cast<size_t>(adr) & 0xFF),
434  static_cast<uint8_t >(reinterpret_cast<size_t>(adr) >> 8),
435  val
436  };
437 
438  usart.transmit(&rq[0], 0, sizeof(rq));
439 
440  uint8_t aw;
441  usart.receive(&aw, 0, sizeof(aw));
442  return aw == val;
443 }
444 
445 uint8_t B15F::getMem8(volatile uint8_t* adr)
446 {
447  usart.clearInputBuffer();
448 
449  uint8_t rq[] =
450  {
451  RQ_GET_MEM_8,
452  static_cast<uint8_t >(reinterpret_cast<size_t>(adr) & 0xFF),
453  static_cast<uint8_t >(reinterpret_cast<size_t>(adr) >> 8)
454  };
455 
456  usart.transmit(&rq[0], 0, sizeof(rq));
457 
458  uint8_t aw;
459  usart.receive(&aw, 0, sizeof(aw));
460  return aw;
461 }
462 
463 bool B15F::setMem16(volatile uint16_t* adr, uint16_t val)
464 {
465  usart.clearInputBuffer();
466 
467  uint8_t rq[] =
468  {
469  RQ_SET_MEM_16,
470  static_cast<uint8_t >(reinterpret_cast<size_t>(adr) & 0xFF),
471  static_cast<uint8_t >(reinterpret_cast<size_t>(adr) >> 8),
472  static_cast<uint8_t >(val & 0xFF),
473  static_cast<uint8_t >(val >> 8)
474  };
475 
476  usart.transmit(&rq[0], 0, sizeof(rq));
477 
478  uint16_t aw;
479  usart.receive(reinterpret_cast<uint8_t *>(&aw), 0, sizeof(aw));
480  return aw == val;
481 }
482 
483 uint16_t B15F::getMem16(volatile uint16_t* adr)
484 {
485  usart.clearInputBuffer();
486 
487  uint8_t rq[] =
488  {
489  RQ_GET_MEM_16,
490  static_cast<uint8_t >(reinterpret_cast<size_t>(adr) & 0xFF),
491  static_cast<uint8_t >(reinterpret_cast<size_t>(adr) >> 8)
492  };
493 
494  usart.transmit(&rq[0], 0, sizeof(rq));
495 
496  uint16_t aw;
497  usart.receive(reinterpret_cast<uint8_t *>(&aw), 0, sizeof(aw));
498  return aw;
499 }
500 
501 bool B15F::setRegister(volatile uint8_t* adr, uint8_t val)
502 {
503  return setMem8(adr, val);
504 }
505 
506 uint8_t B15F::getRegister(volatile uint8_t* adr)
507 {
508  return getMem8(adr);
509 }
510 
512 {
513  usart.clearInputBuffer();
514 
515  uint8_t rq[] =
516  {
517  RQ_COUNTER_OFFSET
518  };
519 
520  usart.transmit(&rq[0], 0, sizeof(rq));
521 
522  uint16_t aw;
523  usart.receive(reinterpret_cast<uint8_t *>(&aw), 0, sizeof(aw));
524  return reinterpret_cast<uint16_t*>(aw);
525 }
526 
527 void B15F::setServoEnabled(void)
528 {
529  usart.clearInputBuffer();
530 
531  uint8_t rq[] =
532  {
533  RQ_SERVO_ENABLE
534  };
535 
536  usart.transmit(&rq[0], 0, sizeof(rq));
537 
538  uint8_t aw;
539  usart.receive(&aw, 0, sizeof(aw));
540  assertCode(aw, MSG_OK);
541 }
542 
543 void B15F::setServoDisabled(void)
544 {
545  usart.clearInputBuffer();
546 
547  uint8_t rq[] =
548  {
549  RQ_SERVO_DISABLE
550  };
551 
552  usart.transmit(&rq[0], 0, sizeof(rq));
553 
554  uint8_t aw;
555  usart.receive(&aw, 0, sizeof(aw));
556  assertCode(aw, MSG_OK);
557 }
558 
559 void B15F::setServoPosition(uint16_t pos)
560 {
561  if(pos > 19000)
562  throw DriverException("Impulslänge ist zu lang: " + std::to_string(pos));
563 
564  usart.clearInputBuffer();
565 
566  uint8_t rq[] =
567  {
568  RQ_SERVO_SET_POS,
569  static_cast<uint8_t >(pos & 0xFF),
570  static_cast<uint8_t >(pos >> 8)
571  };
572 
573  usart.transmit(&rq[0], 0, sizeof(rq));
574 
575  uint8_t aw;
576  usart.receive(&aw, 0, sizeof(aw));
577  assertCode(aw, MSG_OK);
578 }
579 
580 /*************************/
581 
582 
583 /**********************
584  * Private Funktionen *
585  **********************/
586 
587 B15F::B15F()
588 {
589  init();
590 }
591 
592 
593 void B15F::init()
594 {
595 
596  std::string device = exec("bash -c 'ls /dev/ttyUSB*'");
597  while (device.find(' ') != std::string::npos || device.find('\n') != std::string::npos ||
598  device.find('\t') != std::string::npos)
599  device.pop_back();
600 
601  if (device.length() == 0)
602  abort("Adapter nicht gefunden");
603 
604  std::cout << PRE << "Verwende Adapter: " << device << std::endl;
605 
606 
607  std::cout << PRE << "Stelle Verbindung mit Adapter her... " << std::flush;
608  usart.setBaudrate(BAUDRATE);
609  usart.openDevice(device);
610  std::cout << "OK" << std::endl;
611 
612 
613  std::cout << PRE << "Teste Verbindung... " << std::flush;
614  uint8_t tries = 3;
615  while (tries--)
616  {
617  // verwerfe Daten, die µC noch hat
618  //discard();
619 
620  if (!testConnection())
621  continue;
622 
623  if (!testIntConv())
624  continue;
625 
626  break;
627  }
628  if (tries == 0)
629  abort("Verbindungstest fehlgeschlagen. Neueste Version im Einsatz?");
630  std::cout << "OK" << std::endl;
631 
632 
633  // Gib board info aus
634  std::vector<std::string> info = getBoardInfo();
635  std::cout << PRE << "AVR Firmware Version: " << info[0] << " um " << info[1] << " Uhr (" << info[2] << ")"
636  << std::endl;
637 }
638 
639 void B15F::assertCode(uint8_t& code, uint8_t expectation) const
640 {
641  if(code != expectation)
642  throw DriverException("Ungültige Antwort erhalten: " + std::to_string((int) code) + " (erwartet: " + std::to_string((int) expectation) + ")");
643 }
+
1 #include "b15f.h"
2 
3 B15F *B15F::instance = nullptr;
4 errorhandler_t B15F::errorhandler = nullptr;
5 
6 
7 /*************************************
8  * Grundfunktionen des B15F Treibers *
9  *************************************/
10 
12 {
13  if (!instance)
14  instance = new B15F();
15 
16  return *instance;
17 }
18 
19 void B15F::reconnect()
20 {
21  uint8_t tries = RECONNECT_TRIES;
22  while (tries--)
23  {
25  discard();
26 
27  if (testConnection())
28  return;
29  }
30 
31  abort("Verbindung kann nicht repariert werden");
32 }
33 
34 void B15F::discard(void)
35 {
36  try
37  {
38  uint8_t rq[] =
39  {
40  RQ_DISCARD
41  };
42 
43  usart.clearOutputBuffer();
44  for (uint8_t i = 0; i < 16; i++)
45  {
46  usart.transmit(&rq[0], 0, sizeof(rq)); // sende discard Befehl (verwerfe input)
47  delay_ms(4);
48  }
49  usart.clearInputBuffer();
50  }
51  catch (std::exception &ex)
52  {
53  abort(ex);
54  }
55 }
56 
58 {
59  // erzeuge zufälliges Byte
60  srand(time(NULL));
61  uint8_t dummy = rand() % 256;
62 
63  uint8_t rq[] =
64  {
65  RQ_TEST,
66  dummy
67  };
68  usart.transmit(&rq[0], 0, sizeof(rq));
69 
70  uint8_t aw[2];
71  usart.receive(&aw[0], 0, sizeof(aw));
72 
73  return aw[0] == MSG_OK && aw[1] == dummy;
74 }
75 
76 bool B15F::testIntConv()
77 {
78  srand(time(NULL));
79  uint16_t dummy = rand() % (0xFFFF / 3);
80 
81  uint8_t rq[] =
82  {
83  RQ_INT_TEST,
84  static_cast<uint8_t >(dummy & 0xFF),
85  static_cast<uint8_t >(dummy >> 8)
86  };
87  usart.transmit(&rq[0], 0, sizeof(rq));
88 
89  uint16_t aw;
90  usart.receive(reinterpret_cast<uint8_t *>(&aw), 0, sizeof(aw));
91 
92  return aw == dummy * 3;
93 }
94 
95 
96 std::vector<std::string> B15F::getBoardInfo(void)
97 {
98  std::vector<std::string> info;
99 
100  uint8_t rq[] =
101  {
102  RQ_INFO
103  };
104  usart.transmit(&rq[0], 0, sizeof(rq));
105 
106  uint8_t n;
107  usart.receive(&n, 0, sizeof(n));
108  while (n--)
109  {
110  uint8_t len;
111  usart.receive(&len, 0, sizeof(len));
112 
113  char str[len + 1];
114  str[len] = '\0';
115  usart.receive(reinterpret_cast<uint8_t *>(&str[0]), 0, len);
116 
117  info.push_back(std::string(str));
118  }
119 
120  uint8_t aw;
121  usart.receive(&aw, 0, sizeof(aw));
122  if (aw != MSG_OK)
123  abort("Board Info fehlerhalft: code " + std::to_string((int) aw));
124 
125  return info;
126 }
127 
128 void B15F::delay_ms(uint16_t ms)
129 {
130  std::this_thread::sleep_for(std::chrono::milliseconds(ms));
131 }
132 
133 void B15F::delay_us(uint16_t us)
134 {
135  std::this_thread::sleep_for(std::chrono::microseconds(us));
136 }
137 
138 void B15F::reverse(uint8_t& b)
139 {
140  b = (b & 0xF0) >> 4 | (b & 0x0F) << 4;
141  b = (b & 0xCC) >> 2 | (b & 0x33) << 2;
142  b = (b & 0xAA) >> 1 | (b & 0x55) << 1;
143 }
144 
145 // https://stackoverflow.com/a/478960
146 std::string B15F::exec(std::string cmd)
147 {
148  std::array<char, 128> buffer;
149  std::string result;
150  std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd.c_str(), "r"), pclose);
151  if (!pipe)
152  {
153  throw std::runtime_error("popen() failed!");
154  }
155  while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr)
156  {
157  result += buffer.data();
158  }
159  return result;
160 }
161 
162 void B15F::abort(std::string msg)
163 {
164  DriverException ex(msg);
165  abort(ex);
166 }
167 
168 void B15F::abort(std::exception &ex)
169 {
170  if (errorhandler)
171  errorhandler(ex);
172  else
173  {
174  std::cout << ex.what() << std::endl;
175  throw DriverException(ex.what());
176  }
177 }
178 
179 void B15F::setAbortHandler(errorhandler_t func)
180 {
181  errorhandler = func;
182 }
183 
184 /*************************************/
185 
186 
187 
188 /*************************
189  * Steuerbefehle für B15 *
190  *************************/
191 
193 {
194  uint8_t rq[] =
195  {
196  RQ_SELF_TEST
197  };
198 
199  assertRequestLength(rq, RQ_SELF_TEST);
200  usart.transmit(&rq[0], 0, sizeof(rq));
201 
202  uint8_t aw;
203  usart.receive(&aw, 0, sizeof(aw));
204  assertCode(aw, MSG_OK);
205 }
206 
207 void B15F::digitalWrite0(uint8_t port)
208 {
209  uint8_t rq[] =
210  {
211  RQ_DIGITAL_WRITE_0,
212  port
213  };
214 
215  assertRequestLength(rq, RQ_DIGITAL_WRITE_0);
216  usart.transmit(&rq[0], 0, sizeof(rq));
217 
218  uint8_t aw;
219  usart.receive(&aw, 0, sizeof(aw));
220  assertCode(aw, MSG_OK);
221 }
222 
223 void B15F::digitalWrite1(uint8_t port)
224 {
225  uint8_t rq[] =
226  {
227  RQ_DIGITAL_WRITE_1,
228  port
229  };
230 
231  assertRequestLength(rq, RQ_DIGITAL_WRITE_1);
232  usart.transmit(&rq[0], 0, sizeof(rq));
233 
234  uint8_t aw;
235  usart.receive(&aw, 0, sizeof(aw));
236  assertCode(aw, MSG_OK);
237 }
238 
239 uint8_t B15F::digitalRead0()
240 {
241  usart.clearInputBuffer();
242  uint8_t rq[] =
243  {
244  RQ_DIGITAL_READ_0
245  };
246 
247  assertRequestLength(rq, RQ_DIGITAL_READ_0);
248  usart.transmit(&rq[0], 0, sizeof(rq));
249 
250  uint8_t aw;
251  usart.receive(&aw, 0, sizeof(aw));
252  return aw;
253 }
254 
255 uint8_t B15F::digitalRead1()
256 {
257  usart.clearInputBuffer();
258  uint8_t rq[] =
259  {
260  RQ_DIGITAL_READ_1
261  };
262 
263  assertRequestLength(rq, RQ_DIGITAL_READ_1);
264  usart.transmit(&rq[0], 0, sizeof(rq));
265 
266  uint8_t aw;
267  usart.receive(&aw, 0, sizeof(aw));
268  return aw;
269 }
270 
271 uint8_t B15F::readDipSwitch()
272 {
273  usart.clearInputBuffer();
274  uint8_t rq[] =
275  {
276  RQ_READ_DIP_SWITCH
277  };
278 
279  assertRequestLength(rq, RQ_READ_DIP_SWITCH);
280  usart.transmit(&rq[0], 0, sizeof(rq));
281 
282  uint8_t aw;
283  usart.receive(&aw, 0, sizeof(aw));
284 
285  reverse(aw); // DIP Schalter muss invertiert werden!
286 
287  return aw;
288 }
289 
290 void B15F::analogWrite0(uint16_t value)
291 {
292  uint8_t rq[] =
293  {
294  RQ_ANALOG_WRITE_0,
295  static_cast<uint8_t >(value & 0xFF),
296  static_cast<uint8_t >(value >> 8)
297  };
298 
299  assertRequestLength(rq, RQ_ANALOG_WRITE_0);
300  usart.transmit(&rq[0], 0, sizeof(rq));
301 
302  uint8_t aw;
303  usart.receive(&aw, 0, sizeof(aw));
304  assertCode(aw, MSG_OK);
305 }
306 
307 void B15F::analogWrite1(uint16_t value)
308 {
309  uint8_t rq[] =
310  {
311  RQ_ANALOG_WRITE_1,
312  static_cast<uint8_t >(value & 0xFF),
313  static_cast<uint8_t >(value >> 8)
314  };
315 
316  assertRequestLength(rq, RQ_ANALOG_WRITE_1);
317  usart.transmit(&rq[0], 0, sizeof(rq));
318 
319  uint8_t aw;
320  usart.receive(&aw, 0, sizeof(aw));
321  assertCode(aw, MSG_OK);
322 }
323 
324 uint16_t B15F::analogRead(uint8_t channel)
325 {
326  usart.clearInputBuffer();
327  if (channel > 7)
328  abort("Bad ADC channel: " + std::to_string(channel));
329 
330  uint8_t rq[] =
331  {
332  RQ_ANALOG_READ,
333  channel
334  };
335 
336  assertRequestLength(rq, RQ_ANALOG_READ);
337  usart.transmit(&rq[0], 0, sizeof(rq));
338 
339  uint16_t aw;
340  usart.receive(reinterpret_cast<uint8_t *>(&aw), 0, sizeof(aw));
341 
342  if (aw > 1023)
343  abort("Bad ADC data detected (1)");
344  return aw;
345 }
346 
347 void B15F::analogSequence(uint8_t channel_a, uint16_t *buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t *buffer_b,
348  uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count)
349 {
350  // prepare pointers
351  buffer_a += offset_a;
352  buffer_b += offset_b;
353 
354 
355  usart.clearInputBuffer();
356  uint8_t rq[] =
357  {
358  RQ_ADC_DAC_STROKE,
359  channel_a,
360  channel_b,
361  static_cast<uint8_t >(start & 0xFF),
362  static_cast<uint8_t >(start >> 8),
363  static_cast<uint8_t >(delta & 0xFF),
364  static_cast<uint8_t >(delta >> 8),
365  static_cast<uint8_t >(count & 0xFF),
366  static_cast<uint8_t >(count >> 8)
367  };
368 
369  assertRequestLength(rq, RQ_ADC_DAC_STROKE);
370  usart.transmit(&rq[0], 0, sizeof(rq));
371 
372  for (uint16_t i = 0; i < count; i++)
373  {
374  if (buffer_a)
375  {
376  usart.receive(reinterpret_cast<uint8_t *>(&buffer_a[i]), 0, 2);
377 
378  if (buffer_a[i] > 1023) // check for broken usart connection
379  abort("Bad ADC data detected (2)");
380  }
381  else
382  {
383  usart.drop(2);
384  }
385 
386  if (buffer_b)
387  {
388  usart.receive(reinterpret_cast<uint8_t *>(&buffer_b[i]), 0, 2);
389 
390  if (buffer_b[i] > 1023) // check for broken usart connection
391  abort("Bad ADC data detected (3)");
392  }
393  else
394  {
395  usart.drop(2);
396  }
397  }
398 
399  uint8_t aw;
400  usart.receive(&aw, 0, sizeof(aw));
401  assertCode(aw, MSG_OK);
402 }
403 
404 uint8_t B15F::pwmSetFrequency(uint32_t freq)
405 {
406  usart.clearInputBuffer();
407 
408  uint8_t rq[] =
409  {
410  RQ_PWM_SET_FREQ,
411  static_cast<uint8_t>((freq >> 0) & 0xFF),
412  static_cast<uint8_t>((freq >> 8) & 0xFF),
413  static_cast<uint8_t>((freq >> 16) & 0xFF),
414  static_cast<uint8_t>((freq >> 24) & 0xFF)
415  };
416 
417  assertRequestLength(rq, RQ_PWM_SET_FREQ);
418  usart.transmit(&rq[0], 0, sizeof(rq));
419 
420  uint8_t aw;
421  usart.receive(&aw, 0, sizeof(aw));
422  return aw;
423 }
424 
425 void B15F::pwmSetValue(uint8_t value)
426 {
427  usart.clearInputBuffer();
428 
429  uint8_t rq[] =
430  {
431  RQ_PWM_SET_VALUE,
432  value
433  };
434 
435  assertRequestLength(rq, RQ_PWM_SET_VALUE);
436  usart.transmit(&rq[0], 0, sizeof(rq));
437 
438  uint8_t aw;
439  usart.receive(&aw, 0, sizeof(aw));
440  assertCode(aw, MSG_OK);
441 }
442 
443 void B15F::setMem8(volatile uint8_t* adr, uint8_t val)
444 {
445  usart.clearInputBuffer();
446 
447  uint8_t rq[] =
448  {
449  RQ_SET_MEM_8,
450  static_cast<uint8_t >(reinterpret_cast<size_t>(adr) & 0xFF),
451  static_cast<uint8_t >(reinterpret_cast<size_t>(adr) >> 8),
452  val
453  };
454 
455  assertRequestLength(rq, RQ_SET_MEM_8);
456  usart.transmit(&rq[0], 0, sizeof(rq));
457 
458  uint8_t aw;
459  usart.receive(&aw, 0, sizeof(aw));
460  assertCode(aw, MSG_OK);
461 }
462 
463 uint8_t B15F::getMem8(volatile uint8_t* adr)
464 {
465  usart.clearInputBuffer();
466 
467  uint8_t rq[] =
468  {
469  RQ_GET_MEM_8,
470  static_cast<uint8_t >(reinterpret_cast<size_t>(adr) & 0xFF),
471  static_cast<uint8_t >(reinterpret_cast<size_t>(adr) >> 8)
472  };
473 
474  assertRequestLength(rq, RQ_GET_MEM_8);
475  usart.transmit(&rq[0], 0, sizeof(rq));
476 
477  uint8_t aw;
478  usart.receive(&aw, 0, sizeof(aw));
479  return aw;
480 }
481 
482 void B15F::setMem16(volatile uint16_t* adr, uint16_t val)
483 {
484  usart.clearInputBuffer();
485 
486  uint8_t rq[] =
487  {
488  RQ_SET_MEM_16,
489  static_cast<uint8_t >(reinterpret_cast<size_t>(adr) & 0xFF),
490  static_cast<uint8_t >(reinterpret_cast<size_t>(adr) >> 8),
491  static_cast<uint8_t >(val & 0xFF),
492  static_cast<uint8_t >(val >> 8)
493  };
494 
495  assertRequestLength(rq, RQ_SET_MEM_16);
496  usart.transmit(&rq[0], 0, sizeof(rq));
497 
498  uint16_t aw;
499  usart.receive(reinterpret_cast<uint8_t *>(&aw), 0, sizeof(aw));
500  assertCode(aw, MSG_OK);
501 }
502 
503 uint16_t B15F::getMem16(volatile uint16_t* adr)
504 {
505  usart.clearInputBuffer();
506 
507  uint8_t rq[] =
508  {
509  RQ_GET_MEM_16,
510  static_cast<uint8_t >(reinterpret_cast<size_t>(adr) & 0xFF),
511  static_cast<uint8_t >(reinterpret_cast<size_t>(adr) >> 8)
512  };
513 
514  assertRequestLength(rq, RQ_GET_MEM_16);
515  usart.transmit(&rq[0], 0, sizeof(rq));
516 
517  uint16_t aw;
518  usart.receive(reinterpret_cast<uint8_t *>(&aw), 0, sizeof(aw));
519  return aw;
520 }
521 
522 void B15F::setRegister(volatile uint8_t* adr, uint8_t val)
523 {
524  setMem8(adr, val);
525 }
526 
527 uint8_t B15F::getRegister(volatile uint8_t* adr)
528 {
529  return getMem8(adr);
530 }
531 
533 {
534  usart.clearInputBuffer();
535 
536  uint8_t rq[] =
537  {
538  RQ_COUNTER_OFFSET
539  };
540 
541  assertRequestLength(rq, RQ_COUNTER_OFFSET);
542  usart.transmit(&rq[0], 0, sizeof(rq));
543 
544  uint16_t aw;
545  usart.receive(reinterpret_cast<uint8_t *>(&aw), 0, sizeof(aw));
546  return reinterpret_cast<uint16_t*>(aw);
547 }
548 
549 void B15F::setServoEnabled(void)
550 {
551  usart.clearInputBuffer();
552 
553  uint8_t rq[] =
554  {
555  RQ_SERVO_ENABLE
556  };
557 
558  assertRequestLength(rq, RQ_SERVO_ENABLE);
559  usart.transmit(&rq[0], 0, sizeof(rq));
560 
561  uint8_t aw;
562  usart.receive(&aw, 0, sizeof(aw));
563  assertCode(aw, MSG_OK);
564 }
565 
566 void B15F::setServoDisabled(void)
567 {
568  usart.clearInputBuffer();
569 
570  uint8_t rq[] =
571  {
572  RQ_SERVO_DISABLE
573  };
574 
575  assertRequestLength(rq, RQ_SERVO_DISABLE);
576  usart.transmit(&rq[0], 0, sizeof(rq));
577 
578  uint8_t aw;
579  usart.receive(&aw, 0, sizeof(aw));
580  assertCode(aw, MSG_OK);
581 }
582 
583 void B15F::setServoPosition(uint16_t pos)
584 {
585  if(pos > 19000)
586  throw DriverException("Impulslänge ist zu lang: " + std::to_string(pos));
587 
588  usart.clearInputBuffer();
589 
590  uint8_t rq[] =
591  {
592  RQ_SERVO_SET_POS,
593  static_cast<uint8_t >(pos & 0xFF),
594  static_cast<uint8_t >(pos >> 8)
595  };
596 
597  assertRequestLength(rq, RQ_SERVO_SET_POS);
598  usart.transmit(&rq[0], 0, sizeof(rq));
599 
600  uint8_t aw;
601  usart.receive(&aw, 0, sizeof(aw));
602  assertCode(aw, MSG_OK);
603 }
604 
605 /*************************/
606 
607 
608 /**********************
609  * Private Funktionen *
610  **********************/
611 
612 B15F::B15F()
613 {
614  init();
615 }
616 
617 
618 void B15F::init()
619 {
620 
621 #ifdef __arm__
622  // Raspberry Pi serial interface
623  std::string device = exec("bash -c 'ls /dev/ttyAMA* 2> /dev/null'");
624 #else
625  // normal PC serial interface
626  std::string device = exec("bash -c 'ls /dev/ttyUSB* 2> /dev/null'");
627 #endif
628 
629  while (device.find(' ') != std::string::npos || device.find('\n') != std::string::npos ||
630  device.find('\t') != std::string::npos)
631  device.pop_back();
632 
633  if (device.length() == 0)
634  abort("Adapter nicht gefunden");
635 
636  std::cout << PRE << "Verwende Adapter: " << device << std::endl;
637 
638 
639  std::cout << PRE << "Stelle Verbindung mit Adapter her... " << std::flush;
640  usart.setBaudrate(BAUDRATE);
641  usart.openDevice(device);
642  std::cout << "OK" << std::endl;
643 
644 
645  std::cout << PRE << "Teste Verbindung... " << std::flush;
646  uint8_t tries = 3;
647  while (tries--)
648  {
649  // verwerfe Daten, die µC noch hat
650  //discard();
651 
652  if (!testConnection())
653  continue;
654 
655  if (!testIntConv())
656  continue;
657 
658  break;
659  }
660  if (tries == 0)
661  abort("Verbindungstest fehlgeschlagen. Neueste Version im Einsatz?");
662  std::cout << "OK" << std::endl;
663 
664 
665  // Gib board info aus
666  std::vector<std::string> info = getBoardInfo();
667  std::cout << PRE << "AVR Firmware Version: " << info[0] << " um " << info[1] << " Uhr (" << info[2] << ")"
668  << std::endl;
669 }
+
void pwmSetValue(uint8_t value)
Definition: b15f.cpp:423
static std::string exec(std::string cmd)
Definition: b15f.cpp:145
-
void setServoPosition(uint16_t pos)
Definition: b15f.cpp:557
-
uint16_t getMem16(volatile uint16_t *adr)
Definition: b15f.cpp:481
+
void analogWrite0(uint16_t port)
Definition: b15f.cpp:288
+
void setServoPosition(uint16_t pos)
Definition: b15f.cpp:581
+
void analogWrite1(uint16_t port)
Definition: b15f.cpp:305
+
uint16_t getMem16(volatile uint16_t *adr)
Definition: b15f.cpp:501
void delay_us(uint16_t us)
Definition: b15f.cpp:132
-
uint8_t digitalRead0(void)
Definition: b15f.cpp:232
-
uint8_t pwmSetFrequency(uint32_t freq)
Definition: b15f.cpp:387
-
void analogSequence(uint8_t channel_a, uint16_t *buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t *buffer_b, uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count)
Definition: b15f.cpp:330
+
uint8_t digitalRead0(void)
Definition: b15f.cpp:237
+
uint8_t pwmSetFrequency(uint32_t freq)
Definition: b15f.cpp:402
+
void digitalWrite0(uint8_t)
Definition: b15f.cpp:205
+
void analogSequence(uint8_t channel_a, uint16_t *buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t *buffer_b, uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count)
Definition: b15f.cpp:345
bool testConnection(void)
Definition: b15f.cpp:56
-
uint8_t readDipSwitch(void)
Definition: b15f.cpp:260
-
uint8_t getRegister(volatile uint8_t *adr)
Definition: b15f.cpp:504
-
uint8_t getMem8(volatile uint8_t *adr)
Definition: b15f.cpp:443
+
uint8_t readDipSwitch(void)
Definition: b15f.cpp:269
+
uint8_t getRegister(volatile uint8_t *adr)
Definition: b15f.cpp:525
+
uint8_t getMem8(volatile uint8_t *adr)
Definition: b15f.cpp:461
void delay_ms(uint16_t ms)
Definition: b15f.cpp:127
static B15F & getInstance(void)
Definition: b15f.cpp:10
Definition: b15f.h:33
@@ -89,39 +93,35 @@ $(function() {
static void abort(std::string msg)
Definition: b15f.cpp:161
void receive(uint8_t *buffer, uint16_t offset, uint8_t len)
Definition: usart.cpp:84
void clearInputBuffer(void)
Definition: usart.cpp:54
-
uint16_t * getInterruptCounterOffset(void)
Definition: b15f.cpp:509
+
uint16_t * getInterruptCounterOffset(void)
Definition: b15f.cpp:530
+
void setMem16(volatile uint16_t *adr, uint16_t val)
Definition: b15f.cpp:480
void clearOutputBuffer(void)
Definition: usart.cpp:61
-
uint16_t analogRead(uint8_t channel)
Definition: b15f.cpp:307
-
bool digitalWrite0(uint8_t)
Definition: b15f.cpp:204
-
const std::string PRE
B15F stdout prefix.
Definition: b15f.h:302
+
uint16_t analogRead(uint8_t channel)
Definition: b15f.cpp:322
+
void activateSelfTestMode(void)
Definition: b15f.cpp:190
+
const std::string PRE
B15F stdout prefix.
Definition: b15f.h:305
void reverse(uint8_t &b)
Definition: b15f.cpp:137
void setBaudrate(uint32_t baudrate)
Definition: usart.cpp:131
-
bool activateSelfTestMode(void)
Definition: b15f.cpp:191
std::vector< std::string > getBoardInfo(void)
Definition: b15f.cpp:95
-
constexpr static uint16_t RECONNECT_TIMEOUT
Time in ms after which a reconnect attempt aborts.
Definition: b15f.h:305
-
bool analogWrite1(uint16_t port)
Definition: b15f.cpp:292
-
bool setMem16(volatile uint16_t *adr, uint16_t val)
Definition: b15f.cpp:461
-
bool digitalWrite1(uint8_t)
Definition: b15f.cpp:218
-
bool pwmSetValue(uint8_t value)
Definition: b15f.cpp:407
+
constexpr static uint16_t RECONNECT_TIMEOUT
Time in ms after which a reconnect attempt aborts.
Definition: b15f.h:308
void discard(void)
Definition: b15f.cpp:33
-
bool setRegister(volatile uint8_t *adr, uint8_t val)
Definition: b15f.cpp:499
-
constexpr static uint8_t MSG_OK
Value to acknowledge a received command.
Definition: b15f.h:303
+
void setRegister(volatile uint8_t *adr, uint8_t val)
Definition: b15f.cpp:520
+
constexpr static uint8_t MSG_OK
Value to acknowledge a received command.
Definition: b15f.h:306
void openDevice(std::string device)
Definition: usart.cpp:9
-
uint8_t digitalRead1(void)
Definition: b15f.cpp:246
+
uint8_t digitalRead1(void)
Definition: b15f.cpp:253
void reconnect(void)
Definition: b15f.cpp:18
-
constexpr static uint32_t BAUDRATE
USART baudrate for communication with the MCU.
Definition: b15f.h:308
-
bool setMem8(volatile uint8_t *adr, uint8_t val)
Definition: b15f.cpp:424
-
static void setAbortHandler(errorhandler_t func)
Definition: b15f.cpp:179
+
constexpr static uint32_t BAUDRATE
USART baudrate for communication with the MCU.
Definition: b15f.h:311
+
static void setAbortHandler(errorhandler_t func)
Definition: b15f.cpp:178
void drop(uint8_t len)
Definition: usart.cpp:114
-
void setServoEnabled(void)
Definition: b15f.cpp:525
-
bool analogWrite0(uint16_t port)
Definition: b15f.cpp:277
-
constexpr static uint8_t RECONNECT_TRIES
Maximum count of reconnect attempts after which the driver stops.
Definition: b15f.h:307
-
void setServoDisabled(void)
Definition: b15f.cpp:541
+
void digitalWrite1(uint8_t)
Definition: b15f.cpp:221
+
void setServoEnabled(void)
Definition: b15f.cpp:547
+
constexpr static uint8_t RECONNECT_TRIES
Maximum count of reconnect attempts after which the driver stops.
Definition: b15f.h:310
+
void setMem8(volatile uint8_t *adr, uint8_t val)
Definition: b15f.cpp:441
+
void setServoDisabled(void)
Definition: b15f.cpp:564
bool testIntConv(void)
Definition: b15f.cpp:75
diff --git a/docs/html/b15f_8h_source.html b/docs/html/b15f_8h_source.html index ed33fac..0b91531 100644 --- a/docs/html/b15f_8h_source.html +++ b/docs/html/b15f_8h_source.html @@ -70,53 +70,54 @@ $(function() {
b15f.h
-
1 #ifndef B15F_H
2 #define B15F_H
3 
4 #include <iostream>
5 #include <bits/stdc++.h>
6 #include <string>
7 #include <fstream>
8 #include <cstdlib>
9 #include <chrono>
10 #include <cstdint>
11 #include <vector>
12 
13 #include <unistd.h>
14 #include <fcntl.h>
15 #include <sys/ioctl.h>
16 #include <termios.h>
17 
18 #include "requests.h"
19 #include "usart.h"
20 #include "driverexception.h"
21 #include "timeoutexception.h"
22 
23 // wichtig für die Register-Zugriffe
24 #define _AVR_IO_H_ 1 // Erzwinge die Inklusion
25 #include "/usr/lib/avr/include/avr/sfr_defs.h"
26 #include "/usr/lib/avr/include/avr/iom1284p.h"
27 
28 typedef std::function<void(std::exception&)> errorhandler_t;
29 
30 
33 class B15F
34 {
35 public:
36 
37  /*************************************
38  * Grundfunktionen des B15F Treibers *
39  *************************************/
40 
45  static B15F& getInstance(void);
46 
51  void reconnect(void);
52 
57  void discard(void);
58 
63  bool testConnection(void);
64 
69  bool testIntConv(void);
70 
75  std::vector<std::string> getBoardInfo(void);
76 
81  void delay_ms(uint16_t ms);
82 
87  void delay_us(uint16_t us);
88 
94  void reverse(uint8_t& b);
95 
100  static std::string exec(std::string cmd);
101 
106  static void abort(std::string msg);
107 
112  static void abort(std::exception& ex);
113 
118  static void setAbortHandler(errorhandler_t func);
119 
120  /*************************************/
121 
122 
123 
124  /*************************
125  * Steuerbefehle für B15 *
126  *************************/
127 
133  bool activateSelfTestMode(void);
134 
140  bool digitalWrite0(uint8_t);
141 
147  bool digitalWrite1(uint8_t);
148 
154  uint8_t digitalRead0(void);
155 
161  uint8_t digitalRead1(void);
162 
168  uint8_t readDipSwitch(void);
169 
175  bool analogWrite0(uint16_t port);
176 
182  bool analogWrite1(uint16_t port);
183 
189  uint16_t analogRead(uint8_t channel);
190 
206  void analogSequence(uint8_t channel_a, uint16_t* buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t* buffer_b, uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count);
207 
217  uint8_t pwmSetFrequency(uint32_t freq);
218 
224  bool pwmSetValue(uint8_t value);
225 
234  bool setMem8(volatile uint8_t* adr, uint8_t val);
235 
242  uint8_t getMem8(volatile uint8_t* adr);
243 
252  bool setMem16(volatile uint16_t* adr, uint16_t val);
253 
260  uint16_t getMem16(volatile uint16_t* adr);
261 
269  bool setRegister(volatile uint8_t* adr, uint8_t val);
270 
276  uint8_t getRegister(volatile uint8_t* adr);
277 
282  uint16_t* getInterruptCounterOffset(void);
283 
287  void setServoEnabled(void);
288 
292  void setServoDisabled(void);
293 
298  void setServoPosition(uint16_t pos);
299 
300  /*************************/
301 
302 
303  // CONSTANTS
304  const std::string PRE = "[B15F] ";
305  constexpr static uint8_t MSG_OK = 0xFF;
306  constexpr static uint8_t MSG_FAIL = 0xFE;
307  constexpr static uint16_t RECONNECT_TIMEOUT = 64;
308  constexpr static uint16_t WDT_TIMEOUT = 15;
309  constexpr static uint8_t RECONNECT_TRIES = 3;
310  constexpr static uint32_t BAUDRATE = 57600;
311 
312 private:
313 
317  B15F(void);
318 
323  void init(void);
324 
329  void assertCode(uint8_t& code, uint8_t expectation) const;
330 
331  USART usart;
332  static B15F* instance;
333  static errorhandler_t errorhandler;
334 };
335 
336 #endif // B15F_H
+
1 #ifndef B15F_H
2 #define B15F_H
3 
4 #include <iostream>
5 #include <bits/stdc++.h>
6 #include <string>
7 #include <fstream>
8 #include <cstdlib>
9 #include <chrono>
10 #include <cstdint>
11 #include <vector>
12 
13 #include <unistd.h>
14 #include <fcntl.h>
15 #include <sys/ioctl.h>
16 #include <termios.h>
17 
18 #include "requests.h"
19 #include "usart.h"
20 #include "driverexception.h"
21 #include "timeoutexception.h"
22 
23 // wichtig für die Register-Zugriffe
24 #define _AVR_IO_H_ 1 // Erzwinge die Inklusion
25 #include "/usr/lib/avr/include/avr/sfr_defs.h"
26 #include "/usr/lib/avr/include/avr/iom1284p.h"
27 
28 typedef std::function<void(std::exception&)> errorhandler_t;
29 
30 
33 class B15F
34 {
35 public:
36 
37  /*************************************
38  * Grundfunktionen des B15F Treibers *
39  *************************************/
40 
45  static B15F& getInstance(void);
46 
51  void reconnect(void);
52 
57  void discard(void);
58 
63  bool testConnection(void);
64 
69  bool testIntConv(void);
70 
75  std::vector<std::string> getBoardInfo(void);
76 
81  void delay_ms(uint16_t ms);
82 
87  void delay_us(uint16_t us);
88 
94  void reverse(uint8_t& b);
95 
100  static std::string exec(std::string cmd);
101 
106  static void abort(std::string msg);
107 
112  static void abort(std::exception& ex);
113 
118  static void setAbortHandler(errorhandler_t func);
119 
120  /*************************************/
121 
122 
123 
124  /*************************
125  * Steuerbefehle für B15 *
126  *************************/
127 
133  void activateSelfTestMode(void);
134 
140  void digitalWrite0(uint8_t);
141 
147  void digitalWrite1(uint8_t);
148 
154  uint8_t digitalRead0(void);
155 
161  uint8_t digitalRead1(void);
162 
168  uint8_t readDipSwitch(void);
169 
175  void analogWrite0(uint16_t port);
176 
182  void analogWrite1(uint16_t port);
183 
189  uint16_t analogRead(uint8_t channel);
190 
206  void analogSequence(uint8_t channel_a, uint16_t* buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t* buffer_b, uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count);
207 
217  uint8_t pwmSetFrequency(uint32_t freq);
218 
224  void pwmSetValue(uint8_t value);
225 
234  void setMem8(volatile uint8_t* adr, uint8_t val);
235 
242  uint8_t getMem8(volatile uint8_t* adr);
243 
252  void setMem16(volatile uint16_t* adr, uint16_t val);
253 
260  uint16_t getMem16(volatile uint16_t* adr);
261 
269  void setRegister(volatile uint8_t* adr, uint8_t val);
270 
276  uint8_t getRegister(volatile uint8_t* adr);
277 
282  uint16_t* getInterruptCounterOffset(void);
283 
288  void setServoEnabled(void);
289 
294  void setServoDisabled(void);
295 
301  void setServoPosition(uint16_t pos);
302 
303  /*************************/
304 
305 
306  // CONSTANTS
307  const std::string PRE = "[B15F] ";
308  constexpr static uint8_t MSG_OK = 0xFF;
309  constexpr static uint8_t MSG_FAIL = 0xFE;
310  constexpr static uint16_t RECONNECT_TIMEOUT = 64;
311  constexpr static uint16_t WDT_TIMEOUT = 15;
312  constexpr static uint8_t RECONNECT_TRIES = 3;
313  constexpr static uint32_t BAUDRATE = 57600;
314 
315 private:
316 
320  B15F(void);
321 
326  void init(void);
327 
332  template<typename CodeType, typename ExpectationType>
333  void assertCode(CodeType& code, ExpectationType expectation) const
334  {
335  if(code != static_cast<CodeType>(expectation))
336  throw DriverException("Ungültige Antwort erhalten: " + std::to_string((int) code) + " (erwartet: " + std::to_string((int) expectation) + ")");
337  }
338 
343  template<size_t RequestLength>
344  void assertRequestLength(uint8_t (&)[RequestLength], uint8_t rq_num)
345  {
346  if(RequestLength != rq_len[rq_num])
347  throw DriverException("Ungültige Request Länge: " + std::to_string(RequestLength) + " (erwartet: " + std::to_string(rq_len[rq_num]) + ")");
348  }
349 
350  USART usart;
351  static B15F* instance;
352  static errorhandler_t errorhandler;
353 };
354 
355 #endif // B15F_H
+
void pwmSetValue(uint8_t value)
Definition: b15f.cpp:423
static std::string exec(std::string cmd)
Definition: b15f.cpp:145
-
constexpr static uint8_t MSG_FAIL
Value to reject a received command.
Definition: b15f.h:304
-
void setServoPosition(uint16_t pos)
Definition: b15f.cpp:557
-
uint16_t getMem16(volatile uint16_t *adr)
Definition: b15f.cpp:481
+
constexpr static uint8_t MSG_FAIL
Value to reject a received command.
Definition: b15f.h:307
+
void analogWrite0(uint16_t port)
Definition: b15f.cpp:288
+
void setServoPosition(uint16_t pos)
Definition: b15f.cpp:581
+
void analogWrite1(uint16_t port)
Definition: b15f.cpp:305
+
uint16_t getMem16(volatile uint16_t *adr)
Definition: b15f.cpp:501
void delay_us(uint16_t us)
Definition: b15f.cpp:132
-
uint8_t digitalRead0(void)
Definition: b15f.cpp:232
-
uint8_t pwmSetFrequency(uint32_t freq)
Definition: b15f.cpp:387
-
void analogSequence(uint8_t channel_a, uint16_t *buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t *buffer_b, uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count)
Definition: b15f.cpp:330
+
uint8_t digitalRead0(void)
Definition: b15f.cpp:237
+
uint8_t pwmSetFrequency(uint32_t freq)
Definition: b15f.cpp:402
+
void digitalWrite0(uint8_t)
Definition: b15f.cpp:205
+
void analogSequence(uint8_t channel_a, uint16_t *buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t *buffer_b, uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count)
Definition: b15f.cpp:345
bool testConnection(void)
Definition: b15f.cpp:56
-
uint8_t readDipSwitch(void)
Definition: b15f.cpp:260
-
uint8_t getRegister(volatile uint8_t *adr)
Definition: b15f.cpp:504
-
uint8_t getMem8(volatile uint8_t *adr)
Definition: b15f.cpp:443
+
uint8_t readDipSwitch(void)
Definition: b15f.cpp:269
+
uint8_t getRegister(volatile uint8_t *adr)
Definition: b15f.cpp:525
+
uint8_t getMem8(volatile uint8_t *adr)
Definition: b15f.cpp:461
void delay_ms(uint16_t ms)
Definition: b15f.cpp:127
static B15F & getInstance(void)
Definition: b15f.cpp:10
Definition: b15f.h:33
static void abort(std::string msg)
Definition: b15f.cpp:161
-
uint16_t * getInterruptCounterOffset(void)
Definition: b15f.cpp:509
+
uint16_t * getInterruptCounterOffset(void)
Definition: b15f.cpp:530
Definition: usart.h:16
-
uint16_t analogRead(uint8_t channel)
Definition: b15f.cpp:307
-
bool digitalWrite0(uint8_t)
Definition: b15f.cpp:204
-
const std::string PRE
B15F stdout prefix.
Definition: b15f.h:302
+
void setMem16(volatile uint16_t *adr, uint16_t val)
Definition: b15f.cpp:480
+
uint16_t analogRead(uint8_t channel)
Definition: b15f.cpp:322
+
void activateSelfTestMode(void)
Definition: b15f.cpp:190
+
const std::string PRE
B15F stdout prefix.
Definition: b15f.h:305
void reverse(uint8_t &b)
Definition: b15f.cpp:137
-
bool activateSelfTestMode(void)
Definition: b15f.cpp:191
std::vector< std::string > getBoardInfo(void)
Definition: b15f.cpp:95
-
constexpr static uint16_t RECONNECT_TIMEOUT
Time in ms after which a reconnect attempt aborts.
Definition: b15f.h:305
-
bool analogWrite1(uint16_t port)
Definition: b15f.cpp:292
-
bool setMem16(volatile uint16_t *adr, uint16_t val)
Definition: b15f.cpp:461
-
bool digitalWrite1(uint8_t)
Definition: b15f.cpp:218
-
bool pwmSetValue(uint8_t value)
Definition: b15f.cpp:407
+
constexpr static uint16_t RECONNECT_TIMEOUT
Time in ms after which a reconnect attempt aborts.
Definition: b15f.h:308
void discard(void)
Definition: b15f.cpp:33
-
bool setRegister(volatile uint8_t *adr, uint8_t val)
Definition: b15f.cpp:499
-
constexpr static uint8_t MSG_OK
Value to acknowledge a received command.
Definition: b15f.h:303
-
uint8_t digitalRead1(void)
Definition: b15f.cpp:246
-
constexpr static uint16_t WDT_TIMEOUT
Time in ms after which the watch dog timer resets the MCU.
Definition: b15f.h:306
+
void setRegister(volatile uint8_t *adr, uint8_t val)
Definition: b15f.cpp:520
+
constexpr static uint8_t MSG_OK
Value to acknowledge a received command.
Definition: b15f.h:306
+
uint8_t digitalRead1(void)
Definition: b15f.cpp:253
+
constexpr static uint16_t WDT_TIMEOUT
Time in ms after which the watch dog timer resets the MCU.
Definition: b15f.h:309
void reconnect(void)
Definition: b15f.cpp:18
-
constexpr static uint32_t BAUDRATE
USART baudrate for communication with the MCU.
Definition: b15f.h:308
-
bool setMem8(volatile uint8_t *adr, uint8_t val)
Definition: b15f.cpp:424
-
static void setAbortHandler(errorhandler_t func)
Definition: b15f.cpp:179
-
void setServoEnabled(void)
Definition: b15f.cpp:525
-
bool analogWrite0(uint16_t port)
Definition: b15f.cpp:277
-
constexpr static uint8_t RECONNECT_TRIES
Maximum count of reconnect attempts after which the driver stops.
Definition: b15f.h:307
-
void setServoDisabled(void)
Definition: b15f.cpp:541
+
constexpr static uint32_t BAUDRATE
USART baudrate for communication with the MCU.
Definition: b15f.h:311
+
static void setAbortHandler(errorhandler_t func)
Definition: b15f.cpp:178
+
void digitalWrite1(uint8_t)
Definition: b15f.cpp:221
+
void setServoEnabled(void)
Definition: b15f.cpp:547
+
constexpr static uint8_t RECONNECT_TRIES
Maximum count of reconnect attempts after which the driver stops.
Definition: b15f.h:310
+
void setMem8(volatile uint8_t *adr, uint8_t val)
Definition: b15f.cpp:441
+
void setServoDisabled(void)
Definition: b15f.cpp:564
bool testIntConv(void)
Definition: b15f.cpp:75
+ diff --git a/docs/html/classB15F-members.html b/docs/html/classB15F-members.html index 30f93e1..7ee494e 100644 --- a/docs/html/classB15F-members.html +++ b/docs/html/classB15F-members.html @@ -71,18 +71,18 @@ $(function() { - + - - + + - - + + @@ -95,16 +95,16 @@ $(function() { - + - - - + + + @@ -114,7 +114,7 @@ $(function() {
abort(std::string msg)B15Fstatic
abort(std::exception &ex)B15Fstatic
activateSelfTestMode(void)B15F
activateSelfTestMode(void)B15F
analogRead(uint8_t channel)B15F
analogSequence(uint8_t channel_a, uint16_t *buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t *buffer_b, uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count)B15F
analogWrite0(uint16_t port)B15F
analogWrite1(uint16_t port)B15F
analogWrite0(uint16_t port)B15F
analogWrite1(uint16_t port)B15F
BAUDRATEB15Fstatic
delay_ms(uint16_t ms)B15F
delay_us(uint16_t us)B15F
digitalRead0(void)B15F
digitalRead1(void)B15F
digitalWrite0(uint8_t)B15F
digitalWrite1(uint8_t)B15F
digitalWrite0(uint8_t)B15F
digitalWrite1(uint8_t)B15F
discard(void)B15F
exec(std::string cmd)B15Fstatic
getBoardInfo(void)B15F
MSG_OKB15Fstatic
PREB15F
pwmSetFrequency(uint32_t freq)B15F
pwmSetValue(uint8_t value)B15F
pwmSetValue(uint8_t value)B15F
readDipSwitch(void)B15F
reconnect(void)B15F
RECONNECT_TIMEOUTB15Fstatic
RECONNECT_TRIESB15Fstatic
reverse(uint8_t &b)B15F
setAbortHandler(errorhandler_t func)B15Fstatic
setMem16(volatile uint16_t *adr, uint16_t val)B15F
setMem8(volatile uint8_t *adr, uint8_t val)B15F
setRegister(volatile uint8_t *adr, uint8_t val)B15F
setMem16(volatile uint16_t *adr, uint16_t val)B15F
setMem8(volatile uint8_t *adr, uint8_t val)B15F
setRegister(volatile uint8_t *adr, uint8_t val)B15F
setServoDisabled(void)B15F
setServoEnabled(void)B15F
setServoPosition(uint16_t pos)B15F
diff --git a/docs/html/classB15F.html b/docs/html/classB15F.html index 54c9ff3..71f654b 100644 --- a/docs/html/classB15F.html +++ b/docs/html/classB15F.html @@ -93,40 +93,40 @@ Public Member Functions   void reverse (uint8_t &b)   -bool activateSelfTestMode (void) -  -bool digitalWrite0 (uint8_t) -  -bool digitalWrite1 (uint8_t) -  +void activateSelfTestMode (void) +  +void digitalWrite0 (uint8_t) +  +void digitalWrite1 (uint8_t) +  uint8_t digitalRead0 (void)   uint8_t digitalRead1 (void)   uint8_t readDipSwitch (void)   -bool analogWrite0 (uint16_t port) -  -bool analogWrite1 (uint16_t port) -  +void analogWrite0 (uint16_t port) +  +void analogWrite1 (uint16_t port) +  uint16_t analogRead (uint8_t channel)   void analogSequence (uint8_t channel_a, uint16_t *buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t *buffer_b, uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count)   uint8_t pwmSetFrequency (uint32_t freq)   -bool pwmSetValue (uint8_t value) -  -bool setMem8 (volatile uint8_t *adr, uint8_t val) -  +void pwmSetValue (uint8_t value) +  +void setMem8 (volatile uint8_t *adr, uint8_t val) +  uint8_t getMem8 (volatile uint8_t *adr)   -bool setMem16 (volatile uint16_t *adr, uint16_t val) -  +void setMem16 (volatile uint16_t *adr, uint16_t val) +  uint16_t getMem16 (volatile uint16_t *adr)   -bool setRegister (volatile uint8_t *adr, uint8_t val) -  +void setRegister (volatile uint8_t *adr, uint8_t val) +  uint8_t getRegister (volatile uint8_t *adr)   uint16_t * getInterruptCounterOffset (void) @@ -258,14 +258,14 @@ constexpr static uint32_t  - -

◆ activateSelfTestMode()

+ +

◆ activateSelfTestMode()

- + @@ -280,7 +280,7 @@ constexpr static uint32_t  diff --git a/docs/html/classUSARTException-members.html b/docs/html/classUSARTException-members.html index 7632459..fe0ce1b 100644 --- a/docs/html/classUSARTException-members.html +++ b/docs/html/classUSARTException-members.html @@ -77,7 +77,7 @@ $(function() {
bool B15F::activateSelfTestMode void B15F::activateSelfTestMode ( void  ) -

Definition at line 191 of file b15f.cpp.

+

Definition at line 190 of file b15f.cpp.

@@ -312,7 +312,7 @@ constexpr static uint32_t 
-

Definition at line 307 of file b15f.cpp.

+

Definition at line 322 of file b15f.cpp.

@@ -404,18 +404,18 @@ constexpr static uint32_t 
-

Definition at line 330 of file b15f.cpp.

+

Definition at line 345 of file b15f.cpp.

- -

◆ analogWrite0()

+ +

◆ analogWrite0()

- + @@ -436,18 +436,18 @@ constexpr static uint32_t 
bool B15F::analogWrite0 void B15F::analogWrite0 ( uint16_t  port) -

Definition at line 277 of file b15f.cpp.

+

Definition at line 288 of file b15f.cpp.

- -

◆ analogWrite1()

+ +

◆ analogWrite1()

- + @@ -468,7 +468,7 @@ constexpr static uint32_t  diff --git a/docs/html/classTimeoutException-members.html b/docs/html/classTimeoutException-members.html index 96b0f51..622abcb 100644 --- a/docs/html/classTimeoutException-members.html +++ b/docs/html/classTimeoutException-members.html @@ -77,7 +77,7 @@ $(function() {
bool B15F::analogWrite1 void B15F::analogWrite1 ( uint16_t  port) -

Definition at line 292 of file b15f.cpp.

+

Definition at line 305 of file b15f.cpp.

@@ -547,7 +547,7 @@ constexpr static uint32_t 
-

Definition at line 232 of file b15f.cpp.

+

Definition at line 237 of file b15f.cpp.

@@ -574,18 +574,18 @@ constexpr static uint32_t 
-

Definition at line 246 of file b15f.cpp.

+

Definition at line 253 of file b15f.cpp.

- -

◆ digitalWrite0()

+ +

◆ digitalWrite0()

- + @@ -606,18 +606,18 @@ constexpr static uint32_t < diff --git a/docs/html/classPlottyFile-members.html b/docs/html/classPlottyFile-members.html index a5193ac..b797b9b 100644 --- a/docs/html/classPlottyFile-members.html +++ b/docs/html/classPlottyFile-members.html @@ -100,7 +100,7 @@ $(function() {
bool B15F::digitalWrite0 void B15F::digitalWrite0 ( uint8_t  port) -

Definition at line 204 of file b15f.cpp.

+

Definition at line 205 of file b15f.cpp.

- -

◆ digitalWrite1()

+ +

◆ digitalWrite1()

- + @@ -638,7 +638,7 @@ constexpr static uint32_t  diff --git a/docs/html/classDriverException-members.html b/docs/html/classDriverException-members.html index 1b0ad3f..791afe8 100644 --- a/docs/html/classDriverException-members.html +++ b/docs/html/classDriverException-members.html @@ -77,7 +77,7 @@ $(function() {
bool B15F::digitalWrite1 void B15F::digitalWrite1 ( uint8_t  port) -

Definition at line 218 of file b15f.cpp.

+

Definition at line 221 of file b15f.cpp.

@@ -779,7 +779,7 @@ constexpr static uint32_t 
@@ -806,7 +806,7 @@ constexpr static uint32_t 
Returns
Wert der Speicherzelle
-

Definition at line 481 of file b15f.cpp.

+

Definition at line 501 of file b15f.cpp.

@@ -833,7 +833,7 @@ constexpr static uint32_t 
Returns
Wert der Speicherzelle
-

Definition at line 443 of file b15f.cpp.

+

Definition at line 461 of file b15f.cpp.

@@ -860,7 +860,7 @@ constexpr static uint32_t 
Returns
Wert des Registers
-

Definition at line 504 of file b15f.cpp.

+

Definition at line 525 of file b15f.cpp.

@@ -893,18 +893,18 @@ constexpr static uint32_t 
-

Definition at line 387 of file b15f.cpp.

+

Definition at line 402 of file b15f.cpp.

- -

◆ pwmSetValue()

+ +

◆ pwmSetValue()

- + @@ -925,7 +925,7 @@ constexpr static uint32_t 
bool B15F::pwmSetValue void B15F::pwmSetValue ( uint8_t  value) -

Definition at line 407 of file b15f.cpp.

+

Definition at line 423 of file b15f.cpp.

@@ -952,7 +952,7 @@ constexpr static uint32_t 
-

Definition at line 260 of file b15f.cpp.

+

Definition at line 269 of file b15f.cpp.

@@ -1038,18 +1038,18 @@ constexpr static uint32_t 
-

Definition at line 179 of file b15f.cpp.

+

Definition at line 178 of file b15f.cpp.

- -

◆ setMem16()

+ +

◆ setMem16()

- + @@ -1074,20 +1074,25 @@ constexpr static uint32_t 
bool B15F::setMem16 void B15F::setMem16 ( volatile uint16_t *  adr, -
Returns
true, falls Vorgang erfolgreich
+
Exceptions
+ + +
DriverException
+
+
-

Definition at line 461 of file b15f.cpp.

+

Definition at line 480 of file b15f.cpp.

- -

◆ setMem8()

+ +

◆ setMem8()

- + @@ -1114,18 +1119,18 @@ constexpr static uint32_t 
bool B15F::setMem8 void B15F::setMem8 ( volatile uint8_t *  adr,
Returns
true, falls Vorgang erfolgreich
-

Definition at line 424 of file b15f.cpp.

+

Definition at line 441 of file b15f.cpp.

- -

◆ setRegister()

+ +

◆ setRegister()

- + @@ -1143,16 +1148,21 @@ constexpr static uint32_t 
bool B15F::setRegister void B15F::setRegister ( volatile uint8_t *  adr,
-

Diese Funktion ist ein Alias für setMem8(). Wichtig: bei einer falschen Adresse kann das Board 15 ernsthaften Schaden nehmen!

Parameters
+

Diese Funktion ist ein Alias für setMem8(). Wichtig: bei einer falschen Adresse kann das Board 15 ernsthaften Schaden nehmen!

Parameters
adrSpeicheradresse
valNeuer Wert für das Register
-
Returns
true, falls Vorgang erfolgreich
+
Exceptions
+ + +
DriverException
+
+
-

Definition at line 499 of file b15f.cpp.

+

Definition at line 520 of file b15f.cpp.

@@ -1171,9 +1181,14 @@ constexpr static uint32_t 
-

Deaktiviert das Servo Signal an PB2.

+

Deaktiviert das Servo Signal an PB2.

Exceptions
+ + +
DriverException
+
+
-

Definition at line 541 of file b15f.cpp.

+

Definition at line 564 of file b15f.cpp.

@@ -1192,9 +1207,14 @@ constexpr static uint32_t 
-

Aktiviert das Servo Signal an PB2 und Initialisiert es mit 1,5ms Pulselänge.

+

Aktiviert das Servo Signal an PB2 und Initialisiert es mit 1,5ms Pulselänge.

Exceptions
+ + +
DriverException
+
+
-

Definition at line 525 of file b15f.cpp.

+

Definition at line 547 of file b15f.cpp.

@@ -1219,8 +1239,14 @@ constexpr static uint32_t 
+
Exceptions
+ + +
DriverException
+
+
-

Definition at line 557 of file b15f.cpp.

+

Definition at line 581 of file b15f.cpp.

@@ -1283,7 +1309,7 @@ constexpr static uint32_t 
diff --git a/docs/html/classDot-members.html b/docs/html/classDot-members.html index 6285a70..9c7e094 100644 --- a/docs/html/classDot-members.html +++ b/docs/html/classDot-members.html @@ -76,7 +76,7 @@ $(function() {
diff --git a/docs/html/classDot.html b/docs/html/classDot.html index e21180c..7d1744d 100644 --- a/docs/html/classDot.html +++ b/docs/html/classDot.html @@ -196,7 +196,7 @@ Public Member Functions
diff --git a/docs/html/classDriverException.html b/docs/html/classDriverException.html index da5f7fd..4bda33a 100644 --- a/docs/html/classDriverException.html +++ b/docs/html/classDriverException.html @@ -109,7 +109,7 @@ std::string 
msg_
diff --git a/docs/html/classPlottyFile.html b/docs/html/classPlottyFile.html index 9bf07c1..3723d9d 100644 --- a/docs/html/classPlottyFile.html +++ b/docs/html/classPlottyFile.html @@ -811,7 +811,7 @@ Public Member Functions
diff --git a/docs/html/classTimeoutException.html b/docs/html/classTimeoutException.html index 406e0b7..30d3af2 100644 --- a/docs/html/classTimeoutException.html +++ b/docs/html/classTimeoutException.html @@ -239,7 +239,7 @@ std::string 
diff --git a/docs/html/classUSART-members.html b/docs/html/classUSART-members.html index 50e81a6..8a02d38 100644 --- a/docs/html/classUSART-members.html +++ b/docs/html/classUSART-members.html @@ -86,7 +86,7 @@ $(function() {
diff --git a/docs/html/classUSART.html b/docs/html/classUSART.html index f09852d..468f0b7 100644 --- a/docs/html/classUSART.html +++ b/docs/html/classUSART.html @@ -523,7 +523,7 @@ Public Member Functions
diff --git a/docs/html/classUSARTException.html b/docs/html/classUSARTException.html index 58bd757..f863fa3 100644 --- a/docs/html/classUSARTException.html +++ b/docs/html/classUSARTException.html @@ -239,7 +239,7 @@ std::string  diff --git a/docs/html/classView-members.html b/docs/html/classView-members.html index ebf9690..d978970 100644 --- a/docs/html/classView-members.html +++ b/docs/html/classView-members.html @@ -89,7 +89,7 @@ $(function() {
diff --git a/docs/html/classView.html b/docs/html/classView.html index a59ad9a..840003d 100644 --- a/docs/html/classView.html +++ b/docs/html/classView.html @@ -157,7 +157,7 @@ constexpr static int KEY_E diff --git a/docs/html/classViewInfo-members.html b/docs/html/classViewInfo-members.html index d1f1586..904ec53 100644 --- a/docs/html/classViewInfo-members.html +++ b/docs/html/classViewInfo-members.html @@ -99,7 +99,7 @@ $(function() { diff --git a/docs/html/classViewInfo.html b/docs/html/classViewInfo.html index 1c4f46c..6f4053a 100644 --- a/docs/html/classViewInfo.html +++ b/docs/html/classViewInfo.html @@ -185,7 +185,7 @@ static std::vector< std::string >  diff --git a/docs/html/classViewMonitor-members.html b/docs/html/classViewMonitor-members.html index 947d864..e1cafbe 100644 --- a/docs/html/classViewMonitor-members.html +++ b/docs/html/classViewMonitor-members.html @@ -103,7 +103,7 @@ $(function() { diff --git a/docs/html/classViewMonitor.html b/docs/html/classViewMonitor.html index 6025dd1..99a2f95 100644 --- a/docs/html/classViewMonitor.html +++ b/docs/html/classViewMonitor.html @@ -197,7 +197,7 @@ constexpr static int KEY_E diff --git a/docs/html/classViewPromt-members.html b/docs/html/classViewPromt-members.html index 34dac90..010f14d 100644 --- a/docs/html/classViewPromt-members.html +++ b/docs/html/classViewPromt-members.html @@ -105,7 +105,7 @@ $(function() { diff --git a/docs/html/classViewPromt.html b/docs/html/classViewPromt.html index 1f49b31..b5712d9 100644 --- a/docs/html/classViewPromt.html +++ b/docs/html/classViewPromt.html @@ -205,7 +205,7 @@ static std::vector< std::string >  diff --git a/docs/html/classViewSelection-members.html b/docs/html/classViewSelection-members.html index 1d4122a..373b6f6 100644 --- a/docs/html/classViewSelection-members.html +++ b/docs/html/classViewSelection-members.html @@ -94,7 +94,7 @@ $(function() { diff --git a/docs/html/classViewSelection.html b/docs/html/classViewSelection.html index 9932a23..b716df5 100644 --- a/docs/html/classViewSelection.html +++ b/docs/html/classViewSelection.html @@ -172,7 +172,7 @@ static std::vector< std::string >  diff --git a/docs/html/classes.html b/docs/html/classes.html index c6badc6..8c46379 100644 --- a/docs/html/classes.html +++ b/docs/html/classes.html @@ -105,7 +105,7 @@ $(function() { diff --git a/docs/html/cli_8cpp_source.html b/docs/html/cli_8cpp_source.html index 03914a2..eb94b8a 100644 --- a/docs/html/cli_8cpp_source.html +++ b/docs/html/cli_8cpp_source.html @@ -66,13 +66,13 @@ $(function() {
cli.cpp
-
1 //#define B15F_CLI_DEBUG
2 
3 #include <stdio.h>
4 #include <ncurses.h> // sudo apt-get install libncurses5-dev
5 #include <vector>
6 #include <string>
7 #include <iostream>
8 #include <signal.h>
9 #include <sys/ioctl.h>
10 #include <unistd.h>
11 #include <signal.h>
12 #include <future>
13 #include <thread>
14 #include <chrono>
15 #include "drv/b15f.h"
16 #include "ui/ui.h"
17 #include "ui/view_selection.h"
18 #include "ui/view_info.h"
19 #include "ui/view_monitor.h"
20 #include "ui/view_promt.h"
21 
22 constexpr uint8_t WIN_WIDTH = 80;
23 constexpr uint8_t WIN_HEIGHT = 24;
24 
25 volatile int win_changed_cooldown = 0;
26 volatile bool t_refresh_active = false;
27 
28 void signal_handler(int signal)
29 {
30  if(signal == SIGWINCH)
31  {
32  win_changed_cooldown = 10; // 100ms
33 
34  if (!t_refresh_active)
35  {
36  if(t_refresh.joinable())
37  t_refresh.join();
38  t_refresh_active = true;
39  t_refresh = std::thread([]()
40  {
41 
42  while(win_changed_cooldown--)
43  std::this_thread::sleep_for(std::chrono::milliseconds(10));
44 
45  t_refresh_active = false;
46 
47  if(win_stack.size())
48  win_stack.back()->repaint();
49 
50  });
51  }
52 
53  }
54  else if(signal == SIGINT)
55  {
56  cleanup();
57  std::cout << "SIGINT - Abbruch." << std::endl;
58  exit(EXIT_FAILURE);
59  }
60 }
61 
62 void abort_handler(std::exception& ex)
63 {
64  ViewInfo* view = new ViewInfo();
65  view->setTitle("Fehler");
66  std::string msg(ex.what());
67  msg += "\n\nBeende in 5 Sekunden.";
68  view->setText(msg.c_str());
69  view->setLabelClose("");
70  view->repaint();
71 
72  std::this_thread::sleep_for(std::chrono::milliseconds(5000));
73 
74  cleanup();
75  std::cerr << std::endl << "*** EXCEPTION ***" << std::endl << ex.what() << std::endl;
76  exit(EXIT_FAILURE);
77 }
78 
79 void init()
80 {
81  // init b15 driver
83 #ifndef B15F_CLI_DEBUG
84  std::cout << std::endl << "Starte in 3s ..." << std::endl;
85  sleep(3);
86 #endif
87  B15F::setAbortHandler(&abort_handler);
88 
89  // init all ncurses stuff
90  initscr();
91  start_color();
92  curs_set(0); // 0: invisible, 1: normal, 2: very visible
93  clear();
94  noecho();
95  cbreak(); // Line buffering disabled. pass on everything
96  mousemask(ALL_MOUSE_EVENTS, NULL);
97 
98  // connect signals to handler
99  signal(SIGWINCH, signal_handler);
100  signal(SIGINT, signal_handler);
101 
102  // set view context
103  View::setWinContext(newwin(WIN_HEIGHT, WIN_WIDTH, 0, 0));
104 }
105 
106 
107 int main()
108 {
109  init();
110 
111  int exit_code = EXIT_SUCCESS;
112 
113  show_main(0);
114 
115  cleanup();
116 
117  return exit_code;
118 }
+
1 //#define B15F_CLI_DEBUG
2 
3 #include <stdio.h>
4 #include <ncurses.h> // sudo apt-get install libncurses5-dev
5 #include <vector>
6 #include <string>
7 #include <iostream>
8 #include <signal.h>
9 #include <sys/ioctl.h>
10 #include <unistd.h>
11 #include <signal.h>
12 #include <future>
13 #include <thread>
14 #include <chrono>
15 #include "drv/b15f.h"
16 #include "ui/ui.h"
17 #include "ui/view_selection.h"
18 #include "ui/view_info.h"
19 #include "ui/view_monitor.h"
20 #include "ui/view_promt.h"
21 
22 constexpr uint8_t WIN_WIDTH = 80;
23 constexpr uint8_t WIN_HEIGHT = 24;
24 
25 volatile int win_changed_cooldown = 0;
26 volatile bool t_refresh_active = false;
27 
28 void signal_handler(int signal)
29 {
30  if(signal == SIGWINCH)
31  {
32  win_changed_cooldown = 10; // 100ms
33 
34  if (!t_refresh_active)
35  {
36  if(t_refresh.joinable())
37  t_refresh.join();
38  t_refresh_active = true;
39  t_refresh = std::thread([]()
40  {
41 
42  while(win_changed_cooldown--)
43  std::this_thread::sleep_for(std::chrono::milliseconds(10));
44 
45  t_refresh_active = false;
46 
47  if(win_stack.size())
48  win_stack.back()->repaint();
49 
50  });
51  }
52 
53  }
54  else if(signal == SIGINT)
55  {
56  cleanup();
57  std::cout << "SIGINT - Abbruch." << std::endl;
58  exit(EXIT_FAILURE);
59  }
60 }
61 
62 void abort_handler(std::exception& ex)
63 {
64  ViewInfo* view = new ViewInfo();
65  view->setTitle("Fehler");
66  std::string msg(ex.what());
67  msg += "\n\nBeende in 5 Sekunden.";
68  view->setText(msg.c_str());
69  view->setLabelClose("");
70  view->repaint();
71 
72  std::this_thread::sleep_for(std::chrono::milliseconds(5000));
73 
74  cleanup();
75  std::cerr << std::endl << "*** EXCEPTION ***" << std::endl << ex.what() << std::endl;
76  exit(EXIT_FAILURE);
77 }
78 
79 void init()
80 {
81  // init b15 driver
83 #ifndef B15F_CLI_DEBUG
84  std::cout << std::endl << "Starte in 3s ..." << std::endl;
85  sleep(3);
86 #endif
87 
88  // init all ncurses stuff
89  initscr();
90  start_color();
91  curs_set(0); // 0: invisible, 1: normal, 2: very visible
92  clear();
93  noecho();
94  cbreak(); // Line buffering disabled. pass on everything
95  mousemask(ALL_MOUSE_EVENTS, NULL);
96 
97  // connect signals to handler
98  signal(SIGWINCH, signal_handler);
99  signal(SIGINT, signal_handler);
100 
101  // set view context
102  View::setWinContext(newwin(WIN_HEIGHT, WIN_WIDTH, 0, 0));
103 
104  // set graphical error handler
105  B15F::setAbortHandler(&abort_handler);
106 }
107 
108 
109 int main()
110 {
111  init();
112 
113  int exit_code = EXIT_SUCCESS;
114 
115  show_main(0);
116 
117  cleanup();
118 
119  return exit_code;
120 }
static B15F & getInstance(void)
Definition: b15f.cpp:10
-
static void setAbortHandler(errorhandler_t func)
Definition: b15f.cpp:179
+
static void setAbortHandler(errorhandler_t func)
Definition: b15f.cpp:178
diff --git a/docs/html/dir_1788f8309b1a812dcb800a185471cf6c.html b/docs/html/dir_1788f8309b1a812dcb800a185471cf6c.html index 7675978..add7c75 100644 --- a/docs/html/dir_1788f8309b1a812dcb800a185471cf6c.html +++ b/docs/html/dir_1788f8309b1a812dcb800a185471cf6c.html @@ -73,7 +73,7 @@ $(function() { diff --git a/docs/html/dir_587c94d866dbb2f408f78cf41f9b2f8d.html b/docs/html/dir_587c94d866dbb2f408f78cf41f9b2f8d.html index 6096546..babfe9e 100644 --- a/docs/html/dir_587c94d866dbb2f408f78cf41f9b2f8d.html +++ b/docs/html/dir_587c94d866dbb2f408f78cf41f9b2f8d.html @@ -73,7 +73,7 @@ $(function() { diff --git a/docs/html/dot_8cpp_source.html b/docs/html/dot_8cpp_source.html index 28bfdc9..cbf6c54 100644 --- a/docs/html/dot_8cpp_source.html +++ b/docs/html/dot_8cpp_source.html @@ -77,7 +77,7 @@ $(function() {
Dot(uint16_t x, uint16_t y, uint8_t curve)
Definition: dot.cpp:3
diff --git a/docs/html/dot_8h_source.html b/docs/html/dot_8h_source.html index c17b8a2..94edb8f 100644 --- a/docs/html/dot_8h_source.html +++ b/docs/html/dot_8h_source.html @@ -78,7 +78,7 @@ $(function() {
Dot(uint16_t x, uint16_t y, uint8_t curve)
Definition: dot.cpp:3
diff --git a/docs/html/driverexception_8h_source.html b/docs/html/driverexception_8h_source.html index 91e2dd4..836a526 100644 --- a/docs/html/driverexception_8h_source.html +++ b/docs/html/driverexception_8h_source.html @@ -74,7 +74,7 @@ $(function() { diff --git a/docs/html/files.html b/docs/html/files.html index 5568733..230abed 100644 --- a/docs/html/files.html +++ b/docs/html/files.html @@ -100,7 +100,7 @@ $(function() { diff --git a/docs/html/functions.html b/docs/html/functions.html index 6b31be5..c16a9de 100644 --- a/docs/html/functions.html +++ b/docs/html/functions.html @@ -69,7 +69,7 @@ $(function() { : B15F
  • activateSelfTestMode() -: B15F +: B15F
  • addDot() : PlottyFile @@ -81,10 +81,10 @@ $(function() { : B15F
  • analogWrite0() -: B15F +: B15F
  • analogWrite1() -: B15F +: B15F
  • @@ -123,10 +123,10 @@ $(function() { : B15F
  • digitalWrite0() -: B15F +: B15F
  • digitalWrite1() -: B15F +: B15F
  • discard() : B15F @@ -256,7 +256,7 @@ $(function() { : B15F
  • pwmSetValue() -: B15F +: B15F
  • @@ -303,10 +303,10 @@ $(function() { : PlottyFile
  • setMem16() -: B15F +: B15F
  • setMem8() -: B15F +: B15F
  • setParaFirstCurve() : PlottyFile @@ -324,7 +324,7 @@ $(function() { : PlottyFile
  • setRegister() -: B15F +: B15F
  • setServoDisabled() : B15F @@ -407,7 +407,7 @@ $(function() { diff --git a/docs/html/functions_func.html b/docs/html/functions_func.html index a2bc51b..ad264b8 100644 --- a/docs/html/functions_func.html +++ b/docs/html/functions_func.html @@ -69,7 +69,7 @@ $(function() { : B15F
  • activateSelfTestMode() -: B15F +: B15F
  • addDot() : PlottyFile @@ -81,10 +81,10 @@ $(function() { : B15F
  • analogWrite0() -: B15F +: B15F
  • analogWrite1() -: B15F +: B15F
  • @@ -116,10 +116,10 @@ $(function() { : B15F
  • digitalWrite0() -: B15F +: B15F
  • digitalWrite1() -: B15F +: B15F
  • discard() : B15F @@ -232,7 +232,7 @@ $(function() { : B15F
  • pwmSetValue() -: B15F +: B15F
  • @@ -273,10 +273,10 @@ $(function() { : PlottyFile
  • setMem16() -: B15F +: B15F
  • setMem8() -: B15F +: B15F
  • setParaFirstCurve() : PlottyFile @@ -294,7 +294,7 @@ $(function() { : PlottyFile
  • setRegister() -: B15F +: B15F
  • setServoDisabled() : B15F @@ -374,7 +374,7 @@ $(function() { diff --git a/docs/html/functions_vars.html b/docs/html/functions_vars.html index d5084ed..93c6c7e 100644 --- a/docs/html/functions_vars.html +++ b/docs/html/functions_vars.html @@ -92,7 +92,7 @@ $(function() { diff --git a/docs/html/hierarchy.html b/docs/html/hierarchy.html index a6d5f95..94b0aa1 100644 --- a/docs/html/hierarchy.html +++ b/docs/html/hierarchy.html @@ -86,7 +86,7 @@ $(function() { diff --git a/docs/html/index.html b/docs/html/index.html index f976dfa..db64c40 100644 --- a/docs/html/index.html +++ b/docs/html/index.html @@ -170,7 +170,7 @@ Dabei gehören Punkte mit dem gleichen Index für curve (uint8_ diff --git a/docs/html/plottyfile_8cpp_source.html b/docs/html/plottyfile_8cpp_source.html index 0614716..4c1c5af 100644 --- a/docs/html/plottyfile_8cpp_source.html +++ b/docs/html/plottyfile_8cpp_source.html @@ -101,7 +101,7 @@ $(function() {
    std::string getUnitX(void) const
    Definition: plottyfile.cpp:105
    diff --git a/docs/html/plottyfile_8h_source.html b/docs/html/plottyfile_8h_source.html index 926c153..ca366eb 100644 --- a/docs/html/plottyfile_8h_source.html +++ b/docs/html/plottyfile_8h_source.html @@ -102,7 +102,7 @@ $(function() {
    std::string getUnitX(void) const
    Definition: plottyfile.cpp:105
    diff --git a/docs/html/requests_8h_source.html b/docs/html/requests_8h_source.html index 1f1bcdd..5af1eb3 100644 --- a/docs/html/requests_8h_source.html +++ b/docs/html/requests_8h_source.html @@ -73,7 +73,7 @@ $(function() {
    1 #ifndef REQUESTS_H
    2 #define REQUESTS_H
    3 
    4 constexpr static uint8_t RQ_DISCARD = 0;
    5 constexpr static uint8_t RQ_TEST = 1;
    6 constexpr static uint8_t RQ_INFO = 2;
    7 constexpr static uint8_t RQ_INT_TEST = 3;
    8 constexpr static uint8_t RQ_SELF_TEST = 4;
    9 constexpr static uint8_t RQ_DIGITAL_WRITE_0 = 5;
    10 constexpr static uint8_t RQ_DIGITAL_WRITE_1 = 6;
    11 constexpr static uint8_t RQ_DIGITAL_READ_0 = 7;
    12 constexpr static uint8_t RQ_DIGITAL_READ_1 = 8;
    13 constexpr static uint8_t RQ_READ_DIP_SWITCH = 9;
    14 constexpr static uint8_t RQ_ANALOG_WRITE_0 = 10;
    15 constexpr static uint8_t RQ_ANALOG_WRITE_1 = 11;
    16 constexpr static uint8_t RQ_ANALOG_READ = 12;
    17 constexpr static uint8_t RQ_ADC_DAC_STROKE = 13;
    18 constexpr static uint8_t RQ_PWM_SET_FREQ = 14;
    19 constexpr static uint8_t RQ_PWM_SET_VALUE = 15;
    20 constexpr static uint8_t RQ_SET_MEM_8 = 16;
    21 constexpr static uint8_t RQ_GET_MEM_8 = 17;
    22 constexpr static uint8_t RQ_SET_MEM_16 = 18;
    23 constexpr static uint8_t RQ_GET_MEM_16 = 19;
    24 constexpr static uint8_t RQ_COUNTER_OFFSET = 20;
    25 constexpr static uint8_t RQ_SERVO_ENABLE = 21;
    26 constexpr static uint8_t RQ_SERVO_DISABLE = 22;
    27 constexpr static uint8_t RQ_SERVO_SET_POS = 23;
    28 
    29 uint8_t const rq_len[] =
    30 {
    31  1 /* RQ_DISCARD */,
    32  1 /* RQ_TEST */ + 1 /* test byte */,
    33  1 /* RQ_INFO */,
    34  1 /* RQ_INT_TEST */ + 1 /* test int high low */ + 1 /* test int high high */,
    35  1 /* RQ_SELF_TEST */,
    36  1 /* RQ_DIGITAL_WRITE_0 */ + 1 /* port value */,
    37  1 /* RQ_DIGITAL_WRITE_1 */ + 1 /* port value */,
    38  1 /* RQ_DIGITAL_READ_0 */,
    39  1 /* RQ_DIGITAL_READ_1 */,
    40  1 /* RQ_READ_DIP_SWITCH */,
    41  1 /* RQ_ANALOG_WRITE_0 */ + 1 /* test int high low */ + 1 /* test int high high */,
    42  1 /* RQ_ANALOG_WRITE_1 */ + 1 /* test int high low */ + 1 /* test int high high */,
    43  1 /* RQ_ANALOG_READ */ + 1 /* adc channel */,
    44  1 /* RQ_ADC_DAC_STROKE */ + 1 /* channel a */ + 1 /* channel b */ + 1 /* start low */ + 1 /* start high */ + 1 /* delta low */ + 1 /* delta high */ + 1 /* count low */ + 1 /* count high */,
    45  1 /* RQ_PWM_SET_FREQ */ + 1 /* freq low low */ + 1 /* freq low high */ + 1 /* freq high low */ + 1 /* freq high high */,
    46  1 /* RQ_PWM_SET_VALUE */ + 1 /* pwm value */,
    47  1 /* RQ_SET_MEM_8 */ + 1 /* memory address low */ + 1 /* memory address high */ + 1 /* memory value (8-bit) */,
    48  1 /* RQ_GET_MEM_8 */ + 1 /* memory address low */ + 1 /* memory address high */,
    49  1 /* RQ_SET_MEM_16 */ + 1 /* memory address low */ + 1 /* memory address high */ + 1 /* memory value low */ + 1 /* memory value high */,
    50  1 /* RQ_GET_MEM_16 */ + 1 /* memory address low */ + 1 /* memory address high */,
    51  1 /* RQ_COUNTER_OFFSET */,
    52  1 /* RQ_SERVO_ENABLE */,
    53  1 /* RQ_SERVO_DISABLE */,
    54  1 /* RQ_SERVO_SET_POS */ + 1 /* pulse length low */ + 1 /* pulse length high */,
    55 };
    56 
    57 #endif // REQUESTS_H
    diff --git a/docs/html/search/all_0.js b/docs/html/search/all_0.js index c4bd927..3d32647 100644 --- a/docs/html/search/all_0.js +++ b/docs/html/search/all_0.js @@ -1,10 +1,10 @@ var searchData= [ ['abort',['abort',['../classB15F.html#a3f09a418f9e3be5d1d750e4515c96f1e',1,'B15F::abort(std::string msg)'],['../classB15F.html#ac962a6a49bddd0e261a8c7d3aded23f8',1,'B15F::abort(std::exception &ex)']]], - ['activateselftestmode',['activateSelfTestMode',['../classB15F.html#ad9bf80ee2485fb5aac9926c6ef0731f1',1,'B15F']]], + ['activateselftestmode',['activateSelfTestMode',['../classB15F.html#aebb9a8bff15d422b62d21fd4d8408c8a',1,'B15F']]], ['adddot',['addDot',['../classPlottyFile.html#ae091e6eaaca16302f17572ac7dec6f7c',1,'PlottyFile::addDot(Dot &dot)'],['../classPlottyFile.html#a80e4b45219b4e9571992edfc28a28568',1,'PlottyFile::addDot(Dot dot)']]], ['analogread',['analogRead',['../classB15F.html#ae0bd1f69751e2dc3c462db9213fc4627',1,'B15F']]], ['analogsequence',['analogSequence',['../classB15F.html#ab82a324426c3063318c6cafb3089ae02',1,'B15F']]], - ['analogwrite0',['analogWrite0',['../classB15F.html#afc55fd590c7fa5c942d100cb60c4b0d3',1,'B15F']]], - ['analogwrite1',['analogWrite1',['../classB15F.html#a7f1becceac744f5cd2ad529748fd836f',1,'B15F']]] + ['analogwrite0',['analogWrite0',['../classB15F.html#a051da899f0883737dd1de1ba6a86f466',1,'B15F']]], + ['analogwrite1',['analogWrite1',['../classB15F.html#aae7bdafb19bf0adf5c7d9d0aff61c81a',1,'B15F']]] ]; diff --git a/docs/html/search/all_3.js b/docs/html/search/all_3.js index 937a08b..8e2286b 100644 --- a/docs/html/search/all_3.js +++ b/docs/html/search/all_3.js @@ -4,8 +4,8 @@ var searchData= ['delay_5fus',['delay_us',['../classB15F.html#adcaac8ae8db3c28eccb499fbd720361f',1,'B15F']]], ['digitalread0',['digitalRead0',['../classB15F.html#ae0df6d423deeb2fd610968bd1c72060e',1,'B15F']]], ['digitalread1',['digitalRead1',['../classB15F.html#afc76b612dd4faeee0ac02a66b65af5f2',1,'B15F']]], - ['digitalwrite0',['digitalWrite0',['../classB15F.html#a13797edea1c50278988373acbd110064',1,'B15F']]], - ['digitalwrite1',['digitalWrite1',['../classB15F.html#aa225e7fc813849634063e071ef25db1b',1,'B15F']]], + ['digitalwrite0',['digitalWrite0',['../classB15F.html#afd2c5753b8a5d323d9cfca77986fe893',1,'B15F']]], + ['digitalwrite1',['digitalWrite1',['../classB15F.html#a8f0d3891ec613a569b0a4309dfe213da',1,'B15F']]], ['discard',['discard',['../classB15F.html#ae4740cd473f40a1a4121dfa66b25e1d5',1,'B15F']]], ['dot',['Dot',['../classDot.html',1,'Dot'],['../classDot.html#ad975f119c0627a928790b3cd5ca6da05',1,'Dot::Dot()']]], ['driverexception',['DriverException',['../classDriverException.html',1,'']]], diff --git a/docs/html/search/all_9.js b/docs/html/search/all_9.js index 1695de2..26e6d28 100644 --- a/docs/html/search/all_9.js +++ b/docs/html/search/all_9.js @@ -3,5 +3,5 @@ var searchData= ['plottyfile',['PlottyFile',['../classPlottyFile.html',1,'']]], ['pre',['PRE',['../classB15F.html#a3b0fc1f85954b2d9c145af4a3af5b1ec',1,'B15F']]], ['pwmsetfrequency',['pwmSetFrequency',['../classB15F.html#ac6f6532bb9550a0632c28b98c157d0a1',1,'B15F']]], - ['pwmsetvalue',['pwmSetValue',['../classB15F.html#af9aad3c0db5d5a8b37219d713e1977ee',1,'B15F']]] + ['pwmsetvalue',['pwmSetValue',['../classB15F.html#aae99d74a945039c365ebd2f995b5546e',1,'B15F']]] ]; diff --git a/docs/html/search/all_b.js b/docs/html/search/all_b.js index 98be5a6..fc8198d 100644 --- a/docs/html/search/all_b.js +++ b/docs/html/search/all_b.js @@ -6,14 +6,14 @@ var searchData= ['setdescx',['setDescX',['../classPlottyFile.html#aa0449c290265d55d6223b19cf0a88b0a',1,'PlottyFile']]], ['setdescy',['setDescY',['../classPlottyFile.html#a38a3a4dfc76bc70523727584bf01d590',1,'PlottyFile']]], ['setfunctiontype',['setFunctionType',['../classPlottyFile.html#a4e5ab1ebb012a5cc1a3d6458a4cd512f',1,'PlottyFile']]], - ['setmem16',['setMem16',['../classB15F.html#ae2dc09141f3300c751b57adacf2bed71',1,'B15F']]], - ['setmem8',['setMem8',['../classB15F.html#a04e52727c1ac7f5e600163c73deb29f2',1,'B15F']]], + ['setmem16',['setMem16',['../classB15F.html#a62ef2ee9bd945d30979939fcffa6759a',1,'B15F']]], + ['setmem8',['setMem8',['../classB15F.html#a65c0eee6b40b6d3ec58b0335fd668503',1,'B15F']]], ['setparafirstcurve',['setParaFirstCurve',['../classPlottyFile.html#aa676414793becb975506f48d6e949dd0',1,'PlottyFile']]], ['setparastepwidth',['setParaStepWidth',['../classPlottyFile.html#a6caebd31e04e2e7081cc007047350355',1,'PlottyFile']]], ['setquadrant',['setQuadrant',['../classPlottyFile.html#a1953ee0d9a87b7353c16139584e9c2ae',1,'PlottyFile']]], ['setrefx',['setRefX',['../classPlottyFile.html#a80c2c2e97a454566f9c1f2c51e1d7f3e',1,'PlottyFile']]], ['setrefy',['setRefY',['../classPlottyFile.html#a3a371228ddcc007e97eebe7cc04dffc2',1,'PlottyFile']]], - ['setregister',['setRegister',['../classB15F.html#ab446ecffab28d4515dfade79a8efc93d',1,'B15F']]], + ['setregister',['setRegister',['../classB15F.html#a47d7b797129d1ee7ebee4d8ae4f0ff93',1,'B15F']]], ['setservodisabled',['setServoDisabled',['../classB15F.html#aad1b3206761c06c7183ae1b8b95b350b',1,'B15F']]], ['setservoenabled',['setServoEnabled',['../classB15F.html#ab23d8c5a0b520b9d12d94a04f90fcfa0',1,'B15F']]], ['setservoposition',['setServoPosition',['../classB15F.html#aa76f289274e5d0be41c5d4a58b52a416',1,'B15F']]], diff --git a/docs/html/search/functions_0.js b/docs/html/search/functions_0.js index c4bd927..3d32647 100644 --- a/docs/html/search/functions_0.js +++ b/docs/html/search/functions_0.js @@ -1,10 +1,10 @@ var searchData= [ ['abort',['abort',['../classB15F.html#a3f09a418f9e3be5d1d750e4515c96f1e',1,'B15F::abort(std::string msg)'],['../classB15F.html#ac962a6a49bddd0e261a8c7d3aded23f8',1,'B15F::abort(std::exception &ex)']]], - ['activateselftestmode',['activateSelfTestMode',['../classB15F.html#ad9bf80ee2485fb5aac9926c6ef0731f1',1,'B15F']]], + ['activateselftestmode',['activateSelfTestMode',['../classB15F.html#aebb9a8bff15d422b62d21fd4d8408c8a',1,'B15F']]], ['adddot',['addDot',['../classPlottyFile.html#ae091e6eaaca16302f17572ac7dec6f7c',1,'PlottyFile::addDot(Dot &dot)'],['../classPlottyFile.html#a80e4b45219b4e9571992edfc28a28568',1,'PlottyFile::addDot(Dot dot)']]], ['analogread',['analogRead',['../classB15F.html#ae0bd1f69751e2dc3c462db9213fc4627',1,'B15F']]], ['analogsequence',['analogSequence',['../classB15F.html#ab82a324426c3063318c6cafb3089ae02',1,'B15F']]], - ['analogwrite0',['analogWrite0',['../classB15F.html#afc55fd590c7fa5c942d100cb60c4b0d3',1,'B15F']]], - ['analogwrite1',['analogWrite1',['../classB15F.html#a7f1becceac744f5cd2ad529748fd836f',1,'B15F']]] + ['analogwrite0',['analogWrite0',['../classB15F.html#a051da899f0883737dd1de1ba6a86f466',1,'B15F']]], + ['analogwrite1',['analogWrite1',['../classB15F.html#aae7bdafb19bf0adf5c7d9d0aff61c81a',1,'B15F']]] ]; diff --git a/docs/html/search/functions_2.js b/docs/html/search/functions_2.js index 06f50ef..098c341 100644 --- a/docs/html/search/functions_2.js +++ b/docs/html/search/functions_2.js @@ -4,8 +4,8 @@ var searchData= ['delay_5fus',['delay_us',['../classB15F.html#adcaac8ae8db3c28eccb499fbd720361f',1,'B15F']]], ['digitalread0',['digitalRead0',['../classB15F.html#ae0df6d423deeb2fd610968bd1c72060e',1,'B15F']]], ['digitalread1',['digitalRead1',['../classB15F.html#afc76b612dd4faeee0ac02a66b65af5f2',1,'B15F']]], - ['digitalwrite0',['digitalWrite0',['../classB15F.html#a13797edea1c50278988373acbd110064',1,'B15F']]], - ['digitalwrite1',['digitalWrite1',['../classB15F.html#aa225e7fc813849634063e071ef25db1b',1,'B15F']]], + ['digitalwrite0',['digitalWrite0',['../classB15F.html#afd2c5753b8a5d323d9cfca77986fe893',1,'B15F']]], + ['digitalwrite1',['digitalWrite1',['../classB15F.html#a8f0d3891ec613a569b0a4309dfe213da',1,'B15F']]], ['discard',['discard',['../classB15F.html#ae4740cd473f40a1a4121dfa66b25e1d5',1,'B15F']]], ['dot',['Dot',['../classDot.html#ad975f119c0627a928790b3cd5ca6da05',1,'Dot']]], ['drop',['drop',['../classUSART.html#a038d00c0b3d8c0c13c3e7eae5dad7813',1,'USART']]] diff --git a/docs/html/search/functions_7.js b/docs/html/search/functions_7.js index b0de2bf..454721f 100644 --- a/docs/html/search/functions_7.js +++ b/docs/html/search/functions_7.js @@ -1,5 +1,5 @@ var searchData= [ ['pwmsetfrequency',['pwmSetFrequency',['../classB15F.html#ac6f6532bb9550a0632c28b98c157d0a1',1,'B15F']]], - ['pwmsetvalue',['pwmSetValue',['../classB15F.html#af9aad3c0db5d5a8b37219d713e1977ee',1,'B15F']]] + ['pwmsetvalue',['pwmSetValue',['../classB15F.html#aae99d74a945039c365ebd2f995b5546e',1,'B15F']]] ]; diff --git a/docs/html/search/functions_9.js b/docs/html/search/functions_9.js index 98be5a6..fc8198d 100644 --- a/docs/html/search/functions_9.js +++ b/docs/html/search/functions_9.js @@ -6,14 +6,14 @@ var searchData= ['setdescx',['setDescX',['../classPlottyFile.html#aa0449c290265d55d6223b19cf0a88b0a',1,'PlottyFile']]], ['setdescy',['setDescY',['../classPlottyFile.html#a38a3a4dfc76bc70523727584bf01d590',1,'PlottyFile']]], ['setfunctiontype',['setFunctionType',['../classPlottyFile.html#a4e5ab1ebb012a5cc1a3d6458a4cd512f',1,'PlottyFile']]], - ['setmem16',['setMem16',['../classB15F.html#ae2dc09141f3300c751b57adacf2bed71',1,'B15F']]], - ['setmem8',['setMem8',['../classB15F.html#a04e52727c1ac7f5e600163c73deb29f2',1,'B15F']]], + ['setmem16',['setMem16',['../classB15F.html#a62ef2ee9bd945d30979939fcffa6759a',1,'B15F']]], + ['setmem8',['setMem8',['../classB15F.html#a65c0eee6b40b6d3ec58b0335fd668503',1,'B15F']]], ['setparafirstcurve',['setParaFirstCurve',['../classPlottyFile.html#aa676414793becb975506f48d6e949dd0',1,'PlottyFile']]], ['setparastepwidth',['setParaStepWidth',['../classPlottyFile.html#a6caebd31e04e2e7081cc007047350355',1,'PlottyFile']]], ['setquadrant',['setQuadrant',['../classPlottyFile.html#a1953ee0d9a87b7353c16139584e9c2ae',1,'PlottyFile']]], ['setrefx',['setRefX',['../classPlottyFile.html#a80c2c2e97a454566f9c1f2c51e1d7f3e',1,'PlottyFile']]], ['setrefy',['setRefY',['../classPlottyFile.html#a3a371228ddcc007e97eebe7cc04dffc2',1,'PlottyFile']]], - ['setregister',['setRegister',['../classB15F.html#ab446ecffab28d4515dfade79a8efc93d',1,'B15F']]], + ['setregister',['setRegister',['../classB15F.html#a47d7b797129d1ee7ebee4d8ae4f0ff93',1,'B15F']]], ['setservodisabled',['setServoDisabled',['../classB15F.html#aad1b3206761c06c7183ae1b8b95b350b',1,'B15F']]], ['setservoenabled',['setServoEnabled',['../classB15F.html#ab23d8c5a0b520b9d12d94a04f90fcfa0',1,'B15F']]], ['setservoposition',['setServoPosition',['../classB15F.html#aa76f289274e5d0be41c5d4a58b52a416',1,'B15F']]], diff --git a/docs/html/timeoutexception_8h_source.html b/docs/html/timeoutexception_8h_source.html index 332f76a..b7363c1 100644 --- a/docs/html/timeoutexception_8h_source.html +++ b/docs/html/timeoutexception_8h_source.html @@ -79,7 +79,7 @@ $(function() {
    TimeoutException(const std::string &message)
    diff --git a/docs/html/ui_8cpp_source.html b/docs/html/ui_8cpp_source.html index 064ed73..fe95567 100644 --- a/docs/html/ui_8cpp_source.html +++ b/docs/html/ui_8cpp_source.html @@ -70,25 +70,25 @@ $(function() {
    ui.cpp
    -
    1 #include "ui.h"
    2 #include "../drv/b15f.h"
    3 
    4 std::vector<View*> win_stack;
    5 std::thread t_refresh;
    6 
    7 void show_main(int)
    8 {
    9  ViewSelection* view = new ViewSelection();
    10  view->setTitle("B15F - Command Line Interface");
    11  view->addChoice("[ Monitor - Eingaben beobachten ]", &show_monitor);
    12  view->addChoice("[ Digitale Ausgabe BA0 ]", &show_digital_output0);
    13  view->addChoice("[ Digitale Ausgabe BA1 ]", &show_digital_output1);
    14  view->addChoice("[ Analoge Ausgabe AA0 ]", &show_analog_output0);
    15  view->addChoice("[ Analoge Ausgabe AA1 ]", &show_analog_output1);
    16  view->addChoice("[ Selbsttest des B15 ]", &show_selftest_info);
    17  view->addChoice("[ Informationen ]", &show_info);
    18  view->addChoice("", nullptr);
    19  view->addChoice("[ Beenden ]", &finish);
    20  view->repaint();
    21 
    22  win_stack.push_back(view);
    23  input(0);
    24 }
    25 
    26 void input(int)
    27 {
    28  call_t nextCall;
    29  int key;
    30  do
    31  {
    32  key = wgetch(View::getWinContext());
    33  win_stack.back()->repaint();
    34  nextCall = win_stack.back()->keypress(key);
    35 
    36  if(key == -1)
    37  view_back(key);
    38 
    39  if(nextCall)
    40  nextCall(key);
    41  }
    42  while(win_stack.size());
    43 }
    44 
    45 void view_back(int)
    46 {
    47  if(win_stack.size())
    48  {
    49  delete win_stack.back();
    50  win_stack.pop_back();
    51  }
    52  if(win_stack.size())
    53  win_stack.back()->repaint();
    54 }
    55 
    56 void finish(int)
    57 {
    58  cleanup();
    59  exit(EXIT_SUCCESS);
    60 }
    61 
    62 void cleanup()
    63 {
    64  if(t_refresh.joinable())
    65  t_refresh.join();
    66  clrtoeol();
    67  refresh();
    68  endwin();
    69 }
    70 
    71 void show_info(int)
    72 {
    73  ViewInfo* view = new ViewInfo();
    74  view->setTitle("Info");
    75  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");
    76  view->setLabelClose("[ Zurueck ]");
    77  view->repaint();
    78 
    79  win_stack.push_back(view);
    80  input(0);
    81 }
    82 
    83 void show_monitor(int)
    84 {
    85  ViewMonitor* view = new ViewMonitor();
    86  view->setTitle("Monitor");
    87  view->setText("\nErfasse Messwerte...");
    88  view->setLabelClose("[ Zurueck ]");
    89  view->repaint();
    90 
    91  win_stack.push_back(view);
    92  input(0);
    93 }
    94 
    95 void show_invalid_port_input(int)
    96 {
    97  ViewInfo* view = new ViewInfo();
    98  view->setTitle("Falsche Eingabe");
    99  view->setText("Bitte geben Sie einen Wert aus dem Intervall [0, FF] an.");
    100  view->setLabelClose("[ Schliessen ]");
    101  view->repaint();
    102 
    103  win_stack.push_back(view);
    104  input(0);
    105 }
    106 
    107 void show_invalid_dac_input(int)
    108 {
    109  ViewInfo* view = new ViewInfo();
    110  view->setTitle("Falsche Eingabe");
    111  view->setText("Bitte geben Sie einen Wert aus dem Intervall [0, 1023] an.");
    112  view->setLabelClose("[ Schliessen ]");
    113  view->repaint();
    114 
    115  win_stack.push_back(view);
    116  input(0);
    117 }
    118 
    119 void write_digital_output0(int)
    120 {
    121  try
    122  {
    123  int d = std::stoi(static_cast<ViewPromt*>(win_stack.back())->getInput(), 0, 16);
    124  if(d > 255 || 0 > d)
    125  throw std::invalid_argument("bad value");
    126  uint8_t port = static_cast<uint8_t>(d);
    127 
    128  B15F& drv = B15F::getInstance();
    129  drv.digitalWrite0(port);
    130  view_back(0);
    131  }
    132  catch(std::invalid_argument& ex)
    133  {
    134  show_invalid_port_input(0);
    135  }
    136 }
    137 
    138 void write_digital_output1(int)
    139 {
    140  try
    141  {
    142  int d = std::stoi(static_cast<ViewPromt*>(win_stack.back())->getInput(), 0, 16);
    143  if(d > 255 || 0 > d)
    144  throw std::invalid_argument("bad value");
    145  uint8_t port = static_cast<uint8_t>(d);
    146 
    147  B15F& drv = B15F::getInstance();
    148  drv.digitalWrite1(port);
    149  view_back(0);
    150  }
    151  catch(std::invalid_argument& ex)
    152  {
    153  show_invalid_port_input(0);
    154  }
    155 }
    156 
    157 void write_analog_output0(int)
    158 {
    159  try
    160  {
    161  uint16_t port = std::stoi(static_cast<ViewPromt*>(win_stack.back())->getInput());
    162  if(port > 1023)
    163  throw std::invalid_argument("bad value");
    164 
    165  B15F& drv = B15F::getInstance();
    166  drv.analogWrite0(port);
    167  view_back(0);
    168  }
    169  catch(std::invalid_argument& ex)
    170  {
    171  show_invalid_dac_input(0);
    172  }
    173 }
    174 
    175 void write_analog_output1(int)
    176 {
    177  try
    178  {
    179  uint16_t port = std::stoi(static_cast<ViewPromt*>(win_stack.back())->getInput());
    180  if(port > 1023)
    181  throw std::invalid_argument("bad value");
    182 
    183  B15F& drv = B15F::getInstance();
    184  drv.analogWrite1(port);
    185  view_back(0);
    186  }
    187  catch(std::invalid_argument& ex)
    188  {
    189  show_invalid_dac_input(0);
    190  }
    191 }
    192 
    193 void show_digital_output0(int)
    194 {
    195  ViewPromt* view = new ViewPromt();
    196  view->setTitle("Digitale Ausgabe BE0");
    197  view->setMessage("\nAusgabe Port-Wert (hex): 0x");
    198  view->setCancel("[ Zurueck ]", true);
    199  view->setConfirm("[ OK ]", &write_digital_output0);
    200  view->repaint();
    201 
    202  win_stack.push_back(view);
    203  input(0);
    204 }
    205 
    206 void show_digital_output1(int)
    207 {
    208  ViewPromt* view = new ViewPromt();
    209  view->setTitle("Digitale Ausgabe BE1");
    210  view->setMessage("\nAusgabe Port-Wert (hex): 0x");
    211  view->setCancel("[ Zurueck ]", true);
    212  view->setConfirm("[ OK ]", &write_digital_output1);
    213  view->repaint();
    214 
    215  win_stack.push_back(view);
    216  input(0);
    217 }
    218 
    219 void show_analog_output0(int)
    220 {
    221  ViewPromt* view = new ViewPromt();
    222  view->setTitle("Analoge Ausgabe AA0");
    223  view->setMessage("\nAusgabe 10-Bit-Wert (0...1023): ");
    224  view->setCancel("[ Zurueck ]", true);
    225  view->setConfirm("[ OK ]", &write_analog_output0);
    226  view->repaint();
    227 
    228  win_stack.push_back(view);
    229  input(0);
    230 }
    231 
    232 void show_analog_output1(int)
    233 {
    234  ViewPromt* view = new ViewPromt();
    235  view->setTitle("Analoge Ausgabe AA1");
    236  view->setMessage("\nAusgabe 10-Bit-Wert (0...1023): ");
    237  view->setCancel("[ Zurueck ]", true);
    238  view->setConfirm("[ OK ]", &write_analog_output1);
    239  view->repaint();
    240 
    241  win_stack.push_back(view);
    242  input(0);
    243 }
    244 
    245 void start_selftest(int)
    246 {
    247  B15F& drv = B15F::getInstance();
    248  drv.activateSelfTestMode();
    249 
    250  ViewInfo* view = new ViewInfo();
    251  view->setTitle("Selbsttest aktiv");
    252  view->setText("Das B15 befindet sich jetzt im Selbsttestmodus.\n \nSelbsttest:\nZu Beginn geht der Reihe nach jede LED von BA0 bis BA1 an.\nDanach leuchten die LEDs an AA0 und AA1 kurz auf.\nZum Schluss spiegelt in einer Endlosschleife:\n* BA0 Port BE0\n* BA1 die DIP-Schalter S7\n* AA0 ADC0\n* AA1 ADC1");
    253  view->setLabelClose("[ Selbsttest Beenden ]");
    254  view->setCall(&stop_selftest);
    255  view->repaint();
    256 
    257  win_stack.push_back(view);
    258  input(0);
    259 }
    260 
    261 void stop_selftest(int)
    262 {
    263  B15F& drv = B15F::getInstance();
    264  drv.discard();
    266  drv.reconnect();
    267  drv.digitalWrite0(0);
    268  drv.digitalWrite1(0);
    269 }
    270 
    271 void show_selftest_info(int)
    272 {
    273  ViewInfo* view = new ViewInfo();
    274  view->setTitle("Selbsttest");
    275  view->setText("Bitte entfernen Sie jetzt alle Draehte von den Anschlussklemmen und\nbestätigen mit Enter.");
    276  view->setLabelClose("[ Weiter ]");
    277  view->setCall(&start_selftest);
    278  view->repaint();
    279 
    280  win_stack.push_back(view);
    281  input(0);
    282 }
    +
    1 #include "ui.h"
    2 #include "../drv/b15f.h"
    3 
    4 std::vector<View*> win_stack;
    5 std::thread t_refresh;
    6 
    7 void show_main(int)
    8 {
    9  ViewSelection* view = new ViewSelection();
    10  view->setTitle("B15F - Command Line Interface");
    11  view->addChoice("[ Monitor - Eingaben beobachten ]", &show_monitor);
    12  view->addChoice("[ Digitale Ausgabe BA0 ]", &show_digital_output0);
    13  view->addChoice("[ Digitale Ausgabe BA1 ]", &show_digital_output1);
    14  view->addChoice("[ Analoge Ausgabe AA0 ]", &show_analog_output0);
    15  view->addChoice("[ Analoge Ausgabe AA1 ]", &show_analog_output1);
    16  view->addChoice("[ Selbsttest des B15 ]", &show_selftest_info);
    17  view->addChoice("[ Informationen ]", &show_info);
    18  view->addChoice("", nullptr);
    19  view->addChoice("[ Beenden ]", &finish);
    20  view->repaint();
    21 
    22  win_stack.push_back(view);
    23  input(0);
    24 }
    25 
    26 void input(int)
    27 {
    28  call_t nextCall;
    29  int key;
    30  do
    31  {
    32  key = wgetch(View::getWinContext());
    33  win_stack.back()->repaint();
    34  nextCall = win_stack.back()->keypress(key);
    35 
    36  if(key == -1)
    37  view_back(key);
    38 
    39  if(nextCall)
    40  nextCall(key);
    41  }
    42  while(win_stack.size());
    43 }
    44 
    45 void view_back(int)
    46 {
    47  if(win_stack.size())
    48  {
    49  delete win_stack.back();
    50  win_stack.pop_back();
    51  }
    52  if(win_stack.size())
    53  win_stack.back()->repaint();
    54 }
    55 
    56 void finish(int)
    57 {
    58  cleanup();
    59  exit(EXIT_SUCCESS);
    60 }
    61 
    62 void cleanup()
    63 {
    64  if(t_refresh.joinable())
    65  t_refresh.join();
    66  clrtoeol();
    67  refresh();
    68  endwin();
    69 }
    70 
    71 void show_info(int)
    72 {
    73  ViewInfo* view = new ViewInfo();
    74  view->setTitle("Info");
    75  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");
    76  view->setLabelClose("[ Zurueck ]");
    77  view->repaint();
    78 
    79  win_stack.push_back(view);
    80  input(0);
    81 }
    82 
    83 void show_monitor(int)
    84 {
    85  ViewMonitor* view = new ViewMonitor();
    86  view->setTitle("Monitor");
    87  view->setText("\nErfasse Messwerte...");
    88  view->setLabelClose("[ Zurueck ]");
    89  view->repaint();
    90 
    91  win_stack.push_back(view);
    92  input(0);
    93 }
    94 
    95 void show_invalid_port_input(int)
    96 {
    97  ViewInfo* view = new ViewInfo();
    98  view->setTitle("Falsche Eingabe");
    99  view->setText("Bitte geben Sie einen Wert aus dem Intervall [0, FF] an.");
    100  view->setLabelClose("[ Schliessen ]");
    101  view->repaint();
    102 
    103  win_stack.push_back(view);
    104  input(0);
    105 }
    106 
    107 void show_invalid_dac_input(int)
    108 {
    109  ViewInfo* view = new ViewInfo();
    110  view->setTitle("Falsche Eingabe");
    111  view->setText("Bitte geben Sie einen Wert aus dem Intervall [0, 1023] an.");
    112  view->setLabelClose("[ Schliessen ]");
    113  view->repaint();
    114 
    115  win_stack.push_back(view);
    116  input(0);
    117 }
    118 
    119 void write_digital_output0(int)
    120 {
    121  try
    122  {
    123  int d = std::stoi(static_cast<ViewPromt*>(win_stack.back())->getInput(), 0, 16);
    124  if(d > 255 || 0 > d)
    125  throw std::invalid_argument("bad value");
    126  uint8_t port = static_cast<uint8_t>(d);
    127 
    128  B15F& drv = B15F::getInstance();
    129  drv.digitalWrite0(port);
    130  view_back(0);
    131  }
    132  catch(std::invalid_argument& ex)
    133  {
    134  show_invalid_port_input(0);
    135  }
    136 }
    137 
    138 void write_digital_output1(int)
    139 {
    140  try
    141  {
    142  int d = std::stoi(static_cast<ViewPromt*>(win_stack.back())->getInput(), 0, 16);
    143  if(d > 255 || 0 > d)
    144  throw std::invalid_argument("bad value");
    145  uint8_t port = static_cast<uint8_t>(d);
    146 
    147  B15F& drv = B15F::getInstance();
    148  drv.digitalWrite1(port);
    149  view_back(0);
    150  }
    151  catch(std::invalid_argument& ex)
    152  {
    153  show_invalid_port_input(0);
    154  }
    155 }
    156 
    157 void write_analog_output0(int)
    158 {
    159  try
    160  {
    161  uint16_t port = std::stoi(static_cast<ViewPromt*>(win_stack.back())->getInput());
    162  if(port > 1023)
    163  throw std::invalid_argument("bad value");
    164 
    165  B15F& drv = B15F::getInstance();
    166  drv.analogWrite0(port);
    167  view_back(0);
    168  }
    169  catch(std::invalid_argument& ex)
    170  {
    171  show_invalid_dac_input(0);
    172  }
    173 }
    174 
    175 void write_analog_output1(int)
    176 {
    177  try
    178  {
    179  uint16_t port = std::stoi(static_cast<ViewPromt*>(win_stack.back())->getInput());
    180  if(port > 1023)
    181  throw std::invalid_argument("bad value");
    182 
    183  B15F& drv = B15F::getInstance();
    184  drv.analogWrite1(port);
    185  view_back(0);
    186  }
    187  catch(std::invalid_argument& ex)
    188  {
    189  show_invalid_dac_input(0);
    190  }
    191 }
    192 
    193 void show_digital_output0(int)
    194 {
    195  ViewPromt* view = new ViewPromt();
    196  view->setTitle("Digitale Ausgabe BE0");
    197  view->setMessage("\nAusgabe Port-Wert (hex): 0x");
    198  view->setCancel("[ Zurueck ]", true);
    199  view->setConfirm("[ OK ]", &write_digital_output0);
    200  view->repaint();
    201 
    202  win_stack.push_back(view);
    203  input(0);
    204 }
    205 
    206 void show_digital_output1(int)
    207 {
    208  ViewPromt* view = new ViewPromt();
    209  view->setTitle("Digitale Ausgabe BE1");
    210  view->setMessage("\nAusgabe Port-Wert (hex): 0x");
    211  view->setCancel("[ Zurueck ]", true);
    212  view->setConfirm("[ OK ]", &write_digital_output1);
    213  view->repaint();
    214 
    215  win_stack.push_back(view);
    216  input(0);
    217 }
    218 
    219 void show_analog_output0(int)
    220 {
    221  ViewPromt* view = new ViewPromt();
    222  view->setTitle("Analoge Ausgabe AA0");
    223  view->setMessage("\nAusgabe 10-Bit-Wert (0...1023): ");
    224  view->setCancel("[ Zurueck ]", true);
    225  view->setConfirm("[ OK ]", &write_analog_output0);
    226  view->repaint();
    227 
    228  win_stack.push_back(view);
    229  input(0);
    230 }
    231 
    232 void show_analog_output1(int)
    233 {
    234  ViewPromt* view = new ViewPromt();
    235  view->setTitle("Analoge Ausgabe AA1");
    236  view->setMessage("\nAusgabe 10-Bit-Wert (0...1023): ");
    237  view->setCancel("[ Zurueck ]", true);
    238  view->setConfirm("[ OK ]", &write_analog_output1);
    239  view->repaint();
    240 
    241  win_stack.push_back(view);
    242  input(0);
    243 }
    244 
    245 void start_selftest(int)
    246 {
    247  B15F& drv = B15F::getInstance();
    248  drv.activateSelfTestMode();
    249 
    250  ViewInfo* view = new ViewInfo();
    251  view->setTitle("Selbsttest aktiv");
    252  view->setText("Das B15 befindet sich jetzt im Selbsttestmodus.\n \nSelbsttest:\nZu Beginn geht der Reihe nach jede LED von BA0 bis BA1 an.\nDanach leuchten die LEDs an AA0 und AA1 kurz auf.\nZum Schluss spiegelt in einer Endlosschleife:\n* BA0 Port BE0\n* BA1 die DIP-Schalter S7\n* AA0 ADC0\n* AA1 ADC1");
    253  view->setLabelClose("[ Selbsttest Beenden ]");
    254  view->setCall(&stop_selftest);
    255  view->repaint();
    256 
    257  win_stack.push_back(view);
    258  input(0);
    259 }
    260 
    261 void stop_selftest(int)
    262 {
    263  B15F& drv = B15F::getInstance();
    264  drv.discard();
    266  drv.reconnect();
    267  drv.digitalWrite0(0);
    268  drv.digitalWrite1(0);
    269 }
    270 
    271 void show_selftest_info(int)
    272 {
    273  ViewInfo* view = new ViewInfo();
    274  view->setTitle("Selbsttest");
    275  view->setText("Bitte entfernen Sie jetzt alle Draehte von den Anschlussklemmen und\nbestätigen mit Enter.");
    276  view->setLabelClose("[ Weiter ]");
    277  view->setCall(&start_selftest);
    278  view->repaint();
    279 
    280  win_stack.push_back(view);
    281  input(0);
    282 }
    +
    void analogWrite0(uint16_t port)
    Definition: b15f.cpp:288
    +
    void analogWrite1(uint16_t port)
    Definition: b15f.cpp:305
    +
    void digitalWrite0(uint8_t)
    Definition: b15f.cpp:205
    void delay_ms(uint16_t ms)
    Definition: b15f.cpp:127
    static B15F & getInstance(void)
    Definition: b15f.cpp:10
    Definition: b15f.h:33
    -
    bool digitalWrite0(uint8_t)
    Definition: b15f.cpp:204
    -
    bool activateSelfTestMode(void)
    Definition: b15f.cpp:191
    +
    void activateSelfTestMode(void)
    Definition: b15f.cpp:190
    -
    bool analogWrite1(uint16_t port)
    Definition: b15f.cpp:292
    -
    bool digitalWrite1(uint8_t)
    Definition: b15f.cpp:218
    void discard(void)
    Definition: b15f.cpp:33
    -
    constexpr static uint16_t WDT_TIMEOUT
    Time in ms after which the watch dog timer resets the MCU.
    Definition: b15f.h:306
    +
    constexpr static uint16_t WDT_TIMEOUT
    Time in ms after which the watch dog timer resets the MCU.
    Definition: b15f.h:309
    void reconnect(void)
    Definition: b15f.cpp:18
    -
    bool analogWrite0(uint16_t port)
    Definition: b15f.cpp:277
    +
    void digitalWrite1(uint8_t)
    Definition: b15f.cpp:221
    diff --git a/docs/html/ui_8h_source.html b/docs/html/ui_8h_source.html index e0dfc18..d9c78bf 100644 --- a/docs/html/ui_8h_source.html +++ b/docs/html/ui_8h_source.html @@ -73,7 +73,7 @@ $(function() {
    1 #ifndef UI_H
    2 #define UI_H
    3 
    4 #include <vector>
    5 #include "view_selection.h"
    6 #include "view_info.h"
    7 #include "view_monitor.h"
    8 #include "view_promt.h"
    9 
    10 void show_main(int);
    11 void input(int);
    12 void view_back(int);
    13 void finish(int);
    14 void cleanup();
    15 
    16 void show_info(int);
    17 void show_monitor(int);
    18 void show_invalid_port_input(int);
    19 void show_invalid_dac_input(int);
    20 void write_digital_output0(int);
    21 void write_digital_output1(int);
    22 void write_analog_output0(int);
    23 void write_analog_output1(int);
    24 void show_digital_output0(int);
    25 void show_digital_output1(int);
    26 void show_analog_output0(int);
    27 void show_analog_output1(int);
    28 
    29 // selftest group
    30 void show_selftest_info(int);
    31 void start_selftest(int);
    32 void stop_selftest(int);
    33 
    34 
    35 extern std::vector<View*> win_stack;
    36 extern std::thread t_refresh;
    37 
    38 #endif // UI_H
    diff --git a/docs/html/usart_8cpp_source.html b/docs/html/usart_8cpp_source.html index a3d81d9..c616b0a 100644 --- a/docs/html/usart_8cpp_source.html +++ b/docs/html/usart_8cpp_source.html @@ -88,7 +88,7 @@ $(function() { diff --git a/docs/html/usart_8h_source.html b/docs/html/usart_8h_source.html index 6bcbed7..3b8bcc9 100644 --- a/docs/html/usart_8h_source.html +++ b/docs/html/usart_8h_source.html @@ -88,7 +88,7 @@ $(function() {
    void flushOutputBuffer(void)
    Definition: usart.cpp:68
    diff --git a/docs/html/usartexception_8h_source.html b/docs/html/usartexception_8h_source.html index 53736c1..7d55a87 100644 --- a/docs/html/usartexception_8h_source.html +++ b/docs/html/usartexception_8h_source.html @@ -79,7 +79,7 @@ $(function() {
    virtual ~USARTException()=default
    diff --git a/docs/html/view_8cpp_source.html b/docs/html/view_8cpp_source.html index 1038983..25938c6 100644 --- a/docs/html/view_8cpp_source.html +++ b/docs/html/view_8cpp_source.html @@ -74,7 +74,7 @@ $(function() {
    static void abort(std::string msg)
    Definition: b15f.cpp:161
    diff --git a/docs/html/view_8h_source.html b/docs/html/view_8h_source.html index 318c3c6..baeef4a 100644 --- a/docs/html/view_8h_source.html +++ b/docs/html/view_8h_source.html @@ -74,7 +74,7 @@ $(function() {
    Definition: view.h:19
    diff --git a/docs/html/view__info_8cpp_source.html b/docs/html/view__info_8cpp_source.html index aaefc25..8f431f0 100644 --- a/docs/html/view__info_8cpp_source.html +++ b/docs/html/view__info_8cpp_source.html @@ -73,7 +73,7 @@ $(function() {
    1 #include "view_info.h"
    2 
    3 ViewInfo::ViewInfo()
    4 {
    5  calls.push_back(nullptr);
    6 }
    7 
    8 void ViewInfo::setText(std::string text)
    9 {
    10  this->text = text;
    11 }
    12 
    13 void ViewInfo::setLabelClose(std::string label)
    14 {
    15  this->label_close = label;
    16 }
    17 
    18 void ViewInfo::setCall(call_t call)
    19 {
    20  calls[0] = call;
    21 }
    22 
    23 void ViewInfo::draw()
    24 {
    25  int li = 0;
    26  for(std::string line : str_split(text, "\n"))
    27  mvwprintw(win, text_offset_y + li++, text_offset_x, "%s", line.c_str());
    28 
    29  close_offset_x = (width - label_close.length()) / 2;
    30  close_offset_y = height - 2;
    31 
    32  wattron(win, A_REVERSE);
    33  mvwprintw(win, close_offset_y, close_offset_x, "%s", label_close.c_str());
    34  wattroff(win, A_REVERSE);
    35 }
    36 
    37 call_t ViewInfo::keypress(int& key)
    38 {
    39  switch(key)
    40  {
    41 
    42  case KEY_MOUSE:
    43  {
    44  // http://pronix.linuxdelta.de/C/Linuxprogrammierung/Linuxsystemprogrammieren_C_Kurs_Kapitel10b.shtml
    45  MEVENT event;
    46  if(getmouse(&event) == OK && event.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED))
    47  {
    48  size_t column = start_x + close_offset_x;
    49  size_t row = start_y + close_offset_y;
    50  size_t mouse_x = event.x, mouse_y = event.y;
    51  if(mouse_y == row && mouse_x >= column && mouse_x < column + label_close.length())
    52  key = -1; // do return from view
    53  }
    54  break;
    55  }
    56  case KEY_ENT:
    57  key = -1; // do return from view
    58  break;
    59  default:
    60  break;
    61  }
    62  return calls[0];
    63 }
    diff --git a/docs/html/view__info_8h_source.html b/docs/html/view__info_8h_source.html index 1d282d6..8dbd93a 100644 --- a/docs/html/view__info_8h_source.html +++ b/docs/html/view__info_8h_source.html @@ -75,7 +75,7 @@ $(function() {
    Definition: view.h:19
    diff --git a/docs/html/view__monitor_8cpp_source.html b/docs/html/view__monitor_8cpp_source.html index f1c64ee..c17409a 100644 --- a/docs/html/view__monitor_8cpp_source.html +++ b/docs/html/view__monitor_8cpp_source.html @@ -72,19 +72,19 @@ $(function() {
    1 #include "view_monitor.h"
    2 
    3 ViewMonitor::ViewMonitor() : t_worker(&ViewMonitor::worker, this)
    4 {
    5 }
    6 
    7 call_t ViewMonitor::keypress(int& key)
    8 {
    9  switch(key)
    10  {
    11 
    12  case KEY_MOUSE:
    13  {
    14  // http://pronix.linuxdelta.de/C/Linuxprogrammierung/Linuxsystemprogrammieren_C_Kurs_Kapitel10b.shtml
    15  MEVENT event;
    16  bool hit = false;
    17  if(getmouse(&event) == OK && event.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED))
    18  {
    19  size_t column = start_x + close_offset_x;
    20  size_t row = start_y + close_offset_y;
    21  size_t mouse_x = event.x, mouse_y = event.y;
    22  if(mouse_y == row && mouse_x >= column && mouse_x < column + label_close.length())
    23  hit = true;
    24  }
    25  if(!hit)
    26  break;
    27 
    28  // fall through to next case
    29  [[fallthrough]];
    30  }
    31  case KEY_ENT:
    32  run_worker = false;
    33  key = -1; // do return from view
    34  wclear(win);
    35  wrefresh(win);
    36  t_worker.join();
    37  break;
    38  default:
    39  break;
    40  }
    41  return calls[0];
    42 }
    43 
    44 std::string ViewMonitor::fancyDigitalString(uint8_t& b)
    45 {
    46  std::string bitstring(std::bitset<8>(b).to_string());
    47  std::reverse(bitstring.begin(), bitstring.end());
    48 
    49  std::stringstream str;
    50  str << bitstring;
    51  str << " ";
    52  str << "0x" << std::setfill ('0') << std::setw(2) << std::hex << (int) b << std::dec;
    53  return str.str();
    54 }
    55 
    56 std::string ViewMonitor::fancyAnalogString(uint16_t& v)
    57 {
    58  std::stringstream str;
    59  double volt = round(v * 100.0 * 5.0 / 1023.0) / 100.0;
    60 
    61  str << std::setfill ('0') << std::setw(4) << (int) v << " " << std::fixed << std::setprecision(2) << volt << " V ";
    62 
    63  str << "[";
    64  uint8_t p = round(v * 40.0 / 1023.0);
    65  for(uint8_t i = 0; i < p; i++)
    66  str << "X";
    67  for(uint8_t i = 0; i < 40 - p; i++)
    68  str << " ";
    69  str << "]" << std::endl;
    70 
    71  return str.str();
    72 }
    73 
    74 void ViewMonitor::worker()
    75 {
    76  B15F& drv = B15F::getInstance();
    77  while(run_worker)
    78  {
    79  try
    80  {
    81  std::this_thread::sleep_for(std::chrono::milliseconds(100));
    82 
    83  uint8_t be0 = drv.digitalRead0();
    84  uint8_t be1 = drv.digitalRead1();
    85  uint8_t dsw = drv.readDipSwitch();
    86  uint16_t adc[8];
    87  for(uint8_t i = 0; i < sizeof(adc) / sizeof(adc[0]); i++)
    88  adc[i] = drv.analogRead(i);
    89 
    90 
    91  std::stringstream str;
    92 
    93  // hline
    94  for(uint8_t i = 0; i < width - 2 * text_offset_x; i++)
    95  if(i % 2 == 0)
    96  str << "-";
    97  else
    98  str << " ";
    99  str << std::endl;
    100 
    101  str << "Digitale Enigaenge:" << std::endl;
    102  str << "Binaere Eingabe 0: " << fancyDigitalString(be0) << std::endl;
    103  str << "Binaere Eingabe 1: " << fancyDigitalString(be1) << std::endl;
    104  str << "Dip Schalter (S7): " << fancyDigitalString(dsw) << std::endl;
    105 
    106  // hline
    107  for(uint8_t i = 0; i < width - 2 * text_offset_x; i++)
    108  if(i % 2 == 0)
    109  str << "-";
    110  else
    111  str << " ";
    112  str << std::endl;
    113 
    114  str << "Analoge Eingaenge:" << std::endl;
    115  for(uint8_t i = 0; i < sizeof(adc) / sizeof(adc[0]); i++)
    116  {
    117  str << "Kanal " << std::to_string((int) i) << ": ";
    118  str << fancyAnalogString(adc[i]) << std::endl;
    119  }
    120 
    121  text = str.str();
    122  repaint();
    123  }
    124  catch(DriverException& ex)
    125  {
    126  std::cout << "DriverException: " << ex.what() << std::endl;
    127  drv.delay_ms(1000);
    128  }
    129  catch(...)
    130  {
    131  try
    132  {
    133  drv.reconnect();
    134  }
    135  catch(...)
    136  {
    137  B15F::abort("Die Verbindung ist unterbrochen worden. Wurde ein Stecker gezogen? :D");
    138  return;
    139  }
    140  }
    141  }
    142 }
    -
    uint8_t digitalRead0(void)
    Definition: b15f.cpp:232
    -
    uint8_t readDipSwitch(void)
    Definition: b15f.cpp:260
    +
    uint8_t digitalRead0(void)
    Definition: b15f.cpp:237
    +
    uint8_t readDipSwitch(void)
    Definition: b15f.cpp:269
    void delay_ms(uint16_t ms)
    Definition: b15f.cpp:127
    static B15F & getInstance(void)
    Definition: b15f.cpp:10
    Definition: b15f.h:33
    static void abort(std::string msg)
    Definition: b15f.cpp:161
    -
    uint16_t analogRead(uint8_t channel)
    Definition: b15f.cpp:307
    -
    uint8_t digitalRead1(void)
    Definition: b15f.cpp:246
    +
    uint16_t analogRead(uint8_t channel)
    Definition: b15f.cpp:322
    +
    uint8_t digitalRead1(void)
    Definition: b15f.cpp:253
    void reconnect(void)
    Definition: b15f.cpp:18
    diff --git a/docs/html/view__monitor_8h_source.html b/docs/html/view__monitor_8h_source.html index 7e5b1d1..0f16d3c 100644 --- a/docs/html/view__monitor_8h_source.html +++ b/docs/html/view__monitor_8h_source.html @@ -75,7 +75,7 @@ $(function() { diff --git a/docs/html/view__promt_8cpp_source.html b/docs/html/view__promt_8cpp_source.html index ea7260c..6af2b6b 100644 --- a/docs/html/view__promt_8cpp_source.html +++ b/docs/html/view__promt_8cpp_source.html @@ -73,7 +73,7 @@ $(function() {
    1 #include "view_promt.h"
    2 
    3 void ViewPromt::draw()
    4 {
    5  curs_set(1); // show cursor
    6 
    7  int li = text_offset_y;
    8  int ci = 0;
    9  for(std::string line : str_split(message + input, "\n"))
    10  {
    11  mvwprintw(win, ++li, text_offset_x, "%s", line.c_str());
    12  ci = line.length() + text_offset_x;
    13  }
    14 
    15  button_offset_x = (width - label_cancel.length() - sep.length() - label_confirm.length()) / 2;
    16  button_offset_y = height - text_offset_y;
    17 
    18  if(selection == 0)
    19  {
    20  wattron(win, A_REVERSE);
    21  mvwprintw(win, button_offset_y, button_offset_x, "%s", label_cancel.c_str());
    22  wattroff(win, A_REVERSE);
    23  mvwprintw(win, button_offset_y, button_offset_x + label_cancel.length(), "%s", sep.c_str());
    24  mvwprintw(win, button_offset_y, button_offset_x + label_cancel.length() + sep.length(), "%s", label_confirm.c_str());
    25  }
    26  else
    27  {
    28  mvwprintw(win, button_offset_y, button_offset_x, "%s", label_cancel.c_str());
    29  mvwprintw(win, button_offset_y, button_offset_x + label_cancel.length(), "%s", sep.c_str());
    30  wattron(win, A_REVERSE);
    31  mvwprintw(win, button_offset_y, button_offset_x + label_cancel.length() + sep.length(), "%s", label_confirm.c_str());
    32  wattroff(win, A_REVERSE);
    33  }
    34  wmove(win, li, ci);
    35 }
    36 
    37 void ViewPromt::setMessage(std::string message)
    38 {
    39  this->message = message;
    40 }
    41 
    42 void ViewPromt::setConfirm(std::string name, std::function<void(int)> call)
    43 {
    44  label_confirm = name;
    45  call_confirm = call;
    46 }
    47 
    48 void ViewPromt::setCancel(std::string name, bool cancelable)
    49 {
    50  label_cancel = name;
    51  this->cancelable = cancelable;
    52 }
    53 
    54 std::string ViewPromt::getInput()
    55 {
    56  return input;
    57 }
    58 
    59 std::function<void(int)> ViewPromt::keypress(int& key)
    60 {
    61  std::function<void(int)> ret = nullptr;
    62  switch(key)
    63  {
    64  case KEY_BACKSPACE:
    65  if(input.length())
    66  input.pop_back();
    67  break;
    68  case '\t':
    69  case KEY_LEFT:
    70  case KEY_RIGHT:
    71  selection = (selection + 1 ) % 2;
    72  break;
    73  case KEY_MOUSE:
    74  {
    75  // http://pronix.linuxdelta.de/C/Linuxprogrammierung/Linuxsystemprogrammieren_C_Kurs_Kapitel10b.shtml
    76  MEVENT event;
    77  bool hit = false;
    78  if(getmouse(&event) == OK && event.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED))
    79  {
    80  size_t column_start = start_x + button_offset_x;
    81  size_t row_start = start_y + button_offset_y;
    82  size_t mouse_x = event.x, mouse_y = event.y;
    83  if(mouse_y == row_start)
    84  {
    85  if(cancelable && mouse_x >= column_start && mouse_x < column_start + label_cancel.length())
    86  {
    87  if(selection == 0 || event.bstate & BUTTON1_DOUBLE_CLICKED)
    88  hit = true;
    89  selection = 0;
    90  }
    91  if(mouse_x >= column_start + label_cancel.length() + sep.length() && mouse_x < column_start + label_cancel.length() + sep.length() + label_confirm.length())
    92  {
    93  if(selection == 1 || event.bstate & BUTTON1_DOUBLE_CLICKED)
    94  hit = true;
    95  selection = 1;
    96  }
    97  }
    98  }
    99  if(!hit)
    100  break;
    101 
    102  // fall through to next case
    103  [[fallthrough]];
    104  }
    105  case KEY_ENT:
    106  if(selection == 0) // exit
    107  key = -1; // do return from view
    108  else
    109  ret = call_confirm;
    110  break;
    111  default:
    112  break;
    113  }
    114 
    115  if(key >= ' ' && key <= '~')
    116  input += (char) key;
    117 
    118  if(key != KEY_ENT)
    119  repaint();
    120  return ret;
    121 }
    diff --git a/docs/html/view__promt_8h_source.html b/docs/html/view__promt_8h_source.html index 0cf9de4..46e5728 100644 --- a/docs/html/view__promt_8h_source.html +++ b/docs/html/view__promt_8h_source.html @@ -75,7 +75,7 @@ $(function() { diff --git a/docs/html/view__selection_8cpp_source.html b/docs/html/view__selection_8cpp_source.html index 5e83920..fe26602 100644 --- a/docs/html/view__selection_8cpp_source.html +++ b/docs/html/view__selection_8cpp_source.html @@ -73,7 +73,7 @@ $(function() {
    1 #include "view_selection.h"
    2 
    3 void ViewSelection::draw()
    4 {
    5  //curs_set(0); // hide cursor
    6  for(size_t i = 0; i < choices.size(); i++)
    7  {
    8  if(selection == i)
    9  wattron(win, A_REVERSE);
    10  mvwprintw(win, i + choice_offset_y, choice_offset_x, "%s", choices[i].c_str());
    11  if(selection == i)
    12  wattroff(win, A_REVERSE);
    13  }
    14 }
    15 
    16 void ViewSelection::addChoice(std::string name, call_t call)
    17 {
    18  choices.push_back(name);
    19  calls.push_back(call);
    20 }
    21 
    22 call_t ViewSelection::keypress(int& key)
    23 {
    24  call_t ret = nullptr;
    25  switch(key)
    26  {
    27  case KEY_UP:
    28  do
    29  selection = (selection - 1 + choices.size()) % choices.size();
    30  while(!choices[selection].length() && choices.size());
    31  break;
    32 
    33  case '\t':
    34  case KEY_DOWN:
    35  do
    36  selection = (selection + 1) % choices.size();
    37  while(!choices[selection].length() && choices.size());
    38  break;
    39 
    40  case KEY_MOUSE:
    41  {
    42  // http://pronix.linuxdelta.de/C/Linuxprogrammierung/Linuxsystemprogrammieren_C_Kurs_Kapitel10b.shtml
    43  MEVENT event;
    44  bool hit = false;
    45  if(getmouse(&event) == OK && event.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED))
    46  {
    47  size_t column_start = start_x + choice_offset_x;
    48  size_t row_start = start_y + choice_offset_y;
    49  size_t mouse_x = event.x, mouse_y = event.y;
    50  for(size_t i = 0; i < choices.size(); i++)
    51  if(choices[i].length() && mouse_y == row_start + i && mouse_x >= column_start && mouse_x < column_start + choices[i].length())
    52  {
    53  if(selection == i || event.bstate & BUTTON1_DOUBLE_CLICKED)
    54  hit = true;
    55  selection = i;
    56  }
    57  }
    58  if(!hit)
    59  break;
    60 
    61  // fall through to next case
    62  [[fallthrough]];
    63  }
    64 
    65  case KEY_ENT:
    66  if(selection == choices.size() - 1) // exit
    67  key = -1; // do return from view
    68  else
    69  ret = calls[selection];
    70  break;
    71  default:
    72  break;
    73  }
    74  repaint();
    75  return ret;
    76 }
    diff --git a/docs/html/view__selection_8h_source.html b/docs/html/view__selection_8h_source.html index 18b1e0b..695c04a 100644 --- a/docs/html/view__selection_8h_source.html +++ b/docs/html/view__selection_8h_source.html @@ -75,7 +75,7 @@ $(function() {