projet_europ

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
projet_europ [2024/07/01 21:26] – [Code] Mushussuprojet_europ [2024/12/14 21:34] (Version actuelle) – [Démarrage automatique] Mushussu
Ligne 2: Ligne 2:
  
 [[https://github.com/woutgg/ofxGenericDmx/blob/master/ofxGenericDmx_RawDmxExample/src/ofApp.cpp|Gestion du DMX]] [[https://github.com/woutgg/ofxGenericDmx/blob/master/ofxGenericDmx_RawDmxExample/src/ofApp.cpp|Gestion du DMX]]
- 
-Pour Utiliser le boîtier Enttec sous Linux, il faut autoriser l'utilisateur principal à accéder au port USB. 
-Il faut saisir dans un terminal la commande suivante : 
-  sudo nano /etc/udev/rules.d/11-usbuser. 
- 
-Puis, il faut écrire à l'intérieur la règle 
-  rulesACTION=="add", SUBSYSTEMS=="usb", GROUP:="usbuser", MODE:="0666" 
- 
-Sauvegarde le tout avec le raccourci Ctrl + X ; et reboote le PC. 
- 
- 
-Create the file /etc/udev/rules.d/10-ftdi.rules 
- 
-Write on it: 
- 
-SUBSYSTEM=="usb_device", GROUP="dialout", MODE="0664" 
- 
-SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", GROUP="dialout", MODE="0664" 
- 
- 
- 
-https://getdlight.com/wiki/index.php/Interfaces_DMX#Linux 
  
  
Ligne 107: Ligne 85:
 #include "ofxGenericDmx.h" #include "ofxGenericDmx.h"
 #include "ofUtils.h" #include "ofUtils.h"
-//#include "ofGraphics.h" 
 #include <wiringPi.h> #include <wiringPi.h>
 +#include "Compteur.hpp"
  
 #define DMX_DATA_LENGTH 513 #define DMX_DATA_LENGTH 513
-#define TEMOIN 19+#define TEMOIN1 19 
 +#define TEMOIN2 27
 #define ROUE 2.27 #define ROUE 2.27
  
Ligne 119: Ligne 98:
  void update();  void update();
  void draw();  void draw();
-  
- void keyPressed(int key); 
- void keyReleased(int key); 
- void mouseMoved(int x, int y); 
- void mouseDragged(int x, int y, int button); 
- void mousePressed(int x, int y, int button); 
- void mouseReleased(int x, int y, int button); 
- void mouseEntered(int x, int y); 
- void mouseExited(int x, int y); 
- void windowResized(int w, int h); 
- void dragEvent(ofDragInfo dragInfo); 
- void gotMessage(ofMessage msg); 
  
  //pointer to our Enntec DMX USB Pro object  //pointer to our Enntec DMX USB Pro object
Ligne 137: Ligne 104:
  //our DMX packet (which holds the channel values + 1st byte for the start code)  //our DMX packet (which holds the channel values + 1st byte for the start code)
  unsigned char dmxData_[DMX_DATA_LENGTH];  unsigned char dmxData_[DMX_DATA_LENGTH];
 +
 + // Compteurs
 + Compteur compteur1;
 + Compteur compteur2;
  
  ofTrueTypeFont myfont;  ofTrueTypeFont myfont;
 }; };
 +
 </code> </code>
 === ofApp.cpp === === ofApp.cpp ===
Ligne 145: Ligne 117:
 #include <stdlib.h> #include <stdlib.h>
 #include "ofApp.h" #include "ofApp.h"
- 
-uint64_t tempsDepart; 
- 
-int compteur1; 
-uint64_t temps1; 
-uint8_t vitesseIntantanee1; 
-uint8_t vitesseMax1; 
-uint8_t vitesseMoyenne1; 
  
 //-------------------------------------------------------------- //--------------------------------------------------------------
Ligne 171: Ligne 135:
   
  // Initialisation valeurs  // Initialisation valeurs
- compteur1 = 0; + compteur1.set(TEMOIN1, ROUE, ofGetCurrentTime().getAsMilliseconds()); 
- temps1 = 0; + compteur2.set(TEMOIN2, ROUE, ofGetCurrentTime().getAsMilliseconds());
- tempsDepart = ofGetCurrentTime().getAsMilliseconds() ; +
- vitesseIntantanee1 = 0; +
- vitesseMax1 = 0;+
  
  // Affichage  // Affichage
