Compare commits
30 Commits
feat/m5_lc
...
develop
Author | SHA1 | Date | |
---|---|---|---|
265c3b3b39 | |||
6a1786ec9a | |||
e3843db340 | |||
da2a06b23a | |||
1d1874872b | |||
2d32523317 | |||
adc6134d8b | |||
d2dec55110 | |||
c270a764f2 | |||
26b1185bca | |||
627509a2d7 | |||
01728a2499 | |||
57cf250a03 | |||
9c11f62019 | |||
7b975bd9a9 | |||
35ecce7d5d | |||
a105387c21 | |||
3f77acd600 | |||
23258e2682 | |||
f64264631e | |||
68a4ab9755 | |||
b3ef581d28 | |||
29c41b6ccc | |||
04474bfb94 | |||
463e71fe10 | |||
76ebc00763 | |||
8bdd4a9be2 | |||
f947fc7e5f | |||
b96088c4eb | |||
d8f0bb07be |
27
.github/workflows/test_build.yml
vendored
27
.github/workflows/test_build.yml
vendored
@ -1,35 +1,22 @@
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ master ]
|
branches:
|
||||||
|
- main
|
||||||
|
- develop
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ master ]
|
branches:
|
||||||
|
- main
|
||||||
|
- develop
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout project
|
- name: Checkout project
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
# - name: Cache pip
|
|
||||||
# uses: actions/cache@v3
|
|
||||||
# with:
|
|
||||||
# path: ~/.cache/pip
|
|
||||||
# key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
|
|
||||||
# restore-keys: |
|
|
||||||
# ${{ runner.os }}-pip-
|
|
||||||
|
|
||||||
# # this cache the platformio binaries and not the .pio folder
|
|
||||||
# - name: Cache PlatformIO
|
|
||||||
# uses: actions/cache@v3
|
|
||||||
# with:
|
|
||||||
# path: ~/.platformio
|
|
||||||
# key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
|
|
||||||
|
|
||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
uses: https://github.com/actions/setup-python@v3
|
uses: actions/setup-python@v3
|
||||||
|
|
||||||
- name: Install PlatformIO
|
- name: Install PlatformIO
|
||||||
run: pip install platformio
|
run: pip install platformio
|
||||||
|
12
config.ini
12
config.ini
@ -22,7 +22,8 @@ build_flags =
|
|||||||
-D STEPER_ACC=200
|
-D STEPER_ACC=200
|
||||||
;-D STEPER_PAS=755.906 ; = 65mm
|
;-D STEPER_PAS=755.906 ; = 65mm
|
||||||
-D STEPER_PAS=58 ; = 5mm
|
-D STEPER_PAS=58 ; = 5mm
|
||||||
-D STEPER_SPEED=1000 ; 12000
|
-D STEPER_SPEED=2000 ;1000 ; 2500
|
||||||
|
-D GRBL_UPDATE=165 ;update time in ms
|
||||||
;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;;; App config ;;;
|
;;; App config ;;;
|
||||||
;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;
|
||||||
@ -33,7 +34,10 @@ build_flags =
|
|||||||
;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;;; Servo config ;;;
|
;;; Servo config ;;;
|
||||||
;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;
|
||||||
-D RIGHT_POS=18
|
-D RIGHT_POS=14 ;18
|
||||||
-D MIDDLE_POS=32
|
-D MIDDLE_POS=30 ;32
|
||||||
-D LEFT_POS=52
|
-D LEFT_POS=52
|
||||||
-D CONVOYER_LEN=100
|
|
||||||
|
|
||||||
|
|
||||||
|
-D CONVOYER_LEN=70 ; 80 ;mm
|
||||||
|
23
docs/Schématics/Algo.puml
Normal file
23
docs/Schématics/Algo.puml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
@startuml algo
|
||||||
|
|
||||||
|
!pragma useVerticalIf on
|
||||||
|
|
||||||
|
start
|
||||||
|
|
||||||
|
:teste périphérique;
|
||||||
|
|
||||||
|
:gestion bourrage colis;
|
||||||
|
|
||||||
|
if (NFC détecter) then (oui)
|
||||||
|
:j'affiche le tag lu;
|
||||||
|
:je récupère le produit sur Dolibarr;
|
||||||
|
:gestion erreur;
|
||||||
|
:je crée un mouvement de stock Dolibarr;
|
||||||
|
:gestion erreur;
|
||||||
|
:je bouge l'aiguillage de destination;
|
||||||
|
:j'avance de la longueur du tapis;
|
||||||
|
else (non)
|
||||||
|
:avance tapis;
|
||||||
|
endif
|
||||||
|
stop
|
||||||
|
@enduml
|
@ -8,18 +8,6 @@ class Dolibarr {
|
|||||||
+ String createStockMovement(String tagID, String warehouseId)
|
+ String createStockMovement(String tagID, String warehouseId)
|
||||||
}
|
}
|
||||||
|
|
||||||
package "Managers" {
|
|
||||||
abstract AManager {
|
|
||||||
# ILCDScreen lcd
|
|
||||||
# IServoMotor servo
|
|
||||||
# IGRBL grbl
|
|
||||||
# INFCReader nfc
|
|
||||||
}
|
|
||||||
|
|
||||||
class WarehouseManager
|
|
||||||
|
|
||||||
WarehouseManager .|> AManager
|
|
||||||
}
|
|
||||||
|
|
||||||
package "Components" {
|
package "Components" {
|
||||||
package "NFCReader" {
|
package "NFCReader" {
|
||||||
@ -66,12 +54,11 @@ class Program {
|
|||||||
+ void loop
|
+ void loop
|
||||||
}
|
}
|
||||||
|
|
||||||
AManager <-- IServoMotor
|
Program <-- IServoMotor
|
||||||
AManager <-- IGRBL
|
Program <-- IGRBL
|
||||||
AManager <-- ILCDScreen
|
Program <-- ILCDScreen
|
||||||
AManager <-- INFCReader
|
Program <-- INFCReader
|
||||||
|
|
||||||
Program <-- WarehouseManager
|
Dolibarr --> Program
|
||||||
Program <-- Dolibarr
|
|
||||||
|
|
||||||
@enduml
|
@enduml
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
#ifndef PROGRAM_H
|
#ifndef PROGRAM_H
|
||||||
#define PROGRAM_H
|
#define PROGRAM_H
|
||||||
|
|
||||||
#include "Arduino.h"
|
|
||||||
#include "DolibarrClient.h"
|
#include "DolibarrClient.h"
|
||||||
#include <M5Stack.h>
|
#include <M5Stack.h>
|
||||||
#include "ServoMotorComponent.h"
|
#include "ServoMotorComponent.h"
|
||||||
#include "NfcReader.h"
|
#include "NfcReader.h"
|
||||||
#include "GRBL.h"
|
#include "GRBL.h"
|
||||||
|
#include "BigNfcReader.h"
|
||||||
|
|
||||||
class Program {
|
class Program {
|
||||||
public:
|
public:
|
||||||
@ -22,11 +22,14 @@ public:
|
|||||||
void checkNfc();
|
void checkNfc();
|
||||||
void checkServo();
|
void checkServo();
|
||||||
void checkWifi();
|
void checkWifi();
|
||||||
|
void moveStepper();
|
||||||
private:
|
private:
|
||||||
DolibarrClient *client;
|
DolibarrClient *client;
|
||||||
ServoMotorComponent *servo;
|
ServoMotorComponent *servo;
|
||||||
NfcReader *nfcReader;
|
NfcReader *nfcReader;
|
||||||
GRBL *grbl;
|
GRBL *grbl;
|
||||||
|
BigNfcReader* outputReader;
|
||||||
|
int grblUpdateTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "M5LCD.h"
|
#include "M5LCD.h"
|
||||||
|
|
||||||
|
HTTPClient *client = new HTTPClient();
|
||||||
|
|
||||||
DolibarrClient::DolibarrClient(struct DolibarrConfig dolibarr_config) : dolibarr(dolibarr_config) {
|
DolibarrClient::DolibarrClient(struct DolibarrConfig dolibarr_config) : dolibarr(dolibarr_config) {
|
||||||
#if defined(DEBUG)
|
#if defined(DEBUG)
|
||||||
Serial.println(" --- Dolibarr configuration --- ");
|
Serial.println(" --- Dolibarr configuration --- ");
|
||||||
@ -14,7 +16,6 @@ DolibarrClient::DolibarrClient(struct DolibarrConfig dolibarr_config) : dolibarr
|
|||||||
}
|
}
|
||||||
|
|
||||||
HTTPClient *DolibarrClient::build_url(const String& url) const {
|
HTTPClient *DolibarrClient::build_url(const String& url) const {
|
||||||
auto *client = new HTTPClient();
|
|
||||||
String clientUrl = this->dolibarr.url + url;
|
String clientUrl = this->dolibarr.url + url;
|
||||||
client->begin(clientUrl);
|
client->begin(clientUrl);
|
||||||
client->addHeader("Content-Type", "application/json");
|
client->addHeader("Content-Type", "application/json");
|
||||||
@ -25,40 +26,12 @@ HTTPClient *DolibarrClient::build_url(const String& url) const {
|
|||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int DolibarrClient::login() const {
|
|
||||||
HTTPClient *client = this->build_url(API_LOGIN_URL);
|
|
||||||
int httpResponseCode = client->GET();
|
|
||||||
if (httpResponseCode > 0) {
|
|
||||||
DynamicJsonDocument doc(384);
|
|
||||||
DeserializationError error = deserializeJson(doc, client->getString().c_str());
|
|
||||||
if (error) {
|
|
||||||
Serial.println("ERROR: ");
|
|
||||||
Serial.println(error.c_str());
|
|
||||||
delete client;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
delete client;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
delete client;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
String replace_id(const char *str, const char *id) {
|
String replace_id(const char *str, const char *id) {
|
||||||
String url(str);
|
String url(str);
|
||||||
url.replace("{id}", id);
|
url.replace("{id}", id);
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<models::Product> *DolibarrClient::list_products() const {
|
|
||||||
HTTPClient *client = this->build_url(API_LIST_PRODUCT_URL);
|
|
||||||
if (client->GET() == HTTP_CODE_OK) {
|
|
||||||
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
models::Product DolibarrClient::get_product_by_factory_id(const char* factory_id) const {
|
models::Product DolibarrClient::get_product_by_factory_id(const char* factory_id) const {
|
||||||
HTTPClient *client = this->build_url(replace_id("/products?sortorder=ASC&limit=1&sqlfilters=(t.accountancy_code_sell:like:'{id}')", factory_id).c_str());
|
HTTPClient *client = this->build_url(replace_id("/products?sortorder=ASC&limit=1&sqlfilters=(t.accountancy_code_sell:like:'{id}')", factory_id).c_str());
|
||||||
if (client->GET() == HTTP_CODE_OK) {
|
if (client->GET() == HTTP_CODE_OK) {
|
||||||
@ -67,7 +40,6 @@ models::Product DolibarrClient::get_product_by_factory_id(const char* factory_id
|
|||||||
if (error) {
|
if (error) {
|
||||||
Serial.println("ERROR: ");
|
Serial.println("ERROR: ");
|
||||||
Serial.println(error.c_str());
|
Serial.println(error.c_str());
|
||||||
delete client;
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
for (auto obj : doc.as<JsonArray>()) {
|
for (auto obj : doc.as<JsonArray>()) {
|
||||||
@ -80,13 +52,10 @@ models::Product DolibarrClient::get_product_by_factory_id(const char* factory_id
|
|||||||
product.accountancy_code_sell = obj["accountancy_code_sell"].as<std::string>();
|
product.accountancy_code_sell = obj["accountancy_code_sell"].as<std::string>();
|
||||||
product.accountancy_code_sell_export = obj["accountancy_code_sell_export"].as<std::string>();
|
product.accountancy_code_sell_export = obj["accountancy_code_sell_export"].as<std::string>();
|
||||||
product.fk_default_warehouse = obj["fk_default_warehouse"].as<std::string>();
|
product.fk_default_warehouse = obj["fk_default_warehouse"].as<std::string>();
|
||||||
delete client;
|
|
||||||
return product;
|
return product;
|
||||||
}
|
}
|
||||||
delete client;
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
delete client;
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +65,6 @@ models::Product *DolibarrClient::get_product_by_id(const char* id_product) const
|
|||||||
DynamicJsonDocument doc(6144);
|
DynamicJsonDocument doc(6144);
|
||||||
DeserializationError error = deserializeJson(doc, client->getString().c_str());
|
DeserializationError error = deserializeJson(doc, client->getString().c_str());
|
||||||
if (error) {
|
if (error) {
|
||||||
delete client;
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
auto *product = new models::Product();
|
auto *product = new models::Product();
|
||||||
@ -107,10 +75,8 @@ models::Product *DolibarrClient::get_product_by_id(const char* id_product) const
|
|||||||
product->label = doc["label"].as<std::string>();
|
product->label = doc["label"].as<std::string>();
|
||||||
product->accountancy_code_sell = doc["accountancy_code_sell"].as<std::string>();
|
product->accountancy_code_sell = doc["accountancy_code_sell"].as<std::string>();
|
||||||
product->accountancy_code_sell_export = doc["accountancy_code_sell_export"].as<std::string>();
|
product->accountancy_code_sell_export = doc["accountancy_code_sell_export"].as<std::string>();
|
||||||
delete client;
|
|
||||||
return product;
|
return product;
|
||||||
}
|
}
|
||||||
delete client;
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,7 +88,6 @@ std::vector<models::Warehouse> *DolibarrClient::list_warehouse() const {
|
|||||||
if (error) {
|
if (error) {
|
||||||
Serial.println("ERROR: ");
|
Serial.println("ERROR: ");
|
||||||
Serial.println(error.c_str());
|
Serial.println(error.c_str());
|
||||||
delete client;
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
auto *warehouses = new std::vector<models::Warehouse>();
|
auto *warehouses = new std::vector<models::Warehouse>();
|
||||||
@ -132,10 +97,8 @@ std::vector<models::Warehouse> *DolibarrClient::list_warehouse() const {
|
|||||||
warehouse.label = obj["label"].as<std::string>();
|
warehouse.label = obj["label"].as<std::string>();
|
||||||
warehouses->push_back(warehouse);
|
warehouses->push_back(warehouse);
|
||||||
}
|
}
|
||||||
delete client;
|
|
||||||
return warehouses;
|
return warehouses;
|
||||||
}
|
}
|
||||||
delete client;
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,7 +114,6 @@ int DolibarrClient::create_movement(models::CreateProductStock stock) const {
|
|||||||
serializeJson(doc, result);
|
serializeJson(doc, result);
|
||||||
Serial.println(result.c_str());
|
Serial.println(result.c_str());
|
||||||
if (client->POST(result.c_str()) == HTTP_CODE_OK) {
|
if (client->POST(result.c_str()) == HTTP_CODE_OK) {
|
||||||
delete client;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -20,9 +20,7 @@ class DolibarrClient {
|
|||||||
public:
|
public:
|
||||||
DolibarrClient(DolibarrConfig dolibarr_config);
|
DolibarrClient(DolibarrConfig dolibarr_config);
|
||||||
~DolibarrClient() = default;
|
~DolibarrClient() = default;
|
||||||
int login() const;
|
|
||||||
std::vector<models::Warehouse> *list_warehouse() const;
|
std::vector<models::Warehouse> *list_warehouse() const;
|
||||||
std::vector<models::Product> *list_products() const;
|
|
||||||
models::Product *get_product_by_id(const char* id_product) const;
|
models::Product *get_product_by_id(const char* id_product) const;
|
||||||
models::Product get_product_by_factory_id(const char* uuid) const;
|
models::Product get_product_by_factory_id(const char* uuid) const;
|
||||||
int create_movement(models::CreateProductStock stock) const;
|
int create_movement(models::CreateProductStock stock) const;
|
||||||
|
@ -8,6 +8,7 @@ class iGRBL{
|
|||||||
public:
|
public:
|
||||||
virtual void init(int speed, double pas, int accel, String mode = "distance") = 0;
|
virtual void init(int speed, double pas, int accel, String mode = "distance") = 0;
|
||||||
virtual void mouveForward(int mm) = 0;
|
virtual void mouveForward(int mm) = 0;
|
||||||
|
virtual bool isIddle() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GRBL : public iGRBL{
|
class GRBL : public iGRBL{
|
||||||
@ -15,6 +16,7 @@ public:
|
|||||||
GRBL(int grblAddr);
|
GRBL(int grblAddr);
|
||||||
void init(int speed, double pas, int accel, String mode = "distance") override;
|
void init(int speed, double pas, int accel, String mode = "distance") override;
|
||||||
void mouveForward(int mm = 5) override;
|
void mouveForward(int mm = 5) override;
|
||||||
|
bool isIddle() override;
|
||||||
private:
|
private:
|
||||||
Module_GRBL* grbl;
|
Module_GRBL* grbl;
|
||||||
};
|
};
|
||||||
|
@ -32,3 +32,13 @@ void GRBL::mouveForward(int mm){
|
|||||||
sprintf(s, "G1 X%d", mm);
|
sprintf(s, "G1 X%d", mm);
|
||||||
this->grbl->sendGcode(s);
|
this->grbl->sendGcode(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GRBL::isIddle(){
|
||||||
|
bool sortie = false;
|
||||||
|
|
||||||
|
if(this->grbl->readStatus().indexOf("IDLE") != -1) {
|
||||||
|
sortie = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return sortie;
|
||||||
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* M5LCD classe
|
* M5LCD classe
|
||||||
*/
|
*/
|
||||||
|
|
||||||
M5LCD::M5LCD() : _current_page(0), _logs() , _debug_loc_y(0), _components_status({COMPONENT_KO, COMPONENT_KO, COMPONENT_KO, COMPONENT_KO, COMPONENT_KO}) {
|
M5LCD::M5LCD() : _current_page(0), _logs() , _debug_loc_y(0), _components_status({COMPONENT_KO, COMPONENT_KO, COMPONENT_KO, COMPONENT_KO, COMPONENT_OK}) {
|
||||||
this->_product_id = std::string("");
|
this->_product_id = std::string("");
|
||||||
this->_product_label = std::string("");
|
this->_product_label = std::string("");
|
||||||
this->_last_nfc = std::string("");
|
this->_last_nfc = std::string("");
|
||||||
@ -173,6 +173,7 @@ void M5LCD::set_dolibarr_status(AvailableComponentsStatus status) {
|
|||||||
|
|
||||||
void M5LCD::update_dashboard() const {
|
void M5LCD::update_dashboard() const {
|
||||||
if (this->_current_page == DASHBOARD_SCREEN) {
|
if (this->_current_page == DASHBOARD_SCREEN) {
|
||||||
|
M5.Lcd.clear();
|
||||||
this->show_dashboard();
|
this->show_dashboard();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,6 +60,7 @@ public:
|
|||||||
void set_product_label(std::string str);
|
void set_product_label(std::string str);
|
||||||
void set_product_id(std::string str);
|
void set_product_id(std::string str);
|
||||||
void set_servo_message(std::string str);
|
void set_servo_message(std::string str);
|
||||||
|
int _current_page;
|
||||||
private:
|
private:
|
||||||
void update_page() const;
|
void update_page() const;
|
||||||
void show_debug() const;
|
void show_debug() const;
|
||||||
@ -68,7 +69,6 @@ private:
|
|||||||
void update_pagination() const;
|
void update_pagination() const;
|
||||||
void update_dashboard() const;
|
void update_dashboard() const;
|
||||||
|
|
||||||
int _current_page;
|
|
||||||
int _debug_loc_y;
|
int _debug_loc_y;
|
||||||
std::vector<LogMessage> _logs;
|
std::vector<LogMessage> _logs;
|
||||||
ComponentsStatus _components_status;
|
ComponentsStatus _components_status;
|
||||||
|
@ -11,14 +11,14 @@ String NfcReader::ReadNfc()
|
|||||||
this->uid.clear();
|
this->uid.clear();
|
||||||
if (!this->mfrc522->PICC_IsNewCardPresent() ||
|
if (!this->mfrc522->PICC_IsNewCardPresent() ||
|
||||||
!this->mfrc522->PICC_ReadCardSerial()) {
|
!this->mfrc522->PICC_ReadCardSerial()) {
|
||||||
return ("0");
|
return "0";
|
||||||
}
|
}
|
||||||
for (unsigned int i = 0; i < this->mfrc522->uid.size; i++) {
|
for (unsigned int i = 0; i < this->mfrc522->uid.size; i++) {
|
||||||
if (this->mfrc522->uid.uidByte[i] < 0xF) {
|
if (this->mfrc522->uid.uidByte[i] < 0xF) {
|
||||||
this->uid += '0';
|
this->uid += '0';
|
||||||
this->uid += String(this->mfrc522->uid.uidByte[i], HEX);
|
this->uid += String(this->mfrc522->uid.uidByte[i], HEX);
|
||||||
} else {
|
} else {
|
||||||
this->uid += String(this->mfrc522->uid.uidByte[i], HEX);
|
this->uid += String(this->mfrc522->uid.uidByte[i], HEX);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (this->uid);
|
return (this->uid);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef NFCREADER_HPP_
|
#ifndef NFCREADER_H
|
||||||
#define NFCREADER_HPP_
|
#define NFCREADER_H
|
||||||
|
|
||||||
#include <M5Stack.h>
|
#include <M5Stack.h>
|
||||||
#include "MFRC522_I2C.h"
|
#include "MFRC522_I2C.h"
|
||||||
@ -19,4 +19,4 @@ class NfcReader {
|
|||||||
String uid;
|
String uid;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* !NFCREADER_HPP_ */
|
#endif /* !NFCREADER_H */
|
||||||
|
67
lib/NfcReader/include/BigNfcReader.h
Normal file
67
lib/NfcReader/include/BigNfcReader.h
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
#ifndef BIG_NFC_READER_H
|
||||||
|
#define BIG_NFC_READER_H
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "TrameList.h"
|
||||||
|
|
||||||
|
class BigNfcReader{
|
||||||
|
public:
|
||||||
|
BigNfcReader();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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/NfcReader/include/TrameList.h
Normal file
29
lib/NfcReader/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
|
75
lib/NfcReader/src/BigNfcReader.cpp
Normal file
75
lib/NfcReader/src/BigNfcReader.cpp
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
#include "../include/BigNfcReader.h"
|
||||||
|
|
||||||
|
|
||||||
|
BigNfcReader::BigNfcReader(){
|
||||||
|
Serial2.begin(115200, SERIAL_8N1, 16, 17);//TODO: mettre le port série en paramètre
|
||||||
|
this->pair = true;
|
||||||
|
this->trame = new std::vector<byte>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool BigNfcReader::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 BigNfcReader::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 BigNfcReader::digitify(int number){
|
||||||
|
String sortie = "";
|
||||||
|
|
||||||
|
if(number <= 0xF){
|
||||||
|
sortie += '0';
|
||||||
|
sortie += String(number,HEX);
|
||||||
|
}else{
|
||||||
|
sortie += String(number,HEX);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sortie;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void BigNfcReader::printTrame(){
|
||||||
|
for(byte i: *this->trame){
|
||||||
|
Serial.print(this->digitify(i));
|
||||||
|
Serial.print(" ");
|
||||||
|
}
|
||||||
|
Serial.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
int BigNfcReader::getNbTags(){
|
||||||
|
return this->trame->at(8);
|
||||||
|
}
|
@ -77,8 +77,13 @@ Program::Program() {
|
|||||||
lcdScreen = new M5LCD();
|
lcdScreen = new M5LCD();
|
||||||
lcdScreen->add_log("Initialize M5LCD component....");
|
lcdScreen->add_log("Initialize M5LCD component....");
|
||||||
this->nfcReader = new NfcReader(NFC_ADDR);
|
this->nfcReader = new NfcReader(NFC_ADDR);
|
||||||
this->servo = new ServoMotorComponent(2, 1, 1);
|
this->servo = new ServoMotorComponent(2, 1, 1.5);
|
||||||
|
this->servo->setDesiredPosition(Position::MIDDLE);
|
||||||
this->grbl = new GRBL(STEPMOTOR_I2C_ADDR);
|
this->grbl = new GRBL(STEPMOTOR_I2C_ADDR);
|
||||||
|
this->outputReader = new BigNfcReader();
|
||||||
|
this->outputReader->init();
|
||||||
|
this->grblUpdateTime = 0;
|
||||||
|
lcdScreen->set_grbl_status(COMPONENT_OK);
|
||||||
Wire.begin(21, 22);
|
Wire.begin(21, 22);
|
||||||
grbl->init(STEPER_SPEED, STEPER_PAS, STEPER_ACC);
|
grbl->init(STEPER_SPEED, STEPER_PAS, STEPER_ACC);
|
||||||
struct WifiConfig wifi_c = {WIFI_SSID, WIFI_PASSWORD};
|
struct WifiConfig wifi_c = {WIFI_SSID, WIFI_PASSWORD};
|
||||||
@ -96,6 +101,13 @@ void Program::loop() {
|
|||||||
derniereExecution = maintenant;
|
derniereExecution = maintenant;
|
||||||
}
|
}
|
||||||
this->servo->refresh();
|
this->servo->refresh();
|
||||||
|
this->outputReader->refresh();
|
||||||
|
// Serial.println(this->outputReader->getNbTags());
|
||||||
|
|
||||||
|
if(this->outputReader->getNbTags() >= 2){
|
||||||
|
lcdScreen->set_nfc_message("To mutch colis number detected");
|
||||||
|
lcdScreen->set_grbl_status(COMPONENT_KO);
|
||||||
|
}
|
||||||
|
|
||||||
String nfcId = this->nfcReader->ReadNfc();
|
String nfcId = this->nfcReader->ReadNfc();
|
||||||
//si qqc
|
//si qqc
|
||||||
@ -152,9 +164,12 @@ void Program::loop() {
|
|||||||
}
|
}
|
||||||
this->grbl->mouveForward(CONVOYER_LEN);
|
this->grbl->mouveForward(CONVOYER_LEN);
|
||||||
} else {
|
} else {
|
||||||
//si rien
|
if((this->grbl->isIddle()) && lcdScreen->get_components().grbl == COMPONENT_OK){
|
||||||
//je check si le stepper est en iddle
|
//this->grblUpdateTime = maintenant;
|
||||||
//this->grbl->mouveForward(5);
|
this->grbl->mouveForward(5);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if(M5.BtnC.wasReleased() != 0 && lcdScreen->_current_page == DASHBOARD_SCREEN){
|
||||||
}
|
lcdScreen->set_grbl_status(COMPONENT_OK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user