Skip to content

Commit b594476

Browse files
authored
Merge pull request #2 from caternuson/updates
Update examples
2 parents c628716 + e447e7b commit b594476

File tree

9 files changed

+75
-106
lines changed

9 files changed

+75
-106
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 Sandeep Mistry
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

examples/feather_m4can_onreceive/.feather_m4_can.test.only

Whitespace-only changes.

examples/feather_m4can_onreceive/feather_m4can_onreceive.ino

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@
77
CANSAME5x CAN;
88

99
void setup() {
10-
Serial.begin(9600);
11-
while (!Serial);
10+
Serial.begin(115200);
11+
while (!Serial) delay(10);
1212

1313
Serial.println("CAN Receiver Callback");
1414

1515
// start the CAN bus at 250 kbps
16-
if (!CAN.begin(250E3)) {
16+
if (!CAN.begin(250000)) {
1717
Serial.println("Starting CAN failed!");
18-
while (1);
18+
while (1) delay(10);
1919
}
20+
Serial.println("Starting CAN!");
2021

2122
// register the receive callback
2223
CAN.onReceive(onReceive);

examples/feather_m4can_rx/.feather_m4_can.test.only

Whitespace-only changes.

examples/feather_m4can_rx/feather_m4can_rx.ino

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
CANSAME5x CAN;
88

99
void setup() {
10-
Serial.begin(9600);
11-
while (!Serial);
10+
Serial.begin(115200);
11+
while (!Serial) delay(10);
1212

1313
Serial.println("CAN Receiver");
1414

@@ -20,8 +20,9 @@ void setup() {
2020
// start the CAN bus at 250 kbps
2121
if (!CAN.begin(250000)) {
2222
Serial.println("Starting CAN failed!");
23-
while (1);
23+
while (1) delay(10);
2424
}
25+
Serial.println("Starting CAN!");
2526
}
2627

2728
void loop() {

examples/feather_m4can_tx/.feather_m4_can.test.only

Whitespace-only changes.

examples/feather_m4can_tx/feather_m4can_tx renamed to examples/feather_m4can_tx/feather_m4can_tx.ino

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
CANSAME5x CAN;
88

99
void setup() {
10-
Serial.begin(9600);
11-
while (!Serial);
10+
Serial.begin(115200);
11+
while (!Serial) delay(10);
1212

1313
Serial.println("CAN Sender");
14+
1415
pinMode(PIN_CAN_STANDBY, OUTPUT);
1516
digitalWrite(PIN_CAN_STANDBY, false); // turn off STANDBY
1617
pinMode(PIN_CAN_BOOSTEN, OUTPUT);
@@ -19,8 +20,9 @@ void setup() {
1920
// start the CAN bus at 250 kbps
2021
if (!CAN.begin(250000)) {
2122
Serial.println("Starting CAN failed!");
22-
while (1);
23+
while (1) delay(10);
2324
}
25+
Serial.println("Starting CAN!");
2426
}
2527

2628
void loop() {

src/CANController.cpp

Lines changed: 36 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,28 @@
1+
// Forked from:
12
// Copyright (c) Sandeep Mistry. All rights reserved.
2-
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
// Licensed under the MIT license. See LICENSE file in the project root for full
4+
// license information.
35

46
#include "CANController.h"
57

6-
CANControllerClass::CANControllerClass() :
7-
_onReceive(NULL),
8-
9-
_packetBegun(false),
10-
_txId(-1),
11-
_txExtended(-1),
12-
_txRtr(false),
13-
_txDlc(0),
14-
_txLength(0),
15-
16-
_rxId(-1),
17-
_rxExtended(false),
18-
_rxRtr(false),
19-
_rxDlc(0),
20-
_rxLength(0),
21-
_rxIndex(0)
22-
{
8+
CANControllerClass::CANControllerClass()
9+
: _onReceive(NULL),
10+
11+
_packetBegun(false), _txId(-1), _txExtended(-1), _txRtr(false), _txDlc(0),
12+
_txLength(0),
13+
14+
_rxId(-1), _rxExtended(false), _rxRtr(false), _rxDlc(0), _rxLength(0),
15+
_rxIndex(0) {
2316
// overide Stream timeout value
2417
setTimeout(0);
2518
}
2619

27-
CANControllerClass::~CANControllerClass()
28-
{
29-
}
20+
CANControllerClass::~CANControllerClass() {}
3021

31-
int CANControllerClass::begin(long /*baudRate*/)
32-
{
22+
int CANControllerClass::begin(long /*baudRate*/) {
3323
_packetBegun = false;
3424
_txId = -1;
35-
_txRtr =false;
25+
_txRtr = false;
3626
_txDlc = 0;
3727
_txLength = 0;
3828

@@ -45,12 +35,9 @@ int CANControllerClass::begin(long /*baudRate*/)
4535
return 1;
4636
}
4737

48-
void CANControllerClass::end()
49-
{
50-
}
38+
void CANControllerClass::end() {}
5139

52-
int CANControllerClass::beginPacket(int id, int dlc, bool rtr)
53-
{
40+
int CANControllerClass::beginPacket(int id, int dlc, bool rtr) {
5441
if (id < 0 || id > 0x7FF) {
5542
return 0;
5643
}
@@ -71,8 +58,7 @@ int CANControllerClass::beginPacket(int id, int dlc, bool rtr)
7158
return 1;
7259
}
7360

74-
int CANControllerClass::beginExtendedPacket(long id, int dlc, bool rtr)
75-
{
61+
int CANControllerClass::beginExtendedPacket(long id, int dlc, bool rtr) {
7662
if (id < 0 || id > 0x1FFFFFFF) {
7763
return 0;
7864
}
@@ -93,8 +79,7 @@ int CANControllerClass::beginExtendedPacket(long id, int dlc, bool rtr)
9379
return 1;
9480
}
9581

96-
int CANControllerClass::endPacket()
97-
{
82+
int CANControllerClass::endPacket() {
9883
if (!_packetBegun) {
9984
return 0;
10085
}
@@ -107,38 +92,21 @@ int CANControllerClass::endPacket()
10792
return 1;
10893
}
10994

110-
int CANControllerClass::parsePacket()
111-
{
112-
return 0;
113-
}
95+
int CANControllerClass::parsePacket() { return 0; }
11496

115-
long CANControllerClass::packetId()
116-
{
117-
return _rxId;
118-
}
97+
long CANControllerClass::packetId() { return _rxId; }
11998

120-
bool CANControllerClass::packetExtended()
121-
{
122-
return _rxExtended;
123-
}
99+
bool CANControllerClass::packetExtended() { return _rxExtended; }
124100

125-
bool CANControllerClass::packetRtr()
126-
{
127-
return _rxRtr;
128-
}
101+
bool CANControllerClass::packetRtr() { return _rxRtr; }
129102

130-
int CANControllerClass::packetDlc()
131-
{
132-
return _rxDlc;
133-
}
103+
int CANControllerClass::packetDlc() { return _rxDlc; }
134104

135-
size_t CANControllerClass::write(uint8_t byte)
136-
{
105+
size_t CANControllerClass::write(uint8_t byte) {
137106
return write(&byte, sizeof(byte));
138107
}
139108

140-
size_t CANControllerClass::write(const uint8_t *buffer, size_t size)
141-
{
109+
size_t CANControllerClass::write(const uint8_t *buffer, size_t size) {
142110
if (!_packetBegun) {
143111
return 0;
144112
}
@@ -153,64 +121,38 @@ size_t CANControllerClass::write(const uint8_t *buffer, size_t size)
153121
return size;
154122
}
155123

156-
int CANControllerClass::available()
157-
{
158-
return (_rxLength - _rxIndex);
159-
}
124+
int CANControllerClass::available() { return (_rxLength - _rxIndex); }
160125

161-
int CANControllerClass::read()
162-
{
126+
int CANControllerClass::read() {
163127
if (!available()) {
164128
return -1;
165129
}
166130

167131
return _rxData[_rxIndex++];
168132
}
169133

170-
int CANControllerClass::peek()
171-
{
134+
int CANControllerClass::peek() {
172135
if (!available()) {
173136
return -1;
174137
}
175138

176139
return _rxData[_rxIndex];
177140
}
178141

179-
void CANControllerClass::flush()
180-
{
181-
}
142+
void CANControllerClass::flush() {}
182143

183-
void CANControllerClass::onReceive(void(*callback)(int))
184-
{
144+
void CANControllerClass::onReceive(void (*callback)(int)) {
185145
_onReceive = callback;
186146
}
187147

188-
int CANControllerClass::filter(int /*id*/, int /*mask*/)
189-
{
190-
return 0;
191-
}
148+
int CANControllerClass::filter(int /*id*/, int /*mask*/) { return 0; }
192149

193-
int CANControllerClass::filterExtended(long /*id*/, long /*mask*/)
194-
{
195-
return 0;
196-
}
150+
int CANControllerClass::filterExtended(long /*id*/, long /*mask*/) { return 0; }
197151

198-
int CANControllerClass::observe()
199-
{
200-
return 0;
201-
}
152+
int CANControllerClass::observe() { return 0; }
202153

203-
int CANControllerClass::loopback()
204-
{
205-
return 0;
206-
}
154+
int CANControllerClass::loopback() { return 0; }
207155

208-
int CANControllerClass::sleep()
209-
{
210-
return 0;
211-
}
156+
int CANControllerClass::sleep() { return 0; }
212157

213-
int CANControllerClass::wakeup()
214-
{
215-
return 0;
216-
}
158+
int CANControllerClass::wakeup() { return 0; }

src/CANController.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
// Forked from:
12
// Copyright (c) Sandeep Mistry. All rights reserved.
2-
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
// Licensed under the MIT license. See LICENSE file in the project root for full
4+
// license information.
35

46
#ifndef CAN_CONTROLLER_H
57
#define CAN_CONTROLLER_H
@@ -32,7 +34,7 @@ class CANControllerClass : public Stream {
3234
virtual int peek();
3335
virtual void flush();
3436

35-
virtual void onReceive(void(*callback)(int));
37+
virtual void onReceive(void (*callback)(int));
3638

3739
virtual int filter(int id) { return filter(id, 0x7ff); }
3840
virtual int filter(int id, int mask);

0 commit comments

Comments
 (0)