Support spi4teensy3 in all examples automatically

This commit is contained in:
Andrew J. Kroll 2013-12-04 21:56:06 -05:00
parent ac12126477
commit edf9682923
27 changed files with 292 additions and 186 deletions

View file

@ -6,6 +6,10 @@
#include <PS3BT.h>
#include <usbhub.h>
// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
USB Usb;
//USBHub Hub1(&Usb); // Some dongles have a hub inside

View file

@ -7,6 +7,10 @@
#include <PS3BT.h>
#include <usbhub.h>
// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
USB Usb;
//USBHub Hub1(&Usb); // Some dongles have a hub inside

View file

@ -12,6 +12,10 @@
#include <PS3BT.h>
#include <SPP.h>
#include <usbhub.h>
// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
USB Usb;
//USBHub Hub1(&Usb); // Some dongles have a hub inside

View file

@ -6,6 +6,10 @@
#include <SPP.h>
#include <usbhub.h>
// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
USB Usb;
//USBHub Hub1(&Usb); // Some dongles have a hub inside

View file

@ -6,6 +6,10 @@
#include <SPP.h>
#include <usbhub.h>
// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
USB Usb;
//USBHub Hub1(&Usb); // Some dongles have a hub inside

View file

@ -6,6 +6,10 @@
#include <Wii.h>
#include <usbhub.h>
// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
USB Usb;
//USBHub Hub1(&Usb); // Some dongles have a hub inside

View file

@ -13,6 +13,10 @@ Otherwise, wire up a IR LED yourself.
#include <Wii.h>
#include <usbhub.h>
// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
#ifndef WIICAMERA // Used to check if WIICAMERA is defined
#error "Uncomment WIICAMERA in Wii.h to use this example"

View file

@ -7,6 +7,10 @@
#include <Wii.h>
#include <usbhub.h>
// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
USB Usb;
//USBHub Hub1(&Usb); // Some dongles have a hub inside

View file

@ -6,6 +6,10 @@
#include <Wii.h>
#include <usbhub.h>
// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
USB Usb;
//USBHub Hub1(&Usb); // Some dongles have a hub inside

View file

@ -1,5 +1,9 @@
#include <hidboot.h>
#include <usbhub.h>
// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
class KbdRptParser : public KeyboardReportParser
{

View file

@ -1,5 +1,9 @@
#include <hidboot.h>
#include <usbhub.h>
// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
class MouseRptParser : public MouseReportParser
{
@ -12,14 +16,14 @@ protected:
virtual void OnMiddleButtonUp (MOUSEINFO *mi);
virtual void OnMiddleButtonDown (MOUSEINFO *mi);
};
void MouseRptParser::OnMouseMove(MOUSEINFO *mi)
void MouseRptParser::OnMouseMove(MOUSEINFO *mi)
{
Serial.print("dx=");
Serial.print(mi->dX, DEC);
Serial.print(" dy=");
Serial.println(mi->dY, DEC);
};
void MouseRptParser::OnLeftButtonUp (MOUSEINFO *mi)
void MouseRptParser::OnLeftButtonUp (MOUSEINFO *mi)
{
Serial.println("L Butt Up");
};
@ -60,11 +64,11 @@ void setup()
if (Usb.Init() == -1)
Serial.println("OSC did not start.");
delay( 200 );
next_time = millis() + 5000;
HidMouse.SetReportParser(0,(HIDReportParser*)&Prs);
}

View file

@ -2,10 +2,11 @@
#include <hiduniversal.h>
#include <hidescriptorparser.h>
#include <usbhub.h>
#ifdef arm
#include "pgmstrings.h"
// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
#include "pgmstrings.h"
class HIDUniversal2 : public HIDUniversal
{

View file

@ -5,6 +5,10 @@
#include <usbhub.h>
#include "le3dp_rptparser.h"
// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
USB Usb;
USBHub Hub(&Usb);
@ -20,11 +24,11 @@ void setup()
if (Usb.Init() == -1)
Serial.println("OSC did not start.");
delay( 200 );
if (!Hid.SetReportParser(0, &Joy))
ErrorMessage<uint8_t>(PSTR("SetReportParser"), 1 );
ErrorMessage<uint8_t>(PSTR("SetReportParser"), 1 );
}
void loop()

