Outils pour utilisateurs

Outils du site


failomaton

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
failomaton [2024/04/05 19:36] – [Reconnaissance de la clef] Mushussufailomaton [2024/04/06 00:16] (Version actuelle) – [Code C pour la Raspberry Pi] Mushussu
Ligne 306: Ligne 306:
 ==== Code C pour la Raspberry Pi ==== ==== Code C pour la Raspberry Pi ====
 <code c> <code c>
-// gcc -Wall -o test test.c -lwiringPi+// g++ -Wall -o test `cups-config --cflags` test.c `cups-config --libs` -lwiringPi
  
 #include <dirent.h> #include <dirent.h>
Ligne 318: Ligne 318:
 #include <stdlib.h> #include <stdlib.h>
 #include <sys/wait.h> #include <sys/wait.h>
 +#include <cups/cups.h>
 +
 +#include <string>
 +#include <iostream>
 +
 +#define boutonPhoto 26 // Fil rouge
 +#define vibrationArduino 27 // Fil vert
 +#define declenchementArduino 28 // Fil jaune
 +#define monnayeur 29 // Fil blanc
  
-#define declenchementArduino 16 
-#define vibrationArduino 7 
 int nbPhotos = 0; int nbPhotos = 0;
 time_t compteurTemps; time_t compteurTemps;
Ligne 326: Ligne 333:
 static pid_t pidProcedure = 0; static pid_t pidProcedure = 0;
 static pid_t pidPhoto = 0; static pid_t pidPhoto = 0;
 +static pid_t pidAssistance = 0;
 +
 int attente = 0; int attente = 0;
 int procedure = 0; int procedure = 0;
Ligne 339: Ligne 348:
          s[j] = c;          s[j] = c;
      }      }
