From a787f0e7dcc0b80665f4de88730a919f0fb0f2b1 Mon Sep 17 00:00:00 2001 From: TheJoKlLa Date: Wed, 7 Sep 2022 21:38:10 +0200 Subject: [PATCH] Changed to PlatformIO --- src/FabReader_v2/.gitignore | 5 ++ src/FabReader_v2/.vscode/extensions.json | 10 ++++ src/FabReader_v2/Config.h | 28 ----------- src/FabReader_v2/NFC.cpp | 36 --------------- src/FabReader_v2/include/README | 39 ++++++++++++++++ src/FabReader_v2/lib/README | 46 +++++++++++++++++++ src/FabReader_v2/platformio.ini | 20 ++++++++ src/FabReader_v2/{ => src}/Config.cpp | 0 src/FabReader_v2/{ => src}/Display.cpp | 0 src/FabReader_v2/{ => src}/Display.h | 0 src/FabReader_v2/src/NFC.cpp | 37 +++++++++++++++ src/FabReader_v2/{ => src}/NFC.h | 10 ++-- src/FabReader_v2/{ => src}/Pins.h | 0 src/FabReader_v2/{ => src}/Website.h | 0 .../{FabReader_v2.ino => src/main.cpp} | 22 +++++---- src/FabReader_v2/test/README | 11 +++++ 16 files changed, 187 insertions(+), 77 deletions(-) create mode 100644 src/FabReader_v2/.gitignore create mode 100644 src/FabReader_v2/.vscode/extensions.json delete mode 100644 src/FabReader_v2/Config.h delete mode 100644 src/FabReader_v2/NFC.cpp create mode 100644 src/FabReader_v2/include/README create mode 100644 src/FabReader_v2/lib/README create mode 100644 src/FabReader_v2/platformio.ini rename src/FabReader_v2/{ => src}/Config.cpp (100%) rename src/FabReader_v2/{ => src}/Display.cpp (100%) rename src/FabReader_v2/{ => src}/Display.h (100%) create mode 100644 src/FabReader_v2/src/NFC.cpp rename src/FabReader_v2/{ => src}/NFC.h (82%) rename src/FabReader_v2/{ => src}/Pins.h (100%) rename src/FabReader_v2/{ => src}/Website.h (100%) rename src/FabReader_v2/{FabReader_v2.ino => src/main.cpp} (58%) create mode 100644 src/FabReader_v2/test/README diff --git a/src/FabReader_v2/.gitignore b/src/FabReader_v2/.gitignore new file mode 100644 index 0000000..89cc49c --- /dev/null +++ b/src/FabReader_v2/.gitignore @@ -0,0 +1,5 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch diff --git a/src/FabReader_v2/.vscode/extensions.json b/src/FabReader_v2/.vscode/extensions.json new file mode 100644 index 0000000..080e70d --- /dev/null +++ b/src/FabReader_v2/.vscode/extensions.json @@ -0,0 +1,10 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ], + "unwantedRecommendations": [ + "ms-vscode.cpptools-extension-pack" + ] +} diff --git a/src/FabReader_v2/Config.h b/src/FabReader_v2/Config.h deleted file mode 100644 index 0883808..0000000 --- a/src/FabReader_v2/Config.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef CONFIG_H -#define CONFIG_H - -struct Config_Data -{ - int ID = 0; - - char MQTT_Broker[256]; - char MQTT_Username[64]; - char MQTT_Password[64]; -}; - -class Config { - public: - const char WLAN_SSID[32] = "FabReader"; - const char WLAN_Password[64] = "FabReader"; - - Config_Data Data; - - Config(); - Config(int ID, char broker[], char username[], char password[]); - - void Load(); - void Save(); - - bool IsEmpty(); -}; -#endif \ No newline at end of file diff --git a/src/FabReader_v2/NFC.cpp b/src/FabReader_v2/NFC.cpp deleted file mode 100644 index e702fa4..0000000 --- a/src/FabReader_v2/NFC.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "NFC.h" -#include - -NFC::NFC(int pin_ss, int pin_rst, PubSubClient mqtt) -{ - SPI.begin(); - - this->rfid = rfid(pin_ss, pin_rst); - this->rfid.PCD_Init(); -} - -bool NFC::hasNewCard() -{ - return this->rfid.PICC_IsNewCardPresent() && this->rfid.PICC_ReadCardSerial() - -} - -void NFC::hasActiveOTA() -{ - return this->activOTA; -} - -void NFC::startOTA() -{ - // TODO -} - -void NFC::continueOTA() -{ - // TODO -} - -void NFC::cancelOTA() -{ - -} \ No newline at end of file diff --git a/src/FabReader_v2/include/README b/src/FabReader_v2/include/README new file mode 100644 index 0000000..194dcd4 --- /dev/null +++ b/src/FabReader_v2/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/src/FabReader_v2/lib/README b/src/FabReader_v2/lib/README new file mode 100644 index 0000000..6debab1 --- /dev/null +++ b/src/FabReader_v2/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/src/FabReader_v2/platformio.ini b/src/FabReader_v2/platformio.ini new file mode 100644 index 0000000..f96f99f --- /dev/null +++ b/src/FabReader_v2/platformio.ini @@ -0,0 +1,20 @@ +; 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 + +[env:esp12e] +platform = espressif8266 +board = esp12e +framework = arduino +monitor_speed = 115200 +lib_deps = + knolleary/PubSubClient@^2.8 + thingpulse/ESP8266 and ESP32 OLED driver for SSD1306 displays@^4.3.0 + miguelbalboa/MFRC522@^1.4.10 + thijse/ArduinoLog@^1.1.1 diff --git a/src/FabReader_v2/Config.cpp b/src/FabReader_v2/src/Config.cpp similarity index 100% rename from src/FabReader_v2/Config.cpp rename to src/FabReader_v2/src/Config.cpp diff --git a/src/FabReader_v2/Display.cpp b/src/FabReader_v2/src/Display.cpp similarity index 100% rename from src/FabReader_v2/Display.cpp rename to src/FabReader_v2/src/Display.cpp diff --git a/src/FabReader_v2/Display.h b/src/FabReader_v2/src/Display.h similarity index 100% rename from src/FabReader_v2/Display.h rename to src/FabReader_v2/src/Display.h diff --git a/src/FabReader_v2/src/NFC.cpp b/src/FabReader_v2/src/NFC.cpp new file mode 100644 index 0000000..a1552a5 --- /dev/null +++ b/src/FabReader_v2/src/NFC.cpp @@ -0,0 +1,37 @@ +#include "NFC.h" +#include +#include +#include + +NFC::NFC(int pin_ss, int pin_rst, PubSubClient* mqtt) +{ + SPI.begin(); + + rfid = new MFRC522(pin_ss, pin_rst); + rfid->PCD_Init(); +} + +bool NFC::hasNewCard() +{ + return rfid->PICC_IsNewCardPresent() && rfid->PICC_ReadCardSerial() && rfid->uid.sak == 0x20; +} + +bool NFC::hasActiveOTA() +{ + return activOTA; +} + +void NFC::startOTA() +{ + // TODO +} + +void NFC::continueOTA() +{ + // TODO +} + +void NFC::cancelOTA() +{ + +} diff --git a/src/FabReader_v2/NFC.h b/src/FabReader_v2/src/NFC.h similarity index 82% rename from src/FabReader_v2/NFC.h rename to src/FabReader_v2/src/NFC.h index d6dc953..64097a1 100644 --- a/src/FabReader_v2/NFC.h +++ b/src/FabReader_v2/src/NFC.h @@ -4,21 +4,21 @@ #include #include -class NFC_H +class NFC { private: - MFRC522 rfid; + MFRC522* rfid; PubSubClient* mqtt; bool activOTA = false; public: NFC(int pin_ss, int pin_rst, PubSubClient* mqtt); bool hasNewCard(); - void hasActiveOTA(); + bool hasActiveOTA(); void startOTA(); void continueOTA(); void cancelOTA(); -} +}; -#endif \ No newline at end of file +#endif diff --git a/src/FabReader_v2/Pins.h b/src/FabReader_v2/src/Pins.h similarity index 100% rename from src/FabReader_v2/Pins.h rename to src/FabReader_v2/src/Pins.h diff --git a/src/FabReader_v2/Website.h b/src/FabReader_v2/src/Website.h similarity index 100% rename from src/FabReader_v2/Website.h rename to src/FabReader_v2/src/Website.h diff --git a/src/FabReader_v2/FabReader_v2.ino b/src/FabReader_v2/src/main.cpp similarity index 58% rename from src/FabReader_v2/FabReader_v2.ino rename to src/FabReader_v2/src/main.cpp index a106bef..b879f95 100644 --- a/src/FabReader_v2/FabReader_v2.ino +++ b/src/FabReader_v2/src/main.cpp @@ -1,5 +1,9 @@ +#include +#include + #include "Config.h" #include "Pins.h" +#include "NFC.h" #include #include @@ -9,29 +13,31 @@ #include #include #include -#include Config config; WiFiClient wifiClient; -PubSubClient MQTTclient; -MFRC522 rfid(PIN_RFID_SPI_SS, PIN_RFID_RST); +PubSubClient mqttClient; +NFC* nfc; void setup() { Serial.begin(115200); + Serial.print("\n\n\n"); + Serial.println("Booting ..."); pinMode(PIN_BUZZER, OUTPUT); pinMode(PIN_BUTTON, INPUT); pinMode(PIN_ETH_SPI_SS, OUTPUT); digitalWrite(PIN_ETH_SPI_SS, HIGH); - rfid.PCD_Init(); + Serial.println("NFC ..."); + nfc = new NFC(PIN_RFID_SPI_SS, PIN_RFID_RST, &mqttClient); } -void loop() +void loop() { - if (rfid.PICC_IsNewCardPresent() && rfid.PICC_ReadCardSerial()) + if (nfc->hasNewCard()) { - Serial.println(rfid.uid.sak); + Serial.println("New Card"); } -} \ No newline at end of file +} diff --git a/src/FabReader_v2/test/README b/src/FabReader_v2/test/README new file mode 100644 index 0000000..9b1e87b --- /dev/null +++ b/src/FabReader_v2/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PlatformIO Test Runner 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 PlatformIO Unit Testing: +- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html