bool RPi2DOutSI::initialise(int pa_nPin, int pa_nPud) { #ifdef POSIX FZRTE_INFO("RPi2DOutSI: Initialising Gpio Pin %d to %d Mode",pa_nPin, pa_nPud); int nRetVal = ZERO_VALUE; nRetVal = gpioInitialise(); if(nRetVal < ZERO_VALUE){ FZRTE_ERROR("RPi2DOutSI : pigpio gpioInitialisation Failed : errorcode : %d",nRetVal); return false; } nRetVal = gpioSetMode(pa_nPin, PI_OUTPUT); if(nRetVal < ZERO_VALUE){ FZRTE_ERROR("RPi2DOutSI : pigpio SetMode Failed for Pin %d : errorcode : %d", pa_nPin,nRetVal); return false; } switch(pa_nPud){// passing int pa_nPud doesn't work sometime case 1: nRetVal = gpioSetPullUpDown(pa_nPin, PI_PUD_DOWN); break; case 2: nRetVal = gpioSetPullUpDown(pa_nPin, PI_PUD_OFF); break; default: nRetVal = gpioSetPullUpDown(pa_nPin, PI_PUD_UP); break; } if(nRetVal < ZERO_VALUE){ FZRTE_ERROR("RPi2DOutSI : pigpio SetPullUpDown Failed for Pin %d : errorcode : %d", pa_nPin, nRetVal); return false; } #endif return true; }
int main(int argc, char *argv[]) { int secs=60; if (argc>1) secs = atoi(argv[1]); /* program run seconds */ if ((secs<1) || (secs>3600)) secs = 3600; if (gpioInitialise()<0) return 1; gpioSetMode(HALL, PI_INPUT); gpioSetPullUpDown(HALL, PI_PUD_UP); gpioSetAlertFunc(HALL, alert); sleep(secs); printf("%d\n", count); gpioTerminate(); }
Pi_Wieg_t * Pi_Wieg( int gpio_0, int gpio_1, Pi_Wieg_CB_t callback, int timeout) { /* Instantiate with the gpio for 0 (green wire), the gpio for 1 (white wire), the callback function, and the timeout in milliseconds which indicates the end of a code. The callback is passed the code length in bits and the value. */ Pi_Wieg_t *wieg; wieg = malloc(sizeof(Pi_Wieg_t)); wieg->mygpio_0 = gpio_0; wieg->mygpio_1 = gpio_1; wieg->mycallback = callback; wieg->mytimeout = timeout; wieg->in_code = 0; gpioSetMode(gpio_0, PI_INPUT); gpioSetMode(gpio_1, PI_INPUT); gpioSetPullUpDown(gpio_0, PI_PUD_UP); gpioSetPullUpDown(gpio_1, PI_PUD_UP); gpioSetAlertFuncEx(gpio_0, _cb, wieg); gpioSetAlertFuncEx(gpio_1, _cb, wieg); return wieg; }
int main (int argc, char **argv) { struct sigaction act; char configFilePath[MAXPATHLEN]; char hostName[1024]; int c; // for getopt int socket_fd_cms; config_t cfg; struct config config; struct sockaddr_in info_cms; struct hostent *he_cms; // struct data data; struct timeval time_last, time_now; char tcp_buffer[1024]; int num; // print help if no arguments given if (argc==1) { printHelp(); return 1; } // init library if (gpioInitialise()<0) return 1; // load and parse config file opterr = 0; while ((c=getopt(argc, argv, "c:")) != -1) { switch (c) { case 'c': strcpy(configFilePath, optarg); break; case '?': if (optopt=='d' || optopt=='h') fprintf(stderr, "Option -%c requires an argument.\n", optopt); else if (isprint (optopt)) fprintf(stderr, "Unknown option '-%c'.\n", optopt); else fprintf(stderr, "Unknown option character '\\x%x'.\n", optopt); gpioTerminate(); return 1; default: gpioTerminate(); abort(); } } config_init(&cfg); // Read the file. If there is an error, report it and exit. if(! config_read_file(&cfg, configFilePath)) { fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); config_destroy(&cfg); gpioTerminate(); return(EXIT_FAILURE); } // node, host, apikey if (!(config_lookup_string(&cfg, "node", &(config.pNodeName)))) { fprintf(stderr, "No 'node' setting in configuration file.\n"); config_destroy(&cfg); gpioTerminate(); return(EXIT_FAILURE); } if (!(config_lookup_string(&cfg, "host", &(config.pHostName)))) { fprintf(stderr, "No 'host' setting in configuration file.\n"); config_destroy(&cfg); gpioTerminate(); return(EXIT_FAILURE); } if (!(config_lookup_string(&cfg, "apikey", &(config.pApiKey)))) { fprintf(stderr, "No 'apikey' setting in configuration file.\n"); config_destroy(&cfg); gpioTerminate(); return(EXIT_FAILURE); } if (!config.pHostName[0]) { printf("No host name found. Did you specify the '-h hostname' option or mention it in the config file?\n"); config_destroy(&cfg); gpioTerminate(); return EX_UNAVAILABLE; } if (!(he_cms = gethostbyname(config.pHostName))) { fprintf(stderr, "Could not resolve host name '%s', err %d.\n", config.pHostName, h_errno); config_destroy(&cfg); gpioTerminate(); exit(1); } info_cms.sin_family = AF_INET; info_cms.sin_port = htons(80); info_cms.sin_addr = *((struct in_addr *)he_cms->h_addr); /* if ((socket_fd_cms = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { fprintf(stderr, "Could not allocate socket, err %d.\n", errno); config_destroy(&cfg); gpioTerminate(); exit(1); } if (connect(socket_fd_cms, (struct sockaddr *)&info_cms, sizeof(struct sockaddr)) < 0) { fprintf(stderr, "Could not connect to server, err%d.\n", errno); close (socket_fd_cms); config_destroy(&cfg); gpioTerminate(); exit(1); } */ // config GPIO gpioSetMode (GPIO, PI_INPUT); gpioSetPullUpDown (GPIO, PI_PUD_UP); gpioSetAlertFunc (GPIO, myAlert); act.sa_handler = intHandler; sigaction(SIGINT, &act, NULL); // catch Ctrl-C sigaction(SIGTERM, &act, NULL); // catch kill gettimeofday(&time_last, NULL); gettimeofday(&time_now, NULL); unsigned long elapsedtime_us; // [us] float elapsedtime_s; // [s] float power; // [W] syslog(LOG_INFO, "started. waiting for pulse..."); while (!clean_up) { pause(); if (!clean_up) // to avoid running even once if SIGINT arrives during pause() { // printf ("back.\n"); fflush(stdout); gettimeofday(&time_now, NULL); elapsedtime_us = (time_now.tv_sec - time_last.tv_sec)*1000000 - time_last.tv_usec + time_now.tv_usec; printf("elapsed microseconds: %lu\n", elapsedtime_us); elapsedtime_s = elapsedtime_us / 1000000.0; printf("elapsed seconds: %f\n", elapsedtime_s); power = 1.0 * 3600.0 / elapsedtime_s; // 1.0Wh per pulse * 3600 s/h / seconds = Whs/hs = W printf("current power: %f\n", power); syslog(LOG_INFO, "elapsed seconds: %f, current power: %f", elapsedtime_s, power); if (power > 10000.0) { syslog(LOG_INFO, "error: power >10kW."); } else { time_last.tv_sec = time_now.tv_sec; time_last.tv_usec = time_now.tv_usec; // generate json string for emonCMS sprintf (tcp_buffer, "GET /input/post.json?node=\"%s\"&json={pulseBoiler:1,powerBoiler:%5.3f}&apikey=%s HTTP/1.1\r\nHost: %s\r\nUser-Agent: %s %s\r\nConnection: keep-alive\r\n\r\n", config.pNodeName, power, config.pApiKey, config.pHostName, TOOLNAME, RASPI_PULSECOUNT_VERSION); printf ("-----\nbuflen: %ld\n%s\n", strlen(tcp_buffer), tcp_buffer); if ((socket_fd_cms = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { fprintf(stderr, "Could not allocate socket, err %d.\n", errno); } else { if (connect(socket_fd_cms, (struct sockaddr *)&info_cms, sizeof(struct sockaddr)) < 0) // re-connect each time { fprintf(stderr, "Could not connect to server, err %d.\n", errno); syslog(LOG_WARNING,"Could not connect to server, err %d (%s).", errno, strerror(errno)); } else { num=send(socket_fd_cms, tcp_buffer, strlen(tcp_buffer), 0); if (num <0) printf ("send error: %d\n", errno); else printf ("sent: %ld\n", num); } close (socket_fd_cms); } } } } // clean up (not usually executed until Ctrl-C) printf ("clean up.\n"); syslog(LOG_INFO, "clean up."); close (socket_fd_cms); config_destroy(&cfg); gpioTerminate(); return (EX_OK); }
int main(int argc, char* argv[] ) { int i; pthread_t *pS0Thread[NUM_GPIOS]; pthread_t *pW1Thread; cfg_t *cfg; char logBuffer[LOG_BUFFER_SIZE+1]; cfg_opt_t opts[] = { CFG_SIMPLE_FLOAT("thermal_coefficient", &confOptions.termCoefficent), CFG_SIMPLE_INT("flow_per_hour", &confOptions.literAnHour), CFG_SIMPLE_INT("log_level", &confOptions.logLevel), CFG_SIMPLE_INT("temp_reader_delay", &confOptions.tempReaderDelay), CFG_SIMPLE_INT("temp_reader_interval", &confOptions.tempReaderIntval), CFG_SIMPLE_BOOL("push_bullet_notification", &confOptions.bulletNotificationEnabled), CFG_SIMPLE_BOOL("email_notification", &confOptions.emailNotificationEnabled), CFG_SIMPLE_STR("emoncms_api_key", &confOptions.emonApiKey), CFG_SIMPLE_BOOL("client_watchdog", &confOptions.watchdogEnabled), CFG_SIMPLE_INT("gpio_4_s0_in_use", &confOptions.numGPIO4S0InUse), CFG_SIMPLE_STR("therm_id_vorlauf", &confOptions.thermIdVorlauf), CFG_SIMPLE_STR("therm_id_ruecklauf", &confOptions.thermIdRuecklauf), CFG_SIMPLE_INT("oil_consumption_per_hour", &confOptions.oilConsumptionPerHour), CFG_END() }; confOptions.run_mode = DEFAULT_RUN_MODE; confOptions.termCoefficent = CONF_DEFAULT_THERMCOEFF; confOptions.literAnHour = CONF_DEFAULT_LITERANHOUR; confOptions.logLevel = CONF_DEFAULT_LOGLEVEL; confOptions.tempReaderDelay = CONF_DEFAULT_READERDELAY; confOptions.tempReaderIntval = CONF_DEFAULT_READERINTVAL; confOptions.bulletNotificationEnabled = CONF_DEFAULT_BULLETNOTICICATION; confOptions.emailNotificationEnabled = CONF_DEFAULT_EMAILNOTICICATION; confOptions.emonApiKey = CONF_DEFAULT_APIKEY; confOptions.watchdogEnabled = CONF_DEFAULT_WATCHDOGENABLED; confOptions.numGPIO4S0InUse = CONF_DEFAULT_NUMS0PINS; confOptions.thermIdVorlauf = strdup(CONF_DEFAULT_THERMIDVORLAUF); confOptions.thermIdRuecklauf = strdup(CONF_DEFAULT_THERMIDRUECKLAUF); if( (cfg = cfg_init(opts, 0)) != NULL ) { cfg_parse(cfg, CONF_FILE_PATH); #ifdef DEBUG_ALL printf("thermal_coefficient ....: %f\n", confOptions.termCoefficent); printf("flow_per_hour ..........: %ld\n", confOptions.literAnHour); printf("log_level ..............: %ld\n", confOptions.logLevel); printf("temp_reader_delay ......: %ld\n", confOptions.tempReaderDelay); printf("temp_reader_interval ...: %ld\n", confOptions.tempReaderIntval); printf("push_bullet_notification: %s\n", confOptions.bulletNotificationEnabled?"true":"false"); printf("email_notification .....: %s\n", confOptions.emailNotificationEnabled?"true":"false"); printf("emoncms_api_key ........: %s\n", confOptions.emonApiKey?confOptions.emonApiKey:"NULL"); printf("client_watchdog ........: %s\n", confOptions.watchdogEnabled?"true":"false"); printf("gpio_4_s0_in_use .......: %ld\n", confOptions.numGPIO4S0InUse); printf("therm_id_vorlauf .......: %s\n", confOptions.thermIdVorlauf?confOptions.thermIdVorlauf:"NULL"); printf("therm_id_ruecklauf .....: %s\n", confOptions.thermIdRuecklauf?confOptions.thermIdRuecklauf:"NULL"); printf("oil_consumption_per_hour: %ld\n", confOptions.oilConsumptionPerHour); #endif // DEBUG_ALL } else { exit(3); } mainEndFlag = 0; if( confOptions.emonApiKey != NULL && confOptions.thermIdVorlauf != NULL && confOptions.thermIdRuecklauf != NULL && confOptions.tempReaderDelay <= READER_DELAY_MAX && confOptions.tempReaderDelay >= 0 ) { if (gpioInitialise() < 0) { // pigpio initialisation failed. fprintf(stderr, "cannot initialize pigpio!\n"); return(1); } else { signal( SIGINT, sig_handler ); signal( SIGQUIT, sig_handler ); signal( SIGKILL, sig_handler ); signal( SIGTERM, sig_handler ); signal( SIGALRM, alrm_handler ); // pigpio initialisation okay ... for( i = 0; i < NUM_GPIOS; i++) { #ifdef DEBUG_ALL printf("Index %d\n", i); #endif // DEBUG_ALL gpioSetMode( gpioInUse[i].bcm_gpio, PI_INPUT ); // set GPIO as an input gpioSetPullUpDown( gpioInUse[i].bcm_gpio, PI_PUD_DOWN); // activate internal pull-up // create thread for this gpio pS0Thread[i] = gpioStartThread(tickerThread, (void*) &gpioInUse[i]); // gpioSetAlertFunc( gpioInUse[i].bcm_gpio, ticker[i] ); // set event handler "ticker" } if( (pW1Thread = gpioStartThread(W1ThermThread, NULL)) == NULL ) { fprintf(stderr, "W1Thread failed to start ...\n"); for( i = 0; i < NUM_GPIOS; i++) { if( pS0Thread[i] != NULL ) { gpioStopThread( pS0Thread[i] ); } } gpioTerminate(); } else { while( !mainEndFlag ) { gpioSleep(PI_TIME_RELATIVE, 0, 10000); // hold 1/100 sec high level } for( i = 0; i < NUM_GPIOS; i++) { if( pS0Thread[i] != NULL ) { gpioStopThread( pS0Thread[i] ); } } gpioStopThread( pW1Thread ); gpioTerminate(); cfg_free(cfg); if(confOptions.emonApiKey) { free(confOptions.emonApiKey); } if(confOptions.thermIdVorlauf) { free(confOptions.thermIdVorlauf); } if(confOptions.thermIdRuecklauf) { free(confOptions.thermIdRuecklauf); } } } } else { confFail(); } return(0); }
/* * Class: com_diozero_pigpioj_PigpioGpio * Method: setPullUpDown * Signature: (II)I */ JNIEXPORT jint JNICALL Java_com_diozero_pigpioj_PigpioGpio_setPullUpDown (JNIEnv* env, jclass clz, jint gpio, jint pud) { return gpioSetPullUpDown(gpio, pud); }
int main(int argc, char *argv[]) { char fname[120]; FILE *fp; // for output log file struct tm *tm; struct tm * timeinfo; struct timeval t1, deltaT; char tod[80]; // time of day string char tbuf[80]; int millisec; float deltaSec = 0; int retval = 0; if (gpioInitialise()<0) { printf("Cannot initialize GPIO, quitting.\n"); return 1; } fresh = FALSE; // start out with no GPIO level changes yet seen gettimeofday(&t1, NULL); // start time if ((tm = localtime(&t1.tv_sec)) == NULL) return -1; strftime(tod, sizeof tod, "%Y%m%d_%H%M%S.csv",tm); strcpy(fname,BASENAME); strncat(fname,tod,strlen(tod)); printf("Opening %s\n",fname); fp = fopen(fname,"w"); if (fp == NULL) return -1; gpioSetMode(SIGIN, PI_INPUT); // gpioSetPullUpDown(SIGIN, PI_PUD_UP); gpioSetPullUpDown(SIGIN, PI_PUD_DOWN); gpioSetAlertFunc(SIGIN, alert); printf("# Motion log start...\n"); do { if (fresh == TRUE) { fresh = FALSE; timeval_subtract (&deltaT, &t2, &t1); if (g_level == 1) { // is this rising edge (start of new motion event?) t1.tv_sec = t2.tv_sec; // save time structure values for next time t1.tv_usec = t2.tv_usec; } millisec = lrint(t2.tv_usec/1000.0); // round to nearest millisec if (millisec>=1000) { // Allow for rounding up to nearest second millisec -=1000; t2.tv_sec++; } timeinfo = localtime(&t2.tv_sec); strftime(tbuf, 80, "%Y-%m-%d %H:%M:%S",timeinfo); fprintf(fp,"%s.%03d, ",tbuf,millisec); // write to file including milliseconds if (g_level == 0) { // returned to zero; end of motion event deltaSec = (g_tick-lastTick) / 1E6; // ticks in microseconds fprintf(fp,"%d, %4.1f\n", g_level, deltaSec); } else { // start of new motion event deltaSec = deltaT.tv_sec + (deltaT.tv_usec/1.0E6); fprintf(fp,"%d, %4.1f\n", g_level, deltaSec); retval = system(STILLCAP); // command to trigger local capture of still image retval |= system(SENDALARM); // notify other device of motion } lastTick = g_tick; fflush(fp); // make sure it's written to the file /* if (g_level == 1) { // capture still image // raspistill -t 1000 -rot 180 -o test.jpg tm = localtime(&t2.tv_sec); strftime(tod, sizeof tod, "m_%Y%m%d_%H%M%S.jpg",tm); strcpy(fname, "raspistill -t 1000 -rot 180 -o "); // command to record image strcat(fname, tod); printf("Saving %s\n", tod); retval = system(fname); } */ } // if fresh sleep(1); } while (1); gpioTerminate(); // never reached fclose(fp); return retval; }
int gpio_init() { fprintf(stderr,"encoder_init\n"); #ifdef odroid VFO_ENCODER_A=88; VFO_ENCODER_B=87; #endif gpio_restore_state(); #ifdef raspberrypi fprintf(stderr,"encoder_init: VFO_ENCODER_A=%d VFO_ENCODER_B=%d\n",VFO_ENCODER_A,VFO_ENCODER_B); fprintf(stderr,"gpioInitialize\n"); if(gpioInitialise()<0) { fprintf(stderr,"Cannot initialize GPIO\n"); return -1; } if(ENABLE_FUNCTION_BUTTON) { gpioSetMode(FUNCTION_BUTTON, PI_INPUT); gpioSetPullUpDown(FUNCTION_BUTTON,PI_PUD_UP); gpioSetAlertFunc(FUNCTION_BUTTON, functionAlert); } if(ENABLE_VFO_ENCODER) { if(gpioSetMode(VFO_ENCODER_A, PI_INPUT)!=0) { fprintf(stderr,"gpioSetMode for VFO_ENCODER_A failed\n"); } if(gpioSetMode(VFO_ENCODER_B, PI_INPUT)!=0) { fprintf(stderr,"gpioSetMode for VFO_ENCODER_B failed\n"); } if(ENABLE_VFO_PULLUP) { gpioSetPullUpDown(VFO_ENCODER_A, PI_PUD_UP); gpioSetPullUpDown(VFO_ENCODER_B, PI_PUD_UP); } else { gpioSetPullUpDown(VFO_ENCODER_A, PI_PUD_OFF); gpioSetPullUpDown(VFO_ENCODER_B, PI_PUD_OFF); } if(gpioSetAlertFunc(VFO_ENCODER_A, vfoEncoderPulse)!=0) { fprintf(stderr,"gpioSetAlertFunc for VFO_ENCODER_A failed\n"); } if(gpioSetAlertFunc(VFO_ENCODER_B, vfoEncoderPulse)!=0) { fprintf(stderr,"gpioSetAlertFunc for VFO_ENCODER_B failed\n"); } vfoEncoderPos=0; } gpioSetMode(AF_FUNCTION, PI_INPUT); gpioSetPullUpDown(AF_FUNCTION,PI_PUD_UP); gpioSetAlertFunc(AF_FUNCTION, afFunctionAlert); afFunction=0; if(ENABLE_AF_ENCODER) { gpioSetMode(AF_ENCODER_A, PI_INPUT); gpioSetMode(AF_ENCODER_B, PI_INPUT); if(ENABLE_AF_PULLUP) { gpioSetPullUpDown(AF_ENCODER_A, PI_PUD_UP); gpioSetPullUpDown(AF_ENCODER_B, PI_PUD_UP); } else { gpioSetPullUpDown(AF_ENCODER_A, PI_PUD_OFF); gpioSetPullUpDown(AF_ENCODER_B, PI_PUD_OFF); } gpioSetAlertFunc(AF_ENCODER_A, afEncoderPulse); gpioSetAlertFunc(AF_ENCODER_B, afEncoderPulse); afEncoderPos=0; } gpioSetMode(RF_FUNCTION, PI_INPUT); gpioSetPullUpDown(RF_FUNCTION,PI_PUD_UP); gpioSetAlertFunc(RF_FUNCTION, rfFunctionAlert); rfFunction=0; if(ENABLE_RF_ENCODER) { gpioSetMode(RF_ENCODER_A, PI_INPUT); gpioSetMode(RF_ENCODER_B, PI_INPUT); if(ENABLE_AF_PULLUP) { gpioSetPullUpDown(RF_ENCODER_A, PI_PUD_UP); gpioSetPullUpDown(RF_ENCODER_B, PI_PUD_UP); } else { gpioSetPullUpDown(RF_ENCODER_A, PI_PUD_OFF); gpioSetPullUpDown(RF_ENCODER_B, PI_PUD_OFF); } gpioSetAlertFunc(RF_ENCODER_A, rfEncoderPulse); gpioSetAlertFunc(RF_ENCODER_B, rfEncoderPulse); rfEncoderPos=0; } gpioSetMode(AGC_FUNCTION, PI_INPUT); gpioSetPullUpDown(AGC_FUNCTION,PI_PUD_UP); gpioSetAlertFunc(AGC_FUNCTION, agcFunctionAlert); agcFunction=0; if(ENABLE_AGC_ENCODER) { gpioSetMode(AGC_ENCODER_A, PI_INPUT); gpioSetMode(AGC_ENCODER_B, PI_INPUT); if(ENABLE_AF_PULLUP) { gpioSetPullUpDown(AGC_ENCODER_A, PI_PUD_UP); gpioSetPullUpDown(AGC_ENCODER_B, PI_PUD_UP); } else { gpioSetPullUpDown(AGC_ENCODER_A, PI_PUD_OFF); gpioSetPullUpDown(AGC_ENCODER_B, PI_PUD_OFF); } gpioSetAlertFunc(AGC_ENCODER_A, agcEncoderPulse); gpioSetAlertFunc(AGC_ENCODER_B, agcEncoderPulse); agcEncoderPos=0; } if(ENABLE_BAND_BUTTON) { gpioSetMode(BAND_BUTTON, PI_INPUT); gpioSetPullUpDown(BAND_BUTTON,PI_PUD_UP); gpioSetAlertFunc(BAND_BUTTON, bandAlert); } if(ENABLE_BANDSTACK_BUTTON) { gpioSetMode(BANDSTACK_BUTTON, PI_INPUT); gpioSetPullUpDown(BANDSTACK_BUTTON,PI_PUD_UP); gpioSetAlertFunc(BANDSTACK_BUTTON, bandstackAlert); } if(ENABLE_MODE_BUTTON) { gpioSetMode(MODE_BUTTON, PI_INPUT); gpioSetPullUpDown(MODE_BUTTON,PI_PUD_UP); gpioSetAlertFunc(MODE_BUTTON, modeAlert); } if(ENABLE_FILTER_BUTTON) { gpioSetMode(FILTER_BUTTON, PI_INPUT); gpioSetPullUpDown(FILTER_BUTTON,PI_PUD_UP); gpioSetAlertFunc(FILTER_BUTTON, filterAlert); } if(ENABLE_NOISE_BUTTON) { gpioSetMode(NOISE_BUTTON, PI_INPUT); gpioSetPullUpDown(NOISE_BUTTON,PI_PUD_UP); gpioSetAlertFunc(NOISE_BUTTON, noiseAlert); } if(ENABLE_AGC_BUTTON) { gpioSetMode(AGC_BUTTON, PI_INPUT); gpioSetPullUpDown(AGC_BUTTON,PI_PUD_UP); gpioSetAlertFunc(AGC_BUTTON, agcAlert); } if(ENABLE_MOX_BUTTON) { gpioSetMode(MOX_BUTTON, PI_INPUT); gpioSetPullUpDown(MOX_BUTTON,PI_PUD_UP); gpioSetAlertFunc(MOX_BUTTON, moxAlert); } if(ENABLE_LOCK_BUTTON) { gpioSetMode(LOCK_BUTTON, PI_INPUT); gpioSetPullUpDown(LOCK_BUTTON,PI_PUD_UP); gpioSetAlertFunc(LOCK_BUTTON, lockAlert); } #endif #ifdef odroid //VFO_ENCODER_A=ODROID_VFO_ENCODER_A; //VFO_ENCODER_B=ODROID_VFO_ENCODER_B; //VFO_ENCODER_A_PIN=ODROID_VFO_ENCODER_A_PIN; //VFO_ENCODER_B_PIN=ODROID_VFO_ENCODER_B_PIN; fprintf(stderr,"encoder_init: VFO_ENCODER_A=%d VFO_ENCODER_B=%d\n",VFO_ENCODER_A,VFO_ENCODER_B); fprintf(stderr,"wiringPiSetup\n"); if (wiringPiSetup () < 0) { printf ("Unable to setup wiringPi: %s\n", strerror (errno)); return -1; } FILE *fp; fp = popen("echo 88 > /sys/class/gpio/export\n", "r"); pclose(fp); fp = popen("echo \"in\" > /sys/class/gpio/gpio88/direction\n", "r"); pclose(fp); fp = popen("chmod 0666 /sys/class/gpio/gpio88/value\n", "r"); pclose(fp); fp = popen("echo 87 > /sys/class/gpio/export\n", "r"); pclose(fp); fp = popen("echo \"in\" > /sys/class/gpio/gpio87/direction\n", "r"); pclose(fp); fp = popen("chmod 0666 /sys/class/gpio/gpio87/value\n", "r"); pclose(fp); if ( wiringPiISR (0, INT_EDGE_BOTH, &interruptB) < 0 ) { printf ("Unable to setup ISR: %s\n", strerror (errno)); return -1; } if ( wiringPiISR (1, INT_EDGE_BOTH, &interruptA) < 0 ) { printf ("Unable to setup ISR: %s\n", strerror (errno)); return -1; } #endif int rc=pthread_create(&rotary_encoder_thread_id, NULL, rotary_encoder_thread, NULL); if(rc<0) { fprintf(stderr,"pthread_create for rotary_encoder_thread failed %d\n",rc); } return 0; }