diff --git a/control/examples/register/Makefile b/control/examples/register/Makefile new file mode 100644 index 0000000..8000d6e --- /dev/null +++ b/control/examples/register/Makefile @@ -0,0 +1,30 @@ +# Name: Makefile +# Project: B15F (board15 Famulus Edition) +# Author: Tristan Krause +# Creation Date: 2019-05-15 + +# Environment +COMPILER_PATH = g++ + +# Options +CFLAGS = -std=c++17 -O3 -Wall -Wextra +LDFLAGS = -lb15fdrv +OBJECTS = main.o +OUT = main.elf + +COMPILE = $(COMPILER_PATH) $(CFLAGS) + +main: $(OBJECTS) + $(COMPILE) $(OBJECTS) -o $(OUT) $(LDFLAGS) + +help: + @echo "This Makefile has the following targets:" + @echo "make main .... to compile" + @echo "make clean ... to delete objects and executables" + +clean: + @echo "Cleaning..." + rm -f $(OBJECTS) $(OUT) *.bin gnuplotscript.gp + +.cpp.o: + $(COMPILE) -c $< -o $@ diff --git a/control/examples/register/main.cpp b/control/examples/register/main.cpp new file mode 100644 index 0000000..27a15ba --- /dev/null +++ b/control/examples/register/main.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +#include + +const char PLOT_FILE[] = "plot.bin"; + +constexpr uint8_t SFR_OFFSET = 0x20; +constexpr uint8_t SFR_DDRB = 0x04; +constexpr uint8_t SFR_WDTCSR = 0x60; +constexpr uint8_t SFR_PORTB = 0x05; + +/* + * Dieses Beispiel erzeugt einen 300ms langen Impuls an PB0. + * + */ +int main() +{ + uint8_t DDRB, PORTB; + B15F& drv = B15F::getInstance(); + + DDRB = drv.getRegister(SFR_DDRB + SFR_OFFSET); + DDRB |= (1<<0); + drv.setRegister(SFR_DDRB + SFR_OFFSET, DDRB); + + PORTB = drv.getRegister(SFR_PORTB + SFR_OFFSET); + PORTB |= (1<<0); + drv.setRegister(SFR_PORTB + SFR_OFFSET, PORTB); + + drv.delay_ms(300); + + PORTB = drv.getRegister(SFR_PORTB + SFR_OFFSET); + PORTB &= ~(1<<0); + drv.setRegister(SFR_PORTB + SFR_OFFSET, PORTB); +} diff --git a/control/src/drv/b15f.cpp b/control/src/drv/b15f.cpp index 56cb2ed..0c1f736 100644 --- a/control/src/drv/b15f.cpp +++ b/control/src/drv/b15f.cpp @@ -330,6 +330,46 @@ bool B15F::pwmSetValue(uint8_t value) return aw == MSG_OK; } +bool B15F::setRegister(uint8_t adr, uint8_t val) +{ + usart.clearInputBuffer(); + + uint8_t rq[] = + { + RQ_SET_REG, + adr, + val + }; + + int n_sent = usart.write_timeout(&rq[0], 0, sizeof(rq), 1000); + if(n_sent != sizeof(rq)) + abort("Sent failed"); + + uint8_t byte = usart.readByte(); + delay_us(10); + return byte == val; +} + +uint8_t B15F::getRegister(uint8_t adr) +{ + usart.clearInputBuffer(); + + uint8_t rq[] = + { + RQ_GET_REG, + adr + }; + + int n_sent = usart.write_timeout(&rq[0], 0, sizeof(rq), 1000); + if(n_sent != sizeof(rq)) + abort("Sent failed"); + + uint8_t aw = usart.readByte(); + delay_us(10); + return aw; +} + + void B15F::delay_ms(uint16_t ms) { std::this_thread::sleep_for(std::chrono::milliseconds(ms)); diff --git a/control/src/drv/b15f.h b/control/src/drv/b15f.h index 1b011ea..bedca64 100644 --- a/control/src/drv/b15f.h +++ b/control/src/drv/b15f.h @@ -210,6 +210,22 @@ public: */ bool pwmSetValue(uint8_t value); + /** + * Setzt direkt den Wert eines MCU Registers. + * *Wichtig:* bei einer falschen Adresse kann das Board 15 ernsthaften Schaden nehmen! + * \param adr Speicheradresse des Registers + * \param val Neuer Wert für das Register + * \throws DriverException + */ + bool setRegister(uint8_t adr, uint8_t val); + + /** + * Liefert den Wert eines MCU Registers. + * \param adr Speicheradresse des Registers + * \throws DriverException + */ + uint8_t getRegister(uint8_t adr); + /*************************/ @@ -248,9 +264,11 @@ private: constexpr static uint8_t RQ_AA0 = 10; constexpr static uint8_t RQ_AA1 = 11; constexpr static uint8_t RQ_ADC = 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_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_REG = 16; + constexpr static uint8_t RQ_GET_REG = 17; }; #endif // B15F_H diff --git a/docs/atmegaiom1284p.h b/docs/atmegaiom1284p.h new file mode 100644 index 0000000..905029d --- /dev/null +++ b/docs/atmegaiom1284p.h @@ -0,0 +1,1219 @@ +/* Copyright (c) 2007 Atmel Corporation + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + * Neither the name of the copyright holders nor the names of + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id: iom1284p.h 2225 2011-03-02 16:27:26Z arcanum $ */ + +/* avr/iom1284p.h - definitions for ATmega1284P. */ + +/* This file should only be included from , never directly. */ + +#ifndef _AVR_IO_H_ +# error "Include instead of this file." +#endif + +#ifndef _AVR_IOXXX_H_ +# define _AVR_IOXXX_H_ "iom1284p.h" +#else +# error "Attempt to include more than one file." +#endif + + +#ifndef _AVR_IOM1284P_H_ +#define _AVR_IOM1284P_H_ 1 + + +/* Registers and associated bit numbers */ + +#define PINA _SFR_IO8(0x00) +#define PINA0 0 +#define PINA1 1 +#define PINA2 2 +#define PINA3 3 +#define PINA4 4 +#define PINA5 5 +#define PINA6 6 +#define PINA7 7 + +#define DDRA _SFR_IO8(0x01) +#define DDA0 0 +#define DDA1 1 +#define DDA2 2 +#define DDA3 3 +#define DDA4 4 +#define DDA5 5 +#define DDA6 6 +#define DDA7 7 + +#define PORTA _SFR_IO8(0x02) +#define PORTA0 0 +#define PORTA1 1 +#define PORTA2 2 +#define PORTA3 3 +#define PORTA4 4 +#define PORTA5 5 +#define PORTA6 6 +#define PORTA7 7 + +#define PINB _SFR_IO8(0x03) +#define PINB0 0 +#define PINB1 1 +#define PINB2 2 +#define PINB3 3 +#define PINB4 4 +#define PINB5 5 +#define PINB6 6 +#define PINB7 7 + +#define DDRB _SFR_IO8(0x04) +#define DDB0 0 +#define DDB1 1 +#define DDB2 2 +#define DDB3 3 +#define DDB4 4 +#define DDB5 5 +#define DDB6 6 +#define DDB7 7 + +#define PORTB _SFR_IO8(0x05) +#define PORTB0 0 +#define PORTB1 1 +#define PORTB2 2 +#define PORTB3 3 +#define PORTB4 4 +#define PORTB5 5 +#define PORTB6 6 +#define PORTB7 7 + +#define PINC _SFR_IO8(0x06) +#define PINC0 0 +#define PINC1 1 +#define PINC2 2 +#define PINC3 3 +#define PINC4 4 +#define PINC5 5 +#define PINC6 6 +#define PINC7 7 + +#define DDRC _SFR_IO8(0x07) +#define DDC0 0 +#define DDC1 1 +#define DDC2 2 +#define DDC3 3 +#define DDC4 4 +#define DDC5 5 +#define DDC6 6 +#define DDC7 7 + +#define PORTC _SFR_IO8(0x08) +#define PORTC0 0 +#define PORTC1 1 +#define PORTC2 2 +#define PORTC3 3 +#define PORTC4 4 +#define PORTC5 5 +#define PORTC6 6 +#define PORTC7 7 + +#define PIND _SFR_IO8(0x09) +#define PIND0 0 +#define PIND1 1 +#define PIND2 2 +#define PIND3 3 +#define PIND4 4 +#define PIND5 5 +#define PIND6 6 +#define PIND7 7 + +#define DDRD _SFR_IO8(0x0A) +#define DDD0 0 +#define DDD1 1 +#define DDD2 2 +#define DDD3 3 +#define DDD4 4 +#define DDD5 5 +#define DDD6 6 +#define DDD7 7 + +#define PORTD _SFR_IO8(0x0B) +#define PORTD0 0 +#define PORTD1 1 +#define PORTD2 2 +#define PORTD3 3 +#define PORTD4 4 +#define PORTD5 5 +#define PORTD6 6 +#define PORTD7 7 + +#define TIFR0 _SFR_IO8(0x15) +#define TOV0 0 +#define OCF0A 1 +#define OCF0B 2 + +#define TIFR1 _SFR_IO8(0x16) +#define TOV1 0 +#define OCF1A 1 +#define OCF1B 2 +#define ICF1 5 + +#define TIFR2 _SFR_IO8(0x17) +#define TOV2 0 +#define OCF2A 1 +#define OCF2B 2 + +#define TIFR3 _SFR_IO8(0x18) +#define TOV3 0 +#define OCF3A 1 +#define OCF3B 2 +#define ICF3 5 + +#define PCIFR _SFR_IO8(0x1B) +#define PCIF0 0 +#define PCIF1 1 +#define PCIF2 2 +#define PCIF3 3 + +#define EIFR _SFR_IO8(0x1C) +#define INTF0 0 +#define INTF1 1 +#define INTF2 2 + +#define EIMSK _SFR_IO8(0x1D) +#define INT0 0 +#define INT1 1 +#define INT2 2 + +#define GPIOR0 _SFR_IO8(0x1E) +#define GPIOR00 0 +#define GPIOR01 1 +#define GPIOR02 2 +#define GPIOR03 3 +#define GPIOR04 4 +#define GPIOR05 5 +#define GPIOR06 6 +#define GPIOR07 7 + +#define EECR _SFR_IO8(0x1F) +#define EERE 0 +#define EEPE 1 +#define EEMPE 2 +#define EERIE 3 +#define EEPM0 4 +#define EEPM1 5 + +#define EEDR _SFR_IO8(0x20) +#define EEDR0 0 +#define EEDR1 1 +#define EEDR2 2 +#define EEDR3 3 +#define EEDR4 4 +#define EEDR5 5 +#define EEDR6 6 +#define EEDR7 7 + +#define EEAR _SFR_IO16(0x21) + +#define EEARL _SFR_IO8(0x21) +#define EEAR0 0 +#define EEAR1 1 +#define EEAR2 2 +#define EEAR3 3 +#define EEAR4 4 +#define EEAR5 5 +#define EEAR6 6 +#define EEAR7 7 + +#define EEARH _SFR_IO8(0x22) +#define EEAR8 0 +#define EEAR9 1 +#define EEAR10 2 +#define EEAR11 3 + +#define GTCCR _SFR_IO8(0x23) +#define PSRSYNC 0 +#define PSRASY 1 +#define TSM 7 + +#define TCCR0A _SFR_IO8(0x24) +#define WGM00 0 +#define WGM01 1 +#define COM0B0 4 +#define COM0B1 5 +#define COM0A0 6 +#define COM0A1 7 + +#define TCCR0B _SFR_IO8(0x25) +#define CS00 0 +#define CS01 1 +#define CS02 2 +#define WGM02 3 +#define FOC0B 6 +#define FOC0A 7 + +#define TCNT0 _SFR_IO8(0x26) +#define TCNT0_0 0 +#define TCNT0_1 1 +#define TCNT0_2 2 +#define TCNT0_3 3 +#define TCNT0_4 4 +#define TCNT0_5 5 +#define TCNT0_6 6 +#define TCNT0_7 7 + +#define OCR0A _SFR_IO8(0x27) +#define OCR0A_0 0 +#define OCR0A_1 1 +#define OCR0A_2 2 +#define OCR0A_3 3 +#define OCR0A_4 4 +#define OCR0A_5 5 +#define OCR0A_6 6 +#define OCR0A_7 7 + +#define OCR0B _SFR_IO8(0x28) +#define OCR0B_0 0 +#define OCR0B_1 1 +#define OCR0B_2 2 +#define OCR0B_3 3 +#define OCR0B_4 4 +#define OCR0B_5 5 +#define OCR0B_6 6 +#define OCR0B_7 7 + +#define GPIOR1 _SFR_IO8(0x2A) +#define GPIOR10 0 +#define GPIOR11 1 +#define GPIOR12 2 +#define GPIOR13 3 +#define GPIOR14 4 +#define GPIOR15 5 +#define GPIOR16 6 +#define GPIOR17 7 + +#define GPIOR2 _SFR_IO8(0x2B) +#define GPIOR20 0 +#define GPIOR21 1 +#define GPIOR22 2 +#define GPIOR23 3 +#define GPIOR24 4 +#define GPIOR25 5 +#define GPIOR26 6 +#define GPIOR27 7 + +#define SPCR _SFR_IO8(0x2C) +#define SPR0 0 +#define SPR1 1 +#define CPHA 2 +#define CPOL 3 +#define MSTR 4 +#define DORD 5 +#define SPE 6 +#define SPIE 7 + +#define SPSR _SFR_IO8(0x2D) +#define SPI2X 0 +#define WCOL 6 +#define SPIF 7 + +#define SPDR _SFR_IO8(0x2E) +#define SPDR0 0 +#define SPDR1 1 +#define SPDR2 2 +#define SPDR3 3 +#define SPDR4 4 +#define SPDR5 5 +#define SPDR6 6 +#define SPDR7 7 + +#define ACSR _SFR_IO8(0x30) +#define ACIS0 0 +#define ACIS1 1 +#define ACIC 2 +#define ACIE 3 +#define ACI 4 +#define ACO 5 +#define ACBG 6 +#define ACD 7 + +#define OCDR _SFR_IO8(0x31) +#define OCDR0 0 +#define OCDR1 1 +#define OCDR2 2 +#define OCDR3 3 +#define OCDR4 4 +#define OCDR5 5 +#define OCDR6 6 +#define OCDR7 7 + +#define SMCR _SFR_IO8(0x33) +#define SE 0 +#define SM0 1 +#define SM1 2 +#define SM2 3 + +#define MCUSR _SFR_IO8(0x34) +#define PORF 0 +#define EXTRF 1 +#define BORF 2 +#define WDRF 3 +#define JTRF 4 + +#define MCUCR _SFR_IO8(0x35) +#define IVCE 0 +#define IVSEL 1 +#define PUD 4 +#define BODSE 5 +#define BODS 6 +#define JTD 7 + +#define SPMCSR _SFR_IO8(0x37) +#define SPMEN 0 +#define PGERS 1 +#define PGWRT 2 +#define BLBSET 3 +#define RWWSRE 4 +#define SIGRD 5 +#define RWWSB 6 +#define SPMIE 7 + +#define RAMPZ _SFR_IO8(0x3B) +#define RAMPZ0 0 + +#define WDTCSR _SFR_MEM8(0x60) +#define WDP0 0 +#define WDP1 1 +#define WDP2 2 +#define WDE 3 +#define WDCE 4 +#define WDP3 5 +#define WDIE 6 +#define WDIF 7 + +#define CLKPR _SFR_MEM8(0x61) +#define CLKPS0 0 +#define CLKPS1 1 +#define CLKPS2 2 +#define CLKPS3 3 +#define CLKPCE 7 + +#define PRR0 _SFR_MEM8(0x64) +#define PRADC 0 +#define PRUSART0 1 +#define PRSPI 2 +#define PRTIM1 3 +#define PRUSART1 4 +#define PRTIM0 5 +#define PRTIM2 6 +#define PRTWI 7 + +#define __AVR_HAVE_PRR0 ((1< diff --git a/docs/html/b15f_8cpp_source.html b/docs/html/b15f_8cpp_source.html index dd5733f..a76179c 100644 --- a/docs/html/b15f_8cpp_source.html +++ b/docs/html/b15f_8cpp_source.html @@ -70,48 +70,50 @@ $(function() {
b15f.cpp
-
1 #include "b15f.h"
2 
3 B15F* B15F::instance = nullptr;
4 errorhandler_t B15F::errorhandler = nullptr;
5 
6 B15F::B15F()
7 {
8  init();
9 }
10 
11 void B15F::init()
12 {
13 
14  std::string device = exec("bash -c 'ls /dev/ttyUSB*'");
15  while(device.find(' ') != std::string::npos || device.find('\n') != std::string::npos || device.find('\t') != std::string::npos)
16  device.pop_back();
17 
18  if(device.length() == 0)
19  abort("Adapter nicht gefunden");
20 
21  std::cout << PRE << "Verwende Adapter: " << device << std::endl;
22 
23 
24 
25  std::cout << PRE << "Stelle Verbindung mit Adapter her... " << std::flush;
26  usart.setBaudrate(BAUDRATE);
27  usart.openDevice(device);
28  std::cout << "OK" << std::endl;
29 
30 
31 
32  std::cout << PRE << "Teste Verbindung... " << std::flush;
33  uint8_t tries = 3;
34  while(tries--)
35  {
36  // verwerfe Daten, die µC noch hat
37  //discard();
38 
39  if(!testConnection())
40  continue;
41 
42  if(!testIntConv())
43  continue;
44 
45  break;
46  }
47  if(tries == 0)
48  abort("Verbindungstest fehlgeschlagen. Neueste Version im Einsatz?");
49  std::cout << "OK" << std::endl;
50 
51 
52  // Gib board info aus
53  std::vector<std::string> info = getBoardInfo();
54  std::cout << PRE << "AVR Firmware Version: " << info[0] << " um " << info[1] << " Uhr (" << info[2] << ")" << std::endl;
55 }
56 
58 {
59  uint8_t tries = RECONNECT_TRIES;
60  while(tries--)
61  {
63  discard();
64 
65  if(testConnection())
66  return;
67  }
68 
69  abort("Verbindung kann nicht repariert werden");
70 }
71 
72 void B15F::discard(void)
73 {
74  try
75  {
76  usart.clearOutputBuffer();
77  for(uint8_t i = 0; i < 16; i++)
78  {
79  usart.writeByte(RQ_DISC); // sende discard Befehl (verwerfe input)
80  delay_ms(4);
81  }
82  usart.clearInputBuffer();
83  }
84  catch(std::exception& ex)
85  {
86  abort(ex);
87  }
88 }
89 
91 {
92  // erzeuge zufälliges Byte
93  srand(time(NULL));
94  uint8_t dummy = rand() % 256;
95 
96  usart.writeByte(RQ_TEST);
97  usart.writeByte(dummy);
98 
99  uint8_t aw = usart.readByte();
100  uint8_t mirror = usart.readByte();
101 
102  return aw == MSG_OK && mirror == dummy;
103 }
104 
106 {
107  srand(time(NULL));
108  uint16_t dummy = rand() % (0xFFFF / 3);
109 
110  usart.writeByte(RQ_INT);
111  usart.writeInt(dummy);
112 
113  uint16_t aw = usart.readInt();
114  return aw == dummy * 3;
115 }
116 
117 
118 std::vector<std::string> B15F::getBoardInfo(void)
119 {
120  std::vector<std::string> info;
121 
122  usart.writeByte(RQ_INFO);
123 
124  uint8_t n = usart.readByte();
125  while(n--)
126  {
127  uint8_t len = usart.readByte();
128  std::string str;
129 
130  while(len--)
131  {
132  str += static_cast<char>(usart.readByte());
133  }
134 
135  info.push_back(str);
136  }
137 
138  uint8_t aw = usart.readByte();
139  if(aw != MSG_OK)
140  abort("Board Info fehlerhalft: code " + std::to_string((int) aw));
141 
142  return info;
143 }
144 
146 {
147  usart.writeByte(RQ_ST);
148 
149  uint8_t aw = usart.readByte();
150  return aw == MSG_OK;
151 }
152 
153 bool B15F::digitalWrite0(uint8_t port)
154 {
155  usart.writeByte(RQ_BA0);
156  usart.writeByte(port);
157 
158  uint8_t aw = usart.readByte();
159  delay_us(10);
160  return aw == MSG_OK;
161 }
162 
163 bool B15F::digitalWrite1(uint8_t port)
164 {
165  usart.writeByte(RQ_BA1);
166  usart.writeByte(port);
167 
168  uint8_t aw = usart.readByte();
169  delay_us(10);
170  return aw == MSG_OK;
171 }
172 
174 {
175  usart.clearInputBuffer();
176  usart.writeByte(RQ_BE0);
177  uint8_t byte = usart.readByte();
178  delay_us(10);
179  return byte;
180 }
181 
183 {
184  usart.clearInputBuffer();
185  usart.writeByte(RQ_BE1);
186  uint8_t byte = usart.readByte();
187  delay_us(10);
188  return byte;
189 }
190 
192 {
193  usart.clearInputBuffer();
194  usart.writeByte(RQ_DSW);
195  uint8_t byte = usart.readByte();
196  delay_us(10);
197  return byte;
198 }
199 
200 bool B15F::analogWrite0(uint16_t value)
201 {
202  usart.writeByte(RQ_AA0);
203  usart.writeInt(value);
204 
205  uint8_t aw = usart.readByte();
206  delay_us(10);
207  return aw == MSG_OK;
208 }
209 
210 bool B15F::analogWrite1(uint16_t value)
211 {
212  usart.writeByte(RQ_AA1);
213  usart.writeInt(value);
214 
215  uint8_t aw = usart.readByte();
216  delay_us(10);
217  return aw == MSG_OK;
218 }
219 
220 uint16_t B15F::analogRead(uint8_t channel)
221 {
222  usart.clearInputBuffer();
223  if(channel > 7)
224  abort("Bad ADC channel: " + std::to_string(channel));
225 
226  uint8_t rq[] =
227  {
228  RQ_ADC,
229  channel
230  };
231 
232  int n_sent = usart.write_timeout(&rq[0], 0, sizeof(rq), 1000);
233  if(n_sent != sizeof(rq))
234  abort("Sent failed");
235 
236  uint16_t adc = usart.readInt();
237 
238  if(adc > 1023)
239  abort("Bad ADC data detected (1)");
240  return adc;
241 }
242 
243 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)
244 {
245  // check pointers
246  buffer_a += offset_a;
247  buffer_b += offset_b;
248 
249 
250  usart.clearInputBuffer();
251  usart.writeByte(RQ_ADC_DAC_STROKE);
252  usart.writeByte(channel_a);
253  usart.writeByte(channel_b);
254  usart.writeInt(start);
255  usart.writeInt(static_cast<uint16_t>(delta));
256  usart.writeInt(count);
257 
258  for(uint16_t i = 0; i < count; i++)
259  {
260  if(buffer_a)
261  {
262  buffer_a[i] = usart.readInt();
263 
264  if(buffer_a[i] > 1023) // check for broken usart connection
265  abort("Bad ADC data detected (2)");
266  }
267  else
268  {
269  usart.readInt();
270  }
271 
272  if(buffer_b)
273  {
274  buffer_b[i] = usart.readInt();
275 
276  if(buffer_b[i] > 1023) // check for broken usart connection
277  abort("Bad ADC data detected (3)");
278  }
279  else
280  {
281  usart.readInt();
282  }
283  }
284 
285  uint8_t aw = usart.readByte();
286  if(aw != MSG_OK)
287  abort("Sequenz unterbrochen");
288 
289  delay_us(10);
290 }
291 
292 uint8_t B15F::pwmSetFrequency(uint32_t freq)
293 {
294  usart.clearInputBuffer();
295 
296  uint8_t rq[] =
297  {
298  RQ_PWM_SET_FREQ,
299  static_cast<uint8_t>((freq >> 0) & 0xFF),
300  static_cast<uint8_t>((freq >> 8) & 0xFF),
301  static_cast<uint8_t>((freq >> 16) & 0xFF),
302  static_cast<uint8_t>((freq >> 24) & 0xFF)
303  };
304 
305  int n_sent = usart.write_timeout(&rq[0], 0, sizeof(rq), 1000);
306  if(n_sent != sizeof(rq))
307  abort("Sent failed");
308 
309  uint8_t byte = usart.readByte();
310  delay_us(10);
311  return byte;
312 }
313 
314 bool B15F::pwmSetValue(uint8_t value)
315 {
316  usart.clearInputBuffer();
317 
318  uint8_t rq[] =
319  {
320  RQ_PWM_SET_VALUE,
321  value
322  };
323 
324  int n_sent = usart.write_timeout(&rq[0], 0, sizeof(rq), 1000);
325  if(n_sent != sizeof(rq))
326  abort("Sent failed");
327 
328  uint8_t aw = usart.readByte();
329  delay_us(10);
330  return aw == MSG_OK;
331 }
332 
333 void B15F::delay_ms(uint16_t ms)
334 {
335  std::this_thread::sleep_for(std::chrono::milliseconds(ms));
336 }
337 
338 void B15F::delay_us(uint16_t us)
339 {
340  std::this_thread::sleep_for(std::chrono::microseconds(us));
341 }
342 
344 {
345  if(!instance)
346  instance = new B15F();
347 
348  return *instance;
349 }
350 
351 // https://stackoverflow.com/a/478960
352 std::string B15F::exec(std::string cmd)
353 {
354  std::array<char, 128> buffer;
355  std::string result;
356  std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd.c_str(), "r"), pclose);
357  if (!pipe)
358  {
359  throw std::runtime_error("popen() failed!");
360  }
361  while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr)
362  {
363  result += buffer.data();
364  }
365  return result;
366 }
367 
368 void B15F::abort(std::string msg)
369 {
370  DriverException ex(msg);
371  abort(ex);
372 }
373 void B15F::abort(std::exception& ex)
374 {
375  if(errorhandler)
376  errorhandler(ex);
377  else
378  {
379  std::cerr << "NOTICE: B15F::errorhandler not set" << std::endl;
380  std::cout << ex.what() << std::endl;
381  throw DriverException(ex.what());
382  }
383 }
384 
385 void B15F::setAbortHandler(errorhandler_t func)
386 {
387  errorhandler = func;
388 }
-
static std::string exec(std::string cmd)
Definition: b15f.cpp:352
+
1 #include "b15f.h"
2 
3 B15F* B15F::instance = nullptr;
4 errorhandler_t B15F::errorhandler = nullptr;
5 
6 B15F::B15F()
7 {
8  init();
9 }
10 
11 void B15F::init()
12 {
13 
14  std::string device = exec("bash -c 'ls /dev/ttyUSB*'");
15  while(device.find(' ') != std::string::npos || device.find('\n') != std::string::npos || device.find('\t') != std::string::npos)
16  device.pop_back();
17 
18  if(device.length() == 0)
19  abort("Adapter nicht gefunden");
20 
21  std::cout << PRE << "Verwende Adapter: " << device << std::endl;
22 
23 
24 
25  std::cout << PRE << "Stelle Verbindung mit Adapter her... " << std::flush;
26  usart.setBaudrate(BAUDRATE);
27  usart.openDevice(device);
28  std::cout << "OK" << std::endl;
29 
30 
31 
32  std::cout << PRE << "Teste Verbindung... " << std::flush;
33  uint8_t tries = 3;
34  while(tries--)
35  {
36  // verwerfe Daten, die µC noch hat
37  //discard();
38 
39  if(!testConnection())
40  continue;
41 
42  if(!testIntConv())
43  continue;
44 
45  break;
46  }
47  if(tries == 0)
48  abort("Verbindungstest fehlgeschlagen. Neueste Version im Einsatz?");
49  std::cout << "OK" << std::endl;
50 
51 
52  // Gib board info aus
53  std::vector<std::string> info = getBoardInfo();
54  std::cout << PRE << "AVR Firmware Version: " << info[0] << " um " << info[1] << " Uhr (" << info[2] << ")" << std::endl;
55 }
56 
58 {
59  uint8_t tries = RECONNECT_TRIES;
60  while(tries--)
61  {
63  discard();
64 
65  if(testConnection())
66  return;
67  }
68 
69  abort("Verbindung kann nicht repariert werden");
70 }
71 
72 void B15F::discard(void)
73 {
74  try
75  {
76  usart.clearOutputBuffer();
77  for(uint8_t i = 0; i < 16; i++)
78  {
79  usart.writeByte(RQ_DISC); // sende discard Befehl (verwerfe input)
80  delay_ms(4);
81  }
82  usart.clearInputBuffer();
83  }
84  catch(std::exception& ex)
85  {
86  abort(ex);
87  }
88 }
89 
91 {
92  // erzeuge zufälliges Byte
93  srand(time(NULL));
94  uint8_t dummy = rand() % 256;
95 
96  usart.writeByte(RQ_TEST);
97  usart.writeByte(dummy);
98 
99  uint8_t aw = usart.readByte();
100  uint8_t mirror = usart.readByte();
101 
102  return aw == MSG_OK && mirror == dummy;
103 }
104 
106 {
107  srand(time(NULL));
108  uint16_t dummy = rand() % (0xFFFF / 3);
109 
110  usart.writeByte(RQ_INT);
111  usart.writeInt(dummy);
112 
113  uint16_t aw = usart.readInt();
114  return aw == dummy * 3;
115 }
116 
117 
118 std::vector<std::string> B15F::getBoardInfo(void)
119 {
120  std::vector<std::string> info;
121 
122  usart.writeByte(RQ_INFO);
123 
124  uint8_t n = usart.readByte();
125  while(n--)
126  {
127  uint8_t len = usart.readByte();
128  std::string str;
129 
130  while(len--)
131  {
132  str += static_cast<char>(usart.readByte());
133  }
134 
135  info.push_back(str);
136  }
137 
138  uint8_t aw = usart.readByte();
139  if(aw != MSG_OK)
140  abort("Board Info fehlerhalft: code " + std::to_string((int) aw));
141 
142  return info;
143 }
144 
146 {
147  usart.writeByte(RQ_ST);
148 
149  uint8_t aw = usart.readByte();
150  return aw == MSG_OK;
151 }
152 
153 bool B15F::digitalWrite0(uint8_t port)
154 {
155  usart.writeByte(RQ_BA0);
156  usart.writeByte(port);
157 
158  uint8_t aw = usart.readByte();
159  delay_us(10);
160  return aw == MSG_OK;
161 }
162 
163 bool B15F::digitalWrite1(uint8_t port)
164 {
165  usart.writeByte(RQ_BA1);
166  usart.writeByte(port);
167 
168  uint8_t aw = usart.readByte();
169  delay_us(10);
170  return aw == MSG_OK;
171 }
172 
174 {
175  usart.clearInputBuffer();
176  usart.writeByte(RQ_BE0);
177  uint8_t byte = usart.readByte();
178  delay_us(10);
179  return byte;
180 }
181 
183 {
184  usart.clearInputBuffer();
185  usart.writeByte(RQ_BE1);
186  uint8_t byte = usart.readByte();
187  delay_us(10);
188  return byte;
189 }
190 
192 {
193  usart.clearInputBuffer();
194  usart.writeByte(RQ_DSW);
195  uint8_t byte = usart.readByte();
196  delay_us(10);
197  return byte;
198 }
199 
200 bool B15F::analogWrite0(uint16_t value)
201 {
202  usart.writeByte(RQ_AA0);
203  usart.writeInt(value);
204 
205  uint8_t aw = usart.readByte();
206  delay_us(10);
207  return aw == MSG_OK;
208 }
209 
210 bool B15F::analogWrite1(uint16_t value)
211 {
212  usart.writeByte(RQ_AA1);
213  usart.writeInt(value);
214 
215  uint8_t aw = usart.readByte();
216  delay_us(10);
217  return aw == MSG_OK;
218 }
219 
220 uint16_t B15F::analogRead(uint8_t channel)
221 {
222  usart.clearInputBuffer();
223  if(channel > 7)
224  abort("Bad ADC channel: " + std::to_string(channel));
225 
226  uint8_t rq[] =
227  {
228  RQ_ADC,
229  channel
230  };
231 
232  int n_sent = usart.write_timeout(&rq[0], 0, sizeof(rq), 1000);
233  if(n_sent != sizeof(rq))
234  abort("Sent failed");
235 
236  uint16_t adc = usart.readInt();
237 
238  if(adc > 1023)
239  abort("Bad ADC data detected (1)");
240  return adc;
241 }
242 
243 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)
244 {
245  // check pointers
246  buffer_a += offset_a;
247  buffer_b += offset_b;
248 
249 
250  usart.clearInputBuffer();
251  usart.writeByte(RQ_ADC_DAC_STROKE);
252  usart.writeByte(channel_a);
253  usart.writeByte(channel_b);
254  usart.writeInt(start);
255  usart.writeInt(static_cast<uint16_t>(delta));
256  usart.writeInt(count);
257 
258  for(uint16_t i = 0; i < count; i++)
259  {
260  if(buffer_a)
261  {
262  buffer_a[i] = usart.readInt();
263 
264  if(buffer_a[i] > 1023) // check for broken usart connection
265  abort("Bad ADC data detected (2)");
266  }
267  else
268  {
269  usart.readInt();
270  }
271 
272  if(buffer_b)
273  {
274  buffer_b[i] = usart.readInt();
275 
276  if(buffer_b[i] > 1023) // check for broken usart connection
277  abort("Bad ADC data detected (3)");
278  }
279  else
280  {
281  usart.readInt();
282  }
283  }
284 
285  uint8_t aw = usart.readByte();
286  if(aw != MSG_OK)
287  abort("Sequenz unterbrochen");
288 
289  delay_us(10);
290 }
291 
292 uint8_t B15F::pwmSetFrequency(uint32_t freq)
293 {
294  usart.clearInputBuffer();
295 
296  uint8_t rq[] =
297  {
298  RQ_PWM_SET_FREQ,
299  static_cast<uint8_t>((freq >> 0) & 0xFF),
300  static_cast<uint8_t>((freq >> 8) & 0xFF),
301  static_cast<uint8_t>((freq >> 16) & 0xFF),
302  static_cast<uint8_t>((freq >> 24) & 0xFF)
303  };
304 
305  int n_sent = usart.write_timeout(&rq[0], 0, sizeof(rq), 1000);
306  if(n_sent != sizeof(rq))
307  abort("Sent failed");
308 
309  uint8_t byte = usart.readByte();
310  delay_us(10);
311  return byte;
312 }
313 
314 bool B15F::pwmSetValue(uint8_t value)
315 {
316  usart.clearInputBuffer();
317 
318  uint8_t rq[] =
319  {
320  RQ_PWM_SET_VALUE,
321  value
322  };
323 
324  int n_sent = usart.write_timeout(&rq[0], 0, sizeof(rq), 1000);
325  if(n_sent != sizeof(rq))
326  abort("Sent failed");
327 
328  uint8_t aw = usart.readByte();
329  delay_us(10);
330  return aw == MSG_OK;
331 }
332 
333 bool B15F::setRegister(uint8_t adr, uint8_t val)
334 {
335  usart.clearInputBuffer();
336 
337  uint8_t rq[] =
338  {
339  RQ_SET_REG,
340  adr,
341  val
342  };
343 
344  int n_sent = usart.write_timeout(&rq[0], 0, sizeof(rq), 1000);
345  if(n_sent != sizeof(rq))
346  abort("Sent failed");
347 
348  uint8_t byte = usart.readByte();
349  delay_us(10);
350  return byte == val;
351 }
352 
353 uint8_t B15F::getRegister(uint8_t adr)
354 {
355  usart.clearInputBuffer();
356 
357  uint8_t rq[] =
358  {
359  RQ_GET_REG,
360  adr
361  };
362 
363  int n_sent = usart.write_timeout(&rq[0], 0, sizeof(rq), 1000);
364  if(n_sent != sizeof(rq))
365  abort("Sent failed");
366 
367  uint8_t aw = usart.readByte();
368  delay_us(10);
369  return aw;
370 }
371 
372 
373 void B15F::delay_ms(uint16_t ms)
374 {
375  std::this_thread::sleep_for(std::chrono::milliseconds(ms));
376 }
377 
378 void B15F::delay_us(uint16_t us)
379 {
380  std::this_thread::sleep_for(std::chrono::microseconds(us));
381 }
382 
384 {
385  if(!instance)
386  instance = new B15F();
387 
388  return *instance;
389 }
390 
391 // https://stackoverflow.com/a/478960
392 std::string B15F::exec(std::string cmd)
393 {
394  std::array<char, 128> buffer;
395  std::string result;
396  std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd.c_str(), "r"), pclose);
397  if (!pipe)
398  {
399  throw std::runtime_error("popen() failed!");
400  }
401  while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr)
402  {
403  result += buffer.data();
404  }
405  return result;
406 }
407 
408 void B15F::abort(std::string msg)
409 {
410  DriverException ex(msg);
411  abort(ex);
412 }
413 void B15F::abort(std::exception& ex)
414 {
415  if(errorhandler)
416  errorhandler(ex);
417  else
418  {
419  std::cerr << "NOTICE: B15F::errorhandler not set" << std::endl;
420  std::cout << ex.what() << std::endl;
421  throw DriverException(ex.what());
422  }
423 }
424 
425 void B15F::setAbortHandler(errorhandler_t func)
426 {
427  errorhandler = func;
428 }
+
static std::string exec(std::string cmd)
Definition: b15f.cpp:392
+
uint8_t getRegister(uint8_t adr)
Definition: b15f.cpp:353
uint8_t readByte(void)
Definition: usart.cpp:216
-
void delay_us(uint16_t us)
Definition: b15f.cpp:338
+
void delay_us(uint16_t us)
Definition: b15f.cpp:378
uint8_t digitalRead0(void)
Definition: b15f.cpp:173
uint8_t pwmSetFrequency(uint32_t freq)
Definition: b15f.cpp:292
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:243
bool testConnection(void)
Definition: b15f.cpp:90
uint8_t readDipSwitch(void)
Definition: b15f.cpp:191
-
void delay_ms(uint16_t ms)
Definition: b15f.cpp:333
-
static B15F & getInstance(void)
Definition: b15f.cpp:343
+
void delay_ms(uint16_t ms)
Definition: b15f.cpp:373
+
bool setRegister(uint8_t adr, uint8_t val)
Definition: b15f.cpp:333
+
static B15F & getInstance(void)
Definition: b15f.cpp:383
Definition: b15f.h:26
-
static void abort(std::string msg)
Definition: b15f.cpp:368
+
static void abort(std::string msg)
Definition: b15f.cpp:408
void clearInputBuffer(void)
Definition: usart.cpp:39
void clearOutputBuffer(void)
Definition: usart.cpp:46
uint16_t analogRead(uint8_t channel)
Definition: b15f.cpp:220
bool digitalWrite0(uint8_t)
Definition: b15f.cpp:153
-
const std::string PRE
B15F stdout prefix.
Definition: b15f.h:215
+
const std::string PRE
B15F stdout prefix.
Definition: b15f.h:231
void setBaudrate(uint32_t baudrate)
Definition: usart.cpp:322
bool activateSelfTestMode(void)
Definition: b15f.cpp:145
std::vector< std::string > getBoardInfo(void)
Definition: b15f.cpp:118
-
constexpr static uint16_t RECONNECT_TIMEOUT
Time in ms after which a reconnect attempt aborts.
Definition: b15f.h:218
+
constexpr static uint16_t RECONNECT_TIMEOUT
Time in ms after which a reconnect attempt aborts.
Definition: b15f.h:234
bool analogWrite1(uint16_t port)
Definition: b15f.cpp:210
void writeByte(uint8_t b)
Definition: usart.cpp:67
bool digitalWrite1(uint8_t)
Definition: b15f.cpp:163
bool pwmSetValue(uint8_t value)
Definition: b15f.cpp:314
void discard(void)
Definition: b15f.cpp:72
-
constexpr static uint8_t MSG_OK
Value to acknowledge a received command.
Definition: b15f.h:216
+
constexpr static uint8_t MSG_OK
Value to acknowledge a received command.
Definition: b15f.h:232
void openDevice(std::string device)
Definition: usart.cpp:3
uint16_t readInt(void)
Definition: usart.cpp:235
uint8_t digitalRead1(void)
Definition: b15f.cpp:182
void reconnect(void)
Definition: b15f.cpp:57
-
constexpr static uint32_t BAUDRATE
USART baudrate for communication with the MCU.
Definition: b15f.h:221
-
static void setAbortHandler(errorhandler_t func)
Definition: b15f.cpp:385
+
constexpr static uint32_t BAUDRATE
USART baudrate for communication with the MCU.
Definition: b15f.h:237
+
static void setAbortHandler(errorhandler_t func)
Definition: b15f.cpp:425
bool analogWrite0(uint16_t port)
Definition: b15f.cpp:200
-
constexpr static uint8_t RECONNECT_TRIES
Maximum count of reconnect attempts after which the driver stops.
Definition: b15f.h:220
+
constexpr static uint8_t RECONNECT_TRIES
Maximum count of reconnect attempts after which the driver stops.
Definition: b15f.h:236
void writeInt(uint16_t d)
Definition: usart.cpp:81
bool testIntConv(void)
Definition: b15f.cpp:105
diff --git a/docs/html/b15f_8h_source.html b/docs/html/b15f_8h_source.html index 346c23c..1bad799 100644 --- a/docs/html/b15f_8h_source.html +++ b/docs/html/b15f_8h_source.html @@ -70,42 +70,44 @@ $(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 #include "usart.h"
18 #include "driverexception.h"
19 #include "timeoutexception.h"
20 
21 typedef std::function<void(std::exception&)> errorhandler_t;
22 
23 
26 class B15F
27 {
28 private:
29  // privater Konstruktor
30  B15F(void);
31 public:
32 
33  /*************************************
34  * Grundfunktionen des B15F Treibers *
35  *************************************/
36 
41  void reconnect(void);
42 
47  void discard(void);
48 
53  bool testConnection(void);
54 
59  bool testIntConv(void);
60 
65  std::vector<std::string> getBoardInfo(void);
66 
71  void delay_ms(uint16_t ms);
72 
77  void delay_us(uint16_t us);
78 
83  static B15F& getInstance(void);
84 
89  static std::string exec(std::string cmd);
90 
95  static void abort(std::string msg);
96 
101  static void abort(std::exception& ex);
102 
107  static void setAbortHandler(errorhandler_t func);
108 
109  /*************************************/
110 
111 
112 
113  /*************************
114  * Steuerbefehle für B15 *
115  *************************/
116 
122  bool activateSelfTestMode(void);
123 
129  bool digitalWrite0(uint8_t);
130 
136  bool digitalWrite1(uint8_t);
137 
143  uint8_t digitalRead0(void);
144 
150  uint8_t digitalRead1(void);
151 
157  uint8_t readDipSwitch(void);
158 
164  bool analogWrite0(uint16_t port);
165 
171  bool analogWrite1(uint16_t port);
172 
178  uint16_t analogRead(uint8_t channel);
179 
195  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);
196 
204  uint8_t pwmSetFrequency(uint32_t freq);
205 
211  bool pwmSetValue(uint8_t value);
212 
213  /*************************/
214 
215 
216  // CONSTANTS
217  const std::string PRE = "[B15F] ";
218  constexpr static uint8_t MSG_OK = 0xFF;
219  constexpr static uint8_t MSG_FAIL = 0xFE;
220  constexpr static uint16_t RECONNECT_TIMEOUT = 64;
221  constexpr static uint16_t WDT_TIMEOUT = 15;
222  constexpr static uint8_t RECONNECT_TRIES = 3;
223  constexpr static uint32_t BAUDRATE = 57600;
224 
225 private:
226 
231  void init(void);
232 
233  USART usart;
234  static B15F* instance;
235  static errorhandler_t errorhandler;
236 
237  // REQUESTS
238  constexpr static uint8_t RQ_DISC = 0;
239  constexpr static uint8_t RQ_TEST = 1;
240  constexpr static uint8_t RQ_INFO = 2;
241  constexpr static uint8_t RQ_INT = 3;
242  constexpr static uint8_t RQ_ST = 4;
243  constexpr static uint8_t RQ_BA0 = 5;
244  constexpr static uint8_t RQ_BA1 = 6;
245  constexpr static uint8_t RQ_BE0 = 7;
246  constexpr static uint8_t RQ_BE1 = 8;
247  constexpr static uint8_t RQ_DSW = 9;
248  constexpr static uint8_t RQ_AA0 = 10;
249  constexpr static uint8_t RQ_AA1 = 11;
250  constexpr static uint8_t RQ_ADC = 12;
251  constexpr static uint8_t RQ_ADC_DAC_STROKE = 13;
252  constexpr static uint8_t RQ_PWM_SET_FREQ = 14;
253  constexpr static uint8_t RQ_PWM_SET_VALUE = 15;
254 };
255 
256 #endif // B15F_H
-
static std::string exec(std::string cmd)
Definition: b15f.cpp:352
-
constexpr static uint8_t MSG_FAIL
Value to reject a received command.
Definition: b15f.h:217
-
void delay_us(uint16_t us)
Definition: b15f.cpp:338
+
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 #include "usart.h"
18 #include "driverexception.h"
19 #include "timeoutexception.h"
20 
21 typedef std::function<void(std::exception&)> errorhandler_t;
22 
23 
26 class B15F
27 {
28 private:
29  // privater Konstruktor
30  B15F(void);
31 public:
32 
33  /*************************************
34  * Grundfunktionen des B15F Treibers *
35  *************************************/
36 
41  void reconnect(void);
42 
47  void discard(void);
48 
53  bool testConnection(void);
54 
59  bool testIntConv(void);
60 
65  std::vector<std::string> getBoardInfo(void);
66 
71  void delay_ms(uint16_t ms);
72 
77  void delay_us(uint16_t us);
78 
83  static B15F& getInstance(void);
84 
89  static std::string exec(std::string cmd);
90 
95  static void abort(std::string msg);
96 
101  static void abort(std::exception& ex);
102 
107  static void setAbortHandler(errorhandler_t func);
108 
109  /*************************************/
110 
111 
112 
113  /*************************
114  * Steuerbefehle für B15 *
115  *************************/
116 
122  bool activateSelfTestMode(void);
123 
129  bool digitalWrite0(uint8_t);
130 
136  bool digitalWrite1(uint8_t);
137 
143  uint8_t digitalRead0(void);
144 
150  uint8_t digitalRead1(void);
151 
157  uint8_t readDipSwitch(void);
158 
164  bool analogWrite0(uint16_t port);
165 
171  bool analogWrite1(uint16_t port);
172 
178  uint16_t analogRead(uint8_t channel);
179 
195  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);
196 
204  uint8_t pwmSetFrequency(uint32_t freq);
205 
211  bool pwmSetValue(uint8_t value);
212 
220  bool setRegister(uint8_t adr, uint8_t val);
221 
227  uint8_t getRegister(uint8_t adr);
228 
229  /*************************/
230 
231 
232  // CONSTANTS
233  const std::string PRE = "[B15F] ";
234  constexpr static uint8_t MSG_OK = 0xFF;
235  constexpr static uint8_t MSG_FAIL = 0xFE;
236  constexpr static uint16_t RECONNECT_TIMEOUT = 64;
237  constexpr static uint16_t WDT_TIMEOUT = 15;
238  constexpr static uint8_t RECONNECT_TRIES = 3;
239  constexpr static uint32_t BAUDRATE = 57600;
240 
241 private:
242 
247  void init(void);
248 
249  USART usart;
250  static B15F* instance;
251  static errorhandler_t errorhandler;
252 
253  // REQUESTS
254  constexpr static uint8_t RQ_DISC = 0;
255  constexpr static uint8_t RQ_TEST = 1;
256  constexpr static uint8_t RQ_INFO = 2;
257  constexpr static uint8_t RQ_INT = 3;
258  constexpr static uint8_t RQ_ST = 4;
259  constexpr static uint8_t RQ_BA0 = 5;
260  constexpr static uint8_t RQ_BA1 = 6;
261  constexpr static uint8_t RQ_BE0 = 7;
262  constexpr static uint8_t RQ_BE1 = 8;
263  constexpr static uint8_t RQ_DSW = 9;
264  constexpr static uint8_t RQ_AA0 = 10;
265  constexpr static uint8_t RQ_AA1 = 11;
266  constexpr static uint8_t RQ_ADC = 12;
267  constexpr static uint8_t RQ_ADC_DAC_STROKE = 13;
268  constexpr static uint8_t RQ_PWM_SET_FREQ = 14;
269  constexpr static uint8_t RQ_PWM_SET_VALUE = 15;
270  constexpr static uint8_t RQ_SET_REG = 16;
271  constexpr static uint8_t RQ_GET_REG = 17;
272 };
273 
274 #endif // B15F_H
+
static std::string exec(std::string cmd)
Definition: b15f.cpp:392
+
constexpr static uint8_t MSG_FAIL
Value to reject a received command.
Definition: b15f.h:233
+
uint8_t getRegister(uint8_t adr)
Definition: b15f.cpp:353
+
void delay_us(uint16_t us)
Definition: b15f.cpp:378
uint8_t digitalRead0(void)
Definition: b15f.cpp:173
uint8_t pwmSetFrequency(uint32_t freq)
Definition: b15f.cpp:292
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:243
bool testConnection(void)
Definition: b15f.cpp:90
uint8_t readDipSwitch(void)
Definition: b15f.cpp:191
-
void delay_ms(uint16_t ms)
Definition: b15f.cpp:333
-
static B15F & getInstance(void)
Definition: b15f.cpp:343
+
void delay_ms(uint16_t ms)
Definition: b15f.cpp:373
+
bool setRegister(uint8_t adr, uint8_t val)
Definition: b15f.cpp:333
+
static B15F & getInstance(void)
Definition: b15f.cpp:383
Definition: b15f.h:26
-
static void abort(std::string msg)
Definition: b15f.cpp:368
+
static void abort(std::string msg)
Definition: b15f.cpp:408
Definition: usart.h:18
uint16_t analogRead(uint8_t channel)
Definition: b15f.cpp:220
bool digitalWrite0(uint8_t)
Definition: b15f.cpp:153
-
const std::string PRE
B15F stdout prefix.
Definition: b15f.h:215
+
const std::string PRE
B15F stdout prefix.
Definition: b15f.h:231
bool activateSelfTestMode(void)
Definition: b15f.cpp:145
std::vector< std::string > getBoardInfo(void)
Definition: b15f.cpp:118
-
constexpr static uint16_t RECONNECT_TIMEOUT
Time in ms after which a reconnect attempt aborts.
Definition: b15f.h:218
+
constexpr static uint16_t RECONNECT_TIMEOUT
Time in ms after which a reconnect attempt aborts.
Definition: b15f.h:234
bool analogWrite1(uint16_t port)
Definition: b15f.cpp:210
bool digitalWrite1(uint8_t)
Definition: b15f.cpp:163
bool pwmSetValue(uint8_t value)
Definition: b15f.cpp:314
void discard(void)
Definition: b15f.cpp:72
-
constexpr static uint8_t MSG_OK
Value to acknowledge a received command.
Definition: b15f.h:216
+
constexpr static uint8_t MSG_OK
Value to acknowledge a received command.
Definition: b15f.h:232
uint8_t digitalRead1(void)
Definition: b15f.cpp:182
-
constexpr static uint16_t WDT_TIMEOUT
Time in ms after which the watch dog timer resets the MCU.
Definition: b15f.h:219
+
constexpr static uint16_t WDT_TIMEOUT
Time in ms after which the watch dog timer resets the MCU.
Definition: b15f.h:235
void reconnect(void)
Definition: b15f.cpp:57
-
constexpr static uint32_t BAUDRATE
USART baudrate for communication with the MCU.
Definition: b15f.h:221
-
static void setAbortHandler(errorhandler_t func)
Definition: b15f.cpp:385
+
constexpr static uint32_t BAUDRATE
USART baudrate for communication with the MCU.
Definition: b15f.h:237
+
static void setAbortHandler(errorhandler_t func)
Definition: b15f.cpp:425
bool analogWrite0(uint16_t port)
Definition: b15f.cpp:200
-
constexpr static uint8_t RECONNECT_TRIES
Maximum count of reconnect attempts after which the driver stops.
Definition: b15f.h:220
+
constexpr static uint8_t RECONNECT_TRIES
Maximum count of reconnect attempts after which the driver stops.
Definition: b15f.h:236
bool testIntConv(void)
Definition: b15f.cpp:105
diff --git a/docs/html/classB15F-members.html b/docs/html/classB15F-members.html index 119895f..e12f994 100644 --- a/docs/html/classB15F-members.html +++ b/docs/html/classB15F-members.html @@ -87,23 +87,25 @@ $(function() { exec(std::string cmd)B15Fstatic getBoardInfo(void)B15F getInstance(void)B15Fstatic - MSG_FAILB15Fstatic - MSG_OKB15Fstatic - PREB15F - pwmSetFrequency(uint32_t freq)B15F - pwmSetValue(uint8_t value)B15F - readDipSwitch(void)B15F - reconnect(void)B15F - RECONNECT_TIMEOUTB15Fstatic - RECONNECT_TRIESB15Fstatic - setAbortHandler(errorhandler_t func)B15Fstatic + getRegister(uint8_t adr)B15F + MSG_FAILB15Fstatic + MSG_OKB15Fstatic + PREB15F + pwmSetFrequency(uint32_t freq)B15F + pwmSetValue(uint8_t value)B15F + readDipSwitch(void)B15F + reconnect(void)B15F + RECONNECT_TIMEOUTB15Fstatic + RECONNECT_TRIESB15Fstatic + setAbortHandler(errorhandler_t func)B15Fstatic + setRegister(uint8_t adr, uint8_t val)B15F testConnection(void)B15F testIntConv(void)B15F WDT_TIMEOUTB15Fstatic diff --git a/docs/html/classB15F.html b/docs/html/classB15F.html index f22425d..68e4f0d 100644 --- a/docs/html/classB15F.html +++ b/docs/html/classB15F.html @@ -115,6 +115,10 @@ Public Member Functions   bool pwmSetValue (uint8_t value)   +bool setRegister (uint8_t adr, uint8_t val) +  +uint8_t getRegister (uint8_t adr) +  @@ -198,7 +202,7 @@ constexpr static uint32_t 

Static Public Member Functions

-

Definition at line 373 of file b15f.cpp.

+

Definition at line 413 of file b15f.cpp.

@@ -232,7 +236,7 @@ constexpr static uint32_t 
-

Definition at line 368 of file b15f.cpp.

+

Definition at line 408 of file b15f.cpp.

@@ -472,7 +476,7 @@ constexpr static uint32_t 
-

Definition at line 333 of file b15f.cpp.

+

Definition at line 373 of file b15f.cpp.

@@ -498,7 +502,7 @@ constexpr static uint32_t 
-

Definition at line 338 of file b15f.cpp.

+

Definition at line 378 of file b15f.cpp.

@@ -676,7 +680,7 @@ constexpr static uint32_t 
-

Definition at line 352 of file b15f.cpp.

+

Definition at line 392 of file b15f.cpp.

@@ -736,7 +740,39 @@ constexpr static uint32_t 
-

Definition at line 343 of file b15f.cpp.

+

Definition at line 383 of file b15f.cpp.

+ + + + +

◆ getRegister()

+ +
+
+ + + + + + + + +
uint8_t B15F::getRegister (uint8_t adr)
+
+

Liefert den Wert eines MCU Registers.

Parameters
+ + +
adrSpeicheradresse des Registers
+
+
+
Exceptions
+ + +
DriverException
+
+
+ +

Definition at line 353 of file b15f.cpp.

@@ -888,7 +924,50 @@ constexpr static uint32_t 
-

Definition at line 385 of file b15f.cpp.

+

Definition at line 425 of file b15f.cpp.

+ + + + +

◆ setRegister()

+ +
+
+ + + + + + + + + + + + + + + + + + +
bool B15F::setRegister (uint8_t adr,
uint8_t val 
)
+
+

Setzt direkt den Wert eines MCU Registers. Wichtig: bei einer falschen Adresse kann das Board 15 ernsthaften Schaden nehmen!

Parameters
+ + + +
adrSpeicheradresse des Registers
valNeuer Wert für das Register
+
+
+
Exceptions
+ + +
DriverException
+
+
+ +

Definition at line 333 of file b15f.cpp.

@@ -951,7 +1030,7 @@ constexpr static uint32_t 
diff --git a/docs/html/classDot-members.html b/docs/html/classDot-members.html index fafd43d..eecb9f4 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 b05a9bc..4a766ca 100644 --- a/docs/html/classDot.html +++ b/docs/html/classDot.html @@ -196,7 +196,7 @@ Public Member Functions diff --git a/docs/html/classDriverException-members.html b/docs/html/classDriverException-members.html index 5f85cd6..a2ee492 100644 --- a/docs/html/classDriverException-members.html +++ b/docs/html/classDriverException-members.html @@ -77,7 +77,7 @@ $(function() { diff --git a/docs/html/classDriverException.html b/docs/html/classDriverException.html index 95ed51e..ae8c97a 100644 --- a/docs/html/classDriverException.html +++ b/docs/html/classDriverException.html @@ -109,7 +109,7 @@ std::string msg_< diff --git a/docs/html/classPlottyFile-members.html b/docs/html/classPlottyFile-members.html index b38eece..131dda0 100644 --- a/docs/html/classPlottyFile-members.html +++ b/docs/html/classPlottyFile-members.html @@ -100,7 +100,7 @@ $(function() { diff --git a/docs/html/classPlottyFile.html b/docs/html/classPlottyFile.html index de9db48..881cffc 100644 --- a/docs/html/classPlottyFile.html +++ b/docs/html/classPlottyFile.html @@ -811,7 +811,7 @@ Public Member Functions diff --git a/docs/html/classTimeoutException-members.html b/docs/html/classTimeoutException-members.html index 8c3285a..2519544 100644 --- a/docs/html/classTimeoutException-members.html +++ b/docs/html/classTimeoutException-members.html @@ -78,7 +78,7 @@ $(function() { diff --git a/docs/html/classTimeoutException.html b/docs/html/classTimeoutException.html index 6aa40b1..ce3c55b 100644 --- a/docs/html/classTimeoutException.html +++ b/docs/html/classTimeoutException.html @@ -112,7 +112,7 @@ int m_timeout diff --git a/docs/html/classUSART-members.html b/docs/html/classUSART-members.html index 8d603c6..aab4287 100644 --- a/docs/html/classUSART-members.html +++ b/docs/html/classUSART-members.html @@ -94,7 +94,7 @@ $(function() { diff --git a/docs/html/classUSART.html b/docs/html/classUSART.html index aa16cc1..24d0a7e 100644 --- a/docs/html/classUSART.html +++ b/docs/html/classUSART.html @@ -531,7 +531,7 @@ constexpr static uint8_t B diff --git a/docs/html/classUSARTException-members.html b/docs/html/classUSARTException-members.html index fb0f7cc..131e02f 100644 --- a/docs/html/classUSARTException-members.html +++ b/docs/html/classUSARTException-members.html @@ -77,7 +77,7 @@ $(function() { diff --git a/docs/html/classUSARTException.html b/docs/html/classUSARTException.html index 96d050d..d85d089 100644 --- a/docs/html/classUSARTException.html +++ b/docs/html/classUSARTException.html @@ -109,7 +109,7 @@ std::string msg diff --git a/docs/html/classView-members.html b/docs/html/classView-members.html index 0816e70..b4be838 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 ba64d4a..d63c251 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 11fecf3..744892f 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 090a6da..ee1b6e0 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 f8b0248..017648b 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 7566433..ea10ac1 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 0620da4..da76ef6 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 e4f148d..da8106e 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 7eb9d49..ea0d8c3 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 3983a76..59de0b0 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 54bd780..18d3b60 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 941591f..dcdc53f 100644 --- a/docs/html/cli_8cpp_source.html +++ b/docs/html/cli_8cpp_source.html @@ -68,11 +68,11 @@ $(function() {
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 volatile int win_changed_cooldown = 0;
23 volatile bool t_refresh_active = false;
24 
25 void signal_handler(int signal)
26 {
27  if(signal == SIGWINCH)
28  {
29  win_changed_cooldown = 10; // 100ms
30 
31  if (!t_refresh_active)
32  {
33  if(t_refresh.joinable())
34  t_refresh.join();
35  t_refresh_active = true;
36  t_refresh = std::thread([]()
37  {
38 
39  while(win_changed_cooldown--)
40  std::this_thread::sleep_for(std::chrono::milliseconds(10));
41 
42  t_refresh_active = false;
43 
44  if(win_stack.size())
45  win_stack.back()->repaint();
46 
47  });
48  }
49 
50  }
51  else if(signal == SIGINT)
52  {
53  cleanup();
54  std::cout << "SIGINT - Abbruch." << std::endl;
55  exit(EXIT_FAILURE);
56  }
57 }
58 
59 void abort_handler(std::exception& ex)
60 {
61  ViewInfo* view = new ViewInfo();
62  view->setTitle("Fehler");
63  std::string msg(ex.what());
64  msg += "\n\nBeende in 5 Sekunden.";
65  view->setText(msg.c_str());
66  view->setLabelClose("");
67  view->repaint();
68 
69  std::this_thread::sleep_for(std::chrono::milliseconds(5000));
70 
71  cleanup();
72  std::cerr << std::endl << "*** EXCEPTION ***" << std::endl << ex.what() << std::endl;
73  exit(EXIT_FAILURE);
74 }
75 
76 void init()
77 {
78  // init b15 driver
80 #ifndef B15F_CLI_DEBUG
81  std::cout << std::endl << "Starte in 3s ..." << std::endl;
82  sleep(3);
83 #endif
84  B15F::setAbortHandler(&abort_handler);
85 
86  // init all ncurses stuff
87  initscr();
88  start_color();
89  curs_set(0); // 0: invisible, 1: normal, 2: very visible
90  clear();
91  noecho();
92  cbreak(); // Line buffering disabled. pass on everything
93  mousemask(ALL_MOUSE_EVENTS, NULL);
94 
95  // connect signals to handler
96  signal(SIGWINCH, signal_handler);
97  signal(SIGINT, signal_handler);
98 
99  // set view context
100  View::setWinContext(newwin(25, 85, 0, 0));
101 }
102 
103 
104 int main()
105 {
106  init();
107 
108  int exit_code = EXIT_SUCCESS;
109 
110  show_main(0);
111 
112  cleanup();
113 
114  return exit_code;
115 }
-
static B15F & getInstance(void)
Definition: b15f.cpp:343
-
static void setAbortHandler(errorhandler_t func)
Definition: b15f.cpp:385
+
static B15F & getInstance(void)
Definition: b15f.cpp:383
+
static void setAbortHandler(errorhandler_t func)
Definition: b15f.cpp:425
diff --git a/docs/html/dir_1788f8309b1a812dcb800a185471cf6c.html b/docs/html/dir_1788f8309b1a812dcb800a185471cf6c.html index bd969af..e501dfc 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 9d8eb0a..021c216 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 dd83450..6c6b61a 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 9c0bd19..773473b 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 015c2ad..b83ab80 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 e880b89..4d38804 100644 --- a/docs/html/files.html +++ b/docs/html/files.html @@ -99,7 +99,7 @@ $(function() { diff --git a/docs/html/functions.html b/docs/html/functions.html index 26bae8d..ccd1c21 100644 --- a/docs/html/functions.html +++ b/docs/html/functions.html @@ -191,6 +191,9 @@ $(function() {
  • getRefY() : PlottyFile
  • +
  • getRegister() +: B15F +
  • getTimeout() : USART
  • @@ -301,6 +304,9 @@ $(function() {
  • setRefY() : PlottyFile
  • +
  • setRegister() +: B15F +
  • setTimeout() : USART
  • @@ -349,7 +355,7 @@ $(function() { diff --git a/docs/html/functions_func.html b/docs/html/functions_func.html index 1c2fd52..89acf80 100644 --- a/docs/html/functions_func.html +++ b/docs/html/functions_func.html @@ -184,6 +184,9 @@ $(function() {
  • getRefY() : PlottyFile
  • +
  • getRegister() +: B15F +
  • getTimeout() : USART
  • @@ -275,6 +278,9 @@ $(function() {
  • setRefY() : PlottyFile
  • +
  • setRegister() +: B15F +
  • setTimeout() : USART
  • @@ -320,7 +326,7 @@ $(function() { diff --git a/docs/html/functions_vars.html b/docs/html/functions_vars.html index 3172ad7..a041bb7 100644 --- a/docs/html/functions_vars.html +++ b/docs/html/functions_vars.html @@ -88,7 +88,7 @@ $(function() { diff --git a/docs/html/hierarchy.html b/docs/html/hierarchy.html index bf24851..506d51b 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 50426bf..63f9619 100644 --- a/docs/html/index.html +++ b/docs/html/index.html @@ -72,7 +72,7 @@ Dort befindet sich auch eine Übersicht der verfügbaren Befehle.

    diff --git a/docs/html/plottyfile_8cpp_source.html b/docs/html/plottyfile_8cpp_source.html index abd1e0b..1427215 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 dd26e80..1021496 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/search/all_6.js b/docs/html/search/all_6.js index c269a53..9518d98 100644 --- a/docs/html/search/all_6.js +++ b/docs/html/search/all_6.js @@ -13,6 +13,7 @@ var searchData= ['getquadrant',['getQuadrant',['../classPlottyFile.html#a54e94e80061a27614f2d4d63697d3376',1,'PlottyFile']]], ['getrefx',['getRefX',['../classPlottyFile.html#a7dd84b9f0826f3220fc6b5a4f1ce9890',1,'PlottyFile']]], ['getrefy',['getRefY',['../classPlottyFile.html#ae6650c61a3b1a610ce716253418bd7f2',1,'PlottyFile']]], + ['getregister',['getRegister',['../classB15F.html#a43b477a9e2e5b1b2142958fa5e1a78b3',1,'B15F']]], ['gettimeout',['getTimeout',['../classUSART.html#a19cf777956a038878fc2d2b58c3d2b41',1,'USART']]], ['getunitpara',['getUnitPara',['../classPlottyFile.html#abcda4139adf8c5ab8a93b13b84ac097c',1,'PlottyFile']]], ['getunitx',['getUnitX',['../classPlottyFile.html#af952ac5e2c40896acaf6a86063874fe3',1,'PlottyFile']]], diff --git a/docs/html/search/all_b.js b/docs/html/search/all_b.js index 588c06f..552513c 100644 --- a/docs/html/search/all_b.js +++ b/docs/html/search/all_b.js @@ -11,6 +11,7 @@ var searchData= ['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#a2735424cf98bd0e2892b5a9b6eb24582',1,'B15F']]], ['settimeout',['setTimeout',['../classUSART.html#ad7fe866cebe920784d2b17602824c7ff',1,'USART']]], ['setunitpara',['setUnitPara',['../classPlottyFile.html#abbac84109a1e0958a4ca5c270fac0986',1,'PlottyFile']]], ['setunitx',['setUnitX',['../classPlottyFile.html#ab8d35a841ca9c325fca671cf34e03527',1,'PlottyFile']]], diff --git a/docs/html/search/functions_5.js b/docs/html/search/functions_5.js index c269a53..9518d98 100644 --- a/docs/html/search/functions_5.js +++ b/docs/html/search/functions_5.js @@ -13,6 +13,7 @@ var searchData= ['getquadrant',['getQuadrant',['../classPlottyFile.html#a54e94e80061a27614f2d4d63697d3376',1,'PlottyFile']]], ['getrefx',['getRefX',['../classPlottyFile.html#a7dd84b9f0826f3220fc6b5a4f1ce9890',1,'PlottyFile']]], ['getrefy',['getRefY',['../classPlottyFile.html#ae6650c61a3b1a610ce716253418bd7f2',1,'PlottyFile']]], + ['getregister',['getRegister',['../classB15F.html#a43b477a9e2e5b1b2142958fa5e1a78b3',1,'B15F']]], ['gettimeout',['getTimeout',['../classUSART.html#a19cf777956a038878fc2d2b58c3d2b41',1,'USART']]], ['getunitpara',['getUnitPara',['../classPlottyFile.html#abcda4139adf8c5ab8a93b13b84ac097c',1,'PlottyFile']]], ['getunitx',['getUnitX',['../classPlottyFile.html#af952ac5e2c40896acaf6a86063874fe3',1,'PlottyFile']]], diff --git a/docs/html/search/functions_9.js b/docs/html/search/functions_9.js index 588c06f..552513c 100644 --- a/docs/html/search/functions_9.js +++ b/docs/html/search/functions_9.js @@ -11,6 +11,7 @@ var searchData= ['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#a2735424cf98bd0e2892b5a9b6eb24582',1,'B15F']]], ['settimeout',['setTimeout',['../classUSART.html#ad7fe866cebe920784d2b17602824c7ff',1,'USART']]], ['setunitpara',['setUnitPara',['../classPlottyFile.html#abbac84109a1e0958a4ca5c270fac0986',1,'PlottyFile']]], ['setunitx',['setUnitX',['../classPlottyFile.html#ab8d35a841ca9c325fca671cf34e03527',1,'PlottyFile']]], diff --git a/docs/html/timeoutexception_8h_source.html b/docs/html/timeoutexception_8h_source.html index 9351c47..0bfd0e2 100644 --- a/docs/html/timeoutexception_8h_source.html +++ b/docs/html/timeoutexception_8h_source.html @@ -74,7 +74,7 @@ $(function() { diff --git a/docs/html/ui_8cpp_source.html b/docs/html/ui_8cpp_source.html index 2012b32..b82ff5f 100644 --- a/docs/html/ui_8cpp_source.html +++ b/docs/html/ui_8cpp_source.html @@ -73,8 +73,8 @@ $(function() {
    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 BE0 ]", &show_digital_output0);
    13  view->addChoice("[ Digitale Ausgabe BE1 ]", &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\nEs war einmal...");
    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 bestaetigen\nmit 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 delay_ms(uint16_t ms)
    Definition: b15f.cpp:333
    -
    static B15F & getInstance(void)
    Definition: b15f.cpp:343
    +
    void delay_ms(uint16_t ms)
    Definition: b15f.cpp:373
    +
    static B15F & getInstance(void)
    Definition: b15f.cpp:383
    Definition: b15f.h:26
    bool digitalWrite0(uint8_t)
    Definition: b15f.cpp:153
    bool activateSelfTestMode(void)
    Definition: b15f.cpp:145
    @@ -83,12 +83,12 @@ $(function() {
    bool digitalWrite1(uint8_t)
    Definition: b15f.cpp:163
    void discard(void)
    Definition: b15f.cpp:72
    -
    constexpr static uint16_t WDT_TIMEOUT
    Time in ms after which the watch dog timer resets the MCU.
    Definition: b15f.h:219
    +
    constexpr static uint16_t WDT_TIMEOUT
    Time in ms after which the watch dog timer resets the MCU.
    Definition: b15f.h:235
    void reconnect(void)
    Definition: b15f.cpp:57
    bool analogWrite0(uint16_t port)
    Definition: b15f.cpp:200
    diff --git a/docs/html/ui_8h_source.html b/docs/html/ui_8h_source.html index 545b5cb..e3da44c 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 70b7d23..3c613ee 100644 --- a/docs/html/usart_8cpp_source.html +++ b/docs/html/usart_8cpp_source.html @@ -90,7 +90,7 @@ $(function() {
    void writeInt(uint16_t d)
    Definition: usart.cpp:81
    diff --git a/docs/html/usart_8h_source.html b/docs/html/usart_8h_source.html index 25eac7a..fb279ff 100644 --- a/docs/html/usart_8h_source.html +++ b/docs/html/usart_8h_source.html @@ -89,7 +89,7 @@ $(function() {
    void writeInt(uint16_t d)
    Definition: usart.cpp:81
    diff --git a/docs/html/usartexception_8h_source.html b/docs/html/usartexception_8h_source.html index d037b79..ce6e187 100644 --- a/docs/html/usartexception_8h_source.html +++ b/docs/html/usartexception_8h_source.html @@ -74,7 +74,7 @@ $(function() { diff --git a/docs/html/view_8cpp_source.html b/docs/html/view_8cpp_source.html index 030d2a5..ce0f029 100644 --- a/docs/html/view_8cpp_source.html +++ b/docs/html/view_8cpp_source.html @@ -71,10 +71,10 @@ $(function() {
    1 #include "view.h"
    2 
    3 WINDOW* View::win = nullptr;
    4 
    5 View::View()
    6 {
    7  if(!win)
    8  {
    9  B15F::abort("View::win not initialized, missing context");
    10  }
    11  getmaxyx(win, height, width); // init width and height
    12  keypad(win, TRUE);
    13 }
    14 
    15 View::~View()
    16 {
    17 }
    18 
    19 void View::setWinContext(WINDOW* win)
    20 {
    21  View::win = win;
    22 }
    23 
    24 WINDOW* View::getWinContext()
    25 {
    26  return win;
    27 }
    28 
    29 // from: https://stackoverflow.com/a/37454181
    30 std::vector<std::string> View::str_split(const std::string& str, const std::string delim)
    31 {
    32  std::vector<std::string> tokens;
    33  size_t prev = 0, pos = 0;
    34  do
    35  {
    36  pos = str.find(delim, prev);
    37  if (pos == std::string::npos) pos = str.length();
    38  std::string token = str.substr(prev, pos-prev);
    39  if (!token.empty()) tokens.push_back(token);
    40  prev = pos + delim.length();
    41  }
    42  while (pos < str.length() && prev < str.length());
    43  return tokens;
    44 }
    45 
    46 
    47 void View::setTitle(std::string title)
    48 {
    49  this->title = title;
    50 }
    51 
    52 void View::repaint()
    53 {
    54  // get screen size
    55  struct winsize size;
    56  if (ioctl(0, TIOCGWINSZ, (char *) &size) < 0)
    57  throw std::runtime_error("TIOCGWINSZ error");
    58 
    59 
    60  start_x = floor((size.ws_col - width) / 2.);
    61  start_y = floor((size.ws_row - height) / 2.);
    62 
    63  curs_set(0); // hide cursor
    64  mvwin(win, start_y, start_x);
    65  clear();
    66  wclear(win);
    67 
    68  // generic draw
    69  box(win, 0, 0);
    70  int offset_x = (width - title.length()) / 2;
    71  mvwprintw(win, 1, offset_x, "%s", title.c_str());
    72 
    73  // specific draw
    74  draw();
    75 
    76  refresh();
    77  wrefresh(win);
    78 }
    -
    static void abort(std::string msg)
    Definition: b15f.cpp:368
    +
    static void abort(std::string msg)
    Definition: b15f.cpp:408
    diff --git a/docs/html/view_8h_source.html b/docs/html/view_8h_source.html index 8978a3e..34219aa 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 c9d1a98..fc91695 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 4aaf34e..253009d 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 fa3a723..09f6315 100644 --- a/docs/html/view__monitor_8cpp_source.html +++ b/docs/html/view__monitor_8cpp_source.html @@ -74,17 +74,17 @@ $(function() {
    uint8_t digitalRead0(void)
    Definition: b15f.cpp:173
    uint8_t readDipSwitch(void)
    Definition: b15f.cpp:191
    -
    void delay_ms(uint16_t ms)
    Definition: b15f.cpp:333
    -
    static B15F & getInstance(void)
    Definition: b15f.cpp:343
    +
    void delay_ms(uint16_t ms)
    Definition: b15f.cpp:373
    +
    static B15F & getInstance(void)
    Definition: b15f.cpp:383
    Definition: b15f.h:26
    -
    static void abort(std::string msg)
    Definition: b15f.cpp:368
    +
    static void abort(std::string msg)
    Definition: b15f.cpp:408
    uint16_t analogRead(uint8_t channel)
    Definition: b15f.cpp:220
    uint8_t digitalRead1(void)
    Definition: b15f.cpp:182
    void reconnect(void)
    Definition: b15f.cpp:57
    diff --git a/docs/html/view__monitor_8h_source.html b/docs/html/view__monitor_8h_source.html index c050394..b311d44 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 0e91d6e..cb9f31c 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 6acbb7b..3ffc2fc 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 d78a6f9..324fa41 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 19bac8c..e284347 100644 --- a/docs/html/view__selection_8h_source.html +++ b/docs/html/view__selection_8h_source.html @@ -75,7 +75,7 @@ $(function() { diff --git a/firmware/requests.cpp b/firmware/requests.cpp index 55f5cf6..bd3c014 100644 --- a/firmware/requests.cpp +++ b/firmware/requests.cpp @@ -70,6 +70,14 @@ void handleRequest() case RQ_PWM_SET_VALUE: rqPwmSetValue(); break; + + case RQ_SET_REG: + rqSetRegister(); + break; + + case RQ_GET_REG: + rqGetRegister(); + break; default: break; @@ -244,3 +252,24 @@ void rqPwmSetValue() usart.writeByte(USART::MSG_OK); usart.flush(); } + +void rqSetRegister() +{ + usart.initTX(); + uint16_t reg = usart.readByte(); + uint16_t val = usart.readByte(); + + (*(volatile uint8_t *) reg) = val; + usart.writeByte((*(volatile uint8_t *) reg)); + usart.flush(); +} + +void rqGetRegister() +{ + usart.initTX(); + uint16_t reg = usart.readByte(); + + usart.writeByte((*(volatile uint8_t *) reg)); + usart.flush(); +} + diff --git a/firmware/requests.h b/firmware/requests.h index 418b003..336f8f5 100644 --- a/firmware/requests.h +++ b/firmware/requests.h @@ -20,9 +20,11 @@ constexpr static uint8_t RQ_DSW = 9; constexpr static uint8_t RQ_AA0 = 10; constexpr static uint8_t RQ_AA1 = 11; constexpr static uint8_t RQ_ADC = 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_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_REG = 16; +constexpr static uint8_t RQ_GET_REG = 17; uint8_t const rq_len[] = { /* RQ_DISC */ 1, @@ -40,7 +42,9 @@ uint8_t const rq_len[] = { /* RQ_ADC */ 2, /* RQ_ADC_DAC_STROKE */ 9, /* RQ_PWM_SET_FREQ */ 5, - /* RQ_PWM_SET_VALUE */ 2 + /* RQ_PWM_SET_VALUE */ 2, + /* RQ_SET_REG */ 3, + /* RQ_GET_REG */ 2 }; /** @@ -65,5 +69,7 @@ void rqAnalogRead(void); void rqAdcDacStroke(void); void rqPwmSetFreq(void); void rqPwmSetValue(void); +void rqSetRegister(void); +void rqGetRegister(void); #endif // REQUESTS_H