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"); }
void RelayPoll (sRelay* relay) { // если задан период включения if(relay->periodOn) { // если пришло время нового периода включения if(globalTimer - relay->startOn >= relay->periodOn) { relay->startOn = globalTimer; GPIOWrite(relay->onLevel, relay->gpio); } // если время включения в этом периоде вышло else if(globalTimer - relay->startOn >= relay->timeOn) GPIOWrite(!relay->onLevel, relay->gpio); } // если задано время включения else if(relay->timeOn) // если время включения вышло if((globalTimer - relay->startOn) >= relay->timeOn) { GPIOWrite(!relay->onLevel, relay->gpio); relay->timeOn = 0; } }
void init_esbe3_drv () { /* * Export digital pin for "slow-PWM" */ if ((-1 == GPIOExport (POUT_INC)) || (-1 == GPIOExport (POUT_DEC))) { ml_log (LOG_ERROR, "Failed to export GPIO pins"); raise (SIGTERM); } /* * Set GPIO directions */ if ((-1 == GPIODirection (POUT_INC, OUT)) || (-1 == GPIODirection (POUT_DEC, OUT))) { ml_log (LOG_ERROR, "Failed to set GPIO pins as output"); raise (SIGTERM); } if ((-1 == GPIOWrite (POUT_INC, 0)) || (-1 == GPIOWrite (POUT_INC, 0))) { ml_log (LOG_ERROR, "Error reading %s, errno =%d, rasing SIGTERM"); raise (SIGTERM); } }
/** * 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); }
/***************************************************************************************8*/ int write_cmd(unsigned char cmd) { unsigned char temp=0,i=0; int gpio_arr[4] = {GP0,GP1,GP2,GP3}; if (-1 == GPIOWrite(STB, HIGH)) //Make strobe pin high return(3); if (-1 == GPIODirection(GP0, OUT) || -1 == GPIODirection(GP1, OUT) || -1 == GPIODirection(GP2, OUT) || -1 == GPIODirection(GP3, OUT)) return(2); temp = cmd; for(i=0;i<4;i++) { if((temp & 0x01) == 1) { GPIOWrite(gpio_arr[i], HIGH); } else { GPIOWrite(gpio_arr[i], LOW); } temp = temp >> 1; } usleep(10000); if (-1 == GPIOWrite(STB, LOW)) //Make strobe pin low return(0); }
void *buttonVerify(){ while(1){ for(register unsigned int iRow = 0 ; iRow < 4 ; iRow++){ for(register unsigned int iCol = 0; iCol < 4; iCol++){ GPIOWrite(rowBot[iRow],HIGH); if(GPIORead(colBot[iCol])==HIGH){ while(GPIORead(colBot[iCol])==HIGH){} push(iRow,iCol,&sFila[iCol]); } } GPIOWrite(rowBot[iRow],LOW); } } }
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); }
void Esbe3_adjust (esbe3_adjust_t action) { /* Only allowed to adjust in IDLE state */ switch (action) { case ESBE3_STEP_INCREASE: ml_log (LOG_NOTICE, "Increasing shunt ... "); if (-1 == GPIOWrite (POUT_INC, 1)) { ml_log (LOG_ERROR, "Failed to set pin %d to 1", POUT_INC); raise (SIGTERM); } break; case ESBE3_STEP_DECREASE: ml_log (LOG_NOTICE, "Decreasing shunt ... "); if (-1 == GPIOWrite (POUT_DEC, 1)) { ml_log (LOG_ERROR, "Failed to set pin %d to 1", POUT_DEC); raise (SIGTERM); } break; default: /* panic(); */ break; } if (action != m_last_action) { sleep (ESBE3_CHANGE_DIR_LAG_TIME); } sleep (ESBE3_STEP_TIME); if ((-1 == GPIOWrite (POUT_INC, 0)) || (-1 == GPIOWrite (POUT_DEC, 0))) { ml_log (LOG_ERROR, "Failed to set pin both PGIO pins to 0 after increas/decrease"); raise (SIGTERM); } ml_log (LOG_NOTICE, "... done."); m_last_action = action; }
int read_data(void) { unsigned char data=0; if (-1 == GPIOWrite(STB, HIGH)) //Make strobe pin high return(1); if (-1 == GPIODirection(GP0, IN) || -1 == GPIODirection(GP1, IN) || -1 == GPIODirection(GP2, IN) || -1 == GPIODirection(GP3, IN)) return(2); usleep(1000); data = (GPIORead(GP0) | (GPIORead(GP1) << 1) | (GPIORead(GP2) << 2) | (GPIORead(GP3) << 3)); if (-1 == GPIOWrite(STB, LOW)) //Make strobe pin low return(3); return data; }
int main(void){ for(int cont =0;cont < 3; cont++){ GPIOExport(linha[cont]); GPIODirection(linha[cont],SAIDA); } for(int cont =0;cont < 4; cont++){ GPIOExport(coluna[cont]); GPIODirection(coluna[cont],SAIDA); } while(1){ for(int cont = 0 ; cont < 4 ; cont++){ for(int cont1 = 0 ; cont1 < 3;cont1++){ GPIOWrite(coluna[cont],HIGH); GPIOWrite(linha[cont1],HIGH); delay_s(1); GPIOWrite(linha[cont1],LOW); } GPIOWrite(coluna[cont],LOW); } } }
int reset(void) { //syslog(LOG_INFO,"Micro chip Reset...\n"); if (-1 == GPIOWrite(RST, 0)) { //syslog(LOG_INFO,"Error in Reset...\n"); return(3); } usleep(10000); if (-1 == GPIOWrite(RST, 1)) { //syslog(LOG_INFO,"Error in Reset...\n"); return(3); } if (-1 == GPIOWrite(OE, 1)) { //syslog(LOG_INFO,"Error in Reset...\n"); return(3); } }
void RelaySetPeriodOn (uint32_t time, uint32_t period, sRelay* relay) { // если время включения меньше всего периода if(time < period) { // если до этого переключатель не был в данном режиме if(!relay->periodOn) GPIOWrite(relay->onLevel, relay->gpio); relay->timeOn = time; relay->periodOn = period; } }
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); }
bool CGpio::WriteToHardware(const char *pdata, const unsigned char length) { const tRBUF *pSen = reinterpret_cast<const tRBUF*>(pdata); int pin = pSen->LIGHTING1.unitcode; for(std::vector<CGpioPin>::iterator it = pins.begin(); it != pins.end(); ++it) { if (it->GetPin() == pin && !it->GetIsInput()) { unsigned char packettype = pSen->ICMND.packettype; if (packettype == pTypeLighting1) { GPIOWrite(pin, (pSen->LIGHTING1.cmnd == light1_sOn)); return true; } } } return false; }
int main(int argc, char *argv[]) { unsigned char in_ch=0,get_nib=0; pthread_t uit,sit,cit; char hostname[15],pass[10],grp[12],stat[10]; http.host = &hostname[0]; http.password = &pass[0]; http.name = &grp[0]; http.status = &stat[0]; strcpy(hostname,"129.63.205.75"); http.port = 8000; http.id =2 ; strcpy(pass,"gkrd"); strcpy(grp,"microex"); strcpy(stat,"OK"); init_rtc(); if (-1 == GPIOExport(STB) || -1 == GPIOExport(GP0) || -1 == GPIOExport(GP1) || -1 == GPIOExport(GP2) || -1 == GPIOExport(GP3)) return(1); /* * Set GPIO directions */ if (-1 == GPIODirection(STB, OUT)) return(2); GPIOWrite(STB, LOW); printf("\n intializing processes .... ") ; pthread_create(&uit,NULL,UI_thread,NULL); pthread_create(&sit,NULL,sense_thread,NULL); pthread_create(&cit,NULL,client_thread,NULL); pthread_join(uit,NULL); pthread_join(sit,NULL); pthread_join(cit,NULL); return(4); }
void RelayOff (sRelay* relay) { RelayProcessOff(relay); GPIOWrite(!relay->onLevel, relay->gpio); }
static void transfer(int fd, uint8_t * message, size_t message_size) { int ret; sleep(.5); GPIOWrite(CEPIN, 0); sleep(.5); uint8_t rx[message_size]; printf("Array size %i \n", message_size); struct spi_ioc_transfer tr = { .tx_buf = (unsigned long)message, .rx_buf = (unsigned long)rx, .len = message_size, .delay_usecs = delay, .speed_hz = speed, .bits_per_word = bits, }; ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr); sleep(3); GPIOWrite(CEPIN, 1); sleep(.5); } int main(int argc, char *argv[]) { /* * Enable GPIO pins */ if (-1 == GPIOExport(CEPIN)) return(1); /* * Set GPIO directions */ if (-1 == GPIODirection(CEPIN, OUT)) return(2); // Reset VGATonic to ensure we are at pixel 0,0 sleep(.5); GPIOWrite(CEPIN, 1); sleep(.5); GPIOWrite(CEPIN, 0); sleep(.5); GPIOWrite(CEPIN, 1); sleep(.5); GPIOWrite(CEPIN, 0); sleep(.5); GPIOWrite(CEPIN, 1); sleep(.5); int ret = 0; int fd; fd = open(device, O_RDWR); if (fd < 0) pabort("can't open device"); /* * spi mode */ ret = ioctl(fd, SPI_IOC_WR_MODE, &mode); if (ret == -1) pabort("can't set spi mode"); ret = ioctl(fd, SPI_IOC_RD_MODE, &mode); if (ret == -1) pabort("can't get spi mode"); /* * bits per word */ ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits); if (ret == -1) pabort("can't set bits per word"); ret = ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits); if (ret == -1) pabort("can't get bits per word"); /* * max speed hz */ ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed); if (ret == -1) pabort("can't set max speed hz"); ret = ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed); if (ret == -1) pabort("can't get max speed hz"); printf("spi mode: %d\n", mode); printf("bits per word: %d\n", bits); printf("max speed: %d Hz (%d KHz)\n", speed, speed/1000); while (1) { transfer(fd, doge, 307200); transfer(fd, guitars, 307200); } close(fd); return ret; }
int main(void) { uint16_t bits; uint32_t intval = 40; uint32_t tnow; char tmp[92]; RCC_ClocksTypeDef RCC_Clocks; uint16_t i; TIM2_timer_start(); usart_begin(&USerial3, USART3, PC11, PC10, 19200); usart_print(&USerial3, "Happy are those who know they are spiritually poor; \n" "The kingdom of heaven belongs to them!\n"); usart_flush(&USerial3); RCC_GetClocksFreq(&RCC_Clocks); sprintf(tmp, "SYSCLK = %ul\n", RCC_Clocks.SYSCLK_Frequency); usart_print(&USerial3, tmp); sprintf(tmp, "PCLK1 = %ul\n", RCC_Clocks.PCLK1_Frequency); usart_flush(&USerial3); GPIOMode(PinPort(PD12), (PinBit(PD12) | PinBit(PD13) | PinBit(PD14) | PinBit(PD15)), OUTPUT, FASTSPEED, PUSHPULL, NOPULL); /* spi_begin(SPI2, PB13, PB14, PB15, PB12); digitalWrite(PB12, HIGH); */ I2C1_Init(); /* i2c_begin(&Wire1, PB9, PB8, 100000); lcd.init(&Wire1); lcd.begin(); lcd.setContrast(46); lcd.print("Yappee!"); // Classic Hello World! */ bits = GPIO_ReadOutputData(GPIOD ); GPIOWrite(GPIOD, PinBit(PD13) | (bits & 0x0fff)); delay_ms(intval); tnow = millis() / 1000; while (tnow == millis() / 1000) ; tnow = millis() / 1000; while (1) { bits = GPIO_ReadOutputData(GPIOD ); GPIOWrite(GPIOD, PinBit(PD13) | (bits & 0x0fff)); delay_ms(intval); GPIOWrite(GPIOD, PinBit(PD14) | (bits & 0x0fff)); delay_ms(intval); GPIOWrite(GPIOD, PinBit(PD15) | (bits & 0x0fff)); delay_ms(intval); GPIOWrite(GPIOD, PinBit(PD12) | (bits & 0x0fff)); delay_ms(intval); // bits &= 0x0fff; switch ((tnow % 60) / 15) { case 3: bits |= PinBit(PD12); case 2: bits |= PinBit(PD15); case 1: bits |= PinBit(PD14); case 0: default: bits |= PinBit(PD13); break; } GPIOWrite(GPIOD, bits); while (tnow == millis() / 1000); tnow = millis() / 1000; //Serial3.print(tmp); sprintf(tmp, "%04ld\n", millis()); usart_print(&USerial3, tmp); /* digitalWrite(PB12, LOW); spi_transfer(SPI2, (uint8_t *) tmp, 8); digitalWrite(PB12, HIGH); */ i = 0; if (usart_available(&USerial3) > 0) { while (usart_available(&USerial3) > 0 && i < 92) { tmp[i++] = (char) usart_read(&USerial3); } tmp[i] = 0; usart_print(&USerial3, "> "); usart_print(&USerial3, tmp); usart_print(&USerial3, "\n"); } } return 0; }
void C_Flasher_IO_GPIO::SendRVS() { currGPIOVal = !currGPIOVal; //Write high to GPIO Pin GPIOWrite(GPIO_OUTPUT_PIN, currGPIOVal); }
int main(void){ LCDInit(CLK, DIN, DC, CE,RST, contrast); LCDclear(); LCDshowLogo(); struct sGENERAL person; delay_ms(1000); system("clear"); printf("Deseja Sobrescrever os Dados ? S/N\n"); unsigned int choose; do{choose = (int)getchar();}while(choose != 115 && choose != 83 && choose != 110 && choose != 78); getchar(); if(choose == 115 || choose == 83){ LCDDrawBitmap(profile); if(healthProfile(&person) == false){ printf("Falha ao realizar o Cadastro!\n"); return -1; } }else{ system("clear"); LCDDrawBitmap(profile); if(importData(&person)==false){ printf("Falha ao importar dados!\n"); return -1; } } LCDDrawBitmap(sensors); int raspDuino = serialOpen(SERIAL_PORT[1],BAUDS[1]); if(raspDuino == -1){ printf("Houve um erro ao Abrir a porta Serial!\n"); return -1; } serialFlush(raspDuino); GPIOExport(changeDisplay); GPIODirection(changeDisplay,INPUT); GPIOExport(backLight); GPIODirection(backLight,INPUT); GPIOExport(BL); GPIODirection(BL,OUTPUT); GPIOWrite(BL,HIGH); uint8_t change_Layer = 0; while(1){ if(GPIORead(changeDisplay) == HIGH){ while(GPIORead(changeDisplay) == HIGH){} change_Layer++; if(change_Layer > 2) change_Layer = 0; } if(GPIORead(backLight) == HIGH){ while(GPIORead(backLight) == HIGH){} GPIOWrite(BL,!GPIORead(BL)); } switch(change_Layer){ case 0: lcdDisplayMain(raspDuino); break; case 1: lcdDisplayProfile(person); break; case 2: lcdDisplaySensors(raspDuino,person); break; } /*if(serialDataAvail(raspDuino)!=-1){ // Usar Threads Sensors.BPM = (unsigned int)serialGetchar(raspDuino); Sensors.Temp = ((float)serialGetchar(raspDuino)*5/(1023))/0.01; Sensors.BPMState = healthState(person,Sensors.BPM); Sensors.TempState = isNormal(Sensors.Temp); }*/ } }
bool ledControl(uint8_t row, uint8_t col, uint8_t state){ state == HIGH?HIGH:LOW; if(!GPIOWrite(rowLed[row],!state)) return false; if(!GPIOWrite(colLed[col],state)) return false; else return true; }
void RelaySetTimeOn (uint32_t time, sRelay* relay) { relay->startOn = globalTimer; relay->timeOn = time; GPIOWrite(relay->onLevel, relay->gpio); }
void RelayInit (sRelay* relay) { GPIOInit(relay->gpio); GPIOWrite(!relay->onLevel, relay->gpio); }
void lcd_byte(int bits, int mode) { // Send byte to data pins // bits = data // mode = 1 for character // 0 for command GPIOWrite(LCD_RS, mode); // RS if (mode == 0) usleep(2000); // High bits if ((bits & 0x10) == 0x10) GPIOWrite(LCD_D4, 1); else GPIOWrite(LCD_D4, 0); if ((bits & 0x20) == 0x20) GPIOWrite(LCD_D5, 1); else GPIOWrite(LCD_D5, 0); if ((bits & 0x40) == 0x40) GPIOWrite(LCD_D6, 1); else GPIOWrite(LCD_D6, 0); if ((bits & 0x80) == 0x80) GPIOWrite(LCD_D7, 1); else GPIOWrite(LCD_D7, 0); // Toggle 'Enable' pin usleep(E_DELAY); GPIOWrite(LCD_E, 1); usleep(E_PULSE); GPIOWrite(LCD_E, 0); usleep(E_DELAY); // Low bits if ((bits & 0x01) == 0x01) GPIOWrite(LCD_D4, 1); else GPIOWrite(LCD_D4, 0); if ((bits & 0x02) == 0x02) GPIOWrite(LCD_D5, 1); else GPIOWrite(LCD_D5, 0); if ((bits & 0x04) == 0x04) GPIOWrite(LCD_D6, 1); else GPIOWrite(LCD_D6, 0); if ((bits & 0x08) == 0x08) GPIOWrite(LCD_D7, 1); else GPIOWrite(LCD_D7, 0); // Toggle 'Enable' pin usleep(E_DELAY); GPIOWrite(LCD_E, 1); usleep(E_PULSE); GPIOWrite(LCD_E, 0); usleep(E_DELAY); }