View file

@ -6,6 +6,10 @@
#include <usbhub.h>
#include "scale_rptparser.h"
// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
USB Usb;
USBHub Hub(&Usb);
@ -22,18 +26,18 @@ void setup()
if (Usb.Init() == -1)
Serial.println("OSC did not start.");
// set up the LCD's number of rows and columns:
// set up the LCD's number of rows and columns:
LCD.begin(16, 2);
LCD.clear();
LCD.home();
LCD.setCursor(0,0);
LCD.write('R');
LCD.write('R');
delay( 200 );
if (!Hid.SetReportParser(0, &Scale))
ErrorMessage<uint8_t>(PSTR("SetReportParser"), 1 );
ErrorMessage<uint8_t>(PSTR("SetReportParser"), 1 );
}
void loop()

View file

@ -5,6 +5,10 @@
*/
#include <PS3USB.h>
// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
USB Usb;
/* You can create the instance of the class in two ways */

View file

@ -1,6 +1,10 @@
#include <usbhub.h>
#include "pgmstrings.h"
// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
USB Usb;
//USBHub Hub1(&Usb);
@ -50,9 +54,9 @@ void setup()
if (Usb.Init() == -1)
Serial.println("OSC did not start.");
delay( 200 );
next_time = millis() + 10000;
}
@ -62,19 +66,19 @@ void PrintDescriptors(uint8_t addr)
{
uint8_t rcode = 0;
byte num_conf = 0;
rcode = getdevdescr( (byte)addr, num_conf );
if( rcode )
if( rcode )
{
printProgStr(Gen_Error_str);
print_hex( rcode, 8 );
}
Serial.print("\r\n");
for (int i=0; i<num_conf; i++)
{
rcode = getconfdescr( addr, i ); // get configuration descriptor
if( rcode )
if( rcode )
{
printProgStr(Gen_Error_str);
print_hex(rcode, 8);
@ -94,19 +98,19 @@ void PrintAllDescriptors(UsbDevice *pdev)
void loop()
{
Usb.Task();
if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
{
{
//if (millis() >= next_time)
{
Usb.ForEachUsbDevice(&PrintAllDescriptors);
Usb.ForEachUsbDevice(&PrintAllDescriptors);
Usb.ForEachUsbDevice(&PrintAllAddresses);
while( 1 ); //stop
}
}
}
}
byte getdevdescr( byte addr, byte &num_conf )
{
USB_DEVICE_DESCRIPTOR buf;
@ -122,7 +126,7 @@ byte getdevdescr( byte addr, byte &num_conf )
print_hex( buf.bDescriptorType, 8 );
printProgStr(Dev_Version_str);
print_hex( buf.bcdUSB, 16 );
printProgStr(Dev_Class_str);
printProgStr(Dev_Class_str);
print_hex( buf.bDeviceClass, 8 );
printProgStr(Dev_Subclass_str);
print_hex( buf.bDeviceSubClass, 8 );
@ -147,46 +151,46 @@ byte getdevdescr( byte addr, byte &num_conf )
num_conf = buf.bNumConfigurations;
return( 0 );
}
void printhubdescr(uint8_t *descrptr, uint8_t addr)
{
HubDescriptor *pHub = (HubDescriptor*) descrptr;
uint8_t len = *((uint8_t*)descrptr);
printProgStr(PSTR("\r\n\r\nHub Descriptor:\r\n"));
printProgStr(PSTR("bDescLength:\t\t"));
Serial.println(pHub->bDescLength, HEX);
printProgStr(PSTR("bDescriptorType:\t"));
Serial.println(pHub->bDescriptorType, HEX);
printProgStr(PSTR("bNbrPorts:\t\t"));
Serial.println(pHub->bNbrPorts, HEX);
printProgStr(PSTR("LogPwrSwitchMode:\t"));
Serial.println(pHub->LogPwrSwitchMode, BIN);
printProgStr(PSTR("CompoundDevice:\t\t"));
Serial.println(pHub->CompoundDevice, BIN);
printProgStr(PSTR("OverCurrentProtectMode:\t"));
Serial.println(pHub->OverCurrentProtectMode, BIN);
printProgStr(PSTR("TTThinkTime:\t\t"));
Serial.println(pHub->TTThinkTime, BIN);
printProgStr(PSTR("PortIndicatorsSupported:"));
Serial.println(pHub->PortIndicatorsSupported, BIN);
printProgStr(PSTR("Reserved:\t\t"));
Serial.println(pHub->Reserved, HEX);
printProgStr(PSTR("bPwrOn2PwrGood:\t\t"));
Serial.println(pHub->bPwrOn2PwrGood, HEX);
printProgStr(PSTR("bHubContrCurrent:\t"));
Serial.println(pHub->bHubContrCurrent, HEX);
for (uint8_t i=7; i<len; i++)
print_hex(descrptr[i], 8);
@ -229,7 +233,7 @@ byte getconfdescr( byte addr, byte conf )
default:
printunkdescr( buf_ptr );
break;
}//switch( descr_type
}//switch( descr_type
buf_ptr = ( buf_ptr + descr_length ); //advance buffer pointer
}//while( buf_ptr <=...
return( 0 );
@ -240,12 +244,12 @@ byte getconfdescr( byte addr, byte conf )
void print_hex(int v, int num_places)
{
int mask=0, n, num_nibbles, digit;
for (n=1; n<=num_places; n++) {
mask = (mask << 1) | 0x0001;
}
v = v & mask; // truncate v to specified number of places
num_nibbles = num_places / 4;
if ((num_places % 4) != 0) {
++num_nibbles;
@ -253,7 +257,7 @@ void print_hex(int v, int num_places)
do {
digit = ((v >> (num_nibbles-1) * 4)) & 0x0f;
Serial.print(digit, HEX);
}
}
while(--num_nibbles);
}
/* function to print configuration descriptor */
@ -309,7 +313,7 @@ void printepdescr( uint8_t* descr_ptr )
print_hex( ep_ptr->wMaxPacketSize, 16 );
printProgStr(End_Interval_str);
print_hex( ep_ptr->bInterval, 8 );
return;
}
/*function to print unknown descriptor */
@ -329,8 +333,8 @@ void printunkdescr( uint8_t* descr_ptr )
descr_ptr++;
}
}
/* Print a string from Program Memory directly to save RAM */
void printProgStr(const prog_char str[])
{

View file

@ -6,6 +6,10 @@
#include <XBOXOLD.h>
#include <usbhub.h>
// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
USB Usb;
USBHub Hub1(&Usb); // The controller has a built in hub, so this instance is needed

View file

@ -6,6 +6,10 @@
*/
#include <XBOXRECV.h>
// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
USB Usb;
XBOXRECV Xbox(&Usb);

View file

@ -5,6 +5,10 @@
*/
#include <XBOXUSB.h>
// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
USB Usb;
XBOXUSB Xbox(&Usb);

View file

@ -1,7 +1,12 @@
#include <cdcacm.h>
#include <usbhub.h>
#include "pgmstrings.h"
#include "pgmstrings.h"
// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
class ACMAsyncOper : public CDCAsyncOper
{
@ -22,16 +27,16 @@ uint8_t ACMAsyncOper::OnInit(ACM *pacm)
}
LINE_CODING lc;
lc.dwDTERate = 115200;
lc.dwDTERate = 115200;
lc.bCharFormat = 0;
lc.bParityType = 0;
lc.bDataBits = 8;
lc.bDataBits = 8;
rcode = pacm->SetLineCoding(&lc);
if (rcode)
ErrorMessage<uint8_t>(PSTR("SetLineCoding"), rcode);
return rcode;
}
@ -48,17 +53,17 @@ void setup()
if (Usb.Init() == -1)
Serial.println("OSCOKIRQ failed to assert");
delay( 200 );
delay( 200 );
}
void loop()
{
Usb.Task();
if( Acm.isReady()) {
if( Acm.isReady()) {
uint8_t rcode;
/* reading the keyboard */
if(Serial.available()) {
uint8_t data= Serial.read();
@ -69,24 +74,24 @@ void loop()
}//if(Serial.available()...
delay(50);
/* reading the phone */
/* buffer size must be greater or equal to max.packet size */
/* it it set to 64 (largest possible max.packet size) here, can be tuned down
for particular endpoint */
uint8_t buf[64];
uint8_t buf[64];
uint16_t rcvd = 64;
rcode = Acm.RcvData(&rcvd, buf);
if (rcode && rcode != hrNAK)
ErrorMessage<uint8_t>(PSTR("Ret"), rcode);
if( rcvd ) { //more than zero bytes received
for(uint16_t i=0; i < rcvd; i++ ) {
Serial.print((char)buf[i]); //printing on the screen
}
}
}
delay(10);
}//if( Usb.getUsbTaskState() == USB_STATE_RUNNING..
delay(10);
}//if( Usb.getUsbTaskState() == USB_STATE_RUNNING..
}

