<commit_before>/*

SqueezeRotate - Sets the volume of a squeezebox player running on a raspberry pi

<C> 2017 <NAME>

*/


#include <stdio.h>
#include <stdlib.h>

#include <wiringPi.h>

#include "squeezerotate.h"
#include "rotaryencoder/rotaryencoder.h"

static volatile int stop_signal;
static void sigHandler( int sig, siginfo_t *siginfo, void *context );

int main( int argc, char *argv[] ) {

    /*------------------------------------------------------------------------*\
     OK, from here on we catch some terminating signals and ignore others
     \*------------------------------------------------------------------------*/
    struct sigaction act;
    memset( &act, 0, sizeof(act) );
    act.sa_sigaction = &sigHandler;
    act.sa_flags     = SA_SIGINFO;
    sigaction( SIGINT, &act, NULL );
    sigaction( SIGTERM, &act, NULL );

    /*------------------------------------------------------------------------*\
     Setup PID file, ignore errors...
     \*------------------------------------------------------------------------*/
    fp = fopen( pid_fname, "w" );
    if( fp ) {
        fprintf( fp, "%d\n", getpid() );
        fclose( fp );
    }
    

    /*------------------------------------------------------------------------*\
     Setup Rotary Encoder
     \*------------------------------------------------------------------------*/
    wiringPiSetup() ;
    struct encoder *encoder = setupencoder(4, 5);
    

    /*------------------------------------------------------------------------*\
     Mainloop:
     \*------------------------------------------------------------------------*/
    while( !stop_signal ) {
        printf("encoder value: %d", encoder->value);
        /*------------------------------------------------------------------------*\
         Just sleep...
         \*------------------------------------------------------------------------*/
        sleep( 1000 );
        
    } /* end of: while( !stopflag ) */
}

/*=========================================================================*\
 Handle signals
 \*=========================================================================*/
static void sigHandler( int sig, siginfo_t *siginfo, void *context )
{
    
    /*------------------------------------------------------------------------*\
     What sort of signal is to be processed ?
     \*------------------------------------------------------------------------*/
    switch( sig ) {
            
            /*------------------------------------------------------------------------*\
             A normal termination request
             \*------------------------------------------------------------------------*/
        case SIGINT:
        case SIGTERM:
            stop_signal = sig;
            break;
            
            /*------------------------------------------------------------------------*\
             Ignore broken pipes
             \*------------------------------------------------------------------------*/
        case SIGPIPE:
            break;
    }
    
    /*------------------------------------------------------------------------*\
     That's it.
     \*------------------------------------------------------------------------*/  
} 
<commit_msg>Add signals<commit_after>/*

SqueezeRotate - Sets the volume of a squeezebox player running on a raspberry pi

<C> 2017 <NAME>

*/


#include <stdio.h>
#include <stdlib.h>
#include <signal.h>

#include <wiringPi.h>

#include "squeezerotate.h"
#include "rotaryencoder/rotaryencoder.h"

static volatile int stop_signal;
static void sigHandler( int sig, siginfo_t *siginfo, void *context );

int main( int argc, char *argv[] ) {

    /*------------------------------------------------------------------------*\
     OK, from here on we catch some terminating signals and ignore others
     \*------------------------------------------------------------------------*/
    struct sigaction act;
    memset( &act, 0, sizeof(act) );
    act.sa_sigaction = &sigHandler;
    act.sa_flags     = SA_SIGINFO;
    sigaction( SIGINT, &act, NULL );
    sigaction( SIGTERM, &act, NULL );

    /*------------------------------------------------------------------------*\
     Setup PID file, ignore errors...
     \*------------------------------------------------------------------------*/
    fp = fopen( pid_fname, "w" );
    if( fp ) {
        fprintf( fp, "%d\n", getpid() );
        fclose( fp );
    }
    

    /*------------------------------------------------------------------------*\
     Setup Rotary Encoder
     \*------------------------------------------------------------------------*/
    wiringPiSetup() ;
    struct encoder *encoder = setupencoder(4, 5);
    

    /*------------------------------------------------------------------------*\
     Mainloop:
     \*------------------------------------------------------------------------*/
    while( !stop_signal ) {
        printf("encoder value: %d", encoder->value);
        /*------------------------------------------------------------------------*\
         Just sleep...
         \*------------------------------------------------------------------------*/
        sleep( 1000 );
        
    } /* end of: while( !stopflag ) */
}

/*=========================================================================*\
 Handle signals
 \*=========================================================================*/
static void sigHandler( int sig, siginfo_t *siginfo, void *context )
{
    
    /*------------------------------------------------------------------------*\
     What sort of signal is to be processed ?
     \*------------------------------------------------------------------------*/
    switch( sig ) {
            
            /*------------------------------------------------------------------------*\
             A normal termination request
             \*------------------------------------------------------------------------*/
        case SIGINT:
        case SIGTERM:
            stop_signal = sig;
            break;
            
            /*------------------------------------------------------------------------*\
             Ignore broken pipes
             \*------------------------------------------------------------------------*/
        case SIGPIPE:
            break;
    }
    
    /*------------------------------------------------------------------------*\
     That's it.
     \*------------------------------------------------------------------------*/  
} 

{'fraction_non_alphanumeric': 0.5207756232686981, 'fraction_numerical': 0.003385657125269314, 'mean_word_length': 0.6333249560191003, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2681753', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1206, 'n_words': 319}