-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example, add other needed things
- Loading branch information
Showing
11 changed files
with
173 additions
and
69 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Copyright (c) 2019 FIRST | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
* Neither the name of the FIRST nor the | ||
names of its contributors may be used to endorse or promote products | ||
derived from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY FIRST AND CONTRIBUTORS``AS IS'' AND ANY | ||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY NONINFRINGEMENT AND FITNESS FOR A PARTICULAR | ||
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL FIRST OR CONTRIBUTORS BE LIABLE FOR | ||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
============================================================================== | ||
Copyrights and Licenses for Third Party Software Distributed with WPILib | ||
============================================================================== | ||
The WPILib software contains code written by third parties. The copyrights, | ||
license, and restrictions which apply to each piece of software is included | ||
later in this file and/or inside of the individual applicable source files. | ||
|
||
The disclaimer of warranty in the WPILib license above applies to all code in | ||
WPILib, and nothing in any of the other licenses gives permission to use the | ||
names of FIRST nor the names of the WPILib contributors to endorse or promote | ||
products derived from this software. | ||
|
||
============================================================================== | ||
MCP2515 LICENSE | ||
============================================================================== | ||
|
||
The MIT License (MIT) | ||
|
||
Copyright (c) 2013 Seeed Technology Inc. Copyright (c) 2016 Dmitry | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
|
||
#include "mcp2515/mcp2515.h" | ||
#include "frc/CAN.h" | ||
|
||
// Define the CS pin and the interrupt pin | ||
#define CAN_CS 10 | ||
#define CAN_INTERRUPT 2 | ||
|
||
// Create an MCP2515 device. Only need to create 1 of these | ||
MCP2515 mcp2515{CAN_CS}; | ||
|
||
// Create an FRC CAN Device. You can create up to 16 of these in 1 progam | ||
// Any more will overflow a global array | ||
frc::CAN frcCANDevice{1}; | ||
|
||
// Callback function. This will be called any time a new message is received | ||
// Matching one of the enabled devices. | ||
void CANCallback(frc::CAN* can, int apiId, bool rtr, const frc::CANData& data) { | ||
Serial.println(apiId, HEX); | ||
} | ||
|
||
// Callback function for any messages not matching a known device. | ||
// This would still have flags for RTR and Extended set, its a raw ID | ||
void UnknownMessageCallback(uint32_t id, const frc::CANData& data) { | ||
|
||
} | ||
|
||
|
||
void setup() { | ||
// Initialize the MCP2515. If any error values are set, initialization failed | ||
auto err = mcp2515.reset(); | ||
// CAN rate must be 1000KBPS to work with the FRC Ecosystem | ||
// Clock rate must match clock rate of CAN Board. | ||
err = mcp2515.setBitrate(CAN_1000KBPS, CAN_CLOCK::MCP_8MHZ); | ||
|
||
// Set up to normal CAN mode | ||
err = mcp2515.setNormalMode(); | ||
|
||
// Prepare our interrupt pin | ||
pinMode(CAN_INTERRUPT, INPUT); | ||
|
||
// Set up FRC CAN to be able to use the CAN Impl and callbacks | ||
// Last parameter can be set to nullptr if unknown messages should be skipped | ||
frc::CAN::SetCANImpl(&mcp2515, CAN_INTERRUPT, CANCallback, UnknownMessageCallback); | ||
|
||
// All CAN Devices must be added to the read list. Otherwise they will not be handled correctly. | ||
frcCANDevice.AddToReadList(); | ||
} | ||
|
||
unsigned long long lastSend20Ms = 0; | ||
int count = 0; | ||
|
||
void loop() { | ||
// Update must be called every loop in order to receive messages | ||
frc::CAN::Update(); | ||
|
||
uint8_t data[8]; | ||
|
||
// Writes can happen any time, this uses a periodic send | ||
auto now = millis(); | ||
if (now - lastSend20Ms > 20) { | ||
// 20 ms periodic | ||
memset(data, 0, 8); | ||
data[0] = count; | ||
count++; | ||
|
||
frcCANDevice.WritePacket(data, 1, 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.