View file

@ -4,6 +4,10 @@
/* otherwise press any key after getting GPIO error to complete the test */
/**/
#include <usbhub.h>
// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
/* variables */
uint8_t rcode;

View file

@ -1,7 +1,11 @@
#include <cdcftdi.h>
#include <usbhub.h>
#include "pgmstrings.h"
#include "pgmstrings.h"
// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
class FTDIAsync : public FTDIAsyncOper
{
@ -12,7 +16,7 @@ public:
uint8_t FTDIAsync::OnInit(FTDI *pftdi)
{
uint8_t rcode = 0;
rcode = pftdi->SetBaudRate(115200);
if (rcode)
@ -21,10 +25,10 @@ uint8_t FTDIAsync::OnInit(FTDI *pftdi)
return rcode;
}
rcode = pftdi->SetFlowControl(FTDI_SIO_DISABLE_FLOW_CTRL);
if (rcode)
ErrorMessage<uint8_t>(PSTR("SetFlowControl"), rcode);
return rcode;
}
@ -43,48 +47,48 @@ void setup()
if (Usb.Init() == -1)
Serial.println("OSC did not start.");
delay( 200 );
next_time = millis() + 5000;
}
void loop()
{
Usb.Task();
if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
{
{
uint8_t rcode;
char strbuf[] = "DEADBEEF";
//char strbuf[] = "The quick brown fox jumps over the lazy dog";
//char strbuf[] = "This string contains 61 character to demonstrate FTDI buffers"; //add one symbol to it to see some garbage
Serial.print(".");
rcode = Ftdi.SndData(strlen(strbuf), (uint8_t*)strbuf);
if (rcode)
ErrorMessage<uint8_t>(PSTR("SndData"), rcode);
delay(50);
uint8_t buf[64];
for (uint8_t i=0; i<64; i++)
buf[i] = 0;
uint16_t rcvd = 64;
rcode = Ftdi.RcvData(&rcvd, buf);
if (rcode && rcode != hrNAK)
ErrorMessage<uint8_t>(PSTR("Ret"), rcode);
// The device reserves the first two bytes of data
// to contain the current values of the modem and line status registers.
if (rcvd > 2)
Serial.print((char*)(buf+2));
delay(10);
}
if (rcvd > 2)
Serial.print((char*)(buf+2));
delay(10);
}
}

