void Esbe3_safe_shutdown (void) { if ((-1 == GPIOWrite (POUT_INC, 0)) || (-1 == GPIOWrite (POUT_DEC, 0))) { ml_log (LOG_ERROR, "Failed to set both pins to 0"); raise (SIGTERM); } if ((-1 == GPIODirection (POUT_INC, IN)) || (-1 == GPIODirection (POUT_DEC, IN))) { ml_log (LOG_ERROR, "Failed to set both GPIO pins to IN direction"); raise (SIGTERM); } if ((-1 == GPIOUnexport (POUT_INC)) || (-1 == GPIOUnexport (POUT_DEC))) { ml_log (LOG_ERROR, "Failed to unexport both GPIO pins"); raise (SIGTERM); } ml_log (LOG_NOTICE, "Shunt has saftley ended. Bye"); }
C_Flasher_IO_GPIO::~C_Flasher_IO_GPIO() { /* * Disable GPIO pin */ GPIOUnexport(GPIO_OUTPUT_PIN); }
int main(int argc, char *argv[]) { /* * Enable GPIO pins */ if (-1 == GPIOExport(PIN)) return(1); /* * Set GPIO directions */ if (-1 == GPIODirection(PIN, IN)) return(2); while (!terminated) { usleep(500 * 1000); if (GPIORead(PIN) == LOW) { terminated = 1; if (system("shutdown -h now") == -1) fprintf(stderr, "Failed to initiate shutdown!\n"); } } /* * Disable GPIO pins */ if (-1 == GPIOUnexport(PIN)) return(3); return(0); }
int test(int pIn){ int repeat = 10; if (-1 == GPIOExport(POUT) || -1 == GPIOExport(PIN)){ return(1); } if (-1 == GPIODirection(POUT, OUT)){ return(2); } do { if (-1 == GPIOWrite(POUT, repeat % 2)){ return(3); } usleep(100 * 1000); } while (repeat--); if (-1 == GPIOUnexport(POUT)){ return(4); } return(0); }
/** * Turn a pin on and off * @param pout the pin to toggle * @param time how long to hold the pin in milliseconds */ int blinkLED(int pout, int time) { //export pin and set as output if (-1 == GPIOExport(pout)) { return (1); } //delay to allow sysfs to open up gpio files usleep(200 * 1000); if (-1 == GPIODirection(pout, OUT)) { return (2); } if (-1 == GPIOWrite(pout, HIGH)) { return (3); } usleep(1000 * time); if (-1 == GPIOWrite(pout, LOW)) { return (3); } if (-1 == GPIOUnexport(pout)) { return (4); } return (0); }
/** * deinit gpios */ int gpio_deinit() { p_pin pin; int i; // initialize pin for (i = 0; i < config->num_pins; i++) { pin = &(config->pins[i]); if(-1 == GPIOUnexport(pin->number)) { log_message(ERROR, "could not disable GPIO %s", pin->mapname); } } return 0; }
int main(int argc, char *argv[]) { printf("START...\n"); //catch SIGTERM for graceful exit struct sigaction action; memset(&action, 0, sizeof(struct sigaction)); action.sa_handler = term; sigaction(SIGTERM, &action, NULL); printf("INIT GPIO\n"); //Enable GPIO pins if (-1 == GPIOExport(POUT)) return(1); //Set GPIO directions if (-1 == GPIODirection(POUT, OUT)) return(2); while(done == 0) {//while not done... //Write GPIO value printf("ON\n"); if (-1 == GPIOWrite(POUT, HIGH)) return(3); usleep(1000 * 1000); printf("OFF\n"); if (-1 == GPIOWrite(POUT, LOW)) return(3); usleep(1000 * 1000); } //Disable GPIO pins if (-1 == GPIOUnexport(POUT)) return(4); return(0); }
int main(void){ MIDILogo("\n\nDeseja Iniciar o Programa S[1]/N[0] ?\n"); unsigned int iInicia; do{iInicia = getnum();}while((iInicia<0)||iInicia>2); if(iInicia == 1){ printf("Exportando Terminais...\n"); GPIOSetup(colLed[0],SAIDA); GPIOSetup(colLed[1],SAIDA); GPIOSetup(colLed[2],SAIDA); GPIOSetup(colLed[3],SAIDA); GPIOSetup(rowLed[0],SAIDA); GPIOSetup(rowLed[1],SAIDA); GPIOSetup(rowLed[2],SAIDA); GPIOSetup(rowLed[3],SAIDA); GPIOSetup(colBot[0],ENTRADA); GPIOSetup(colBot[1],ENTRADA); GPIOSetup(colBot[2],ENTRADA); GPIOSetup(colBot[3],ENTRADA); GPIOSetup(rowBot[0],SAIDA); GPIOSetup(rowBot[1],SAIDA); GPIOSetup(rowBot[2],SAIDA); GPIOSetup(rowBot[3],SAIDA); printf("Terminais Exportados!!!\n"); pthread_t pBotControl,pSongControl[4]; if(pthread_create(&pBotControl,NULL,buttonVerify,NULL)){ printf("Não Conseguiu Criar a Thread para o Controle dos Botões!\n"); return 0; } struct Argumentos col[4]; for(register unsigned int iCount=0;iCount<4;iCount++){ col[iCount].col = iCount; if(pthread_create(&pSongControl[iCount],NULL,songControl,(void*)&col[iCount])){ printf("Não Conseguiu Criar a Thread %d para o Controle dos Tons!\n",iCount); return 0; } if(iniciar(100,&sFila[iCount])==false){ printf("Problemas ao iniciar a Fila %d!\n",iCount); return 0; } } int iSelec = 10; do{ MIDILogo("\n\nInsira uma Opção:\n"); printf("[1]-Skrillex_-_Bangarang\n"); printf("[2]-Skrillex_-_Cinema\n"); printf("[3]-Skrillex_-_First Of The Year\n"); printf("[4]-Avicii_-_Levels (Skrillex Remix)\n"); printf("[5]-Clássicos dos GAMES\n");//Até a conversão dos sons Para .wav iSelec = getnum();//scanf("%d",&iSelec); if(iSelec == 1) strcpy(TONES_DIR,"Bangarang"); else if(iSelec == 2) strcpy(TONES_DIR,"Cinema"); else if(iSelec == 3) strcpy(TONES_DIR,"FOTY"); else if(iSelec == 4) strcpy(TONES_DIR,"Levels"); else if(iSelec == 5) strcpy(TONES_DIR,"Sons"); else strcpy(TONES_DIR,"Levels"); }while(iSelec != 0); for(register unsigned int iCount=0;iCount<4;iCount++){ encerrar(&sFila[iCount]); if(pthread_cancel(pSongControl[iCount])!=0) printf("Não Cancelou a Thread %d \n",iCount); GPIOUnexport(colLed[iCount]); GPIOUnexport(colBot[iCount]); GPIOUnexport(rowLed[iCount]); GPIOUnexport(rowBot[iCount]); } return EXIT_SUCCESS; }else return EXIT_SUCCESS; }