- +} 
 void itoa(int n, char s[]) void itoa(int n, char s[])
  {  {
Ligne 354: Ligne 364:
      s[i] = '\0';      s[i] = '\0';
      reverse(s);      reverse(s);
-+}
  
 void photo() { void photo() {
Ligne 367: Ligne 377:
             if((pidProcedure = fork()) == 0)             if((pidProcedure = fork()) == 0)
             {             {
-                execl("/usr/bin/mplayer",  +                execl("/usr/bin/mplayer", 
-                    "/usr/bin/mplayer",  +                    "/usr/bin/mplayer", 
-                    "-really-quiet",  +                    "-really-quiet", 
-                    "-loop", "0",  +                    "-loop", "0", 
-                    "/home/pi/Audio/Procedure.wav",  +                    "/media/usb/Audio/Procedure.wav", 
-                    NULL);    +                    NULL);
             }             }
             sleep(13);             sleep(13);
Ligne 383: Ligne 393:
             if((pidPhoto = fork()) == 0)             if((pidPhoto = fork()) == 0)
             {             {
-                execl("/usr/bin/mplayer",  +                execl("/usr/bin/mplayer", 
-                    "/usr/bin/mplayer",  +                    "/usr/bin/mplayer", 
-                    "-really-quiet",  +                    "-really-quiet", 
-                    "-loop", "0",  +                    "-loop", "0", 
-                    "/home/pi/Audio/Photo.wav",  +                    "/media/usb/Audio/Photo.wav", 
-                    NULL);    +                    NULL);
             }             }
             sleep(5);             sleep(5);
             char buffer [6];             char buffer [6];
             itoa(nbPhotos, buffer);             itoa(nbPhotos, buffer);
-            char src[40] = "/home/pi/Photos/photo_" ;+            char src[40] = "/media/usb/Photos/photo_" ;
             strcat(src, buffer);             strcat(src, buffer);
             strcat(src, ".jpg");             strcat(src, ".jpg");
Ligne 401: Ligne 411:
             static pid_t pid = 0;             static pid_t pid = 0;
             if ((pid = fork()) == 0)             if ((pid = fork()) == 0)
-            {   +            {
                 // libcamera-jpeg -o photo_0.jpg -c config.txt                 // libcamera-jpeg -o photo_0.jpg -c config.txt
-                execl("/usr/bin/libcamera-jpeg",  +                execl("/usr/bin/libcamera-jpeg", 
-                    "",  +                    "", 
-                    "-o", src,  +                    "-o", src
-                    "-c", "config.txt", + "--shutter", "800000"
 +                    "-c", "config.txt",
                     NULL);                     NULL);
             }             }
Ligne 419: Ligne 430:
             static pid_t pid1 = 0;             static pid_t pid1 = 0;
             if ((pid1 = fork()) == 0)             if ((pid1 = fork()) == 0)
-            {   +            {
                 // convert -crop 3836x2592+386+0 -rotate -90 Photos/photo_0.jpg Photos/photo1.jpg                 // convert -crop 3836x2592+386+0 -rotate -90 Photos/photo_0.jpg Photos/photo1.jpg
                 execl(                 execl(
-                    "/usr/bin/convert",  +                    "/usr/bin/convert", 
-                    "",  +                    "", 
-                    "-crop",  +                    "-crop", 
-                    "3836x2592+386+0",  +                    "3836x2592+386+0", 
-                    "-rotate", "90",  +                    "-rotate", "90", 
-                    src, src, +                    src, src,
                     NULL);                     NULL);
             }             }
             sleep(2);             sleep(2);
 +            //const char *filename = "photo.jpg";
  
-            static pid_t pid2 = 0+            // Impression de la photo 
-            if ((pid2 fork()) == 0) +            http_t *http
-            {    +            ipp_t *request, *response; 
-                // convert -crop 3836x2592+386+0 -rotate -90 Photos/photo_0.jpg Photos/photo1.jpg + 
-                execl("/usr/bin/lp",  +            static const char * const requested_attributes[] 
-                    "",  +            { 
-                    "-d",  +                "printer-description", 
-                    "Canon_SELPHY_CP1300",  +                "job-template", 
-                    src,  +                "media-col-database" 
-                    NULL); +            }; 
-            } +            http = httpConnect2("localhost", 631, NULL, AF_UNSPEC, HTTP_ENCRYPTION_IF_REQUESTED, 1, 30000, NULL); 
-  + 
-           sleep(12);+            request = ippNewRequest(IPP_OP_PRINT_JOB); 
 +            ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, "ipp://localhost/printers/Canon_SELPHY_CP1300"); 
 +            ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, "pi"); 
 +            ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE, "document-format", NULL"image/jpeg"); 
 +            ippAddString(request, IPP_TAG_JOB, IPP_TAG_KEYWORD, "media", NULL, "jpn_hagaki_100x148mm"); 
 +            ippDelete(cupsDoFileRequest(http, request, "/ipp/print", src)); 
 +            sleep(17);
             kill(pidPhoto, SIGTERM);             kill(pidPhoto, SIGTERM);
 +
 +            // Test si il manque du papier
 +            ipp_attribute_t *attr;
 +            char value[2048];
 +            // Procedure
 +            uint8_t erreur;
 +            uint8_t assistance = 0;
 +            do {
 +                erreur = 0;
 +                request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES);
 +                ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, "ipp://localhost/printers/Canon_SELPHY_CP1300");
 +                ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE, "document-format", NULL, "image/pwg-raster");
 +                ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "requested-attributes", (int)(sizeof(requested_attributes) / sizeof(requested_attributes[0])), NULL, requested_attributes);
 +
 +                response = cupsDoRequest(http, request, "/ipp/print");
 +                for (attr = ippFirstAttribute(response); attr; attr = ippNextAttribute(response))
 +                {
 +                    if (strcmp(ippGetName(attr), "printer-state-reasons") == 0)
 +                    {
 +                        ippAttributeString(attr, value, sizeof(value));
 +                        std::string valeur(value);
 +                        std::size_t erreurCartouche = valeur.find("marker-supply-empty-error");
 +                        std::size_t erreurPapier = valeur.find("media-empty-error");
 +                        if (erreurCartouche <= 2048)
 +                        {
 +                            // Plus d'encre
 +                            erreur = 1;
 +                            if (assistance == 0) {
 +                                printf("Assistance\n");
 +
 +                                assistance = 1;
 +                                if((pidAssistance = fork()) == 0)
 +                                {
 +                                    execl("/usr/bin/mplayer",
 +                                    "/usr/bin/mplayer",
 +                                    "-really-quiet",
 +                                    "-loop", "0",
 +                                    "/media/usb/Audio/AssistanceCartouche.wav",
 +                                    NULL);
 +                                }
 +                            }
 +                        }
 +                        if (erreurPapier <= 2048)
 +                        {
 +                            // Plus de papier
 +                            erreur = 2;
 +                            if (assistance == 0) {
 +                                printf("Assistance\n");
 +
 +                                assistance = 1;
 +
 +                                if((pidAssistance = fork()) == 0)
 +                                {
 +                                    execl("/usr/bin/mplayer",
 +                                    "/usr/bin/mplayer",
 +                                    "-really-quiet",
 +                                    "-loop", "0",
 +                                    "/media/usb/Audio/AssistancePapier.wav",
 +                                    NULL);
 +                                }
 +                            }
 +                        }
 +                    }
 +                }
 +                sleep(3);
 +            } while (erreur != 0);
 +
 +            if (assistance != 0) {
 + kill(pidAssistance, SIGTERM);
 +        }
             printf("Fin Photo\n");             printf("Fin Photo\n");
             procedure = 0;             procedure = 0;