View file

@ -1,5 +1,9 @@
#include <usbhub.h>
#include "pgmstrings.h"
// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
USB Usb;
USBHub Hub1(&Usb);
@ -46,9 +50,9 @@ void setup()
if (Usb.Init() == -1)
Serial.println("OSC did not start.");
delay( 200 );
next_time = millis() + 10000;
}
@ -58,19 +62,19 @@ void PrintDescriptors(uint8_t addr)
{
uint8_t rcode = 0;
byte num_conf = 0;
rcode = getdevdescr( (byte)addr, num_conf );
if( rcode )
if( rcode )
{
printProgStr(Gen_Error_str);
print_hex( rcode, 8 );
}
Serial.print("\r\n");
for (int i=0; i<num_conf; i++)
{
rcode = getconfdescr( addr, i ); // get configuration descriptor
if( rcode )
if( rcode )
{
printProgStr(Gen_Error_str);
print_hex(rcode, 8);
@ -90,19 +94,19 @@ void PrintAllDescriptors(UsbDevice *pdev)
void loop()
{
Usb.Task();
if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
{
{
if (millis() >= next_time)
{
Usb.ForEachUsbDevice(&PrintAllDescriptors);
Usb.ForEachUsbDevice(&PrintAllDescriptors);
Usb.ForEachUsbDevice(&PrintAllAddresses);
while( 1 ); //stop
}
}
}
}
byte getdevdescr( byte addr, byte &num_conf )
{
USB_DEVICE_DESCRIPTOR buf;
@ -118,7 +122,7 @@ byte getdevdescr( byte addr, byte &num_conf )
print_hex( buf.bDescriptorType, 8 );
printProgStr(Dev_Version_str);
print_hex( buf.bcdUSB, 16 );
printProgStr(Dev_Class_str);
printProgStr(Dev_Class_str);
print_hex( buf.bDeviceClass, 8 );
printProgStr(Dev_Subclass_str);
print_hex( buf.bDeviceSubClass, 8 );
@ -143,46 +147,46 @@ byte getdevdescr( byte addr, byte &num_conf )
num_conf = buf.bNumConfigurations;
return( 0 );
}
void printhubdescr(uint8_t *descrptr, uint8_t addr)
{
HubDescriptor *pHub = (HubDescriptor*) descrptr;
uint8_t len = *((uint8_t*)descrptr);
printProgStr(PSTR("\r\n\r\nHub Descriptor:\r\n"));
printProgStr(PSTR("bDescLength:\t\t"));
Serial.println(pHub->bDescLength, HEX);
printProgStr(PSTR("bDescriptorType:\t"));
Serial.println(pHub->bDescriptorType, HEX);
printProgStr(PSTR("bNbrPorts:\t\t"));
Serial.println(pHub->bNbrPorts, HEX);
printProgStr(PSTR("LogPwrSwitchMode:\t"));
Serial.println(pHub->LogPwrSwitchMode, BIN);
printProgStr(PSTR("CompoundDevice:\t\t"));
Serial.println(pHub->CompoundDevice, BIN);
printProgStr(PSTR("OverCurrentProtectMode:\t"));
Serial.println(pHub->OverCurrentProtectMode, BIN);
printProgStr(PSTR("TTThinkTime:\t\t"));
Serial.println(pHub->TTThinkTime, BIN);
printProgStr(PSTR("PortIndicatorsSupported:"));
Serial.println(pHub->PortIndicatorsSupported, BIN);
printProgStr(PSTR("Reserved:\t\t"));
Serial.println(pHub->Reserved, HEX);
printProgStr(PSTR("bPwrOn2PwrGood:\t\t"));
Serial.println(pHub->bPwrOn2PwrGood, HEX);
printProgStr(PSTR("bHubContrCurrent:\t"));
Serial.println(pHub->bHubContrCurrent, HEX);
for (uint8_t i=7; i<len; i++)
print_hex(descrptr[i], 8);
@ -225,7 +229,7 @@ byte getconfdescr( byte addr, byte conf )
default:
printunkdescr( buf_ptr );
break;
}//switch( descr_type
}//switch( descr_type
buf_ptr = ( buf_ptr + descr_length ); //advance buffer pointer
}//while( buf_ptr <=...
return( 0 );
@ -236,12 +240,12 @@ byte getconfdescr( byte addr, byte conf )
void print_hex(int v, int num_places)
{
int mask=0, n, num_nibbles, digit;
for (n=1; n<=num_places; n++) {
mask = (mask << 1) | 0x0001;
}
v = v & mask; // truncate v to specified number of places
num_nibbles = num_places / 4;
if ((num_places % 4) != 0) {
++num_nibbles;
@ -249,7 +253,7 @@ void print_hex(int v, int num_places)
do {
digit = ((v >> (num_nibbles-1) * 4)) & 0x0f;
Serial.print(digit, HEX);
}
}
while(--num_nibbles);
}
/* function to print configuration descriptor */
@ -305,7 +309,7 @@ void printepdescr( uint8_t* descr_ptr )
print_hex( ep_ptr->wMaxPacketSize, 16 );
printProgStr(End_Interval_str);
print_hex( ep_ptr->bInterval, 8 );
return;
}
/*function to print unknown descriptor */
@ -325,8 +329,8 @@ void printunkdescr( uint8_t* descr_ptr )
descr_ptr++;
}
}
/* Print a string from Program Memory directly to save RAM */
void printProgStr(const prog_char str[])
{

View file

@ -4,6 +4,10 @@
/* CDC support */
#include <cdcacm.h>
#include <cdcprolific.h>
// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
class PLAsyncOper : public CDCAsyncOper
{
@ -14,7 +18,7 @@ public:
uint8_t PLAsyncOper::OnInit(ACM *pacm)
{
uint8_t rcode;
// Set DTR = 1
rcode = pacm->SetControlLineState(1);
@ -29,13 +33,13 @@ uint8_t PLAsyncOper::OnInit(ACM *pacm)
lc.dwDTERate = 115200;
lc.bCharFormat = 0;
lc.bParityType = 0;
lc.bDataBits = 8;
lc.bDataBits = 8;
rcode = pacm->SetLineCoding(&lc);
if (rcode)
ErrorMessage<uint8_t>(PSTR("SetLineCoding"), rcode);
return rcode;
}
USB Usb;
@ -51,43 +55,43 @@ void setup()
if (Usb.Init() == -1)
Serial.println("OSCOKIRQ failed to assert");
delay( 200 );
delay( 200 );
}
void loop()
{
Usb.Task();
if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
{
{
uint8_t rcode;
/* reading the keyboard */
if(Serial.available()) {
uint8_t data= Serial.read();
/* sending to the phone */
rcode = Pl.SndData(1, &data);
if (rcode)
ErrorMessage<uint8_t>(PSTR("SndData"), rcode);
}//if(Serial.available()...
/* reading the converter */
/* buffer size must be greater or equal to max.packet size */
/* it it set to 64 (largest possible max.packet size) here, can be tuned down
for particular endpoint */
uint8_t buf[64];
uint8_t buf[64];
uint16_t rcvd = 64;
rcode = Pl.RcvData(&rcvd, buf);
if (rcode && rcode != hrNAK)
ErrorMessage<uint8_t>(PSTR("Ret"), rcode);
if( rcvd ) { //more than zero bytes received
for(uint16_t i=0; i < rcvd; i++ ) {
Serial.print((char)buf[i]); //printing on the screen
}
Serial.print((char)buf[i]); //printing on the screen
}
}//if( rcvd ...
}//if( Usb.getUsbTaskState() == USB_STATE_RUNNING..
}//if( Usb.getUsbTaskState() == USB_STATE_RUNNING..
}

