Compare commits
2 Commits
feature/se
...
feat/nfc-o
Author | SHA1 | Date | |
---|---|---|---|
04a3639252 | |||
acc5944323 |
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@ -1,5 +0,0 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"new": "cpp"
|
||||
}
|
||||
}
|
@ -27,8 +27,9 @@ build_flags =
|
||||
|
||||
; nfc addr
|
||||
-D NFC_ADDR=0x28
|
||||
;;; Servo config ;;;
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;
|
||||
-D RIGHT_POS=18
|
||||
-D MIDDLE_POS=32
|
||||
-D LEFT_POS=52
|
||||
;;; BigNfc config ;;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;
|
||||
-D BIG_NFC_RX=5
|
||||
-D BIG_NFC_TX=17
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include "Arduino.h"
|
||||
#include "DolibarrClient.h"
|
||||
#include <M5Stack.h>
|
||||
#include "ServoMotorComponent.h"
|
||||
|
||||
class Program {
|
||||
public:
|
||||
@ -19,7 +18,6 @@ public:
|
||||
void loop();
|
||||
private:
|
||||
DolibarrClient *client;
|
||||
ServoMotorComponent *servo;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
63
lib/BigNFC/include/BigNFC.h
Normal file
63
lib/BigNFC/include/BigNFC.h
Normal file
@ -0,0 +1,63 @@
|
||||
#ifndef BIG_NFC_H
|
||||
#define BIG_NFC_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <vector>
|
||||
#include "TrameList.h"
|
||||
|
||||
class BigNFC{
|
||||
public:
|
||||
BigNFC(int pinRX, int pinTX, int baud = 115200);
|
||||
|
||||
/**
|
||||
* @brief initialise le lecteur NFC
|
||||
*
|
||||
* @return true le lecteur NFC est initialisé
|
||||
* @return false le lecteur NFC n'est pas initialisé (erreur)
|
||||
*/
|
||||
bool init();
|
||||
|
||||
/**
|
||||
* @brief rafraichit les données du lecteur NFC
|
||||
*
|
||||
*/
|
||||
void refresh();
|
||||
|
||||
/**
|
||||
* @brief affiche la dernière trame lue
|
||||
*
|
||||
*/
|
||||
void printTrame();
|
||||
|
||||
/**
|
||||
* @brief retourne le nombre de tags lus
|
||||
*
|
||||
* @return int nombre de tags lus
|
||||
*/
|
||||
int getNbTags();
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* @brief convertit un nombre en hexadécimal (a 2 chiffres)
|
||||
*
|
||||
* @param number nombre à convertir
|
||||
* @return String nombre converti
|
||||
*/
|
||||
String digitify(int number);
|
||||
|
||||
/**
|
||||
* @brief variable pair/impair pour le type de trame
|
||||
*
|
||||
*/
|
||||
bool pair;
|
||||
|
||||
/**
|
||||
* @brief dernière trame lue
|
||||
*
|
||||
*/
|
||||
std::vector<byte>* trame;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
29
lib/BigNFC/include/TrameList.h
Normal file
29
lib/BigNFC/include/TrameList.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef TRAM_LIST_H
|
||||
#define TRAM_LIST_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <vector>
|
||||
|
||||
const std::vector<byte> SEARCH_TRAM_0 = {0x05, 0x07, 0x01, 0x01, 0x01, 0x00, 0xEB, 0x5F};
|
||||
|
||||
const std::vector<byte> INIT_TRAM_0 = {0xFA, 0x05, 0x01, 0xC0, 0x5A, 0xDF};
|
||||
const std::vector<byte> INIT_TRAM_1 = {0xFA, 0x08, 0x01, 0x00, 0x01, 0x01, 0x01, 0xE1, 0x70};
|
||||
const std::vector<byte> INIT_TRAM_2 = {0xFA, 0x08, 0x01, 0x40, 0x01, 0x02, 0x01, 0x3E, 0x4C};
|
||||
const std::vector<byte> INIT_TRAM_3 = {0xFA, 0x08, 0x01, 0x00, 0x01, 0x03, 0x01, 0x51, 0x43};
|
||||
const std::vector<byte> INIT_TRAM_4 = {0xFA, 0x08, 0x01, 0x40, 0x01, 0x04, 0x01, 0xEE, 0x18};
|
||||
const std::vector<byte> INIT_TRAM_5 = {0xFA, 0x08, 0x01, 0x00, 0x01, 0x05, 0x01, 0x81, 0x17};
|
||||
const std::vector<byte> INIT_TRAM_6 = {0xFA, 0x08, 0x01, 0x40, 0x01, 0x06, 0x01, 0x5E, 0x2B};
|
||||
const std::vector<byte> INIT_TRAM_7 = {0xFA, 0x08, 0x01, 0x00, 0x01, 0x07, 0x01, 0x31, 0x24};
|
||||
|
||||
const std::vector<byte> REP_TRAM_0 = {0xFA, 0x05, 0x01, 0xE0, 0x58, 0xFE};
|
||||
const std::vector<byte> REP_TRAM_1 = {0xFA, 0x17, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x04, 0x00, 0x00, 0x03, 0x01, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x95, 0x8A};
|
||||
const std::vector<byte> REP_TRAM_2 = {0xFA, 0x17, 0x01, 0x40, 0x01, 0x00, 0x00, 0x01, 0x00, 0x09, 0x00, 0xFF, 0x00, 0x10, 0x07, 0x13, 0x01, 0x0E, 0x08, 0x09, 0x0B, 0x00, 0x2D, 0x98};
|
||||
const std::vector<byte> REP_TRAM_3 = {0xFA, 0x17, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xE8, 0x03, 0x00, 0x00, 0x00, 0x00, 0x43, 0x83, 0x00, 0x00, 0x00, 0x9A, 0xBF};
|
||||
const std::vector<byte> REP_TRAM_4 = {0xFA, 0x17, 0x01, 0x40, 0x01, 0x00, 0x00, 0x01, 0x04, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD7, 0x15};
|
||||
const std::vector<byte> REP_TRAM_5 = {0xFA, 0x17, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0A, 0x03, 0x0A, 0x00, 0xF6, 0xCD};
|
||||
const std::vector<byte> REP_TRAM_6 = {0xFA, 0x17, 0x01, 0x40, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x03, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0xD4, 0x03};
|
||||
const std::vector<byte> REP_TRAM_7 = {0xFA, 0x17, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x52, 0xF6};
|
||||
|
||||
const std::vector<byte> READ_TRAM_0 = {0xFA, 0x24, 0x01, 0x00, 0x31, 0x02, 0x07, 0x0E, 0x00, 0x00, 0x04, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x06, 0x00, 0x03, 0x00, 0xFF, 0x00, 0x03, 0x00, 0x02, 0x00, 0x00, 0x02, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x5D, 0x74};
|
||||
const std::vector<byte> READ_TRAM_1 = {0xFA, 0x24, 0x01, 0x40, 0x31, 0x02, 0x07, 0x0E, 0x00, 0x00, 0x04, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x06, 0x00, 0x03, 0x00, 0xFF, 0x00, 0x03, 0x00, 0x02, 0x00, 0x00, 0x02, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x10, 0x45};
|
||||
#endif
|
73
lib/BigNFC/src/BigNFC.cpp
Normal file
73
lib/BigNFC/src/BigNFC.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
#include "../include/BigNFC.h"
|
||||
|
||||
|
||||
BigNFC::BigNFC(int pinRX, int pinTX, int baud){
|
||||
Serial2.begin(baud, SERIAL_8N1, pinRX, pinTX);//TODO: mettre le port série en paramètre
|
||||
this->pair = true;
|
||||
this->trame = new std::vector<byte>();
|
||||
}
|
||||
|
||||
bool BigNFC::init(){
|
||||
const std::vector<std::vector<byte>> INIT_TRAMES = {INIT_TRAM_0, INIT_TRAM_1, INIT_TRAM_2, INIT_TRAM_3, INIT_TRAM_4, INIT_TRAM_5, INIT_TRAM_6, INIT_TRAM_7};
|
||||
const std::vector<std::vector<byte>> REP_TRAMES = {REP_TRAM_0, REP_TRAM_1, REP_TRAM_2, REP_TRAM_3, REP_TRAM_4, REP_TRAM_5, REP_TRAM_6, REP_TRAM_7};
|
||||
int repnb = 0;
|
||||
for(std::vector<byte> i: INIT_TRAMES){
|
||||
for(byte j: i){
|
||||
Serial2.write(j);
|
||||
}
|
||||
while (Serial2.available() == 0);
|
||||
while (Serial2.available() > 0){
|
||||
for(byte j: REP_TRAMES[repnb]){
|
||||
if(Serial2.read() != j){
|
||||
Serial.println("NFC reader init failed");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
repnb++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void BigNFC::refresh(){
|
||||
this->trame->clear();
|
||||
std::vector<byte> trame = READ_TRAM_0;
|
||||
if (this->pair){
|
||||
trame = READ_TRAM_1;
|
||||
}
|
||||
this->pair = !this->pair;
|
||||
|
||||
for(byte i: trame){
|
||||
Serial2.write(i);
|
||||
}
|
||||
while (Serial2.available() == 0);
|
||||
while (Serial2.available() > 0){
|
||||
this->trame->push_back(Serial2.read());
|
||||
}
|
||||
}
|
||||
|
||||
String BigNFC::digitify(int number){
|
||||
String sortie = "";
|
||||
|
||||
if(number <= 0xF){
|
||||
sortie += '0';
|
||||
sortie += String(number,HEX);
|
||||
}else{
|
||||
sortie += String(number,HEX);
|
||||
}
|
||||
|
||||
return sortie;
|
||||
}
|
||||
|
||||
|
||||
void BigNFC::printTrame(){
|
||||
for(byte i: *this->trame){
|
||||
Serial.print(this->digitify(i));
|
||||
Serial.print(" ");
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
int BigNFC::getNbTags(){
|
||||
return this->trame->at(8);
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
#include "ServoMotorComponent.h"
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
// Functions for setting up the ServoMotor
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* Prepares the ServoMotor.
|
||||
*/
|
||||
ServoMotorComponent::ServoMotorComponent(int PIN, unsigned long updatePeriod, float step) {
|
||||
this->PIN = PIN;
|
||||
this->myservo.attach(PIN);
|
||||
this->desiredposition = Position::MIDDLE;
|
||||
this->currentPosition = MIDDLE_POS;
|
||||
this->lastUpTime = millis();
|
||||
this->updatePeriod = updatePeriod;
|
||||
this->step = step;
|
||||
this->myservo.write(this->PIN, this->currentPosition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the desired position
|
||||
* @desiredPosition: Give desired position
|
||||
*/
|
||||
void ServoMotorComponent::setDesiredPosition(Position desiredPosition) {
|
||||
switch (desiredPosition) {
|
||||
case Position::LEFT:
|
||||
this->desiredposition = LEFT_POS;
|
||||
break;
|
||||
case Position::MIDDLE:
|
||||
this->desiredposition = MIDDLE_POS;
|
||||
break;
|
||||
case Position::RIGHT:
|
||||
this->desiredposition = RIGHT_POS;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Write a new servoMotor position when it's necessary
|
||||
*/
|
||||
void ServoMotorComponent::refresh() {
|
||||
if (this->desiredposition == this->currentPosition
|
||||
|| millis() - this->lastUpTime <= this->updatePeriod) return;
|
||||
|
||||
if (this->currentPosition > this->desiredposition) {
|
||||
this->currentPosition -= this->step;
|
||||
}
|
||||
if (this->currentPosition < this->desiredposition) {
|
||||
this->currentPosition += this->step;
|
||||
}
|
||||
this->lastUpTime = millis();
|
||||
this->myservo.write(this->PIN, this->currentPosition);
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
#ifndef SERVOMOTOT_COMPONENT_H
|
||||
#define SERVOMOTOT_COMPONENT_H
|
||||
|
||||
#include <Servo.h>
|
||||
|
||||
enum Position {
|
||||
LEFT,
|
||||
MIDDLE,
|
||||
RIGHT
|
||||
};
|
||||
|
||||
class ServoMotorComponent
|
||||
{
|
||||
public:
|
||||
ServoMotorComponent(int PIN, unsigned long updatePeriod, float step = 1);
|
||||
void setDesiredPosition(Position desiredPosition);
|
||||
void refresh();
|
||||
|
||||
private:
|
||||
int PIN;
|
||||
float currentPosition;
|
||||
float desiredposition;
|
||||
Servo myservo;
|
||||
unsigned long lastUpTime;
|
||||
unsigned long updatePeriod;
|
||||
float step;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif //SERVOMOTOT_COMPONENT_H
|
@ -55,7 +55,6 @@ lib_deps =
|
||||
m5stack/M5Stack@^0.4.5 ; M5 Lib
|
||||
m5stack/M5GFX@^0.1.9 ; M5 Lib pour le LCD
|
||||
m5stack/Module_GRBL_13.2@^0.0.3 ; M5 Lib pour Stepper (GRBL)
|
||||
dlloydev/ESP32 ESP32S2 AnalogWrite ; Lib pour le Servo Motor
|
||||
; example:
|
||||
; erropix/ESP32 AnalogWrite@0.2
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include "Program.h"
|
||||
#include "Arduino.h"
|
||||
#include "DolibarrClient.h"
|
||||
#include "ServoMotorComponent.h"
|
||||
|
||||
int initialize_wifi(WifiConfig wifi) {
|
||||
WiFiClass::mode(WIFI_STA); //Optional
|
||||
@ -18,16 +17,13 @@ int initialize_wifi(WifiConfig wifi) {
|
||||
|
||||
Program::Program() {
|
||||
Serial.begin(MONITOR_SPEED);
|
||||
this->servo = new ServoMotorComponent(2, 1, 0.1);
|
||||
//struct WifiConfig wifi_c = {WIFI_SSID, WIFI_PASSWORD};
|
||||
//struct DolibarrConfig dolibarr = {DOLIBARR_URL, DOLIBARR_API_TOKEN};
|
||||
//initialize_wifi(wifi_c);
|
||||
//this->client = new DolibarrClient(dolibarr);
|
||||
struct WifiConfig wifi_c = {WIFI_SSID, WIFI_PASSWORD};
|
||||
struct DolibarrConfig dolibarr = {DOLIBARR_URL, DOLIBARR_API_TOKEN};
|
||||
initialize_wifi(wifi_c);
|
||||
this->client = new DolibarrClient(dolibarr);
|
||||
}
|
||||
|
||||
void Program::loop() {
|
||||
this->servo->refresh();
|
||||
this->servo->setDesiredPosition(Position::LEFT);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user