Ligne 456: Ligne 544:
 { {
     wiringPiSetup();     wiringPiSetup();
-    pinMode (15, INPUT); // Pin de l'interrupteur +    pinMode (boutonPhoto, INPUT); // Pin de l'interrupteur 
-    pullUpDnControl(15, PUD_UP); +    pullUpDnControl(boutonPhoto, PUD_UP); 
-//    wiringPiISR (15, INT_EDGE_FALLING, &photo); +    pinMode (monnayeur, INPUT); // Pin du monnayeur 
-//    pinMode (25, INPUT); // Pin du Monnayeur +    pullUpDnControl(monnayeur, PUD_UP); 
-  //  pullUpDnControl(25, PUD_UP); + 
- // +    //   wiringPiISR (25, INT_EDGE_FALLING, &monnayeur);
-//   wiringPiISR (25, INT_EDGE_FALLING, &monnayeur);+
     pinMode (declenchementArduino, OUTPUT); // Pin de déclenchement de l'arduino     pinMode (declenchementArduino, OUTPUT); // Pin de déclenchement de l'arduino
     pinMode (vibrationArduino, OUTPUT); // Pin de déclenchement de l'arduino     pinMode (vibrationArduino, OUTPUT); // Pin de déclenchement de l'arduino
     compteurTemps = time(NULL);     compteurTemps = time(NULL);
 +
     // Comptage des fichiers     // Comptage des fichiers
     struct dirent *dir;     struct dirent *dir;
-    DIR *d = opendir("/home/pi/Photos/"); +    DIR *d = opendir("/media/usb/Photos/");
     if (d)     if (d)
     {     {
-        while ((dir = readdir(d)) != NULL) +        while ((dir = readdir(d)) != NULL)
         {         {
             if (dir->d_name[0] != '.')             if (dir->d_name[0] != '.')
Ligne 482: Ligne 570:
     }     }
     // Efface tous les travaux d'impression en cours     // Efface tous les travaux d'impression en cours
-    system("cancel -a -x") +    system("cancel -a -x");
-;+
     while(1) {     while(1) {
         if (attente == 0)         if (attente == 0)
Ligne 489: Ligne 576:
             attente = 1;             attente = 1;
             printf("Invitation\n");             printf("Invitation\n");
 +            // Message d'attente
             if ((pidAttente = fork()) == 0)             if ((pidAttente = fork()) == 0)
             {             {
-                execl("/usr/bin/mplayer",  +                execl("/usr/bin/mplayer", 
-                    "/usr/bin/mplayer",  +                    "/usr/bin/mplayer", 
-                    "-really-quiet",  +                    "-really-quiet", 
-                    "-loop", "0",  +                    "-loop", "0", 
-                    "/home/pi/Audio/Attente.wav",  +                    "/media/usb/Audio/Attente.wav", 
-                    NULL);    +                    NULL);
             }             }
         }         }
-        if ((digitalRead(15) == 0) && (attente == 1)) {+        if ((digitalRead(monnayeur) == 0) && (attente == 1) &&  (procedure == 0)) { 
 +             photo(); 
 +        } 
 +        if ((digitalRead(boutonPhoto) == 0) && (attente == 1) &&  (procedure == 1)) {
              photo();              photo();
         }         }
failomaton.txt · Dernière modification : 2024/04/06 00:16 de Mushussu