diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e426dbd --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.pio +.pioenvs +.piolibdeps +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..a8bbc57 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,67 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < https://docs.platformio.org/page/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < https://docs.platformio.org/page/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < https://docs.platformio.org/page/userguide/cmd_ci.html > +# +# +# Please choose one of the following templates (proposed below) and uncomment +# it (remove "# " before each line) or use own configuration according to the +# Travis CI documentation (see above). +# + + +# +# Template #1: General project. Test it using existing `platformio.ini`. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# install: +# - pip install -U platformio +# - platformio update +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to be used as a library with examples. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# env: +# - PLATFORMIO_CI_SRC=path/to/test/file.c +# - PLATFORMIO_CI_SRC=examples/file.ino +# - PLATFORMIO_CI_SRC=path/to/test/directory +# +# install: +# - pip install -U platformio +# - platformio update +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..8281e64 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ] +} \ No newline at end of file diff --git a/Sketch/Sketch.ino b/Sketch/Sketch.ino index 082e4b3..f1995fb 100644 --- a/Sketch/Sketch.ino +++ b/Sketch/Sketch.ino @@ -1,18 +1,11 @@ /************************************* - CAN-bus receive - Author: Michel Bats - Website: www.batssoft.nl - Version: 0.0.1 - Revision: 20161122 - - Used libraries: - Adafruit_SSD1306\Adafruit_SSD1306 by adafruit - https://github.com/adafruit/Adafruit_SSD1306 - Adafruit-GFX-Library\Adafruit_GFX by adafruit - https://github.com/adafruit/Adafruit-GFX-Library - CAN Bus Shield - MCP2515&MCP2551\CAN_BUS_Shield by Seeed-Studio - https://github.com/Seeed-Studio/CAN_BUS_Shield + * CAN-bus receive + * Author: Michel Bats + * Website: www.batssoft.nl + * Version: 0.0.2 + * Revision: 20190418 *************************************/ + #include #include #include @@ -20,6 +13,8 @@ // Bepalingen Display #define OLED_ADDR 60 // 60 = 0x3C / 61 = 0x3D +#define SCREEN_WIDTH 128 // OLED-scherm breedte, in pixels +#define SCREEN_HEIGHT 64 // OLED-scherm hoogte, in pixels #define OLED_RESET 4 // Bepalingen CAN-bus interface @@ -34,24 +29,17 @@ unsigned char bufDisp[8]; int canIdDisp = 0; int tel = 0; int canIdToReadArray[] = {16, 24, 32, 54, 162, 182, 223, 225, 230, 237, 246, 267, 272, 277, 288, 294, 296, 301, 308, 318, 332, 347, 353, 359, 360, 382, 396, 400, 417, 419, 424, 446, 460, 464, 471, 479, 535, 543, 545, 551, 588, 597, 608, 609, 652, 672, 673, 694, 725, 789, 791, 822, 853, 865, 935, 950, 1014, 1189, 1203, 1291, 1292, 1298, 1309, 1311, 1317, 1318, 1325, 1331}; -//int canIdToReadArray[] = {261, 264, 274, 520, 761, 773, 781, 840, 845, 909, 973, 1037, 1042, 1074, 1101, 1128, 1160, 1293, 1294, 1303, 1362, 1401, 1416, 1426, 1544, 1554, 1792, 1928, 1933, 1938, 1943, 2034}; int canIdToRead = canIdToReadArray[0]; #define CAN_ID_COUNT 68 -//#define CAN_ID_COUNT 32 int canIdCount = 0; int telDisp = 0; // Initialisatie Adafruit_SSD1306 -Adafruit_SSD1306 display(OLED_RESET); +Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); // Initialisatie mcp_can MCP_CAN CAN(MCP_CAN_SPI_CS_PIN); -// Controleren of de SSD1306-library correct is ingesteld. -#if (SSD1306_LCDHEIGHT != 64) -#error("Height incorrect, please fix Adafruit_SSD1306.h!"); -#endif - // SETUP void setup() { @@ -68,7 +56,6 @@ void setup() // Verbinding met de MCP2515 controleren while (CAN_OK != CAN.begin(CAN_125KBPS)) - //while (CAN_OK != CAN.begin(CAN_500KBPS)) { // Cursor verplaatsen naar linkerbovenhoek display.setCursor(0, 0); @@ -111,6 +98,7 @@ void loop() unsigned int canId = CAN.getCanId(); + if (canId == canIdToRead) { bufDisp[0] = buf[0]; @@ -179,11 +167,10 @@ void loop() display.display(); display.clearDisplay(); } - } void canIdToReadChange() { - while (digitalRead(INTERRUPT_PIN) == 0) { + while(digitalRead(INTERRUPT_PIN) == 0){ delay(250); } canIdCount++; @@ -193,4 +180,4 @@ void canIdToReadChange() { canIdToRead = canIdToReadArray[canIdCount]; telDisp = 0; tel = 0; -} +} diff --git a/include/README b/include/README new file mode 100644 index 0000000..45496b1 --- /dev/null +++ b/include/README @@ -0,0 +1,39 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/lib/README b/lib/README new file mode 100644 index 0000000..8c9c29c --- /dev/null +++ b/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into executable file. + +The source code of each library should be placed in a an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..27b69c0 --- /dev/null +++ b/platformio.ini @@ -0,0 +1,21 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[platformio] +src_dir = Sketch + +[env:uno] +platform = atmelavr +board = uno +framework = arduino +lib_deps = + Adafruit GFX Library + Adafruit SSD1306 + CAN_BUS_Shield \ No newline at end of file diff --git a/test/README b/test/README new file mode 100644 index 0000000..c3b0ed6 --- /dev/null +++ b/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PIO Unit Testing and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PIO Unit Testing: +- https://docs.platformio.org/page/plus/unit-testing.html