Ceci est une ancienne révision du document !
Table des matières
Vélos interactifs
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”
Installation du driver FTDI
Tous les boîtiers ENTTEC utilisent une puce FTDI pour la communications à travers le port USB. Voici la procédure pour l'installer sur une RPI4 :
wget https://ftdichip.com/wp-content/uploads/2022/07/libftd2xx-arm-v8-1.4.27.tgz tar -xvf libftd2xx-arm-v8-1.4.27.tgz sudo cp release/build/lib* /usr/local/lib cd /usr/local/lib ls sudo ln -s libftd2xx.so.1.4.27 libftd2xx.so sudo chmod 0755 libftd2xx.so.1.4.27
Brancher le boîtier ENTTEC
sudo rmmod ftdi_sio sudo rmmod usbserial cd cd release/examples make cd EEPROM/read ls sudo ./read
Installation du addon ofxGenericDmx
Installation de la librairie ftdi :
sudo apt-get install libftdi-dev
Pour certaines distributions, il pourrait être nécessaire d'autoriser l'utilisateur à accéder à l'interface via son port USB. Des solutions diverses sont détaillées ici
wget https://github.com/woutgg/ofxGenericDmx/archive/refs/heads/master.zip cd openFrameworks/addons/ofxGenericDmx/ofxGenericDmx_EnttecDmxUsbProExample make startx ./bin/ofxGenericDmx_EnttecDmxUsbProExample -- -s off
Si vous souhaitez partir d'un projet vierge, il faudra ajouter des instructions pour le linker lors de la compilation : Dans le fichier config.make du projet :
sudo nano config.make
Vérifiez les lignes suivantes :
PROJECT_LDFLAGS=-Wl,-rpath=./libs PROJECT_LDFLAGS+=-lftdi
Code
// g++ -Wall -o compteur compteur.c -l wiringPi // ./compteur #include <wiringPi.h> #include <stdio.h> #include <stdlib.h> #define COMPTEUR 26 #define TEMOIN 19 int drapeau = 0; int main() { wiringPiSetupGpio(); pinMode (COMPTEUR, INPUT); pullUpDnControl(COMPTEUR, PUD_UP); pinMode (TEMOIN, OUTPUT); digitalWrite(TEMOIN, LOW); while(1) { if ((digitalRead(COMPTEUR) == LOW) && (drapeau == 0)) { digitalWrite(TEMOIN, HIGH); delay(20); drapeau = 1; } if (digitalRead(COMPTEUR) == HIGH) { drapeau = 0; } } return 0; }
ofApp.h
#pragma once #include "ofMain.h" #include "ofxGenericDmx.h" #include "ofUtils.h" //#include "ofGraphics.h" #include <wiringPi.h> #define DMX_DATA_LENGTH 513 #define TEMOIN 19 #define ROUE 2.27 class ofApp : public ofBaseApp{ public: void setup(); void update(); 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 DmxDevice* dmxInterface_; //our DMX packet (which holds the channel values + 1st byte for the start code) unsigned char dmxData_[DMX_DATA_LENGTH]; ofTrueTypeFont myfont; };
ofApp.cpp
#include <stdlib.h> #include "ofApp.h" uint64_t tempsDepart; int compteur1; uint64_t temps1; uint8_t vitesseIntantanee1; uint8_t vitesseMax1; uint8_t vitesseMoyenne1; //-------------------------------------------------------------- void ofApp::setup(){ ofSetFrameRate( 44 ); //zero our DMX value array memset( dmxData_, 0, DMX_DATA_LENGTH ); //open the device dmxInterface_ = ofxGenericDmx::openFirstDevice(); if ( dmxInterface_ == 0 ) printf( "No Enttec Device Found\n" ); else printf( "isOpen: %i\n", dmxInterface_->isOpen() ); //frames = 0; printf("ofxGenericDmx addon version: %s.%s\n", ofxGenericDmx::VERSION_MAJOR, ofxGenericDmx::VERSION_MINOR); // Initialisation valeurs compteur1 = 0; temps1 = 0; tempsDepart = ofGetCurrentTime().getAsMilliseconds() ; vitesseIntantanee1 = 0; vitesseMax1 = 0; // Affichage myfont.load("arial.ttf", 32); // WiringPi wiringPiSetupGpio(); } //-------------------------------------------------------------- void ofApp::update(){ dmxData_[401] = 80; dmxData_[402] = 160; dmxData_[403] = 255; //force first byte to zero (it is not a channel but DMX type info - start code) dmxData_[0] = 0; if ( ! dmxInterface_ || ! dmxInterface_->isOpen() ) { printf( "Not updating, enttec device is not open.\n"); } else{ //send the data to the dmx interface dmxInterface_->writeDmx( dmxData_, DMX_DATA_LENGTH ); } // Calcul coureur 1 if (digitalRead(TEMOIN) == 1) { digitalWrite(TEMOIN, 0); compteur1++; uint64_t tempsCourant = ofGetCurrentTime().getAsMilliseconds(); vitesseIntantanee1 = (int)(3.6 * 1000 * ROUE) / (tempsCourant - temps1); if (vitesseMax1 < vitesseIntantanee1) { vitesseMax1 = vitesseIntantanee1; } vitesseMoyenne1 = (int)(3.6 * 1000 * ROUE * compteur1) / (tempsCourant - tempsDepart); temps1 = tempsCourant; } // Mise à zéro de la vitesse si la roue est arrêtée if ((ofGetCurrentTime().getAsMilliseconds() - temps1) > 8000) { vitesseIntantanee1 = 0; } } //-------------------------------------------------------------- void ofApp::draw(){ ofBackground(100, 100, 100); ofSetColor(255,0,0); char ligneVitesse[255]; // an array of chars sprintf(ligneVitesse, "Vitesse : %i Moyenne : %i", vitesseIntantanee1, vitesseMoyenne1); myfont.drawString(ligneVitesse, 100,100); }
