bugsuche+

This commit is contained in:
Tristan Krause 2019-04-05 15:04:59 +02:00
parent e0a4be7685
commit bb5d16ca88
4 changed files with 22 additions and 31 deletions

View file

@ -56,17 +56,14 @@ void B15F::init()
void B15F::reconnect()
{
uint8_t tries = RECONNECT_TRIES;
while(tries--)
while(tries-- && false)
{
delay_ms(RECONNECT_TIMEOUT);
discard();
if(testConnection())
{
std::cout << "OK" << std::endl << std::flush;
return;
}
}
@ -76,10 +73,10 @@ void B15F::reconnect()
void B15F::discard(void)
{
usart.clearOutputBuffer();
for(uint8_t i = 0; i < 8; i++)
for(uint8_t i = 0; i < 16; i++)
{
usart.writeByte(RQ_DISC); // sende discard Befehl (verwerfe input)
delay_ms((16000 / BAUDRATE) + 1); // warte mindestens eine Millisekunde, gegebenenfalls mehr
delay_ms(4);
}
usart.clearInputBuffer();
}
@ -140,7 +137,6 @@ std::vector<std::string> B15F::getBoardInfo(void)
bool B15F::activateSelfTestMode()
{
//usart.clearInputBuffer();
usart.writeByte(RQ_ST);
uint8_t aw = usart.readByte();
@ -149,86 +145,82 @@ bool B15F::activateSelfTestMode()
bool B15F::digitalWrite0(uint8_t port)
{
//usart.clearInputBuffer();
usart.writeByte(RQ_BA0);
usart.writeByte(port);
uint8_t aw = usart.readByte();
delay_us(1);
delay_us(10);
return aw == MSG_OK;
}
bool B15F::digitalWrite1(uint8_t port)
{
//usart.clearInputBuffer();
usart.writeByte(RQ_BA1);
usart.writeByte(port);
uint8_t aw = usart.readByte();
delay_us(1);
delay_us(10);
return aw == MSG_OK;
}
uint8_t B15F::digitalRead0()
{
//usart.clearInputBuffer();
usart.clearInputBuffer();
usart.writeByte(RQ_BE0);
uint8_t byte = usart.readByte();
delay_us(1);
delay_us(10);
return byte;
}
uint8_t B15F::digitalRead1()
{
//usart.clearInputBuffer();
usart.clearInputBuffer();
usart.writeByte(RQ_BE1);
uint8_t byte = usart.readByte();
delay_us(1);
delay_us(10);
return byte;
}
uint8_t B15F::readDipSwitch()
{
//usart.clearInputBuffer();
usart.clearInputBuffer();
usart.writeByte(RQ_DSW);
uint8_t byte = usart.readByte();
delay_us(1);
delay_us(10);
return byte;
}
bool B15F::analogWrite0(uint16_t value)
{
//usart.clearInputBuffer();
usart.writeByte(RQ_AA0);
usart.writeInt(value);
uint8_t aw = usart.readByte();
delay_us(1);
delay_us(10);
return aw == MSG_OK;
}
bool B15F::analogWrite1(uint16_t value)
{
//usart.clearInputBuffer();
usart.writeByte(RQ_AA1);
usart.writeInt(value);
uint8_t aw = usart.readByte();
delay_us(1);
delay_us(10);
return aw == MSG_OK;
}
uint16_t B15F::analogRead(uint8_t channel)
{
usart.clearInputBuffer();
if(channel > 7)
throw DriverException("Bad ADC channel: " + std::to_string(channel));
//usart.clearInputBuffer();
usart.writeByte(RQ_ADC);
usart.writeByte(channel);
uint16_t adc = usart.readInt();
if(adc > 1023)
throw DriverException("Bad ADC data detected");
delay_us(1);
delay_us(50);
return adc;
}
@ -258,7 +250,7 @@ void B15F::analogSequence(uint8_t channel_a, uint16_t* buffer_a, uint32_t offset
if(aw != MSG_OK)
throw DriverException("Sequenz unterbrochen");
delay_us(1);
delay_us(10);
}
void B15F::delay_ms(uint16_t ms)