/* * ActionPi.cpp * Version 1.02 * IT-Hardware Projekt GWS-Bühl * Copyright 2016 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * *zum kompilieren ---> g++ -Wall "%f" -o"%e" -l raspicam -l bcm2835 -std=c++0x *oder---> g++ -Wall "%f" -o"%e" -l raspicam -l bcm2835 -std=c++14 */ #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; string gibDateiName(); string getFolderName(); void videoAufnehmen(); int fotoAufnehmen(); void liveAusgabe(); void videoAbspeichern(); void initialisierung(); void blinken(); void herunterfahren(); void programmBeenden(); void convert(); void creatNewFolder(); void creatDCIM(); bool ordnerExistiert(string pfad); void pruefeNewFolder(string input); void rueckschau(string input); void setStandardWerte(); void einstellungen(); void einstellungErhoehen(); void einstellungVerringern(); void zuruecksetzten(); void iso(int richtung); void helligkeit(int richtung); void kontrast(int richtung); void saettigung(int richtung); void verschlusszeit(int richtung); void setISO ( int iso ); void setBrightness ( unsigned int brightness ); void setContrast ( int contrast ); void setSaturation ( int saturation ); void setExposureCompensation ( int val ); void setShutterSpeed ( unsigned int ss ); int getMODI(); int getREC(); int getEx1(); int getEx2(); int getEx3(); #define LED RPI_V2_GPIO_P1_13 #define MODI RPI_V2_GPIO_P1_22 #define REC RPI_V2_GPIO_P1_18 #define Ex1 RPI_V2_GPIO_P1_16 #define Ex2 RPI_V2_GPIO_P1_15 #define Ex3 RPI_V2_GPIO_P1_11 int valMODI; int valREC; int valEx1; int valEx2; int valEx3; int valISO; int valHelligkeit; int valKontrast; int valSaettigung; int valVerschlusszeit; int zaehlerISO = 1; int zaehlerHelligkeit = 1; int zaehlerKontrast = 1; int zaehlerSaettigung = 2; int zaehlerVerschlusszeit = 4; int einstellung = 0; // 0=Verschlusszeit;1=ISO;2=Kontrast;3=Helligkeit;4=Sättigung; int wieLangeGedrueckt = 0; bool aktiv = true; bool videoAufnahme = false; bool liveBildWirdAngezeigt = false; int main(int argc, char **argv) { creatDCIM(); //prüft ob DCIM Ordner existiert, sollt er nicht existieren wird er erstellt creatNewFolder(); //prüft ob Datums-Ordner existiert, sollt er nicht existieren wird er erstellt if (!bcm2835_init()) return 1; initialisierung(); setStandardWerte(); while (aktiv) { if(videoAufnahme && getMODI() ) { videoAbspeichern(); } if(!liveBildWirdAngezeigt) { liveAusgabe(); // Live-Ausgabe wird gestartet } if(getREC()) { //REC Taster gedrückt if(getMODI()) { //Fotomodus fotoAufnehmen(); } else{ //Videomodus if(!videoAufnahme) { videoAufnehmen(); delay(1000); // mindestens 1sec Video } else{ videoAbspeichern(); } } } if(getMODI()){ // Eindtellungen nur im Fotomodus einstellungen(); einstellungErhoehen(); einstellungVerringern(); zuruecksetzten(); } delay(100); programmBeenden(); // prüft ob das Programm beendet werden soll herunterfahren(); // prüft ob der Pi heruntergefahren werden soll } //while Ende bcm2835_close(); return 0; } //setzt Fotoeinstellungen zurück void zuruecksetzten() { if(getEx2()){ if(wieLangeGedrueckt < 20){ wieLangeGedrueckt = wieLangeGedrueckt +1; //cout<tm_hour; //holen der Stunden int imin = aT->tm_min; //holen der Minuten int isec = aT->tm_sec; //holen der Sekunden std::string sstd = to_string(istd); //in String konvertieren std::string smin = to_string(imin); std::string ssec = to_string(isec); std::string datName = sstd + "-" + smin + "-" + ssec + "ActionPi"; //zu einem String zusammenfügen return datName; } //erstellen des neuen Ordners void creatNewFolder() { std::string folderName = getFolderName(); //holen des Ordnernamen std::string pfad = "/media/usb0/DCIM/" + folderName; //Pafd des Ordners bool exists = ordnerExistiert(pfad); //prüfen ob Ordner existiert if(exists == false) //wenn nein dann neuen Ordner erstellen { std::string comand = "mkdir " + pfad + ""; //Befehl zum erstellen des Ordners const char *cComand = comand.c_str(); system(cComand); cout << "Ordner erstellt." << endl; } else //falls Ordner bereits vorhanden { cout << "Ordner existiert bereits." << endl; } return; } //erstellen des DCIM Ordners void creatDCIM() { std::string dcmiPfad = "/media/usb0/DCIM"; bool dcmiExists = ordnerExistiert(dcmiPfad); if(dcmiExists == false){ std::string dcmiComand = "mkdir /media/usb0/DCIM"; const char *dcmicComand = dcmiComand.c_str(); system(dcmicComand); cout << "DCIM Ordner erstellt." << endl; } else { cout << "DCIM existiert bereits." << endl; } } //prüft ob Ordner/DCIM bereits existiert bool ordnerExistiert(string pfad) { const char *cPfad = pfad.c_str(); DIR *pDir; //Verzeichniss wird auf aktuellen Pfad gesetzt bool oExists = false; pDir = opendir(cPfad); //öffnen des Pfades if(pDir != NULL) //falls Ordner unter dem aktuellen Pfad vorhanden pDIR ungleich NULL { oExists = true; closedir(pDir); //schließen des Ordners } return oExists; } //prüft ob Ordner bereits existiert (wird gebraucht sollt die Kamera länger als 0.00 Uhr in Betrieb sein "0 Uhr Bug") void pruefeNewFolder(string input) { std::string pfad = "/media/usb0/DCIM/" + input; bool newFolderExists = ordnerExistiert(pfad); if(newFolderExists == false) { creatNewFolder(); } else { } return; } //erstellt den Ordnernamen aus der auktuellen Uhrzeit (siehe gibDateiName) string getFolderName() { char *wtagName[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; char *monatName[] = { "Dec", "Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov" }; time_t t = time(0); struct tm *aT = localtime(&t); int tag = aT->tm_mday; int wtag = aT->tm_wday; int monat = aT->tm_mon; std::string stag = std::to_string(tag); std::string tagumonat = std::string() + wtagName[wtag] + "-" + monatName[monat]; std::string folName = tagumonat + "-" + stag; return folName; } void initialisierung() { bcm2835_gpio_fsel(LED, BCM2835_GPIO_FSEL_OUTP); //Setze LED als Ausgang bcm2835_gpio_fsel(MODI, BCM2835_GPIO_FSEL_INPT); //Setze MODI als Eingang bcm2835_gpio_fsel(REC, BCM2835_GPIO_FSEL_INPT); //Setze REC als Eingang bcm2835_gpio_fsel(Ex1, BCM2835_GPIO_FSEL_INPT); //Setze Ex1 als Eingang bcm2835_gpio_fsel(Ex2, BCM2835_GPIO_FSEL_INPT); //Setze Ex2 als Eingang bcm2835_gpio_fsel(Ex3, BCM2835_GPIO_FSEL_INPT); //Setze Ex3 als Eingang bcm2835_gpio_set_pud(MODI, BCM2835_GPIO_PUD_UP); //Schalter als Öffner bcm2835_gpio_set_pud(REC, BCM2835_GPIO_PUD_UP); //Schalter als Öffner bcm2835_gpio_set_pud(Ex1, BCM2835_GPIO_PUD_UP); //Schalter als Öffner bcm2835_gpio_set_pud(Ex2, BCM2835_GPIO_PUD_UP); //Schalter als Öffner bcm2835_gpio_set_pud(Ex3, BCM2835_GPIO_PUD_UP); //Schalter als Öffner return; } //liest die Schalterstellung von MODI ein int getMODI() { valMODI = !bcm2835_gpio_lev(MODI); return valMODI; } //liest die Schalterstellung von REC ein int getREC() { valREC = !bcm2835_gpio_lev(REC); return valREC; } //liest die Schalterstellung von Ex1 ein int getEx1() { valEx1 = !bcm2835_gpio_lev(Ex1); return valEx1; } //liest die Schalterstellung von Ex2 ein int getEx2() { valEx2 = !bcm2835_gpio_lev(Ex2); return valEx2; } //liest die Schalterstellung von Ex3 ein int getEx3() { valEx3 = !bcm2835_gpio_lev(Ex3); return valEx3; } //lässt die Status-LED 10 mal blinken void blinken() { for(int i=0; i<10; i++) { bcm2835_gpio_set(LED); delay(100); bcm2835_gpio_clr(LED); delay(50); } return; } //Herunterfahren der Kamera bei gleizeitgem drücken des REC Knopfes und der mittleren Funktionstaste void herunterfahren() { if(getREC() && getEx2()) { cout << "Herunterfahren" << endl; system("killall raspivid"); blinken(); system("sudo shutdown -h now "); } return; } //beenden des Kameraprogramms bei gleichzeitigen drücken der äußeren Funktionstasten void programmBeenden() { if(getEx3() && getEx1()) { aktiv = false; // Merker für while-Schleife system("killall raspivid"); blinken(); } return; }