View file

@ -5,6 +5,10 @@
/* CDC support */
#include <cdcacm.h>
#include <cdcprolific.h>
// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
class PLAsyncOper : public CDCAsyncOper
{
@ -15,7 +19,7 @@ public:
uint8_t PLAsyncOper::OnInit(ACM *pacm)
{
uint8_t rcode;
// Set DTR = 1
rcode = pacm->SetControlLineState(1);
@ -26,16 +30,16 @@ uint8_t PLAsyncOper::OnInit(ACM *pacm)
}
LINE_CODING lc;
lc.dwDTERate = 4800; //default serial speed of GPS unit
lc.dwDTERate = 4800; //default serial speed of GPS unit
lc.bCharFormat = 0;
lc.bParityType = 0;
lc.bDataBits = 8;
lc.bDataBits = 8;
rcode = pacm->SetLineCoding(&lc);
if (rcode)
ErrorMessage<uint8_t>(PSTR("SetLineCoding"), rcode);
return rcode;
}
@ -54,32 +58,32 @@ void setup()
if (Usb.Init() == -1)
Serial.println("OSCOKIRQ failed to assert");
delay( 200 );
delay( 200 );
}
void loop()
{
uint8_t rcode;
uint8_t buf[64]; //serial buffer equals Max.packet size of bulk-IN endpoint
uint16_t rcvd = 64;
uint8_t buf[64]; //serial buffer equals Max.packet size of bulk-IN endpoint
uint16_t rcvd = 64;
Usb.Task();
if( Pl.isReady()) {
if( Pl.isReady()) {
/* reading the GPS */
if( read_delay < millis() ){
read_delay += READ_DELAY;
read_delay += READ_DELAY;
rcode = Pl.RcvData(&rcvd, buf);
if ( rcode && rcode != hrNAK )
ErrorMessage<uint8_t>(PSTR("Ret"), rcode);
ErrorMessage<uint8_t>(PSTR("Ret"), rcode);
if( rcvd ) { //more than zero bytes received
for( uint16_t i=0; i < rcvd; i++ ) {
Serial.print((char)buf[i]); //printing on the screen
}//for( uint16_t i=0; i < rcvd; i++...
}//for( uint16_t i=0; i < rcvd; i++...
}//if( rcvd
}//if( read_delay > millis()...
}//if( Usb.getUsbTaskState() == USB_STATE_RUNNING..
}//if( read_delay > millis()...
}//if( Usb.getUsbTaskState() == USB_STATE_RUNNING..
}

