Dans l'idée de base non, ce serais des objets séparé.
le .h devrais resembler à ceci:
#ifndef _NAME_H
#define _NAME_H
class slave1 {
public:
// Constructeur
slave1(int valA);
private:
int _valA;
};
class slave2 {
public:
// Constructeur
slave2(int valB);
private:
int _valB;
};
class master {
protected:
slave1 _sousClassA;
slave2 _sousClassB;
public:
// Constructeur
master(int valeurA, int valeurB);
private:
bool pasDeSousClassA = false;
bool pasDeSousClassB = false;
};
#endif
Après réflexion, je trouve que de mettre les class slave dans la class master serais mieux pour mon projet, mais ça fais pas mal de code à modifier. Pourrai-je le faire par pointeurs ?
Et j'aimerais quand même savoir si mon idée de base est réalisable ?
Si ça peut aider, je veux bien mettre le code de mon projet dans son état actuel, mais c'est très brouillon et j'y vais à taton, c'est sûrement plein d'erreurs.
.ino
#define NBR_LEDS_LIGHTBAR 48
#define NBR_LEDS_SECTIONS_MAX 16
// #define BLUETOOTH_DEBUG /*Includ le port bluetooth AOG_DEBUG_L-Bar pour le débugage*/
#if NBR_LEDS_LIGHTBAR > 0
#define PIXEL_START_LIGHT_BAR 10
#define PIN_LIGHT_BAR 4
// Option:
#define Auto_Day_Night
#endif
#if NBR_LEDS_SECTIONS_MAX > 0
#define NBR_LEDS_SECTIONS_MAX 10
#define PIN_SECTIONS_BAR 5
#if defined(PIN_LIGHT_BAR) && PIN_LIGHT_BAR != PIN_SECTIONS_BAR
// Option:
#define Auto_Day_Night_Scet_bar
#endif
#endif
////////////////// Librairie déclaration ////////////////////
#ifdef BLUETOOTH_DEBUG
#include <BluetoothSerial.h>
BluetoothSerial SerialBT;
#endif
#if NBR_LEDS_LIGHTBAR > 0 || NBR_LEDS_SECTION_MAX > 0
#include <Adafruit_NeoPixel.h>
#include "AOG_NeoPixel.h"
#include "AOG_NeoPixelsColors.h"
AOG_NeoPixelsColors AOG_RGB;
#if defined(PIN_LIGHT_BAR) && PIN_LIGHT_BAR >= 0
#if defined(PIN_SECTIONS_BAR) && PIN_SECTIONS_BAR >= 0
#if PIN_LIGHT_BAR != PIN_SECTIONS_BAR
#define SEND_PIXELS_TYPE 4 // light-bar et sections-bar sur un ruban-neopixels différent
//Adafruit_NeoPixel AOG_Pixels = Adafruit_NeoPixel(NBR_LEDS_LIGHTBAR + PIXEL_START_LIGHT_BAR, PIN_LIGHT_BAR, NEO_GRB + NEO_KHZ800);
//Adafruit_NeoPixel AOG_2_Pixels = Adafruit_NeoPixel(NBR_LEDS_SECTIONS_MAX + NBR_LEDS_SECTIONS_MAX, PIN_SECTIONS_BAR, NEO_GRB + NEO_KHZ800);
//AOG_Light_bar lightBar = AOG_Light_bar(NBR_LEDS_LIGHTBAR, PIXEL_START_LIGHT_BAR, 0, 0, AOG_RGB, AOG_Pixels);
//AOG_Light_bar lightBar2 = AOG_Light_bar(0, 0, NBR_LEDS_SECTIONS_MAX, NBR_LEDS_SECTIONS_MAX, AOG_RGB, AOG_2_Pixels);
/* - Ancien constructeur - */
Adafruit_NeoPixel AOG_2_Pixels = Adafruit_NeoPixel(NBR_LEDS_SECTIONS_MAX + NBR_LEDS_SECTIONS_MAX, PIN_SECTIONS_BAR, NEO_GRB + NEO_KHZ800);
AOG_Light_bar lightBar2 = AOG_Light_bar(NBR_LEDS_SECTIONS_MAX, NBR_LEDS_SECTIONS_MAX, AOG_RGB, AOG_2_Pixels);
#else
#define SEND_PIXELS_TYPE 3 // light-bar et sections-bar sur le même ruban-neopixels
//Adafruit_NeoPixel AOG_Pixels = Adafruit_NeoPixel(max(NBR_LEDS_LIGHTBAR + PIXEL_START_LIGHT_BAR, NBR_LEDS_SECTIONS_MAX + NBR_LEDS_SECTIONS_MAX), PIN_LIGHT_BAR, NEO_GRB + NEO_KHZ800);
//AOG_Light_bar lightBar = AOG_Light_bar(NBR_LEDS_LIGHTBAR, PIXEL_START_LIGHT_BAR, NBR_LEDS_SECTIONS_MAX, NBR_LEDS_SECTIONS_MAX, AOG_RGB, AOG_Pixels);
#endif
#else
#define SEND_PIXELS_TYPE 1 // seulement light-bar
//Adafruit_NeoPixel AOG_Pixels = Adafruit_NeoPixel(NBR_LEDS_LIGHTBAR + PIXEL_START_LIGHT_BAR, PIN_LIGHT_BAR, NEO_GRB + NEO_KHZ800);
//AOG_Light_bar lightBar = AOG_Light_bar(NBR_LEDS_LIGHTBAR, PIXEL_START_LIGHT_BAR, 0, 0, AOG_RGB, AOG_Pixels);
#endif
#elif defined(PIN_SECTIONS_BAR) && PIN_SECTIONS_BAR >= 0
#define SEND_PIXELS_TYPE 2 // seulement sections-bar
//Adafruit_NeoPixel AOG_2_Pixels = Adafruit_NeoPixel(NBR_LEDS_SECTIONS_MAX + NBR_LEDS_SECTIONS_MAX, PIN_SECTIONS_BAR, NEO_GRB + NEO_KHZ800);
//AOG_Light_bar lightBar2 = AOG_Light_bar(0, 0, NBR_LEDS_SECTIONS_MAX, NBR_LEDS_SECTIONS_MAX, AOG_RGB, AOG_2_Pixels);
#endif
/* - Ancien constructeur - */
Adafruit_NeoPixel AOG_Pixels = Adafruit_NeoPixel(NBR_LEDS_LIGHTBAR + PIXEL_START_LIGHT_BAR, PIN_LIGHT_BAR, NEO_GRB + NEO_KHZ800);
AOG_Light_bar lightBar = AOG_Light_bar(NBR_LEDS_LIGHTBAR, PIXEL_START_LIGHT_BAR, AOG_RGB, AOG_Pixels);
#else
#define SEND_PIXELS_TYPE 0
#endif
/* ==> exemple d'utilisation de [pixelsSendType] :
* #if (pixelsSendType == 1 || pixelsSendType == 3 || pixelsSendType == 4) AOG_Light_bar.Refrech();
* #if (pixelsSendType == 2 || pixelsSendType == 4) AOG_2_Light_bar.Refrech();
*/
////////////// END Librairie déclaration ////////////////////
////// light-bar variables //////////
uint8_t nLbRefrech = 0;
uint8_t helloAgIO[] = {0x80,0x81, 0x7f, 0xC7, 1, 0, 0x47 };
// END light-bar variables //////////
////// AOG variables ////////////////
//Comm checks
uint32_t currentTime = millis();
uint32_t lastTime = millis();
uint8_t watchdogTimer = 0; //make sure we are talking to AOG
uint8_t serialResetTimer = 0; //if serial buffer is getting full, empty it
//Parsing PGN
bool isPGNFound = false, isHeaderFound = false;
uint8_t pgn = 0, dataLength = 0, idx = 0;
int16_t tempHeader = 0;
//uint8_t AOG_ED[] = { 0x80, 0x81, 0x7f, 0xED, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0xCC };
// END AOG variables ////////////////
void setup() {
Serial.begin(38400);
#ifdef BLUETOOTH_DEBUG
SerialBT.begin("AOG_DEBUG_L-Bar"); //Bluetooth device name
#endif
#if NBR_LEDS_LIGHTBAR > 0
/*Réglage optionnels*/
lightBar.SetLightBarMode(1); // default 0 <Actuelement de 0 à 1> ==> Mode d'affichage: 0) standardt || 1) un quart de point
lightBar.SetCmParPixel(10); // default: 8 ==> cm par *point afficher. *[en mode 1, les trois premier points sont des quarts de point]
// lightBar.SetLightBarReverse(true); //default false ==> inverser le sens d'affichage des points
//lightBar.SetBrightness(60); // default 120 <min 20 / max 255> ==> luminosité des leds
//lightBar.SetBrightnessNight(100); // default 40% <min 10 / max 100> ==> luminosité des leds la nuit [ en % de SetBrightness]
//lightBar.SetIsDay(false); // default true ==> éclairage en mode jour
lightBar.SetNightNighting(true); // default false ==> point blanc aux extrémitée de la bar si "IsDay = false"
/* Info: AOG_Pixels.Color( R, G, B ) >> return: uint32_t >> fonction de la librerie: Adafruit_NeoPixel */
// AOG_RGB.lBar1 = (AOG_Pixels.Color(5,200,5)); // définire la couleur des point à droite (en mode 1 = quarts de point)
// AOG_RGB.lBar2 = (AOG_Pixels.Color(200,5,5)); // définire la couleur des point à gauche (en mode 1 = points entiers)
// AOG_RGB.lBarCentre = (AOG_Pixels.Color(100,100,5)); // définire la couleur du point central
#endif
} // END SETUP //////////////////////
void loop() {
currentTime = millis();
if (currentTime - lastTime >= nLbRefrech *29) { // Interval entre les rafraichissements de la ligth-bar
nLbRefrech++;
#if SEND_PIXELS_TYPE == 1 || SEND_PIXELS_TYPE == 3 || SEND_PIXELS_TYPE == 4
lightBar.Refrech();
#endif
#if SEND_PIXELS_TYPE == 2 || SEND_PIXELS_TYPE == 4
lightBar2.Refrech();
//test.print("Ne doit pas compiler");
#endif
//if (pixelsSendType == 2 || pixelsSendType == 4) AOG_2_Light_bar.Refrech();
// #if NBR_LEDS_LIGHTBAR > 0
// lightBar.Refrech();
// #endif
}
//Loop triggers every 200 msec and sends back gyro heading, and roll, steer angle etc
if (currentTime - lastTime >= 200) {
lastTime = currentTime;
nLbRefrech = 0;
if (watchdogTimer++ > 250) watchdogTimer = 13; // Pour éviter qu'il boucle et recommance à zéro // "watchdogTimer++" ajoute 1 à watchdogTimer
//clean out serial buffer to prevent buffer overflow
if (serialResetTimer++ > 20) {
while (Serial.available() > 0) Serial.read();
serialResetTimer = 0;
#if NBR_LEDS_LIGHTBAR > 0 //show life in AgIO --> copier depuis : Autosteer_USBv5_0
Serial.write(helloAgIO,sizeof(helloAgIO));
#endif
}
} //end of timed loop
// Serial Receive
//Do we have a match with 0x8081?
if (Serial.available() > 4 && !isHeaderFound && !isPGNFound) {
uint8_t temp = Serial.read();
if (tempHeader == 0x80 && temp == 0x81) {
isHeaderFound = true;
tempHeader = 0;
} else {
tempHeader = temp; //save for next time
return;
}
}
//Find Source, PGN, and Length
if (Serial.available() > 2 && isHeaderFound && !isPGNFound) {
Serial.read(); //The 7F or less
pgn = Serial.read();
dataLength = Serial.read();
isPGNFound = true;
}
//The data package
if (Serial.available() > dataLength && isHeaderFound && isPGNFound) {
// if (pgn == 239) { // EF Machine Data
// //reset watchdog
// watchdogTimer = 0;
// //Reset serial Watchdog
// serialResetTimer = 0;
// }
// else if (pgn == 238) //EE Machine Settings
// else if (pgn == 236) //EC Relay Pin Settings
// else if (pgn == 254) { // FE Machine
if (pgn == 247) { // Sections color
uint8_t tempSectByte[9];
for (int i = 0; i < 9; i++){
tempSectByte[i] = (Serial.read();
}
// ==>> envoyer tempSectByte : sectbar.colors(tempSectByte, sizeof(tempSectByte))
}
#if NBR_LEDS_LIGHTBAR > 0
//else if (pgn == 248) { } // F8 Light bar configue
else if (pgn == 249) { // F9 Light bar data
lightBar.distance((int16_t)(Serial.read() << 8 | Serial.read()));
#ifdef Auto_Day_Night
{ int8_t tempPhByte = Serial.read();
if (tempPhByte == 2) lightBar.SetIsDay(false);
else if (tempPhByte == 1) lightBar.SetIsDay(true);
//SerialBT.print("IsDay = ");SerialBT.println(lightBar.GetIsDay(true));
}
#else
Serial.read();
#endif
Serial.read(); // read: crc
} //END : (pgn == 249) F9 Light bar
#endif
//reset for next pgn sentence
isHeaderFound = isPGNFound = false;
pgn = dataLength = 0;
} // end Serial Receive
} // END LOOP ///////////////////////
================================================
AOG_NeoPixel.h
#ifndef AOG_NEOPIXEL_H
#define AOG_NEOPIXEL_H
//#define _Bluetooth_debug /*Ajout le reseau bluetooth _AOG_DEBUG_L-Bar pour le debugage*/
#include <stdint.h>
#include <Arduino.h>
#include <Adafruit_NeoPixel.h>
#include "AOG_NeoPixelsColors.h"
#ifdef _Bluetooth_debug
#include <BluetoothSerial.h>
BluetoothSerial _SerialBT;
// Plus utile : class BluetoothSerial; // Partage de class voir: https://forum.arduino.cc/t/inclure-liquidcrystal-dans-une-classe-perso/177782/5
#endif
class AOG_NeoPixelsColors;
class Adafruit_NeoPixel;
class AOG_Light_bar {
protected:
AOG_NeoPixelsColors& Z_AOG_RGB;
Adafruit_NeoPixel& Z_AdaPixels;
public: // Constructeur :
//AOG_Light_bar(AOG_NeoPixelsColors& AOG_RGB, Adafruit_NeoPixel& AdaPixels);
AOG_Light_bar(uint8_t nbrPixels, uint16_t ignoreStartPixel, AOG_NeoPixelsColors& AOG_RGB, Adafruit_NeoPixel& AdaPixels);
private: // Fonction private:
void _f_newBrightness();
void _f_refrech();
void _f_turnOnOff();
void _f_showConnect(bool conected);
bool _f_showMode();
int16_t _f_nbLevelMode(int16_t distance); //Avec REVERSELIGHTBAR!
///////////// A Ecrire ///////////////////////
void _f_sendHelloF9 ();
uint16_t _f_AOG_CK_A(uint8_t *Message);
//////////// END à écrire //////////////////////
public: // Fonctions public:
//void begin(bool testPixels);
//void beginNew(bool testPixels);
bool valeurs(uint8_t nbrPixels, uint16_t mmParLightbarPixel, bool lightBarON);
void Refrech();
void turnOn();
void turnOff();
void distancePlus(int16_t distanceLigne, bool isDay){SetIsDay(isDay); distance(distanceLigne);};
void distance(int16_t distanceLigne);
// Set / Get
bool GetIsOff();
bool GetIsOn();
uint16_t GetDistanceLigne() const {return this->_distanceLineLast;}
uint16_t GetLevelPixels() const {return this->_nLevel;}
void SetMmParPixel(uint16_t mmPixel);
void SetCmParPixel(uint16_t cmPixel) {SetMmParPixel(cmPixel * 10);}
uint16_t GetMmParPixel() const {return this->_lbMmPixel;}
uint16_t GetCmParPixel() const {return (this->_lbMmPixel + 4) / 10;}
void SetIgnorePixel(uint8_t ignoreStartPixel);
void SetDelayShutdown(uint16_t delayShutdown);
uint16_t GetDelayShutdown() const {return this->_delayShutdown;}
void SetBrightness(uint8_t brightnessPixels);
uint16_t GetBrightness() const {return this->_lbBrightness;}
void SetIsDay(bool IsDay);
bool GetIsDay() const {return !this->_lbNight;}
void SetNightNighting(bool nighting);
void SetBrightnessNight(uint8_t brightnessPixelsNight); // % d'éclairage la nuit
uint16_t GetBrightnessNight() const {return this->_brightnessNight;}
void SetLightBarReverse(bool reverseLightBar);
bool GetLightBarReverse() const {return this->_lbReverse;}
void SetLightBarMode(uint8_t ModeLightBar);
uint8_t GetLightBarMode();
private: // Variables private:
uint32_t _lbOnOff_TimerTurne = millis();
int16_t _distanceLine = -32123;
int16_t _distanceLineLast = -32123;
uint8_t _nbrPixels = 0; // number pixel light-bar || Odd number dont use =0 (if = 0 Light-Bar disable)
uint8_t _startPixels = 0; // Pixel ignorés en début de bande
uint8_t _centrePixel = 0; //
uint16_t _lbMmPixel = 80; // 40 = 4cm (value between 1 and 255)
uint8_t _lbBrightness = 120; // brightness value between 0 and 255
bool _brightnessChange = false; //
bool _lbNight = false; // valeur si Neo_Phare_Pin non utilisé autrement voir ci-dessous
bool _lbNighting = false; // si activé remplace les pixels d'extrémités noir par du blanc-léger (pour voir la longueur de la bar dans la nuit) Combinable avec Neo_Phre_Pin.
uint8_t _brightnessNight = 40; // [en %]
bool _lbReverse = false; //bool ReverseLightBar = false;
int8_t _lbModeShow = 1; //
int16_t _nLevel = -32666;
uint16_t _delayShutdown = 751; //[ms] Temps avant la déactivation en cas de non réception de valeurs depuis AOG (tablette)
uint16_t _delayRefrech = 106;
uint32_t _lastDistanceTime = 0;
uint32_t _lastShowTime = 0;
int8_t _lbStatus = -2; // -2: pas de connection avec AOG || -1: AGO distance invalide || 0: start || 1: distance valide || -5: tourne à On || -6: tourne à Off || -7 Off
int8_t _lbStatusLast = 0;
};
class AOG_Sect_bar {
protected:
AOG_NeoPixelsColors& Y_AOG_RGB;
Adafruit_NeoPixel& Y_AdaPixels;
public:
// Constructeur
AOG_Sect_bar(uint8_t Sections_nbr_Pixels, uint16_t Sections_Start_Pixel, AOG_NeoPixelsColors& AOG_RGB, Adafruit_NeoPixel& AdaPixels);
private:
};
class AOG_Pixels {
protected:
//AOG_Light_bar _Light_bar;
//AOG_Sect_bar _Sect_bar;
//AOG_NeoPixelsColors& _AOG_RGB;
//Adafruit_NeoPixel& _AdaPixels;
public: // Constructeur :
AOG_Pixels(uint8_t Light_bar_nbr_Pixels, uint16_t Light_bar_Start_Pixel, uint8_t Sections_nbr_Pixels, uint16_t Sections_Start_Pixel, AOG_NeoPixelsColors& AOG_RGB, Adafruit_NeoPixel& AdaPixels){};
};
#endif
================================================
AOG_NeoPixel.cpp
#include <stdint.h>
#include "AOG_NeoPixel.h"
#include <Adafruit_NeoPixel.h>
#ifdef _Bluetooth_debug
#include <BluetoothSerial.h>
#endif
//Constructeur // Partage de class voir: https://forum.arduino.cc/t/inclure-liquidcrystal-dans-une-classe-perso/177782/5
AOG_Light_bar::AOG_Light_bar(uint8_t nbrPixels, uint16_t ignoreStartPixel, AOG_NeoPixelsColors& AOG_RGB, Adafruit_NeoPixel& AdaPixels) : Z_AOG_RGB(AOG_RGB), Z_AdaPixels(AdaPixels) {
if (nbrPixels>1) {
this->_nbrPixels = nbrPixels-1;
this->_startPixels = ignoreStartPixel;
this->_centrePixel = this->_startPixels + nbrPixels/2;
this->_lbStatus = 0; this->_lbStatusLast = -3; //this->_lbOn_Off = true;
}
#ifdef _Bluetooth_debug
_SerialBT.begin("_AOG_DEBUG_L-Bar"); //Bluetooth device name
#endif
Z_AdaPixels.begin();
delay(50);
Z_AdaPixels.clear();
Z_AdaPixels.show();
}
AOG_Sect_bar::AOG_Sect_bar(uint8_t Sections_nbr_Pixels, uint16_t Sections_Start_Pixel, AOG_NeoPixelsColors& AOG_RGB, Adafruit_NeoPixel& AdaPixels) : Y_AOG_RGB(AOG_RGB), Y_AdaPixels(AdaPixels) {
}
/*AOG_Pixels::AOG_Pixels(uint8_t Light_bar_nbr_Pixels, uint16_t Light_bar_Start_Pixel, uint8_t Sections_nbr_Pixels, uint16_t Sections_Start_Pixel, AOG_NeoPixelsColors& AOG_RGB, Adafruit_NeoPixel& AdaPixels)
: _Light_bar(Light_bar_nbr_Pixels, Light_bar_Start_Pixel, AOG_RGB, AdaPixels),
_Sect_bar(Sections_nbr_Pixels, Sections_Start_Pixel, AOG_RGB, AdaPixels) {
// Ou :
* {
if (Light_bar_nbr_Pixels > 0) {
this->_Light_bar = AOG_Light_bar(Light_bar_nbr_Pixels, Light_bar_Start_Pixel, AOG_RGB, AdaPixels);
}
else {
// Il n'y a pas de light-bar
}
if (Sections_nbr_Pixels > 0) {
if (Light_bar_nbr_Pixels + Light_bar_Start_Pixel < Sections_Start_Pixel || Sections_nbr_Pixels + Sections_Start_Pixel < Light_bar_Start_Pixel){
this->_Sect_bar = AOG_Sect_bar(Sections_nbr_Pixels, Sections_Start_Pixel, AOG_RGB, AdaPixels);
}
else {
// Il n'y a pas de section-bar
}
*
}*/
//Méthode redéfinition de valeurs
// void AOG_Light_bar::begin(bool testPixels){
// #ifdef _Bluetooth_debug
// _SerialBT.begin("_AOG_DEBUG_L-Bar"); //Bluetooth device name
// #endif
// _AdaPixels.updateLength(this->_startPixels + this->_nbrPixels); // Adafruit_NeoPixel ->void updateLength(uint16_t n);
// _AdaPixels.updateType(NEO_GRB + NEO_KHZ800); // Adafruit_NeoPixel ->void updateType(neoPixelType t);
// _AdaPixels.begin();
// delay(50);
// _f_newBrightness();
// delay(20);
// _AdaPixels.clear();
// delay(20);
// if (this->_lbStatus > -5) { // if (this->_lbOn_Off) {
// if (!testPixels) {
// this->_lbStatusLast = this->_lbStatus; this->_lbStatus = -7; //this->_lbOn_Off = false;
// _f_turnOnOff();
// this->_lbOnOff_TimerTurne += 250;
// }
// _AdaPixels.show();
// delay(20);
// }
// if (testPixels) {
// //TestPixels();
// }
// }
void AOG_Light_bar::Refrech() {
_f_refrech();
}
void AOG_Light_bar::SetIgnorePixel(uint8_t ignoreStartPixel) {
if (this->_startPixels != ignoreStartPixel) {
this->_startPixels = ignoreStartPixel;
this->_centrePixel = this->_nbrPixels/2 + ignoreStartPixel;
}
}
void AOG_Light_bar::SetMmParPixel(uint16_t mmPixel) {
if (this->_lbMmPixel != mmPixel) {
this->_lbMmPixel = mmPixel;
this->_lbStatusLast = -3;
}
}
//void AOG_Light_bar::SetCmParPixel(uint16_t cmPixel) {SetmmParPixel(cmPixel * 10);}
void AOG_Light_bar::SetDelayShutdown(uint16_t delayShutdown) {
this->_delayShutdown = delayShutdown;
}
void AOG_Light_bar::SetBrightness(uint8_t brightnessPixels) {
// if (brightnessPixels > 10) {
// LIGHTBARONOFF(false);
// }
// else {
// if (_lbOnOff == false) LIGHTBARONOFF(false);
// ...}
if (brightnessPixels < 10) brightnessPixels = 10;
if (abs(this->_lbBrightness - brightnessPixels) > 5) {
this->_lbBrightness = brightnessPixels;
this->_brightnessChange = true;
}
}
void AOG_Light_bar::SetBrightnessNight(uint8_t brightnessPixelsNight) {
uint8_t tempN = brightnessPixelsNight;
if (brightnessPixelsNight < 10) tempN = 10; // % minimum
else if (brightnessPixelsNight > 100) tempN = 100; // % maximum
this->_brightnessNight = tempN;
this->_brightnessChange = true;
}
void AOG_Light_bar::SetIsDay(bool IsDay) {
if (!IsDay != this->_lbNight) {
this->_lbNight = !IsDay;
this->_brightnessChange = true;
}
}
void AOG_Light_bar::SetNightNighting(bool nighting) {
if (this->_lbNighting != nighting){
this->_lbNighting = nighting;
this->_brightnessChange = true;
}
}
void AOG_Light_bar::SetLightBarReverse(bool reverseLightBar) {
if (this->_lbReverse != reverseLightBar) {
this->_lbReverse = reverseLightBar;
this->_lbStatusLast = -3; //pour forcer le rafraîchissement de l'affichage
}
}
void AOG_Light_bar::SetLightBarMode(uint8_t ModeLightBar) {
if (this->_lbModeShow != ModeLightBar) {
this->_lbModeShow = ModeLightBar;
this->_lbStatusLast = -3; //pour forcer le rafraîchissement de l'affichage
}
}
uint8_t AOG_Light_bar::GetLightBarMode() {
if (this->_lbModeShow < 1) {return 0;}
else {return this->_lbModeShow;}
}
void AOG_Light_bar::distance(int16_t distanceLigne){
this->_lastDistanceTime = millis();
int8_t tempLevel = this->_nLevel;
_f_nbLevelMode(distanceLigne);
this->_distanceLine = distanceLigne;
if (distanceLigne < -30000) {
this->_lbStatus = -2;
}
else if (distanceLigne > 30000) {
this->_lbStatus = -1;
}
else {
if (tempLevel != this->_nLevel || this->_lbStatusLast != 1) {
this->_lbStatusLast = 0;
this->_lbStatus = 1;
}
}
}
void AOG_Light_bar::_f_refrech() {
uint32_t tempTime = millis();
if (this->_brightnessChange) {
_f_newBrightness();
this->_lbStatusLast = -3; //pour forcer le rafraîchissement de l'affichage
}
if (this->_lbStatus <= -5) { // if (!this->_lbOn_Off || this->_lbOnOff_Turne) {
if (this->_lbStatus != -7) _f_turnOnOff();
return;
} // END if(this->_lbOn_Off)
if (int64_t(tempTime - this->_lastDistanceTime) >= this->_delayShutdown) {
this->_lbStatus = -2;
this->_lbStatusLast = -3; //pour forcer le rafraîchissement de l'affichage
this->_lastDistanceTime = tempTime + this->_delayShutdown; //Réinitier le compteur (2* delais pour éviter d'envoyer des message dans le vide)
_f_sendHelloF9();
}
if (abs(int64_t(tempTime- this->_lastShowTime)) >= this->_delayRefrech) {
this->_lbStatusLast = -3;
}
if (this->_lbStatusLast == -3) _f_nbLevelMode(this->_distanceLineLast);
if (this->_lbStatus != this->_lbStatusLast && this->_lbStatus != 0) { // Si Old status et différent du status afficher les dels correspondant
if (this->_lbStatus == -2) {
_f_showConnect(false);
}
else if (this->_lbStatus == -1) {
_f_showConnect(true);
}
else if (this->_lbStatus == 1){
_f_showMode();
}
else { //Status inconnu !!!
_f_showConnect(false);
this->_lbStatus = 0;
}
this->_lastShowTime = tempTime;
if (this->_lbStatusLast == -3 && this->_lbStatus == 1) {this->_lbStatusLast = -4;}
else {this->_lbStatusLast = this->_lbStatus;}
this->_lbStatus = 0;
}
}
int16_t AOG_Light_bar::_f_nbLevelMode(int16_t distance) { //Avec REVERSELIGHTBAR!
int16_t tempreponse = -127;
if (abs(distance) > 31000) {
this->_distanceLineLast = this->_distanceLine;
this->_nLevel = distance;
//_SerialBT.print("XXX ");_SerialBT.println(distance);
return tempreponse;
}
int16_t tempError = distance;
//if (this->_distanceLineLast < -29999 || this->_distanceLineLast > 29999) tempError = (distance + this->_distanceLineLast) / 2;
//if (abs(_distanceLineLast) < 29999 || abs(tempError) < 29999) tempError = (distance + this->_distanceLineLast) / 2;
this->_distanceLineLast = tempError;
if(this->_lbReverse) tempError = tempError * -1;
switch (this->_lbModeShow) {
case 1: // Mode == 1
// élever la valeur pour l'arrondi_inf fait par l'arduino.
if (tempError > this->_lbMmPixel * 0.9) {tempError += (int)(this->_lbMmPixel * 0.4);}
else if (tempError > 0) {tempError += (int)(this->_lbMmPixel * 0.1);}
else if (tempError < this->_lbMmPixel * -0.9) {tempError -= (int)(this->_lbMmPixel * 0.4);}
else if (tempError < 0) {tempError -= (int)(this->_lbMmPixel * 0.1);}
tempreponse = constrain((int8_t)(tempError / this->_lbMmPixel),-(this->_centrePixel - this->_startPixels -3), (this->_nbrPixels - (this->_centrePixel - this->_startPixels) -3));
if (tempreponse < 0) { tempreponse = tempreponse - 3; } //Arondi Arduino: 0.99 = 0 <> -0.99 = 0 //Calcul les entiers à gauche
else if (tempreponse > 0) { tempreponse = tempreponse + 3; } //Calcul les entiers à droite
else {tempreponse = (tempError * 4) / this->_lbMmPixel;} // calcul les trois premier quarts à gauche et à droite et le centre
break;
default: // Mode == 0 <<Ou>> Mode == Non parametré
// élever la valeur pour l'arrondi_inf fait par l'arduino.
if (tempError > 0) {tempError += (int)(this->_lbMmPixel * 0.4);}
else if (tempError < 0) {tempError -= (int)(this->_lbMmPixel * 0.4);}
tempreponse = constrain((int8_t)(tempError / this->_lbMmPixel),-(this->_centrePixel - this->_startPixels), (this->_nbrPixels - (this->_centrePixel - this->_startPixels)));
break;
}
//_SerialBT.print(distance); _SerialBT.print(" \t ");_SerialBT.println(tempreponse);
this->_nLevel = tempreponse;
return tempreponse;
}
void AOG_Light_bar::_f_showConnect(bool conected){
uint32_t tempColor;
if (!conected) {tempColor = Z_AOG_RGB.error;}
else {tempColor = Z_AOG_RGB.green;}
for (int i = this->_startPixels; i < this->_nbrPixels +1 + this->_startPixels; i++) {
Z_AdaPixels.setPixelColor(i, Z_AOG_RGB.black);
}
Z_AdaPixels.setPixelColor(this->_startPixels, tempColor);
Z_AdaPixels.setPixelColor(this->_startPixels + this->_nbrPixels, tempColor);
Z_AdaPixels.setPixelColor(this->_startPixels + this->_nbrPixels /3, tempColor);
Z_AdaPixels.setPixelColor(this->_startPixels + this->_nbrPixels *2/3, tempColor);
Z_AdaPixels.show();
delay(20); // 20ms pour laisser le temp dècrire les pixels en cas de changement de status
}
bool AOG_Light_bar::_f_showMode() {
if (abs(this->_nLevel) > this->_nbrPixels / 2 + 1) { // Test que la variable numérot de pixel correspond au nombre de pixels affichables
this->_lbStatus = -3;
return false;
}
int tempLevel = this->_nLevel;
int tempN = this->_centrePixel + tempLevel;
switch (this->_lbModeShow) {
case 1: //ModePixel == 1 "1/4"
if (tempLevel <0) {
for (int i = this->_startPixels; i < this->_nbrPixels + 1 + this->_startPixels; i++) {
if (i < tempN || i > this->_centrePixel) {
Z_AdaPixels.setPixelColor(i, Z_AOG_RGB.black);
}
else if ( i < this->_centrePixel -3 ) {Z_AdaPixels.setPixelColor(i, Z_AOG_RGB.lBar2);}
else if (i == this->_centrePixel) {Z_AdaPixels.setPixelColor(i, Z_AOG_RGB.lBarCentre);}
else {Z_AdaPixels.setPixelColor(i, Z_AOG_RGB.lBar1);}
}
}
else if (tempLevel >0) {
for (int i = this->_startPixels; i < this->_nbrPixels +1 + this->_startPixels; i++) {
if (i > tempN || i < this->_centrePixel) {Z_AdaPixels.setPixelColor(i, Z_AOG_RGB.black);}
else if ( i > this->_centrePixel +3 ) {Z_AdaPixels.setPixelColor(i, Z_AOG_RGB.lBar2);}
else if (i == this->_centrePixel) {Z_AdaPixels.setPixelColor(i, Z_AOG_RGB.lBarCentre);}
else {Z_AdaPixels.setPixelColor(i, Z_AOG_RGB.lBar1);}
}
}
else {
for (int i = this->_startPixels; i < this->_nbrPixels +1 + this->_startPixels; i++) {
if (i == this->_centrePixel) {Z_AdaPixels.setPixelColor(i, Z_AOG_RGB.lBarCentre);}
else {Z_AdaPixels.setPixelColor(i, Z_AOG_RGB.black);}
}
}
break;
default: //ModePixel == 0 (OU par défaut)
if (tempLevel < 0) {
for (int i = this->_startPixels; i < this->_nbrPixels +1 + this->_startPixels; i++) {
if (i < tempN || i > this->_centrePixel) {Z_AdaPixels.setPixelColor(i, Z_AOG_RGB.black);}
else if (i >= tempN && i < this->_centrePixel) {Z_AdaPixels.setPixelColor(i, Z_AOG_RGB.lBar1);}
else {Z_AdaPixels.setPixelColor(i, Z_AOG_RGB.lBarCentre);}
}
} else if (tempLevel > 0) {
for (int i = this->_startPixels; i < this->_nbrPixels +1 + this->_startPixels; i++) {
if (i > tempN || i < this->_centrePixel) {Z_AdaPixels.setPixelColor(i, Z_AOG_RGB.black);}
else if (i <= tempN && i > this->_centrePixel) {Z_AdaPixels.setPixelColor(i, Z_AOG_RGB.lBar2);}
else {Z_AdaPixels.setPixelColor(i, Z_AOG_RGB.lBarCentre);}
}
} else {
for (int i = this->_startPixels; i < this->_nbrPixels +1 + this->_startPixels; i++) {
if (i < this->_centrePixel || i > this->_centrePixel) {Z_AdaPixels.setPixelColor(i, Z_AOG_RGB.black);}
else {Z_AdaPixels.setPixelColor(i, Z_AOG_RGB.lBarCentre);}
}
}
break;
}
if (this->_lbNight && this->_lbNighting) { //Activer les leds d'éclairage "nighting"
// _SerialBT.print(tempN);
//if (_AdaPixels.getPixelColor(this->_startPixels) == _AOG_RGB.black) _AdaPixels.setPixelColor(this->_startPixels, _AOG_RGB.with_light);
//if (_AdaPixels.getPixelColor(this->_startPixels + this->_nbrPixels) == _AOG_RGB.black) _AdaPixels.setPixelColor(this->_startPixels + this->_nbrPixels, _AOG_RGB.with_light);
if (tempN > this->_startPixels) Z_AdaPixels.setPixelColor(this->_startPixels, Z_AOG_RGB.with_light);
if (tempN < this->_startPixels + this->_nbrPixels) Z_AdaPixels.setPixelColor(this->_startPixels + this->_nbrPixels, Z_AOG_RGB.with_light);
}
// test pour distinguer le pixel "nLevelPixelMode"
//_AdaPixels.setPixelColor(tempN, 0, 0, 255); //blue
//_AdaPixels.setPixelColor(this->_centrePixel, _AOG_RGB.blue);
Z_AdaPixels.show();
return true;
}
void AOG_Light_bar::_f_newBrightness() {
uint8_t tempBrightness = this->_lbBrightness;
if (this->_lbNight) {
tempBrightness = tempBrightness * this->_brightnessNight / 100;
}
Z_AdaPixels.setBrightness(tempBrightness);
this->_brightnessChange = false;
}
void AOG_Light_bar::_f_turnOnOff() {
uint32_t tempColor = 0;
// -2: pas de connection avec AOG || -1: AGO distance invalide || 0: start || 1: distance valide || -5: tourne à On || -6: tourne à Off || -7 Off
if (this->_lbStatus != -5 && this->_lbStatus != -6) { // si elle n'est pas entrain de tourner
this->_lbOnOff_TimerTurne = millis();
Z_AdaPixels.setBrightness(30);
if (this->_lbStatus != -7) { // si elle est à On
this->_lbStatus != -6; // => tourne à Off
tempColor = Z_AOG_RGB.red;
} else { //si elle est à Off
this->_lbStatus != -5; // =>tourne à On
tempColor = Z_AOG_RGB.green;
}
}
else if (abs(int64_t(millis() - this->_lbOnOff_TimerTurne)) > 700) { // si elle est entrain de tourner est que le timer est atteint
if (this->_lbStatus == -6) { // si elle est à tourne à Off
this->_lbStatus = -7; // => OFF
tempColor = Z_AOG_RGB.black;
}
else { // si elle est à tourne à On
this->_brightnessChange = true;
this->_lbStatus = this->_lbStatusLast; // => On (dernier status utilisé)
if (this->_lbStatus < -2) this->_lbStatus = 0; // confirme le passage à On
this->_lbStatusLast = -5;
}
}
if (this->_lbStatus <= -5) { // si elle n'est pas à ON, gère la couleur
for (int i = this->_startPixels; i < this->_startPixels + this->_nbrPixels + 1; i++) {
Z_AdaPixels.setPixelColor(i, tempColor);
}
}
Z_AdaPixels.show();
}
void AOG_Light_bar::turnOn(){
if (this->_lbStatus == -6) this->_lbStatus = -7;
if (this->_lbStatus == -7) _f_turnOnOff();
}
void AOG_Light_bar::turnOff(){
if (this->_lbStatus == -5) this->_lbStatus = 0;
if (this->_lbStatus > -5) {
this->_lbStatusLast = this->_lbStatus;
_f_turnOnOff();
}
}
bool AOG_Light_bar::GetIsOff(){
if (this->_lbStatus == -7) return true;
else return false;
}
bool AOG_Light_bar::GetIsOn(){
if (this->_lbStatus > -5) return true;
else return false;
}
void AOG_Light_bar::_f_sendHelloF9() {
uint8_t AOG_SendF9[] = { 0x80, 0x81, 0x7f,
0xF9, // nom de fonction : 0xF8 = LightBar config | 0xF6 = SctionsLeds config
2,
2, // 1 = Je n'ai pas de light-bar | 2 = J'informe AOG que j'ai une light-bar | autre = ne pas changer cet état
0, // 0 = simple | 238 = module configurable depuis AOG
0x7C // crc
};
Serial.write(AOG_SendF9, sizeof(AOG_SendF9));
//// AOG-Visual_studio:
// private void Receive[ModulName]Port(byte[] Data) {
// if (Data[0] == 0x80 && Data[1] == 0x81 && Data[3] == 0xF9) {
// if (Data[5] == 1) imuLightBar = false; else if (Data[5] == 2) imuLightBar = true;
// } else if (Data[0] == 0x80 && Data[1] == 0x81 && Data[3] == 0xF6) {
// if (Data[5] == 1) imuSectionsLeds = false; else if (Data[5] == 2) imuSectionsLeds = true;
// }
// //...
// }
//// END AOG-Visual_studio:
}
/// A écrire
uint16_t AOG_Light_bar::_f_AOG_CK_A(uint8_t *pMessage) { //add the checksum for AOG
int16_t CK_A = 0;
for (uint8_t i = 2; i < sizeof(pMessage) - 1; i++)
{
CK_A = (CK_A + pMessage[i]);
}
return CK_A;
}
================================================
AOG_NeoPixelsColors.h
#ifndef AOG_NEOPIXELSCOLOR_H
#define AOG_NEOPIXELSCOLOR_H
//#include <Adafruit_NeoPixel.h>
class AOG_NeoPixelsColors {
public:
AOG_NeoPixelsColors() {
red = (200 <<16) +( 0 <<8) + (0); //pixels.Color( 200 , 0 , 0 );
//red = Color( 200 , 0 , 0 );
red_light = (80 <<16) +( 0 <<8) + (0); //pixels.Color( 80 , 0 , 0 );
green = (0 <<16) +( 200 <<8) + (0); //pixels.Color( 0 , 200 , 0 );
yellow = (170 <<16) +( 170 <<8) + (0); //pixels.Color( 170 , 170 , 0 );
yellow_light = (70 <<16) +( 70 <<8) + (0); //pixels.Color( 70 , 70 , 0 );
orange = (170 <<16) +( 68 <<8) + (0); //pixels.Color( 170 , 68 , 0 ); //( 255 , 102 , 0 );
blue = (0 <<16) +( 0 <<8) + (200); //pixels.Color( 0 , 0 , 200 );
black = 0;
with_light = (30 <<16) +( 30 <<8) + (30); //pixels.Color( 50 , 50 , 50 );
error = (200 <<16) +( 10 <<8) + (20);
test = (80 <<16) +( 80 <<8) + (80);
lBar2 = (180 <<16) +( 0 <<8) + (50); //pixels.Color( 180 , 102 , 0 );
lBar1 = (50 <<16) +( 0 <<8) + (180); //pixels.Color( 240 , 20 , 0 );
lBarCentre = (0 <<16) +( 180 <<8) + (0); //pixels.Color( 0 , 150 , 0 );
};
uint32_t red;
uint32_t red_light;
uint32_t green;
uint32_t yellow;
uint32_t yellow_light;
uint32_t orange;
uint32_t blue;
uint32_t black = 0;
uint32_t with_light;
uint32_t error;
uint32_t test;
uint32_t lBar1;
uint32_t lBar2;
uint32_t lBarCentre;
private:
// copie depuis Adafruit_NeoPixel.h
static uint32_t Color(uint8_t r, uint8_t g, uint8_t b) {
return ((uint32_t)r << 16) | ((uint32_t)g << 8) | b;
};
static uint32_t Color(uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
return ((uint32_t)w << 24) | ((uint32_t)r << 16) | ((uint32_t)g << 8) | b;
};
};
#endif
Salutations, bonne journée