Ligne 200: Ligne 161:
  dmxInterface_->writeDmx( dmxData_, DMX_DATA_LENGTH );  dmxInterface_->writeDmx( dmxData_, DMX_DATA_LENGTH );
  }  }
- // Calcul coureur 1 + compteur1.mettreAJour(); 
- if (digitalRead(TEMOIN) == 1) { + compteur2.mettreAJour(); 
- digitalWrite(TEMOIN, 0); +} 
- compteur1++;+ 
 +//-------------------------------------------------------------- 
 +void ofApp::draw(){ 
 + ofBackground(0x21, 0X80, 0XC3); 
 + compteur1.afficher(0, 0, myfont); 
 + compteur2.afficher(640, 0, myfont); 
 +} 
 +</code> 
 +=== Compteur.hpp === 
 +<code cpp> 
 +#include "ofUtils.h" 
 +#include "ofGraphics.h" 
 +#include "ofTrueTypeFont.h" 
 +#include <wiringPi.h> 
 + 
 +class Compteur 
 +{ 
 +public: 
 + // Constructeur 
 + Compteur(); 
 + 
 + void set(uint8_t _pinTemoin, float _roue, uint64_t _tempsDepart); 
 + 
 + //Accesseurs et mutateurs 
 + //void setX(int x); 
 + //void setY(int y); 
 + //int getX() const; 
 + //int getY() const; 
 + 
 + // Autres méthodes 
 + void afficher(int x, int y, ofTrueTypeFont police); 
 + void mettreAJour(); 
 + 
 +private:  
 + int x, y; 
 + int pinTemoin; 
 + float roue; 
 + int compteur; 
 + uint64_t temps, tempsDepart; 
 + uint16_t distance; 
 + float vitesseIntantanee; 
 + float vitesseMax; 
 + ofTrueTypeFont policeVitesse, policeDistance, policeLabel; 
 +}; 
 +</code> 
 +=== Compteur.cpp === 
 +<code cpp> 
 +#include "Compteur.hpp" 
 + 
 +//-------------------------------------------------------------- 
 +Compteur::Compteur() 
 +{  
 + compteur = 0; 
 + temps = 0; 
 + vitesseIntantanee = 0.0; 
 + vitesseMax = 0.0; 
 + policeVitesse.load("AUDIMRG_.TTF", 12); 
 + policeDistance.load("arial.ttf", 50); 
 + policeLabel.load("arial.ttf", 20); 
 + distance = 0; 
 +} 
 + 
 +//-------------------------------------------------------------- 
 +void Compteur::afficher(int x, int y, ofTrueTypeFont police) 
 +{  
 + ofPushMatrix(); 
 + ofTranslate(x, y); 
 + ofSetCircleResolution(100); 
 + ofSetLineWidth(3); 
 + // Dessin du compteur 
 + ofPushMatrix(); 
 + ofTranslate(150, 800); 
 + // Aiguille de la vitesse Max 
 + ofSetColor(255, 0, 0); 
 + ofFill(); 
 + ofPushMatrix(); 
 + ofRotateDeg(60 + vitesseMax * 4); 
 + ofDrawTriangle(-6, 0, 0, 90, 6, 0); 
 + ofPopMatrix(); 
 + // Aiguille de la vitesse  instantanée 
 + ofSetColor(0, 0, 0); 
 + ofPushMatrix(); 
 + ofRotateDeg(60 + vitesseIntantanee * 4); 
 + ofDrawTriangle(-6, 0, 0, 90, 6, 0); 
 + ofPopMatrix(); 
 + // Dessin du cadran 
 + ofSetColor(255, 255, 255); 
 +    ofFill(); 
 + ofDrawCircle(0,0,20); 
 + ofSetColor(0,0,0); 
 + ofNoFill(); 
 + ofDrawCircle(0,0,100); 
 + ofDrawCircle(0,0,20); 
 + char nombre[3]; 
 + for (int i = 0; i < 61; i += 5) { 
 + ofPushMatrix(); 
 + ofRotateDeg(4 * i - 120); 
 + sprintf(nombre, "%i", i); 
 + policeVitesse.drawString(nombre, -policeVitesse.stringWidth(nombre) / 2, -115); 
 + ofDrawLine(0, -100, 0, -110); 
 + ofPopMatrix(); 
 + } 
 + ofSetColor(0, 0, 0); 
 + char labelCompteur[255]; 
 + sprintf(labelCompteur, "Vitesse max."); 
 + policeLabel.drawString(labelCompteur, -policeLabel.stringWidth(labelCompteur) / 2, 130); 
 + ofPopMatrix(); 
 + // Affichage de la distance 
 + ofPushMatrix(); 
 + ofTranslate(320, 750); 
 + ofSetColor(0, 0, 0); 
 +    ofFill(); 
 + ofDrawRectangle(00, 00, 300, 100); 
 + ofSetColor(255, 255, 255); 
 + char ligneDistance[255]; 
 + sprintf(ligneDistance, "%i m", distance); 
 + policeDistance.drawString(ligneDistance,  290 - policeDistance.stringWidth(ligneDistance), 75); 
 + ofSetColor(0, 0, 0); 
 + char labelDistance[255]; 
 + sprintf(labelDistance, "Distance parcourue"); 
 + policeLabel.drawString(labelDistance, 20, 180); 
 + ofPopMatrix(); 
 + ofPopMatrix(); 
 +} 
 + 
 +//-------------------------------------------------------------- 
 +void Compteur::mettreAJour() { 
 + if (digitalRead(pinTemoin) == 1) { 
 + digitalWrite(pinTemoin, 0); 
 + compteur++;
  uint64_t tempsCourant = ofGetCurrentTime().getAsMilliseconds();  uint64_t tempsCourant = ofGetCurrentTime().getAsMilliseconds();
- vitesseIntantanee1 = (int)(3.6 * 1000 * ROUE) / (tempsCourant - temps1); + vitesseIntantanee = (3.6 * 1000 * roue) / (tempsCourant - temps); 
- if (vitesseMax1 < vitesseIntantanee1) { + if (vitesseMax < vitesseIntantanee) { 
- vitesseMax1 = vitesseIntantanee1;+ vitesseMax = vitesseIntantanee;
  }  }
- vitesseMoyenne1 = (int)(3.6 * 1000 * ROUE * compteur1) / (tempsCourant - tempsDepart); + temps = tempsCourant;
- temps1 = tempsCourant;+
  }  }
  // Mise à zéro de la vitesse si la roue est arrêtée  // Mise à zéro de la vitesse si la roue est arrêtée