View file

@ -11,6 +11,10 @@
#include <cdcprolific.h>
#include <TinyGPS.h>
// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
/* This sample code demonstrates the normal use of a TinyGPS object.
Modified to be used with USB Host Shield Library r2.0
@ -26,7 +30,7 @@ public:
uint8_t PLAsyncOper::OnInit(ACM *pacm)
{
uint8_t rcode;
// Set DTR = 1
rcode = pacm->SetControlLineState(1);
@ -36,17 +40,17 @@ uint8_t PLAsyncOper::OnInit(ACM *pacm)
}
LINE_CODING lc;
lc.dwDTERate = 4800; //default serial speed of GPS unit
lc.dwDTERate = 4800; //default serial speed of GPS unit
lc.bCharFormat = 0;
lc.bParityType = 0;
lc.bDataBits = 8;
lc.bDataBits = 8;
rcode = pacm->SetLineCoding(&lc);
if (rcode) {
ErrorMessage<uint8_t>(PSTR("SetLineCoding"), rcode);
}
return rcode;
}
@ -65,7 +69,7 @@ void setup()
Serial.begin(115200);
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
Serial.print("Testing TinyGPS library v. "); Serial.println(TinyGPS::library_version());
Serial.println("by Mikal Hart");
Serial.println();
@ -75,16 +79,16 @@ void setup()
if (Usb.Init() == -1) {
Serial.println("OSCOKIRQ failed to assert");
}
delay( 200 );
delay( 200 );
}
void loop()
{
Usb.Task();
if( Pl.isReady()) {
bool newdata = false;
unsigned long start = millis();
@ -94,7 +98,7 @@ void loop()
newdata = true;
}
}//while (millis()...
if (newdata) {
Serial.println("Acquired Data");
Serial.println("-------------");
@ -118,7 +122,7 @@ void printFloat(double number, int digits)
double rounding = 0.5;
for (uint8_t i=0; i<digits; ++i)
rounding /= 10.0;
number += rounding;
// Extract the integer part of the number and print it
@ -128,7 +132,7 @@ void printFloat(double number, int digits)
// Print the decimal point, but only if there are digits beyond
if (digits > 0)
Serial.print(".");
Serial.print(".");
// Extract digits from the remainder one at a time
while (digits-- > 0)
@ -136,8 +140,8 @@ void printFloat(double number, int digits)
remainder *= 10.0;
int toPrint = int(remainder);
Serial.print(toPrint);
remainder -= toPrint;
}
remainder -= toPrint;
}
}
void gpsdump(TinyGPS &gps)
@ -150,9 +154,9 @@ void gpsdump(TinyGPS &gps)
unsigned short sentences, failed;
gps.get_position(&lat, &lon, &age);
Serial.print("Lat/Long(10^-5 deg): "); Serial.print(lat); Serial.print(", "); Serial.print(lon);
Serial.print("Lat/Long(10^-5 deg): "); Serial.print(lat); Serial.print(", "); Serial.print(lon);
Serial.print(" Fix age: "); Serial.print(age); Serial.println("ms.");
feedgps(); // If we don't feed the gps during this long routine, we may drop characters and get checksum errors
gps.f_get_position(&flat, &flon, &age);
@ -171,7 +175,7 @@ void gpsdump(TinyGPS &gps)
Serial.print("Date: "); Serial.print(static_cast<int>(month)); Serial.print("/"); Serial.print(static_cast<int>(day)); Serial.print("/"); Serial.print(year);
Serial.print(" Time: "); Serial.print(static_cast<int>(hour)); Serial.print(":"); Serial.print(static_cast<int>(minute)); Serial.print(":"); Serial.print(static_cast<int>(second)); Serial.print("."); Serial.print(static_cast<int>(hundredths));
Serial.print(" Fix age: "); Serial.print(age); Serial.println("ms.");
feedgps();
Serial.print("Alt(cm): "); Serial.print(gps.altitude()); Serial.print(" Course(10^-2 deg): "); Serial.print(gps.course()); Serial.print(" Speed(10^-2 knots): "); Serial.println(gps.speed());
@ -184,13 +188,13 @@ void gpsdump(TinyGPS &gps)
gps.stats(&chars, &sentences, &failed);
Serial.print("Stats: characters: "); Serial.print(chars); Serial.print(" sentences: "); Serial.print(sentences); Serial.print(" failed checksum: "); Serial.println(failed);
}
bool feedgps()
{
uint8_t rcode;
uint8_t buf[64]; //serial buffer equals Max.packet size of bulk-IN endpoint
uint16_t rcvd = 64;
{
uint8_t buf[64]; //serial buffer equals Max.packet size of bulk-IN endpoint
uint16_t rcvd = 64;
{
/* reading the GPS */
rcode = Pl.RcvData(&rcvd, buf);
if (rcode && rcode != hrNAK)
@ -201,7 +205,7 @@ bool feedgps()
if( gps.encode((char)buf[i])) { //feed a character to gps object
rcode = true;
}//if( gps.encode(buf[i]...
}//for( uint16_t i=0; i < rcvd; i++...
}//for( uint16_t i=0; i < rcvd; i++...
}//if( rcvd...
}
return( rcode );

