mirror of
https://gitlab.com/fabinfra/fabhardware/fabreader.git
synced 2025-03-12 22:51:43 +01:00
Changed to PlatformIO
This commit is contained in:
parent
750ae399e0
commit
a787f0e7dc
5
src/FabReader_v2/.gitignore
vendored
Normal file
5
src/FabReader_v2/.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
.pio
|
||||
.vscode/.browse.c_cpp.db*
|
||||
.vscode/c_cpp_properties.json
|
||||
.vscode/launch.json
|
||||
.vscode/ipch
|
10
src/FabReader_v2/.vscode/extensions.json
vendored
Normal file
10
src/FabReader_v2/.vscode/extensions.json
vendored
Normal file
@ -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"
|
||||
]
|
||||
}
|
@ -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
|
@ -1,36 +0,0 @@
|
||||
#include "NFC.h"
|
||||
#include <SPI.h>
|
||||
|
||||
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()
|
||||
{
|
||||
|
||||
}
|
39
src/FabReader_v2/include/README
Normal file
39
src/FabReader_v2/include/README
Normal file
@ -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
|
46
src/FabReader_v2/lib/README
Normal file
46
src/FabReader_v2/lib/README
Normal file
@ -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 <Foo.h>
|
||||
#include <Bar.h>
|
||||
|
||||
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
|
20
src/FabReader_v2/platformio.ini
Normal file
20
src/FabReader_v2/platformio.ini
Normal file
@ -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
|
37
src/FabReader_v2/src/NFC.cpp
Normal file
37
src/FabReader_v2/src/NFC.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
#include "NFC.h"
|
||||
#include <SPI.h>
|
||||
#include <PubSubClient.h>
|
||||
#include <MFRC522.h>
|
||||
|
||||
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()
|
||||
{
|
||||
|
||||
}
|
@ -4,21 +4,21 @@
|
||||
#include <PubSubClient.h>
|
||||
#include <MFRC522.h>
|
||||
|
||||
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
|
||||
#endif
|
@ -1,5 +1,9 @@
|
||||
#include <Arduino.h>
|
||||
#include <ArduinoLog.h>
|
||||
|
||||
#include "Config.h"
|
||||
#include "Pins.h"
|
||||
#include "NFC.h"
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
@ -9,29 +13,31 @@
|
||||
#include <SPI.h>
|
||||
#include <MFRC522.h>
|
||||
#include <SSD1306Wire.h>
|
||||
#include <DES.h>
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
11
src/FabReader_v2/test/README
Normal file
11
src/FabReader_v2/test/README
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user