|
10 | 10 | #include <spi4teensy3.h> |
11 | 11 | #endif |
12 | 12 |
|
13 | | -class PLAsyncOper : public CDCAsyncOper |
14 | | -{ |
| 13 | +class PLAsyncOper : public CDCAsyncOper { |
15 | 14 | public: |
16 | | - virtual uint8_t OnInit(ACM *pacm); |
| 15 | + virtual uint8_t OnInit(ACM *pacm); |
17 | 16 | }; |
18 | 17 |
|
19 | | -uint8_t PLAsyncOper::OnInit(ACM *pacm) |
20 | | -{ |
21 | | - uint8_t rcode; |
| 18 | +uint8_t PLAsyncOper::OnInit(ACM *pacm) { |
| 19 | + uint8_t rcode; |
22 | 20 |
|
23 | | - // Set DTR = 1 |
24 | | - rcode = pacm->SetControlLineState(1); |
| 21 | + // Set DTR = 1 |
| 22 | + rcode = pacm->SetControlLineState(1); |
25 | 23 |
|
26 | | - if (rcode) |
27 | | - { |
28 | | - ErrorMessage<uint8_t>(PSTR("SetControlLineState"), rcode); |
29 | | - return rcode; |
30 | | - } |
| 24 | + if(rcode) { |
| 25 | + ErrorMessage<uint8_t>(PSTR("SetControlLineState"), rcode); |
| 26 | + return rcode; |
| 27 | + } |
31 | 28 |
|
32 | | - LINE_CODING lc; |
33 | | - lc.dwDTERate = 4800; //default serial speed of GPS unit |
34 | | - lc.bCharFormat = 0; |
35 | | - lc.bParityType = 0; |
36 | | - lc.bDataBits = 8; |
| 29 | + LINE_CODING lc; |
| 30 | + lc.dwDTERate = 4800; //default serial speed of GPS unit |
| 31 | + lc.bCharFormat = 0; |
| 32 | + lc.bParityType = 0; |
| 33 | + lc.bDataBits = 8; |
37 | 34 |
|
38 | | - rcode = pacm->SetLineCoding(&lc); |
| 35 | + rcode = pacm->SetLineCoding(&lc); |
39 | 36 |
|
40 | | - if (rcode) |
41 | | - ErrorMessage<uint8_t>(PSTR("SetLineCoding"), rcode); |
| 37 | + if(rcode) |
| 38 | + ErrorMessage<uint8_t>(PSTR("SetLineCoding"), rcode); |
42 | 39 |
|
43 | | - return rcode; |
| 40 | + return rcode; |
44 | 41 | } |
45 | 42 |
|
46 | | -USB Usb; |
47 | | -USBHub Hub(&Usb); |
48 | | -PLAsyncOper AsyncOper; |
49 | | -PL2303 Pl(&Usb, &AsyncOper); |
| 43 | +USB Usb; |
| 44 | +USBHub Hub(&Usb); |
| 45 | +PLAsyncOper AsyncOper; |
| 46 | +PL2303 Pl(&Usb, &AsyncOper); |
50 | 47 | uint32_t read_delay; |
51 | 48 | #define READ_DELAY 100 |
52 | 49 |
|
53 | | -void setup() |
54 | | -{ |
55 | | - Serial.begin( 115200 ); |
56 | | - while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection |
57 | | - Serial.println("Start"); |
| 50 | +void setup() { |
| 51 | + Serial.begin(115200); |
| 52 | + while(!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection |
| 53 | + Serial.println("Start"); |
58 | 54 |
|
59 | | - if (Usb.Init() == -1) |
60 | | - Serial.println("OSCOKIRQ failed to assert"); |
| 55 | + if(Usb.Init() == -1) |
| 56 | + Serial.println("OSCOKIRQ failed to assert"); |
61 | 57 |
|
62 | | - delay( 200 ); |
| 58 | + delay(200); |
63 | 59 | } |
64 | 60 |
|
65 | | -void loop() |
66 | | -{ |
67 | | -uint8_t rcode; |
68 | | -uint8_t buf[64]; //serial buffer equals Max.packet size of bulk-IN endpoint |
69 | | -uint16_t rcvd = 64; |
70 | | - |
71 | | - Usb.Task(); |
72 | | - |
73 | | - if( Pl.isReady()) { |
74 | | - /* reading the GPS */ |
75 | | - if( read_delay < millis() ){ |
76 | | - read_delay += READ_DELAY; |
77 | | - rcode = Pl.RcvData(&rcvd, buf); |
78 | | - if ( rcode && rcode != hrNAK ) |
79 | | - ErrorMessage<uint8_t>(PSTR("Ret"), rcode); |
80 | | - if( rcvd ) { //more than zero bytes received |
81 | | - for( uint16_t i=0; i < rcvd; i++ ) { |
82 | | - Serial.print((char)buf[i]); //printing on the screen |
83 | | - }//for( uint16_t i=0; i < rcvd; i++... |
84 | | - }//if( rcvd |
85 | | - }//if( read_delay > millis()... |
86 | | - }//if( Usb.getUsbTaskState() == USB_STATE_RUNNING.. |
| 61 | +void loop() { |
| 62 | + uint8_t rcode; |
| 63 | + uint8_t buf[64]; //serial buffer equals Max.packet size of bulk-IN endpoint |
| 64 | + uint16_t rcvd = 64; |
| 65 | + |
| 66 | + Usb.Task(); |
| 67 | + |
| 68 | + if(Pl.isReady()) { |
| 69 | + /* reading the GPS */ |
| 70 | + if((long)(millis() - read_delay) >= 0L) { |
| 71 | + read_delay += READ_DELAY; |
| 72 | + rcode = Pl.RcvData(&rcvd, buf); |
| 73 | + if(rcode && rcode != hrNAK) |
| 74 | + ErrorMessage<uint8_t>(PSTR("Ret"), rcode); |
| 75 | + if(rcvd) { //more than zero bytes received |
| 76 | + for(uint16_t i = 0; i < rcvd; i++) { |
| 77 | + Serial.print((char)buf[i]); //printing on the screen |
| 78 | + }//for( uint16_t i=0; i < rcvd; i++... |
| 79 | + }//if( rcvd |
| 80 | + }//if( read_delay > millis()... |
| 81 | + }//if( Usb.getUsbTaskState() == USB_STATE_RUNNING.. |
87 | 82 | } |
88 | 83 |
|
89 | 84 |
|
0 commit comments