View file

@ -5,6 +5,10 @@
/* CDC support */
#include <cdcacm.h>
#include <cdcprolific.h>
// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
class PLAsyncOper : public CDCAsyncOper
{
@ -15,7 +19,7 @@ public:
uint8_t PLAsyncOper::OnInit(ACM *pacm)
{
uint8_t rcode;
// Set DTR = 1
rcode = pacm->SetControlLineState(1);
@ -26,16 +30,16 @@ uint8_t PLAsyncOper::OnInit(ACM *pacm)
}
LINE_CODING lc;
lc.dwDTERate = 115200;
lc.dwDTERate = 115200;
lc.bCharFormat = 0;
lc.bParityType = 0;
lc.bDataBits = 8;
lc.bDataBits = 8;
rcode = pacm->SetLineCoding(&lc);
if (rcode)
ErrorMessage<uint8_t>(PSTR("SetLineCoding"), rcode);
return rcode;
}
USB Usb;
@ -51,29 +55,29 @@ void setup()
if (Usb.Init() == -1)
Serial.println("OSCOKIRQ failed to assert");
delay( 200 );
delay( 200 );
}
void loop()
{
Usb.Task();
if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
{
{
uint8_t rcode;
/* reading the keyboard */
if(Serial.available()) {
uint8_t data= Serial.read();
if ( data == '\r' ) {
Serial.print("\r\n"); //insert linefeed
}
else {
Serial.print( data ); //echo back to the screen
}
/* sending to the phone */
rcode = Pl.SndData(1, &data);
if (rcode)
@ -81,17 +85,17 @@ void loop()
}//if(Serial.available()...
delay(50);
/* reading the converter */
/* buffer size must be greater or equal to max.packet size */
/* it it set to 64 (largest possible max.packet size) here, can be tuned down
for particular endpoint */
uint8_t buf[64];
uint8_t buf[64];
uint16_t rcvd = 64;
rcode = Pl.RcvData(&rcvd, buf);
if (rcode && rcode != hrNAK)
ErrorMessage<uint8_t>(PSTR("Ret"), rcode);
if( rcvd ) { //more than zero bytes received
for(uint16_t i=0; i < rcvd; i++ ) {
if( buf[i] =='\r' ) {
@ -100,10 +104,10 @@ void loop()
else {
Serial.print((char)buf[i]); //printing on the screen
}
}
}
}
delay(10);
}//if( Usb.getUsbTaskState() == USB_STATE_RUNNING..
delay(10);
}//if( Usb.getUsbTaskState() == USB_STATE_RUNNING..
}