- if ((ofGetCurrentTime().getAsMilliseconds() - temps1) > 8000) { + if ((ofGetCurrentTime().getAsMilliseconds() - temps) > 6000) { 
- vitesseIntantanee1 = 0;+ vitesseIntantanee = 0;
  }  }
 + distance = (int)(roue * compteur);
 } }
  
 //-------------------------------------------------------------- //--------------------------------------------------------------
-void ofApp::draw(){ +void Compteur::set(uint8_t _pinTemoin, float _roue, uint64_t _tempsDepart) 
- ofBackground(100, 100, 100); +{ 
- ofSetColor(255,0,0); + pinTemoin = _pinTemoin; 
- char ligneVitesse[255]; // an array of chars + roue = _roue; 
- sprintf(ligneVitesse, "Vitesse : %i         Moyenne : %i", vitesseIntantanee1, vitesseMoyenne1); + tempsDepart = _tempsDepart;
- myfont.drawString(ligneVitesse, 100,100);+
 } }
 </code> </code>
 +
 +===== Démarrage automatique =====
 +  sudo nano /etc/systemd/system/compteur.service
 +
 +  [Unit]
 +  Description=Met en route le compteur des vélos
 +  
 +  [Service]
 +  Type=simple
 +  WorkingDirectory=/home/pi/openFrameworks/apps/myApps/velosInteractifs/
 +  ExecStart=/home/pi/openFrameworks/apps/myApps/velosInteractifs/./compteur
 +  Restart=on-failure
 +  RestartSec=1
 +  User=pi
 +  Group=pi
 +  
 +  [Install]
 +  WantedBy=multi-user.target
 +
 +  sudo systemctl enable compteur.service
 +
 +  sudo systemctl status compteur.service
 +Construction d'un autre service pour la course :
 +
 +  sudo nano /etc/rc.local
 +Ajouter avant la ligne exit 0
 +  startx ./home/pi/openFrameworks/apps/myApps/velosInteractifs/bin/velosInteractifs -- -s off &
 +Il faut aussi désactiver les sorties audio par l'HDMI. Ajouter ,noaudio à la fin de la ligne dtoverlay=vc4-kms-v3d dans le fichier /boot/firmware/config.txt :
 +  sudo nano /boot/firmware/config.txt
 +  dtoverlay=vc4-kms-v3d,noaudio
 +
 +{{tag>raspberry_pi sylvain OpenFrameworks}}
projet_europ.1719869163.txt.gz · Dernière modification : de Mushussu