projet_europ
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| projet_europ [2024/07/01 21:26] – [Code] Mushussu | projet_europ [2024/12/14 21:34] (Version actuelle) – [Démarrage automatique] Mushussu | ||
|---|---|---|---|
| Ligne 2: | Ligne 2: | ||
| [[https:// | [[https:// | ||
| - | |||
| - | Pour Utiliser le boîtier Enttec sous Linux, il faut autoriser l' | ||
| - | Il faut saisir dans un terminal la commande suivante : | ||
| - | sudo nano / | ||
| - | |||
| - | Puis, il faut écrire à l' | ||
| - | rulesACTION==" | ||
| - | |||
| - | Sauvegarde le tout avec le raccourci Ctrl + X ; et reboote le PC. | ||
| - | |||
| - | |||
| - | Create the file / | ||
| - | |||
| - | Write on it: | ||
| - | |||
| - | SUBSYSTEM==" | ||
| - | |||
| - | SUBSYSTEM==" | ||
| - | |||
| - | |||
| - | |||
| - | https:// | ||
| Ligne 107: | Ligne 85: | ||
| #include " | #include " | ||
| #include " | #include " | ||
| - | //#include " | ||
| #include < | #include < | ||
| + | #include " | ||
| #define DMX_DATA_LENGTH 513 | #define DMX_DATA_LENGTH 513 | ||
| - | # | + | # |
| + | #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; | ||
| }; | }; | ||
| + | |||
| </ | </ | ||
| === ofApp.cpp === | === ofApp.cpp === | ||
| Ligne 145: | Ligne 117: | ||
| #include < | #include < | ||
| #include " | #include " | ||
| - | |||
| - | 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 | + | compteur1.set(TEMOIN1, |
| - | temps1 = 0; | + | compteur2.set(TEMOIN2, |
| - | tempsDepart = ofGetCurrentTime().getAsMilliseconds() ; | + | |
| - | vitesseIntantanee1 = 0; | + | |
| - | vitesseMax1 = 0; | + | |
| // Affichage | // Affichage | ||
| Ligne 200: | Ligne 161: | ||
| dmxInterface_-> | dmxInterface_-> | ||
| } | } | ||
| - | // Calcul coureur 1 | + | compteur1.mettreAJour(); |
| - | if (digitalRead(TEMOIN) == 1) { | + | compteur2.mettreAJour(); |
| - | digitalWrite(TEMOIN, 0); | + | } |
| - | compteur1++; | + | |
| + | //-------------------------------------------------------------- | ||
| + | void ofApp:: | ||
| + | ofBackground(0x21, | ||
| + | compteur1.afficher(0, | ||
| + | compteur2.afficher(640, | ||
| + | } | ||
| + | </ | ||
| + | === Compteur.hpp === | ||
| + | <code cpp> | ||
| + | #include " | ||
| + | #include " | ||
| + | #include " | ||
| + | #include < | ||
| + | |||
| + | class Compteur | ||
| + | { | ||
| + | public: | ||
| + | // Constructeur | ||
| + | Compteur(); | ||
| + | |||
| + | void set(uint8_t _pinTemoin, float _roue, uint64_t _tempsDepart); | ||
| + | |||
| + | // | ||
| + | //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, | ||
| + | }; | ||
| + | </ | ||
| + | === Compteur.cpp === | ||
| + | <code cpp> | ||
| + | #include " | ||
| + | |||
| + | // | ||
| + | Compteur:: | ||
| + | { | ||
| + | compteur = 0; | ||
| + | temps = 0; | ||
| + | vitesseIntantanee = 0.0; | ||
| + | vitesseMax = 0.0; | ||
| + | policeVitesse.load(" | ||
| + | policeDistance.load(" | ||
| + | policeLabel.load(" | ||
| + | distance = 0; | ||
| + | } | ||
| + | |||
| + | // | ||
| + | void Compteur:: | ||
| + | { | ||
| + | ofPushMatrix(); | ||
| + | ofTranslate(x, | ||
| + | ofSetCircleResolution(100); | ||
| + | ofSetLineWidth(3); | ||
| + | // Dessin du compteur | ||
| + | ofPushMatrix(); | ||
| + | ofTranslate(150, | ||
| + | // Aiguille de la vitesse Max | ||
| + | ofSetColor(255, | ||
| + | ofFill(); | ||
| + | ofPushMatrix(); | ||
| + | ofRotateDeg(60 + vitesseMax * 4); | ||
| + | ofDrawTriangle(-6, | ||
| + | ofPopMatrix(); | ||
| + | // Aiguille de la vitesse | ||
| + | ofSetColor(0, | ||
| + | ofPushMatrix(); | ||
| + | ofRotateDeg(60 + vitesseIntantanee * 4); | ||
| + | ofDrawTriangle(-6, | ||
| + | ofPopMatrix(); | ||
| + | // Dessin du cadran | ||
| + | ofSetColor(255, | ||
| + | ofFill(); | ||
| + | ofDrawCircle(0, | ||
| + | ofSetColor(0, | ||
| + | ofNoFill(); | ||
| + | ofDrawCircle(0, | ||
| + | ofDrawCircle(0, | ||
| + | char nombre[3]; | ||
| + | for (int i = 0; i < 61; i += 5) { | ||
| + | ofPushMatrix(); | ||
| + | ofRotateDeg(4 * i - 120); | ||
| + | sprintf(nombre, | ||
| + | policeVitesse.drawString(nombre, | ||
| + | ofDrawLine(0, | ||
| + | ofPopMatrix(); | ||
| + | } | ||
| + | ofSetColor(0, | ||
| + | char labelCompteur[255]; | ||
| + | sprintf(labelCompteur, | ||
| + | policeLabel.drawString(labelCompteur, | ||
| + | ofPopMatrix(); | ||
| + | // Affichage de la distance | ||
| + | ofPushMatrix(); | ||
| + | ofTranslate(320, | ||
| + | ofSetColor(0, | ||
| + | ofFill(); | ||
| + | ofDrawRectangle(00, | ||
| + | ofSetColor(255, | ||
| + | char ligneDistance[255]; | ||
| + | sprintf(ligneDistance, | ||
| + | policeDistance.drawString(ligneDistance, | ||
| + | ofSetColor(0, | ||
| + | char labelDistance[255]; | ||
| + | sprintf(labelDistance, | ||
| + | policeLabel.drawString(labelDistance, | ||
| + | ofPopMatrix(); | ||
| + | ofPopMatrix(); | ||
| + | } | ||
| + | |||
| + | // | ||
| + | void Compteur:: | ||
| + | if (digitalRead(pinTemoin) == 1) { | ||
| + | digitalWrite(pinTemoin, 0); | ||
| + | compteur++; | ||
| uint64_t tempsCourant = ofGetCurrentTime().getAsMilliseconds(); | uint64_t tempsCourant = ofGetCurrentTime().getAsMilliseconds(); | ||
| - | vitesseIntantanee1 | + | vitesseIntantanee |
| - | if (vitesseMax1 | + | if (vitesseMax |
| - | vitesseMax1 | + | vitesseMax |
| } | } | ||
| - | vitesseMoyenne1 = (int)(3.6 * 1000 * ROUE * compteur1) / (tempsCourant - tempsDepart); | + | temps = tempsCourant; |
| - | temps1 | + | |
| } | } | ||
| // 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 | + | vitesseIntantanee |
| } | } | ||
| + | distance = (int)(roue * compteur); | ||
| } | } | ||
| // | // | ||
| - | void ofApp::draw(){ | + | void Compteur::set(uint8_t _pinTemoin, float _roue, uint64_t _tempsDepart) |
| - | ofBackground(100, 100, 100); | + | { |
| - | ofSetColor(255, | + | pinTemoin = _pinTemoin; |
| - | char ligneVitesse[255]; // an array of chars | + | roue = _roue; |
| - | sprintf(ligneVitesse, | + | tempsDepart = _tempsDepart; |
| - | myfont.drawString(ligneVitesse, | + | |
| } | } | ||
| </ | </ | ||
| + | |||
| + | ===== Démarrage automatique ===== | ||
| + | sudo nano / | ||
| + | |||
| + | [Unit] | ||
| + | Description=Met en route le compteur des vélos | ||
| + | | ||
| + | [Service] | ||
| + | Type=simple | ||
| + | WorkingDirectory=/ | ||
| + | ExecStart=/ | ||
| + | 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 / | ||
| + | Ajouter avant la ligne exit 0 | ||
| + | startx ./ | ||
| + | Il faut aussi désactiver les sorties audio par l' | ||
| + | sudo nano / | ||
| + | dtoverlay=vc4-kms-v3d, | ||
| + | |||
| + | {{tag> | ||
projet_europ.1719869163.txt.gz · Dernière modification : de Mushussu
