servo geht
This commit is contained in:
parent
7b2e5aa1ef
commit
eaa8ca721a
207 changed files with 278 additions and 15300 deletions
|
@ -524,6 +524,59 @@ uint16_t* B15F::getInterruptCounterOffset()
|
|||
return reinterpret_cast<uint16_t*>(aw);
|
||||
}
|
||||
|
||||
void B15F::setServoEnabled(void)
|
||||
{
|
||||
usart.clearInputBuffer();
|
||||
|
||||
uint8_t rq[] =
|
||||
{
|
||||
RQ_SERVO_ENABLE
|
||||
};
|
||||
|
||||
usart.transmit(&rq[0], 0, sizeof(rq));
|
||||
|
||||
uint8_t aw;
|
||||
usart.receive(&aw, 0, sizeof(aw));
|
||||
assertCode(aw, MSG_OK);
|
||||
}
|
||||
|
||||
void B15F::setServoDisabled(void)
|
||||
{
|
||||
usart.clearInputBuffer();
|
||||
|
||||
uint8_t rq[] =
|
||||
{
|
||||
RQ_SERVO_DISABLE
|
||||
};
|
||||
|
||||
usart.transmit(&rq[0], 0, sizeof(rq));
|
||||
|
||||
uint8_t aw;
|
||||
usart.receive(&aw, 0, sizeof(aw));
|
||||
assertCode(aw, MSG_OK);
|
||||
}
|
||||
|
||||
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[] =
|
||||
{
|
||||
RQ_SERVO_SET_POS,
|
||||
static_cast<uint8_t >(pos & 0xFF),
|
||||
static_cast<uint8_t >(pos >> 8)
|
||||
};
|
||||
|
||||
usart.transmit(&rq[0], 0, sizeof(rq));
|
||||
|
||||
uint8_t aw;
|
||||
usart.receive(&aw, 0, sizeof(aw));
|
||||
assertCode(aw, MSG_OK);
|
||||
}
|
||||
|
||||
/*************************/
|
||||
|
||||
|
||||
|
@ -582,3 +635,9 @@ 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) + ")");
|
||||
}
|
||||
|
|
|
@ -1,584 +0,0 @@
|
|||
#include "b15f.h"
|
||||
|
||||
B15F *B15F::instance = nullptr;
|
||||
errorhandler_t B15F::errorhandler = nullptr;
|
||||
|
||||
|
||||
/*************************************
|
||||
* Grundfunktionen des B15F Treibers *
|
||||
*************************************/
|
||||
|
||||
B15F &B15F::getInstance(void)
|
||||
{
|
||||
if (!instance)
|
||||
instance = new B15F();
|
||||
|
||||
return *instance;
|
||||
}
|
||||
|
||||
void B15F::reconnect()
|
||||
{
|
||||
uint8_t tries = RECONNECT_TRIES;
|
||||
while (tries--)
|
||||
{
|
||||
delay_ms(RECONNECT_TIMEOUT);
|
||||
discard();
|
||||
|
||||
if (testConnection())
|
||||
return;
|
||||
}
|
||||
|
||||
abort("Verbindung kann nicht repariert werden");
|
||||
}
|
||||
|
||||
void B15F::discard(void)
|
||||
{
|
||||
try
|
||||
{
|
||||
uint8_t rq[] =
|
||||
{
|
||||
RQ_DISCARD
|
||||
};
|
||||
|
||||
usart.clearOutputBuffer();
|
||||
for (uint8_t i = 0; i < 16; i++)
|
||||
{
|
||||
usart.transmit(&rq[0], 0, sizeof(rq)); // sende discard Befehl (verwerfe input)
|
||||
delay_ms(4);
|
||||
}
|
||||
usart.clearInputBuffer();
|
||||
}
|
||||
catch (std::exception &ex)
|
||||
{
|
||||
abort(ex);
|
||||
}
|
||||
}
|
||||
|
||||
bool B15F::testConnection()
|
||||
{
|
||||
// erzeuge zufälliges Byte
|
||||
srand(time(NULL));
|
||||
uint8_t dummy = rand() % 256;
|
||||
|
||||
uint8_t rq[] =
|
||||
{
|
||||
RQ_TEST,
|
||||
dummy
|
||||
};
|
||||
usart.transmit(&rq[0], 0, sizeof(rq));
|
||||
|
||||
uint8_t aw[2];
|
||||
usart.receive(&aw[0], 0, sizeof(aw));
|
||||
|
||||
return aw[0] == MSG_OK && aw[1] == dummy;
|
||||
}
|
||||
|
||||
bool B15F::testIntConv()
|
||||
{
|
||||
srand(time(NULL));
|
||||
uint16_t dummy = rand() % (0xFFFF / 3);
|
||||
|
||||
uint8_t rq[] =
|
||||
{
|
||||
RQ_INT_TEST,
|
||||
static_cast<uint8_t >(dummy & 0xFF),
|
||||
static_cast<uint8_t >(dummy >> 8)
|
||||
};
|
||||
usart.transmit(&rq[0], 0, sizeof(rq));
|
||||
|
||||
uint16_t aw;
|
||||
usart.receive(reinterpret_cast<uint8_t *>(&aw), 0, sizeof(aw));
|
||||
|
||||
return aw == dummy * 3;
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::string> B15F::getBoardInfo(void)
|
||||
{
|
||||
std::vector<std::string> info;
|
||||
|
||||
uint8_t rq[] =
|
||||
{
|
||||
RQ_INFO
|
||||
};
|
||||
usart.transmit(&rq[0], 0, sizeof(rq));
|
||||
|
||||
uint8_t n;
|
||||
usart.receive(&n, 0, sizeof(n));
|
||||
while (n--)
|
||||
{
|
||||
uint8_t len;
|
||||
usart.receive(&len, 0, sizeof(len));
|
||||
|
||||
char str[len + 1];
|
||||
str[len] = '\0';
|
||||
usart.receive(reinterpret_cast<uint8_t *>(&str[0]), 0, len);
|
||||
|
||||
info.push_back(std::string(str));
|
||||
}
|
||||
|
||||
uint8_t aw;
|
||||
usart.receive(&aw, 0, sizeof(aw));
|
||||
if (aw != MSG_OK)
|
||||
abort("Board Info fehlerhalft: code " + std::to_string((int) aw));
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
void B15F::delay_ms(uint16_t ms)
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
|
||||
}
|
||||
|
||||
void B15F::delay_us(uint16_t us)
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(us));
|
||||
}
|
||||
|
||||
void B15F::reverse(uint8_t& b)
|
||||
{
|
||||
b = (b & 0xF0) >> 4 | (b & 0x0F) << 4;
|
||||
b = (b & 0xCC) >> 2 | (b & 0x33) << 2;
|
||||
b = (b & 0xAA) >> 1 | (b & 0x55) << 1;
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/a/478960
|
||||
std::string B15F::exec(std::string cmd)
|
||||
{
|
||||
std::array<char, 128> buffer;
|
||||
std::string result;
|
||||
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd.c_str(), "r"), pclose);
|
||||
if (!pipe)
|
||||
{
|
||||
throw std::runtime_error("popen() failed!");
|
||||
}
|
||||
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr)
|
||||
{
|
||||
result += buffer.data();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void B15F::abort(std::string msg)
|
||||
{
|
||||
DriverException ex(msg);
|
||||
abort(ex);
|
||||
}
|
||||
|
||||
void B15F::abort(std::exception &ex)
|
||||
{
|
||||
if (errorhandler)
|
||||
errorhandler(ex);
|
||||
else
|
||||
{
|
||||
std::cerr << "NOTICE: B15F::errorhandler not set" << std::endl;
|
||||
std::cout << ex.what() << std::endl;
|
||||
throw DriverException(ex.what());
|
||||
}
|
||||
}
|
||||
|
||||
void B15F::setAbortHandler(errorhandler_t func)
|
||||
{
|
||||
errorhandler = func;
|
||||
}
|
||||
|
||||
/*************************************/
|
||||
|
||||
|
||||
|
||||
/*************************
|
||||
* Steuerbefehle für B15 *
|
||||
*************************/
|
||||
|
||||
bool B15F::activateSelfTestMode()
|
||||
{
|
||||
uint8_t rq[] =
|
||||
{
|
||||
RQ_SELF_TEST
|
||||
};
|
||||
usart.transmit(&rq[0], 0, sizeof(rq));
|
||||
|
||||
uint8_t aw;
|
||||
usart.receive(&aw, 0, sizeof(aw));
|
||||
return aw == MSG_OK;
|
||||
}
|
||||
|
||||
bool B15F::digitalWrite0(uint8_t port)
|
||||
{
|
||||
uint8_t rq[] =
|
||||
{
|
||||
RQ_DIGITAL_WRITE_0,
|
||||
port
|
||||
};
|
||||
usart.transmit(&rq[0], 0, sizeof(rq));
|
||||
|
||||
uint8_t aw;
|
||||
usart.receive(&aw, 0, sizeof(aw));
|
||||
return aw == MSG_OK;
|
||||
}
|
||||
|
||||
bool B15F::digitalWrite1(uint8_t port)
|
||||
{
|
||||
uint8_t rq[] =
|
||||
{
|
||||
RQ_DIGITAL_WRITE_1,
|
||||
port
|
||||
};
|
||||
usart.transmit(&rq[0], 0, sizeof(rq));
|
||||
|
||||
uint8_t aw;
|
||||
usart.receive(&aw, 0, sizeof(aw));
|
||||
return aw == MSG_OK;
|
||||
}
|
||||
|
||||
uint8_t B15F::digitalRead0()
|
||||
{
|
||||
usart.clearInputBuffer();
|
||||
uint8_t rq[] =
|
||||
{
|
||||
RQ_DIGITAL_READ_0
|
||||
};
|
||||
usart.transmit(&rq[0], 0, sizeof(rq));
|
||||
|
||||
uint8_t aw;
|
||||
usart.receive(&aw, 0, sizeof(aw));
|
||||
return aw;
|
||||
}
|
||||
|
||||
uint8_t B15F::digitalRead1()
|
||||
{
|
||||
usart.clearInputBuffer();
|
||||
uint8_t rq[] =
|
||||
{
|
||||
RQ_DIGITAL_READ_1
|
||||
};
|
||||
usart.transmit(&rq[0], 0, sizeof(rq));
|
||||
|
||||
uint8_t aw;
|
||||
usart.receive(&aw, 0, sizeof(aw));
|
||||
return aw;
|
||||
}
|
||||
|
||||
uint8_t B15F::readDipSwitch()
|
||||
{
|
||||
usart.clearInputBuffer();
|
||||
uint8_t rq[] =
|
||||
{
|
||||
RQ_READ_DIP_SWITCH
|
||||
};
|
||||
usart.transmit(&rq[0], 0, sizeof(rq));
|
||||
|
||||
uint8_t aw;
|
||||
usart.receive(&aw, 0, sizeof(aw));
|
||||
|
||||
reverse(aw); // DIP Schalter muss invertiert werden!
|
||||
|
||||
return aw;
|
||||
}
|
||||
|
||||
bool B15F::analogWrite0(uint16_t value)
|
||||
{
|
||||
uint8_t rq[] =
|
||||
{
|
||||
RQ_ANALOG_WRITE_0,
|
||||
static_cast<uint8_t >(value & 0xFF),
|
||||
static_cast<uint8_t >(value >> 8)
|
||||
};
|
||||
usart.transmit(&rq[0], 0, sizeof(rq));
|
||||
|
||||
uint8_t aw;
|
||||
usart.receive(&aw, 0, sizeof(aw));
|
||||
return aw == MSG_OK;
|
||||
}
|
||||
|
||||
bool B15F::analogWrite1(uint16_t value)
|
||||
{
|
||||
uint8_t rq[] =
|
||||
{
|
||||
RQ_ANALOG_WRITE_1,
|
||||
static_cast<uint8_t >(value & 0xFF),
|
||||
static_cast<uint8_t >(value >> 8)
|
||||
};
|
||||
usart.transmit(&rq[0], 0, sizeof(rq));
|
||||
|
||||
uint8_t aw;
|
||||
usart.receive(&aw, 0, sizeof(aw));
|
||||
return aw == MSG_OK;
|
||||
}
|
||||
|
||||
uint16_t B15F::analogRead(uint8_t channel)
|
||||
{
|
||||
usart.clearInputBuffer();
|
||||
if (channel > 7)
|
||||
abort("Bad ADC channel: " + std::to_string(channel));
|
||||
|
||||
uint8_t rq[] =
|
||||
{
|
||||
RQ_ANALOG_READ,
|
||||
channel
|
||||
};
|
||||
|
||||
usart.transmit(&rq[0], 0, sizeof(rq));
|
||||
|
||||
uint16_t aw;
|
||||
usart.receive(reinterpret_cast<uint8_t *>(&aw), 0, sizeof(aw));
|
||||
|
||||
if (aw > 1023)
|
||||
abort("Bad ADC data detected (1)");
|
||||
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,
|
||||
uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count)
|
||||
{
|
||||
// prepare pointers
|
||||
buffer_a += offset_a;
|
||||
buffer_b += offset_b;
|
||||
|
||||
|
||||
usart.clearInputBuffer();
|
||||
uint8_t rq[] =
|
||||
{
|
||||
RQ_ADC_DAC_STROKE,
|
||||
channel_a,
|
||||
channel_b,
|
||||
static_cast<uint8_t >(start & 0xFF),
|
||||
static_cast<uint8_t >(start >> 8),
|
||||
static_cast<uint8_t >(delta & 0xFF),
|
||||
static_cast<uint8_t >(delta >> 8),
|
||||
static_cast<uint8_t >(count & 0xFF),
|
||||
static_cast<uint8_t >(count >> 8)
|
||||
};
|
||||
|
||||
usart.transmit(&rq[0], 0, sizeof(rq));
|
||||
|
||||
for (uint16_t i = 0; i < count; i++)
|
||||
{
|
||||
if (buffer_a)
|
||||
{
|
||||
usart.receive(reinterpret_cast<uint8_t *>(&buffer_a[i]), 0, 2);
|
||||
|
||||
if (buffer_a[i] > 1023) // check for broken usart connection
|
||||
abort("Bad ADC data detected (2)");
|
||||
}
|
||||
else
|
||||
{
|
||||
usart.drop(2);
|
||||
}
|
||||
|
||||
if (buffer_b)
|
||||
{
|
||||
usart.receive(reinterpret_cast<uint8_t *>(&buffer_b[i]), 0, 2);
|
||||
|
||||
if (buffer_b[i] > 1023) // check for broken usart connection
|
||||
abort("Bad ADC data detected (3)");
|
||||
}
|
||||
else
|
||||
{
|
||||
usart.drop(2);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t aw;
|
||||
usart.receive(&aw, 0, sizeof(aw));
|
||||
if(aw != MSG_OK)
|
||||
abort("Sequenz unterbrochen");
|
||||
}
|
||||
|
||||
uint8_t B15F::pwmSetFrequency(uint32_t freq)
|
||||
{
|
||||
usart.clearInputBuffer();
|
||||
|
||||
uint8_t rq[] =
|
||||
{
|
||||
RQ_PWM_SET_FREQ,
|
||||
static_cast<uint8_t>((freq >> 0) & 0xFF),
|
||||
static_cast<uint8_t>((freq >> 8) & 0xFF),
|
||||
static_cast<uint8_t>((freq >> 16) & 0xFF),
|
||||
static_cast<uint8_t>((freq >> 24) & 0xFF)
|
||||
};
|
||||
|
||||
usart.transmit(&rq[0], 0, sizeof(rq));
|
||||
|
||||
uint8_t aw;
|
||||
usart.receive(&aw, 0, sizeof(aw));
|
||||
return aw;
|
||||
}
|
||||
|
||||
bool B15F::pwmSetValue(uint8_t value)
|
||||
{
|
||||
usart.clearInputBuffer();
|
||||
|
||||
uint8_t rq[] =
|
||||
{
|
||||
RQ_PWM_SET_VALUE,
|
||||
value
|
||||
};
|
||||
|
||||
usart.transmit(&rq[0], 0, sizeof(rq));
|
||||
|
||||
uint8_t aw;
|
||||
usart.receive(&aw, 0, sizeof(aw));
|
||||
return aw == MSG_OK;
|
||||
}
|
||||
|
||||
bool B15F::setMem8(volatile uint8_t* adr, uint8_t val)
|
||||
{
|
||||
usart.clearInputBuffer();
|
||||
|
||||
uint8_t rq[] =
|
||||
{
|
||||
RQ_SET_MEM_8,
|
||||
static_cast<uint8_t >(reinterpret_cast<size_t>(adr) & 0xFF),
|
||||
static_cast<uint8_t >(reinterpret_cast<size_t>(adr) >> 8),
|
||||
val
|
||||
};
|
||||
|
||||
usart.transmit(&rq[0], 0, sizeof(rq));
|
||||
|
||||
uint8_t aw;
|
||||
usart.receive(&aw, 0, sizeof(aw));
|
||||
return aw == val;
|
||||
}
|
||||
|
||||
uint8_t B15F::getMem8(volatile uint8_t* adr)
|
||||
{
|
||||
usart.clearInputBuffer();
|
||||
|
||||
uint8_t rq[] =
|
||||
{
|
||||
RQ_GET_MEM_8,
|
||||
static_cast<uint8_t >(reinterpret_cast<size_t>(adr) & 0xFF),
|
||||
static_cast<uint8_t >(reinterpret_cast<size_t>(adr) >> 8)
|
||||
};
|
||||
|
||||
usart.transmit(&rq[0], 0, sizeof(rq));
|
||||
|
||||
uint8_t aw;
|
||||
usart.receive(&aw, 0, sizeof(aw));
|
||||
return aw;
|
||||
}
|
||||
|
||||
bool B15F::setMem16(volatile uint16_t* adr, uint16_t val)
|
||||
{
|
||||
usart.clearInputBuffer();
|
||||
|
||||
uint8_t rq[] =
|
||||
{
|
||||
RQ_SET_MEM_16,
|
||||
static_cast<uint8_t >(reinterpret_cast<size_t>(adr) & 0xFF),
|
||||
static_cast<uint8_t >(reinterpret_cast<size_t>(adr) >> 8),
|
||||
static_cast<uint8_t >(val & 0xFF),
|
||||
static_cast<uint8_t >(val >> 8)
|
||||
};
|
||||
|
||||
usart.transmit(&rq[0], 0, sizeof(rq));
|
||||
|
||||
uint16_t aw;
|
||||
usart.receive(reinterpret_cast<uint8_t *>(&aw), 0, sizeof(aw));
|
||||
return aw == val;
|
||||
}
|
||||
|
||||
uint16_t B15F::getMem16(volatile uint16_t* adr)
|
||||
{
|
||||
usart.clearInputBuffer();
|
||||
|
||||
uint8_t rq[] =
|
||||
{
|
||||
RQ_GET_MEM_16,
|
||||
static_cast<uint8_t >(reinterpret_cast<size_t>(adr) & 0xFF),
|
||||
static_cast<uint8_t >(reinterpret_cast<size_t>(adr) >> 8)
|
||||
};
|
||||
|
||||
usart.transmit(&rq[0], 0, sizeof(rq));
|
||||
|
||||
uint16_t aw;
|
||||
usart.receive(reinterpret_cast<uint8_t *>(&aw), 0, sizeof(aw));
|
||||
return aw;
|
||||
}
|
||||
|
||||
bool B15F::setRegister(volatile uint8_t* adr, uint8_t val)
|
||||
{
|
||||
return setMem8(adr, val);
|
||||
}
|
||||
|
||||
uint8_t B15F::getRegister(volatile uint8_t* adr)
|
||||
{
|
||||
return getMem8(adr);
|
||||
}
|
||||
|
||||
uint16_t* B15F::getInterruptCounterOffset()
|
||||
{
|
||||
usart.clearInputBuffer();
|
||||
|
||||
uint8_t rq[] =
|
||||
{
|
||||
RQ_COUNTER_OFFSET
|
||||
};
|
||||
|
||||
usart.transmit(&rq[0], 0, sizeof(rq));
|
||||
|
||||
uint16_t aw;
|
||||
usart.receive(reinterpret_cast<uint8_t *>(&aw), 0, sizeof(aw));
|
||||
return reinterpret_cast<uint16_t*>(aw);
|
||||
}
|
||||
|
||||
/*************************/
|
||||
|
||||
|
||||
/**********************
|
||||
* Private Funktionen *
|
||||
**********************/
|
||||
|
||||
B15F::B15F()
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
void B15F::init()
|
||||
{
|
||||
|
||||
std::string device = exec("bash -c 'ls /dev/ttyUSB*'");
|
||||
while (device.find(' ') != std::string::npos || device.find('\n') != std::string::npos ||
|
||||
device.find('\t') != std::string::npos)
|
||||
device.pop_back();
|
||||
|
||||
if (device.length() == 0)
|
||||
abort("Adapter nicht gefunden");
|
||||
|
||||
std::cout << PRE << "Verwende Adapter: " << device << std::endl;
|
||||
|
||||
|
||||
std::cout << PRE << "Stelle Verbindung mit Adapter her... " << std::flush;
|
||||
usart.setBaudrate(BAUDRATE);
|
||||
usart.openDevice(device);
|
||||
std::cout << "OK" << std::endl;
|
||||
|
||||
|
||||
std::cout << PRE << "Teste Verbindung... " << std::flush;
|
||||
uint8_t tries = 3;
|
||||
while (tries--)
|
||||
{
|
||||
// verwerfe Daten, die µC noch hat
|
||||
//discard();
|
||||
|
||||
if (!testConnection())
|
||||
continue;
|
||||
|
||||
if (!testIntConv())
|
||||
continue;
|
||||
|
||||
break;
|
||||
}
|
||||
if (tries == 0)
|
||||
abort("Verbindungstest fehlgeschlagen. Neueste Version im Einsatz?");
|
||||
std::cout << "OK" << std::endl;
|
||||
|
||||
|
||||
// Gib board info aus
|
||||
std::vector<std::string> info = getBoardInfo();
|
||||
std::cout << PRE << "AVR Firmware Version: " << info[0] << " um " << info[1] << " Uhr (" << info[2] << ")"
|
||||
<< std::endl;
|
||||
}
|
|
@ -206,18 +206,19 @@ public:
|
|||
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);
|
||||
|
||||
/**
|
||||
* Frequenz von PWM an PB4.
|
||||
* Setzt die Register so, dass näherungsweise die gewünschte Frequenz erzeugt wird.
|
||||
* Ist freq == 0 wird PWM deaktiviert.
|
||||
* Standardfrequenz: 31300 (empfohlen, da dann TOP == 255)
|
||||
* \param freq PWM Frequenz
|
||||
* \return Top Wert des PWM Value für die gesetzte Frequenz
|
||||
* \return TOP Wert des PWM Value für die gesetzte Frequenz
|
||||
* \throws DriverException
|
||||
*/
|
||||
uint8_t pwmSetFrequency(uint32_t freq);
|
||||
|
||||
/**
|
||||
* Setzt den PWM Wert.
|
||||
* \param value PWM Wert [0..0xFF]
|
||||
* Setzt den PWM Wert an PB4.
|
||||
* \param value PWM Wert [0..TOP]
|
||||
* \throws DriverException
|
||||
*/
|
||||
bool pwmSetValue(uint8_t value);
|
||||
|
@ -279,6 +280,22 @@ public:
|
|||
* \return Adresse (in der MCU)
|
||||
*/
|
||||
uint16_t* getInterruptCounterOffset(void);
|
||||
|
||||
/**
|
||||
* Aktiviert das Servo Signal an PB2 und Initialisiert es mit 1,5ms Pulselänge.
|
||||
*/
|
||||
void setServoEnabled(void);
|
||||
|
||||
/**
|
||||
* Deaktiviert das Servo Signal an PB2.
|
||||
*/
|
||||
void setServoDisabled(void);
|
||||
|
||||
/**
|
||||
* Setzt die Pulselänge des Servo Signals und damit die Position.
|
||||
* \param pos Pulselänge des Signals in Mikrosekunden
|
||||
*/
|
||||
void setServoPosition(uint16_t pos);
|
||||
|
||||
/*************************/
|
||||
|
||||
|
@ -304,10 +321,16 @@ 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;
|
||||
|
||||
USART usart;
|
||||
static B15F* instance;
|
||||
static errorhandler_t errorhandler;
|
||||
USART usart; //!< USART Instanz für serielle Verbindung
|
||||
static B15F* instance; //!< private Instanz für Singleton
|
||||
static errorhandler_t errorhandler; //!< Error Handler für Exceptions und Fehler
|
||||
};
|
||||
|
||||
#endif // B15F_H
|
||||
|
|
|
@ -1,313 +0,0 @@
|
|||
#ifndef B15F_H
|
||||
#define B15F_H
|
||||
|
||||
#include <iostream>
|
||||
#include <bits/stdc++.h>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <cstdlib>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <termios.h>
|
||||
|
||||
#include "requests.h"
|
||||
#include "usart.h"
|
||||
#include "driverexception.h"
|
||||
#include "timeoutexception.h"
|
||||
|
||||
// wichtig für die Register-Zugriffe
|
||||
#define _AVR_IO_H_ 1 // Erzwinge die Inklusion
|
||||
#include "/usr/lib/avr/include/avr/sfr_defs.h"
|
||||
#include "/usr/lib/avr/include/avr/iom1284p.h"
|
||||
|
||||
typedef std::function<void(std::exception&)> errorhandler_t;
|
||||
|
||||
|
||||
/*! main driver class */
|
||||
|
||||
class B15F
|
||||
{
|
||||
public:
|
||||
|
||||
/*************************************
|
||||
* Grundfunktionen des B15F Treibers *
|
||||
*************************************/
|
||||
|
||||
/**
|
||||
* Liefert eine Referenz zur aktuellen Treiber-Instanz, die Verbindung wird gegebenenfalls automatisch hergestellt.
|
||||
* @throws DriverException
|
||||
*/
|
||||
static B15F& getInstance(void);
|
||||
|
||||
/**
|
||||
* Versucht die Verbindung zum B15 wiederherzustellen
|
||||
* \throws DriverException
|
||||
*/
|
||||
void reconnect(void);
|
||||
|
||||
/**
|
||||
* Verwirft Daten im USART Puffer auf dieser Maschine und B15
|
||||
* \throws DriverException
|
||||
*/
|
||||
void discard(void);
|
||||
|
||||
/**
|
||||
* Testet die USART Verbindung auf Funktion
|
||||
* \throws DriverException
|
||||
*/
|
||||
bool testConnection(void);
|
||||
|
||||
/**
|
||||
* Testet die Integer Konvertierung der USART Verbindung
|
||||
* \throws DriverException
|
||||
*/
|
||||
bool testIntConv(void);
|
||||
|
||||
/**
|
||||
* Liefert Informationen zur aktuellen Firmware des B15
|
||||
* \throws DriverException
|
||||
*/
|
||||
std::vector<std::string> getBoardInfo(void);
|
||||
|
||||
/**
|
||||
* Lässt den Treiber für eine angegebene Zeit pausieren
|
||||
* \param ms Verzögerung in Millisekunden
|
||||
*/
|
||||
void delay_ms(uint16_t ms);
|
||||
|
||||
/**
|
||||
* Lässt den Treiber für eine angegebene Zeit pausieren
|
||||
* \param us Verzögerung in Microsekunden
|
||||
*/
|
||||
void delay_us(uint16_t us);
|
||||
|
||||
/**
|
||||
* Invertiert das Bitmuster eines Bytes
|
||||
* z.B.: 10100001 --> 10000101
|
||||
* \param b Byte, das invertiert wird
|
||||
*/
|
||||
void reverse(uint8_t& b);
|
||||
|
||||
/**
|
||||
* Führt ein Befehl auf dieser Maschine aus und liefert stdout zurück
|
||||
* \param cmd Der Befehl
|
||||
*/
|
||||
static std::string exec(std::string cmd);
|
||||
|
||||
/**
|
||||
* Multithread sicherer Abbruch des B15F-Treibers
|
||||
* \param msg Beschreibung der Abbruchursache
|
||||
*/
|
||||
static void abort(std::string msg);
|
||||
|
||||
/**
|
||||
* Multithread sicherer Abbruch des B15F-Treibers
|
||||
* \param ex Exception als Abbruchursache
|
||||
*/
|
||||
static void abort(std::exception& ex);
|
||||
|
||||
/**
|
||||
* Setzt eine Fehlerbehandlungsroutine für den Treiberabbruch (abort)
|
||||
* \param func Funktion, die Exception als Parameter bekommt
|
||||
*/
|
||||
static void setAbortHandler(errorhandler_t func);
|
||||
|
||||
/*************************************/
|
||||
|
||||
|
||||
|
||||
/*************************
|
||||
* Steuerbefehle für B15 *
|
||||
*************************/
|
||||
|
||||
/**
|
||||
* Versetzt das Board in den Selbsttest-Modus
|
||||
* WICHTIG: Es darf dabei nichts an den Klemmen angeschlossen sein!
|
||||
* \throws DriverException
|
||||
*/
|
||||
bool activateSelfTestMode(void);
|
||||
|
||||
/**
|
||||
* Setzt den Wert des digitalen Ausgabeports 0
|
||||
* \param port Wert für gesamten Port
|
||||
* \throws DriverException
|
||||
*/
|
||||
bool digitalWrite0(uint8_t);
|
||||
|
||||
/**
|
||||
* Setzt den Wert des digitalen Ausgabeports 1
|
||||
* \param port Wert für gesamten Port
|
||||
* \throws DriverException
|
||||
*/
|
||||
bool digitalWrite1(uint8_t);
|
||||
|
||||
/**
|
||||
* Liest den Wert des digitalen Eingabeports 0
|
||||
* \return Wert für gesamten Port
|
||||
* \throws DriverException
|
||||
*/
|
||||
uint8_t digitalRead0(void);
|
||||
|
||||
/**
|
||||
* Liest den Wert des digitalen Eingabeports 1
|
||||
* \return Wert für gesamten Port
|
||||
* \throws DriverException
|
||||
*/
|
||||
uint8_t digitalRead1(void);
|
||||
|
||||
/**
|
||||
* Liest den Wert des digitalen Eingabeports, an dem der DIP-switch angeschlossen ist (S7)
|
||||
* \return Wert für gesamten Port
|
||||
* \throws DriverException
|
||||
*/
|
||||
uint8_t readDipSwitch(void);
|
||||
|
||||
/**
|
||||
* Setzt den Wert des Digital-Analog-Converters (DAC / DAU) 0
|
||||
* \param port 10-Bit Wert
|
||||
* \throws DriverException
|
||||
*/
|
||||
bool 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);
|
||||
|
||||
/**
|
||||
* Liest den Wert des Analog-Digital-Converters (ADC / ADU)
|
||||
* \param channel Kanalwahl von 0 - 7
|
||||
* \throws DriverException
|
||||
*/
|
||||
uint16_t analogRead(uint8_t channel);
|
||||
|
||||
/**
|
||||
* DAC 0 wird auf den Startwert gesetzt und dann schrittweise um Delta inkrementiert.
|
||||
* Für jeden eingestelleten DAC-Wert werden zwei ADCs (channel_a und channel_b) angesprochen und die Werte übermittelt.
|
||||
* Die Werte werden in buffer_a für Kanal a und buffer_b für Kanal b gespeichert.
|
||||
* \param channel_a Auswahl des ADC a, von 0 - 7
|
||||
* \param buffer_a Speichertort für Werte des Kanals a
|
||||
* \param offset_a Anzahl an Werten des Kanals a, die im Speicher übersprungen werden sollen
|
||||
* \param channel_b Auswahl des ADC b, von 0 - 7
|
||||
* \param buffer_b Speichertort für Werte des Kanals b
|
||||
* \param offset_b Anzahl an Werten des Kanals b, die im Speicher übersprungen werden
|
||||
* \param start Startwert des DACs
|
||||
* \param delta Schrittweite, mit welcher der DAC inkrementiert wird
|
||||
* \param count Anzahl an Inkrementierungen
|
||||
* \throws DriverException
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* Setzt die Register so, dass näherungsweise die gewünschte Frequenz erzeugt wird.
|
||||
* Ist freq == 0 wird PWM deaktiviert.
|
||||
* Standardfrequenz: 31300 (empfohlen, da dann TOP == 255)
|
||||
* \param freq PWM Frequenz
|
||||
* \return Top Wert des PWM Value für die gesetzte Frequenz
|
||||
* \throws DriverException
|
||||
*/
|
||||
uint8_t pwmSetFrequency(uint32_t freq);
|
||||
|
||||
/**
|
||||
* Setzt den PWM Wert.
|
||||
* \param value PWM Wert [0..0xFF]
|
||||
* \throws DriverException
|
||||
*/
|
||||
bool pwmSetValue(uint8_t value);
|
||||
|
||||
/**
|
||||
* Setzt direkt den Wert einer MCU Speicherzelle der Größe 8 Bit.
|
||||
* Diese kann ein Register oder RAM-Daten sein.
|
||||
* *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
|
||||
*/
|
||||
bool setMem8(volatile uint8_t* adr, uint8_t val);
|
||||
|
||||
/**
|
||||
* Liefert den Wert einer MCU Speicherzelle der Größe 8 Bit.
|
||||
* Diese kann ein Register oder RAM-Daten sein.
|
||||
* \param adr Speicheradresse
|
||||
* \return Wert der Speicherzelle
|
||||
*/
|
||||
uint8_t getMem8(volatile uint8_t* adr);
|
||||
|
||||
/**
|
||||
* Setzt direkt den Wert einer MCU Speicherzelle der Größe 16 Bit.
|
||||
* Diese kann ein Register oder RAM-Daten sein.
|
||||
* *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
|
||||
*/
|
||||
bool setMem16(volatile uint16_t* adr, uint16_t val);
|
||||
|
||||
/**
|
||||
* Liefert den Wert einer MCU Speicherzelle der Größe 16 Bit.
|
||||
* Diese kann ein Register oder RAM-Daten sein.
|
||||
* \param adr Speicheradresse
|
||||
* \return Wert der Speicherzelle
|
||||
*/
|
||||
uint16_t getMem16(volatile uint16_t* adr);
|
||||
|
||||
/**
|
||||
* Diese Funktion ist ein Alias für setMem8().
|
||||
* *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
|
||||
*/
|
||||
bool setRegister(volatile uint8_t* adr, uint8_t val);
|
||||
|
||||
/**
|
||||
* Diese Funktion ist ein Alias für getMem8().
|
||||
* \param adr Speicheradresse
|
||||
* \return Wert des Registers
|
||||
*/
|
||||
uint8_t getRegister(volatile uint8_t* adr);
|
||||
|
||||
/**
|
||||
* Liefert die Adresse des ersten Interrupt Counters (BASISR).
|
||||
* \return Adresse (in der MCU)
|
||||
*/
|
||||
uint16_t* getInterruptCounterOffset(void);
|
||||
|
||||
/*************************/
|
||||
|
||||
|
||||
// CONSTANTS
|
||||
const std::string PRE = "[B15F] "; //!< B15F stdout prefix
|
||||
constexpr static uint8_t MSG_OK = 0xFF; //!< Value to acknowledge a received command
|
||||
constexpr static uint8_t MSG_FAIL = 0xFE; //!< Value to reject a received command
|
||||
constexpr static uint16_t RECONNECT_TIMEOUT = 64; //!< Time in ms after which a reconnect attempt aborts
|
||||
constexpr static uint16_t WDT_TIMEOUT = 15; //!< Time in ms after which the watch dog timer resets the MCU
|
||||
constexpr static uint8_t RECONNECT_TRIES = 3; //!< Maximum count of reconnect attempts after which the driver stops
|
||||
constexpr static uint32_t BAUDRATE = 57600; //!< USART baudrate for communication with the MCU
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Privater Konstruktor
|
||||
*/
|
||||
B15F(void);
|
||||
|
||||
/**
|
||||
* Initialisiert und testet die Verbindung zum B15
|
||||
* \throws DriverException
|
||||
*/
|
||||
void init(void);
|
||||
|
||||
USART usart;
|
||||
static B15F* instance;
|
||||
static errorhandler_t errorhandler;
|
||||
};
|
||||
|
||||
#endif // B15F_H
|
|
@ -22,6 +22,9 @@ 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[] =
|
||||
{
|
||||
|
@ -46,6 +49,9 @@ uint8_t const rq_len[] =
|
|||
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
|
||||
|
|
|
@ -1,50 +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;
|
||||
|
||||
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 */,
|
||||
};
|
||||
|
||||
#endif // REQUESTS_H
|
2
control/src/kleine_hilfe
Executable file
2
control/src/kleine_hilfe
Executable file
|
@ -0,0 +1,2 @@
|
|||
make
|
||||
su krause -c "sudo -S make install"
|
|
@ -1,142 +0,0 @@
|
|||
#include "view_monitor.h"
|
||||
|
||||
ViewMonitor::ViewMonitor() : t_worker(&ViewMonitor::worker, this)
|
||||
{
|
||||
}
|
||||
|
||||
call_t ViewMonitor::keypress(int& key)
|
||||
{
|
||||
switch(key)
|
||||
{
|
||||
|
||||
case KEY_MOUSE:
|
||||
{
|
||||
// http://pronix.linuxdelta.de/C/Linuxprogrammierung/Linuxsystemprogrammieren_C_Kurs_Kapitel10b.shtml
|
||||
MEVENT event;
|
||||
bool hit = false;
|
||||
if(getmouse(&event) == OK && event.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED))
|
||||
{
|
||||
size_t column = start_x + close_offset_x;
|
||||
size_t row = start_y + close_offset_y;
|
||||
size_t mouse_x = event.x, mouse_y = event.y;
|
||||
if(mouse_y == row && mouse_x >= column && mouse_x < column + label_close.length())
|
||||
hit = true;
|
||||
}
|
||||
if(!hit)
|
||||
break;
|
||||
|
||||
// fall through to next case
|
||||
[[fallthrough]];
|
||||
}
|
||||
case KEY_ENT:
|
||||
run_worker = false;
|
||||
key = -1; // do return from view
|
||||
wclear(win);
|
||||
wrefresh(win);
|
||||
t_worker.join();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return calls[0];
|
||||
}
|
||||
|
||||
std::string ViewMonitor::fancyDigitalString(uint8_t& b)
|
||||
{
|
||||
std::string bitstring(std::bitset<8>(b).to_string());
|
||||
std::reverse(bitstring.begin(), bitstring.end());
|
||||
|
||||
std::stringstream str;
|
||||
str << bitstring;
|
||||
str << " ";
|
||||
str << "0x" << std::setfill ('0') << std::setw(2) << std::hex << (int) b << std::dec;
|
||||
return str.str();
|
||||
}
|
||||
|
||||
std::string ViewMonitor::fancyAnalogString(uint16_t& v)
|
||||
{
|
||||
std::stringstream str;
|
||||
double volt = round(v * 100.0 * 5.0 / 1023.0) / 100.0;
|
||||
|
||||
str << std::setfill ('0') << std::setw(4) << (int) v << " " << std::fixed << std::setprecision(2) << volt << " V ";
|
||||
|
||||
str << "[";
|
||||
uint8_t p = round(v * 40.0 / 1023.0);
|
||||
for(uint8_t i = 0; i < p; i++)
|
||||
str << "X";
|
||||
for(uint8_t i = 0; i < 40 - p; i++)
|
||||
str << " ";
|
||||
str << "]" << std::endl;
|
||||
|
||||
return str.str();
|
||||
}
|
||||
|
||||
void ViewMonitor::worker()
|
||||
{
|
||||
B15F& drv = B15F::getInstance();
|
||||
while(run_worker)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
|
||||
uint8_t be0 = drv.digitalRead0();
|
||||
uint8_t be1 = drv.digitalRead1();
|
||||
uint8_t dsw = drv.readDipSwitch();
|
||||
uint16_t adc[8];
|
||||
for(uint8_t i = 0; i < sizeof(adc) / sizeof(adc[0]); i++)
|
||||
adc[i] = drv.analogRead(i);
|
||||
|
||||
|
||||
std::stringstream str;
|
||||
|
||||
// hline
|
||||
for(uint8_t i = 0; i < width - 2 * text_offset_x; i++)
|
||||
if(i % 2 == 0)
|
||||
str << "-";
|
||||
else
|
||||
str << " ";
|
||||
str << std::endl;
|
||||
|
||||
str << "Digitale Enigaenge:" << std::endl;
|
||||
str << "Binaere Eingabe 0: " << fancyDigitalString(be0) << std::endl;
|
||||
str << "Binaere Eingabe 1: " << fancyDigitalString(be1) << std::endl;
|
||||
str << "Dip Schalter (S7): " << fancyDigitalString(dsw) << std::endl;
|
||||
|
||||
// hline
|
||||
for(uint8_t i = 0; i < width - 2 * text_offset_x; i++)
|
||||
if(i % 2 == 0)
|
||||
str << "-";
|
||||
else
|
||||
str << " ";
|
||||
str << std::endl;
|
||||
|
||||
str << "Analoge Eingaenge:" << std::endl;
|
||||
for(uint8_t i = 0; i < sizeof(adc) / sizeof(adc[0]); i++)
|
||||
{
|
||||
str << "Kanal " << std::to_string((int) i) << ": ";
|
||||
str << fancyAnalogString(adc[i]) << std::endl;
|
||||
}
|
||||
|
||||
text = str.str();
|
||||
repaint();
|
||||
}
|
||||
catch(DriverException& ex)
|
||||
{
|
||||
std::cout << "DriverException: " << ex.what() << std::endl;
|
||||
drv.delay_ms(1000);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
try
|
||||
{
|
||||
drv.reconnect();
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
B15F::abort("Die Verbindung ist unterbrochen worden. Wurde ein Stecker gezogen? :D");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue