Merge remote-tracking branch 'origin/develop' into develop

# Conflicts:
#	config.ini
#	src/Program.cpp
This commit is contained in:
Nicolas SANS 2024-02-09 08:32:54 +01:00
commit adc6134d8b
7 changed files with 219 additions and 25 deletions

View File

@ -15,26 +15,29 @@ build_flags =
; DO NOT TOUCH --- END ; DO NOT TOUCH --- END
-D WAITING_WIFI_DELAY=1000 -D WAITING_WIFI_DELAY=1000
-D TIMEZONE=\"Europe/Paris\" -D TIMEZONE=\"Europe/Paris\"
;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;
;;; stepper config ;;; ;;; stepper config ;;;
;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;
-D STEPMOTOR_I2C_ADDR=0x70 -D STEPMOTOR_I2C_ADDR=0x70
-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=2700 ;1000 ; 2500 -D STEPER_SPEED=2700 ;1000 ; 2500
;;;;;;;;;;;;;;;;;;;;;; -D GRBL_UPDATE=165 ;update time in ms
;;; App config ;;; ;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;; ;;; App config ;;;
;;;;;;;;;;;;;;;;;;;;;;
-D APP_TITLE=\"Warehouse\" -D APP_TITLE=\"Warehouse\"
-D APP_VERSION=\"1.0\" -D APP_VERSION=\"1.0\"
; nfc addr ; nfc addr
-D NFC_ADDR=0x28 -D NFC_ADDR=0x28
;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;
;;; Servo config ;;; ;;; Servo config ;;;
;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;
-D RIGHT_POS=14 ;18 -D RIGHT_POS=14 ;18
-D MIDDLE_POS=30 ;32 -D MIDDLE_POS=30 ;32
-D LEFT_POS=52 -D LEFT_POS=52
-D CONVOYER_LEN=80 ;mm
-D CONVOYER_LEN=80 ;mm

View File

@ -6,6 +6,7 @@
#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:
@ -27,6 +28,8 @@ private:
ServoMotorComponent *servo; ServoMotorComponent *servo;
NfcReader *nfcReader; NfcReader *nfcReader;
GRBL *grbl; GRBL *grbl;
BigNfcReader* outputReader;
int grblUpdateTime;
}; };
#endif #endif

View File

@ -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;

View 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

View 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

View 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);
}

View File

@ -6,8 +6,6 @@
#include "NfcReader.h" #include "NfcReader.h"
#include <Ticker.h> #include <Ticker.h>
TaskHandle_t task1;
uint32_t derniereExecution = 0; uint32_t derniereExecution = 0;
const uint32_t intervalle = 1000; const uint32_t intervalle = 1000;
std::vector<models::Warehouse> *warehouses; std::vector<models::Warehouse> *warehouses;
@ -80,19 +78,18 @@ Program::Program() {
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);
this->servo->setDesiredPosition(MIDDLE); 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};
initialize_wifi(wifi_c); initialize_wifi(wifi_c);
} }
void Program::moveStepper() {
Serial.printf("moveStepper\n");
this->grbl->mouveForward(5);
}
void Program::loop() { void Program::loop() {
lcdScreen->update(); lcdScreen->update();
@ -104,13 +101,25 @@ 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
if(nfcId != "0"){ if(nfcId != "0"){
if (lcdScreen->get_components().wifi != COMPONENT_OK) { if (lcdScreen->get_components().wifi != COMPONENT_OK) {
lcdScreen->add_log("Wifi not connected !"); lcdScreen->add_log("Wifi not connected !");
lcdScreen->set_nfc_message("Cannot send wifi request !"); lcdScreen->set_nfc_message("Cannot send wifi request !");
return; return;
} }
//j'arrète le stepper
//this->grbl->stop(); //FIXME: implemente
//j'affiche le tag lue
Serial.print("new colis in comming : "); Serial.print("new colis in comming : ");
lcdScreen->add_log("new colis detected: "); lcdScreen->add_log("new colis detected: ");
lcdScreen->add_log(nfcId.c_str()); lcdScreen->add_log(nfcId.c_str());
@ -119,6 +128,10 @@ void Program::loop() {
Serial.printf("Product: %s\n%s", product.label.c_str(), product.accountancy_code_sell_export.c_str()); Serial.printf("Product: %s\n%s", product.label.c_str(), product.accountancy_code_sell_export.c_str());
lcdScreen->set_product_label(product.label); lcdScreen->set_product_label(product.label);
lcdScreen->set_product_id(product.id); lcdScreen->set_product_id(product.id);
/*if (product.fk_default_warehouse == product.accountancy_code_sell_export) {
Serial.printf("Product already in the good warehouse !\n");
return;
}*/
auto ware = std::find_if(warehouses->begin(), warehouses->end(), [&product](models::Warehouse w) {return w.id == product.accountancy_code_sell_export;}); auto ware = std::find_if(warehouses->begin(), warehouses->end(), [&product](models::Warehouse w) {return w.id == product.accountancy_code_sell_export;});
if (ware.base() == nullptr) { if (ware.base() == nullptr) {
Serial.printf("Warehouse not found !\n"); Serial.printf("Warehouse not found !\n");
@ -149,10 +162,14 @@ void Program::loop() {
this->servo->setDesiredPosition(Position::MIDDLE); this->servo->setDesiredPosition(Position::MIDDLE);
lcdScreen->set_servo_message("MIDDLE"); lcdScreen->set_servo_message("MIDDLE");
} }
//this->grbl->mouveForward(CONVOYER_LEN); this->grbl->mouveForward(CONVOYER_LEN);
} else { } else {
/*if(this->grbl->isIddle()){ if((this->grbl->isIddle() || (maintenant - this->grblUpdateTime >= GRBL_UPDATE)) && lcdScreen->get_components().grbl == COMPONENT_OK){
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);
}
}