Skip to content

Commit

Permalink
Added USBSerial operator int() to test for USB connectivity (a-la Leo…
Browse files Browse the repository at this point in the history
…nardo)

Former-commit-id: 76a4078
  • Loading branch information
majenkotech committed Aug 8, 2013
1 parent f6f88bf commit 64244df
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions hardware/pic32/cores/pic32/HardwareSerial.cpp
Expand Up @@ -582,6 +582,10 @@ USBSerial::USBSerial(ring_buffer *rx_buffer)
_rx_buffer->tail = 0;
}

USBSerial::operator int() {
return gConnected ? 1 : 0;
}

#ifdef _DEBUG_USB_VIA_SERIAL0_
#define DebugViaSerial0(x) Serial0.println(x)
#else
Expand Down
1 change: 1 addition & 0 deletions hardware/pic32/cores/pic32/HardwareSerial.h
Expand Up @@ -141,6 +141,7 @@ class USBSerial : public Stream
virtual void write(uint8_t);
virtual void write(const char *str);
virtual void write(const uint8_t *buffer, size_t size);
operator int();

using Print::write; // pull in write(str) and write(buf, size) from Print
};
Expand Down
2 changes: 1 addition & 1 deletion hardware/pic32/cores/pic32/HardwareSerial_cdcacm.c
Expand Up @@ -164,7 +164,7 @@ static int gRX_length[NRX];
static volatile byte gRX_in;
static volatile byte gRX_out;

static boolean gConnected = false;
boolean gConnected = false;


//*******************************************************************************
Expand Down
1 change: 1 addition & 0 deletions hardware/pic32/cores/pic32/HardwareSerial_cdcacm.h
Expand Up @@ -7,6 +7,7 @@
#define USB_SERIAL_MIN_BUFFER_FREE 128

extern boolean gCdcacm_active;
extern boolean gConnected;

typedef void (*cdcacm_reset_cbfn)(void);
typedef boolean (*cdcacm_storedata_cbfn)(const byte *buffer, int length);
Expand Down

0 comments on commit 64244df

Please sign in to comment.