Remove tud_cdc_connected check from examples

This commit is contained in:
Jan Dümpelmann
2020-09-04 17:25:32 +02:00
parent 9cc22b635c
commit e09ebea7b9
3 changed files with 34 additions and 43 deletions

View File

@@ -168,25 +168,22 @@ void cdc_task(void* params)
// RTOS forever loop
while ( 1 )
{
if ( tud_cdc_connected() )
// is data available to read from rx fifo
if ( tud_cdc_available() )
{
// connected and there are data available
if ( tud_cdc_available() )
uint8_t buf[64];
// read and echo back
uint32_t count = tud_cdc_read(buf, sizeof(buf));
for(uint32_t i=0; i<count; i++)
{
uint8_t buf[64];
tud_cdc_write_char(buf[i]);
// read and echo back
uint32_t count = tud_cdc_read(buf, sizeof(buf));
for(uint32_t i=0; i<count; i++)
{
tud_cdc_write_char(buf[i]);
if ( buf[i] == '\r' ) tud_cdc_write_char('\n');
}
tud_cdc_write_flush();
if ( buf[i] == '\r' ) tud_cdc_write_char('\n');
}
tud_cdc_write_flush();
}
// For ESP32-S2 this delay is essential to allow idle how to run and reset wdt
@@ -194,12 +191,12 @@ void cdc_task(void* params)
}
}
// Invoked when cdc when line state changed e.g connected/disconnected
// Invoked when cdc line state changed e.g connected/disconnected
void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts)
{
(void) itf;
// connected
// usually terminal software sets DTR and RTS when connected
if ( dtr && rts )
{
// print initial message when connected