diff options
-rw-r--r-- | libk8055/k8055.h | 52 | ||||
-rw-r--r-- | libk8055/libk8055.c | 124 | ||||
-rw-r--r-- | libk8055/main.c | 32 |
3 files changed, 104 insertions, 104 deletions
diff --git a/libk8055/k8055.h b/libk8055/k8055.h index 2966ab6..9758e37 100644 --- a/libk8055/k8055.h +++ b/libk8055/k8055.h @@ -32,32 +32,32 @@ extern "C" { unsigned char data_out[PACKET_LEN+1]; }; - char* version( void ); - void set_debug_on( void ); - void set_debug_off( void ); - long search_devices( void ); - int open_device( struct k8055_dev* dev, int board_address ); - int close_device( struct k8055_dev* dev ); - long read_analog_channel( struct k8055_dev* dev, int channel ); - int read_all_analog( struct k8055_dev* dev, long* data1, long* data2 ); - int output_analog_channel( struct k8055_dev* dev ,int channel, long data ); - int output_all_analog( struct k8055_dev* dev, long data1, long data2 ); - int clear_all_analog( struct k8055_dev* dev ); - int clear_analog_channel( struct k8055_dev* dev, int channel ); - int set_analog_channel( struct k8055_dev* dev, int channel ); - int set_all_analog( struct k8055_dev* dev ); - int write_all_digital( struct k8055_dev* dev, long data ); - int clear_digital_channel( struct k8055_dev* dev, int channel ); - int clear_all_digital( struct k8055_dev* dev ); - int set_digital_channel( struct k8055_dev* dev, int channel ); - int set_all_digital( struct k8055_dev* dev ); - int read_digital_channel( struct k8055_dev* dev, int channel ); - long read_all_digital( struct k8055_dev* dev ); - int read_all_values( struct k8055_dev* dev, long int* data1, long int* data2, long int* data3, long int* data4, long int* data5 ); - int set_all_values( struct k8055_dev* dev, int digital_data, int ad_data1, int ad_data2 ); - int reset_counter( struct k8055_dev* dev, int counter ); - long read_counter( struct k8055_dev* dev, int counter ); - int set_counter_debounce_time( struct k8055_dev* dev, int counter, long debounce_time ); + char* k8055_version( void ); + void k8055_set_debug_on( void ); + void k8055_set_debug_off( void ); + long k8055_search_devices( void ); + int k8055_open_device( struct k8055_dev* dev, int board_address ); + int k8055_close_device( struct k8055_dev* dev ); + long k8055_read_analog_channel( struct k8055_dev* dev, int channel ); + int k8055_read_all_analog( struct k8055_dev* dev, long* data1, long* data2 ); + int k8055_output_analog_channel( struct k8055_dev* dev ,int channel, long data ); + int k8055_output_all_analog( struct k8055_dev* dev, long data1, long data2 ); + int k8055_clear_all_analog( struct k8055_dev* dev ); + int k8055_clear_analog_channel( struct k8055_dev* dev, int channel ); + int k8055_set_analog_channel( struct k8055_dev* dev, int channel ); + int k8055_set_all_analog( struct k8055_dev* dev ); + int k8055_write_all_digital( struct k8055_dev* dev, long data ); + int k8055_clear_digital_channel( struct k8055_dev* dev, int channel ); + int k8055_clear_all_digital( struct k8055_dev* dev ); + int k8055_set_digital_channel( struct k8055_dev* dev, int channel ); + int k8055_set_all_digital( struct k8055_dev* dev ); + int k8055_read_digital_channel( struct k8055_dev* dev, int channel ); + long k8055_read_all_digital( struct k8055_dev* dev ); + int k8055_read_all_values( struct k8055_dev* dev, long int* data1, long int* data2, long int* data3, long int* data4, long int* data5 ); + int k8055_set_all_values( struct k8055_dev* dev, int digital_data, int ad_data1, int ad_data2 ); + int k8055_reset_counter( struct k8055_dev* dev, int counter ); + long k8055_read_counter( struct k8055_dev* dev, int counter ); + int k8055_set_counter_debounce_time( struct k8055_dev* dev, int counter, long debounce_time ); /* Velleman API */ char* Version( void ); diff --git a/libk8055/libk8055.c b/libk8055/libk8055.c index 8db1f13..8ddd419 100644 --- a/libk8055/libk8055.c +++ b/libk8055/libk8055.c @@ -139,7 +139,7 @@ static int k8055_write( struct k8055_dev* dev ) { } /* If device is owned by some kernel driver, try to disconnect it and claim the device*/ -static int takeover_device( usb_dev_handle* udev, int interface ) { +static int k8055_takeover_device( usb_dev_handle* udev, int interface ) { char driver_name[STR_BUFF]; memset( driver_name, 0, STR_BUFF ); int ret = K8055_ERROR; @@ -165,19 +165,19 @@ static int takeover_device( usb_dev_handle* udev, int interface ) { return 0; } -void set_debug_on( void ) { +void k8055_set_debug_on( void ) { debug = 1; } -void set_debug_off( void ) { +void k8055_set_debug_off( void ) { debug = 0; } -char* version( void ) { +char* k8055_version( void ) { return( VERSION ); } -int open_device( struct k8055_dev* dev, int board_address ) { +int k8055_open_device( struct k8055_dev* dev, int board_address ) { usb_init(); usb_find_busses(); usb_find_devices(); @@ -193,7 +193,7 @@ int open_device( struct k8055_dev* dev, int board_address ) { return K8055_ERROR; } if( debug ) fprintf( stderr, "Velleman Device Found @ Address %s Vendor 0x0%x Product ID 0x0%x\n", usb_dev->filename, usb_dev->descriptor.idVendor, usb_dev->descriptor.idProduct ); - if( takeover_device( dev->device_handle, 0 )<0 ) { + if( k8055_takeover_device( dev->device_handle, 0 )<0 ) { if( debug ) fprintf( stderr, "Can not take over the device from the OS driver\n" ); usb_close( dev->device_handle ); dev->device_handle = NULL; @@ -221,7 +221,7 @@ int open_device( struct k8055_dev* dev, int board_address ) { return K8055_ERROR; } -int close_device( struct k8055_dev* dev ) { +int k8055_close_device( struct k8055_dev* dev ) { if ( dev->dev_no == 0 ) { if ( debug ) fprintf( stderr, "Current device is not open\n" ); return 0; @@ -239,7 +239,7 @@ int close_device( struct k8055_dev* dev ) { return rc; } -long search_devices( void ) { +long k8055_search_devices( void ) { int ret = 0; usb_init(); usb_find_busses(); @@ -260,7 +260,7 @@ long search_devices( void ) { return ret; } -long read_analog_channel( struct k8055_dev* dev, int channel ) { +long k8055_read_analog_channel( struct k8055_dev* dev, int channel ) { if ( !( channel==1 || channel==2 ) ) return K8055_ERROR; if ( k8055_read( dev )==0 ) { if ( channel==1 ) { @@ -272,14 +272,14 @@ long read_analog_channel( struct k8055_dev* dev, int channel ) { return K8055_ERROR; } -int read_all_analog( struct k8055_dev* dev, long* data1, long* data2 ) { +int k8055_read_all_analog( struct k8055_dev* dev, long* data1, long* data2 ) { if ( k8055_read( dev )!=0 ) return K8055_ERROR; *data1 = dev->data_in[ANALOG_1_OFFSET]; *data2 = dev->data_in[ANALOG_2_OFFSET]; return 0; } -int output_analog_channel( struct k8055_dev* dev ,int channel, long data ) { +int k8055_output_analog_channel( struct k8055_dev* dev ,int channel, long data ) { if ( !( channel==1 || channel==2 ) ) return K8055_ERROR; dev->data_out[0] = CMD_SET_ANALOG_DIGITAL; if ( channel==1 ) { @@ -290,75 +290,75 @@ int output_analog_channel( struct k8055_dev* dev ,int channel, long data ) { return k8055_write( dev ); } -int output_all_analog( struct k8055_dev* dev, long data1, long data2 ) { +int k8055_output_all_analog( struct k8055_dev* dev, long data1, long data2 ) { dev->data_out[0] = CMD_SET_ANALOG_DIGITAL; dev->data_out[2] = ( unsigned char )data1; dev->data_out[3] = ( unsigned char )data2; return k8055_write( dev ); } -int clear_all_analog( struct k8055_dev* dev ) { - return output_all_analog( dev, 0, 0 ); +int k8055_clear_all_analog( struct k8055_dev* dev ) { + return k8055_output_all_analog( dev, 0, 0 ); } -int clear_analog_channel( struct k8055_dev* dev, int channel ) { +int k8055_clear_analog_channel( struct k8055_dev* dev, int channel ) { if ( !( channel==1 || channel==2 ) ) return K8055_ERROR; if ( channel==1 ) { - return output_analog_channel( dev, 1, 0 ); + return k8055_output_analog_channel( dev, 1, 0 ); } else { - return output_analog_channel( dev, 2, 0 ); + return k8055_output_analog_channel( dev, 2, 0 ); } } -int set_analog_channel( struct k8055_dev* dev, int channel ) { +int k8055_set_analog_channel( struct k8055_dev* dev, int channel ) { if ( !( channel==1 || channel==2 ) ) return K8055_ERROR; if ( channel == 2 ) { - return output_analog_channel( dev, 2, 0xff ); + return k8055_output_analog_channel( dev, 2, 0xff ); } else { - return output_analog_channel( dev, 1, 0xff ); + return k8055_output_analog_channel( dev, 1, 0xff ); } } -int set_all_analog( struct k8055_dev* dev ) { - return output_all_analog( dev, 0xff, 0xff ); +int k8055_set_all_analog( struct k8055_dev* dev ) { + return k8055_output_all_analog( dev, 0xff, 0xff ); } -int write_all_digital( struct k8055_dev* dev, long data ) { +int k8055_write_all_digital( struct k8055_dev* dev, long data ) { dev->data_out[0] = CMD_SET_ANALOG_DIGITAL; dev->data_out[1] = ( unsigned char )data; return k8055_write( dev ); } -int clear_digital_channel( struct k8055_dev* dev, int channel ) { +int k8055_clear_digital_channel( struct k8055_dev* dev, int channel ) { unsigned char data; if ( channel<1 || channel>8 ) return K8055_ERROR; data = dev->data_out[1] & ~( 1 << ( channel-1 ) ); - return write_all_digital( dev, data ); + return k8055_write_all_digital( dev, data ); } -int clear_all_digital( struct k8055_dev* dev ) { - return write_all_digital( dev, 0x00 ); +int k8055_clear_all_digital( struct k8055_dev* dev ) { + return k8055_write_all_digital( dev, 0x00 ); } -int set_digital_channel( struct k8055_dev* dev, int channel ) { +int k8055_set_digital_channel( struct k8055_dev* dev, int channel ) { unsigned char data; if ( channel<1 || channel>8 ) return K8055_ERROR; data = dev->data_out[1] | ( 1 << ( channel-1 ) ); - return write_all_digital( dev, data ); + return k8055_write_all_digital( dev, data ); } -int set_all_digital( struct k8055_dev* dev ) { - return write_all_digital( dev, 0xff ); +int k8055_set_all_digital( struct k8055_dev* dev ) { + return k8055_write_all_digital( dev, 0xff ); } -int read_digital_channel( struct k8055_dev* dev, int channel ) { +int k8055_read_digital_channel( struct k8055_dev* dev, int channel ) { int rval; if ( channel<1 || channel>8 ) return K8055_ERROR; - if ( ( rval = read_all_digital( dev ) ) == K8055_ERROR ) return K8055_ERROR; + if ( ( rval = k8055_read_all_digital( dev ) ) == K8055_ERROR ) return K8055_ERROR; return ( ( rval & ( 1 << ( channel-1 ) ) ) > 0 ); } -long read_all_digital( struct k8055_dev* dev ) { +long k8055_read_all_digital( struct k8055_dev* dev ) { int return_data = 0; if ( k8055_read( dev )!=0 ) return K8055_ERROR; return_data = ( @@ -368,7 +368,7 @@ long read_all_digital( struct k8055_dev* dev ) { return return_data; } -int read_all_values( struct k8055_dev* dev, long int* data1, long int* data2, long int* data3, long int* data4, long int* data5 ) { +int k8055_read_all_values( struct k8055_dev* dev, long int* data1, long int* data2, long int* data3, long int* data4, long int* data5 ) { if ( k8055_read( dev )!=0 ) return K8055_ERROR; *data1 = ( ( ( dev->data_in[0] >> 4 ) & 0x03 ) | /* Input 1 and 2 */ @@ -381,7 +381,7 @@ int read_all_values( struct k8055_dev* dev, long int* data1, long int* data2, lo return 0; } -int set_all_values( struct k8055_dev* dev, int digital_data, int ad_data1, int ad_data2 ) { +int k8055_set_all_values( struct k8055_dev* dev, int digital_data, int ad_data1, int ad_data2 ) { dev->data_out[0] = CMD_SET_ANALOG_DIGITAL; dev->data_out[1] = ( unsigned char )digital_data; dev->data_out[2] = ( unsigned char )ad_data1; @@ -389,14 +389,14 @@ int set_all_values( struct k8055_dev* dev, int digital_data, int ad_data1, int a return k8055_write( dev ); } -int reset_counter( struct k8055_dev* dev, int counter ) { +int k8055_reset_counter( struct k8055_dev* dev, int counter ) { if ( !( counter==1 || counter==2 ) ) return K8055_ERROR; dev->data_out[0] = 0x02 + ( unsigned char )counter; dev->data_out[3+counter] = 0x00; return k8055_write( dev ); } -long read_counter( struct k8055_dev* dev, int counter ) { +long k8055_read_counter( struct k8055_dev* dev, int counter ) { if ( !( counter==1 || counter==2 ) ) return K8055_ERROR; if ( k8055_read( dev )!=0 ) return K8055_ERROR; if ( counter==1 ) { @@ -406,7 +406,7 @@ long read_counter( struct k8055_dev* dev, int counter ) { } } -int set_counter_debounce_time( struct k8055_dev* dev, int counter, long debounce_time ) { +int k8055_set_counter_debounce_time( struct k8055_dev* dev, int counter, long debounce_time ) { float value; if ( !( counter==1 || counter==2 ) ) return K8055_ERROR; dev->data_out[0] = ( unsigned char )counter; @@ -440,13 +440,13 @@ char* Version( void ) { } /* New function in version 2 of Velleman DLL, should return devices-found bitmask or 0*/ long SearchDevices( void ) { - return search_devices(); + return k8055_search_devices(); } /* Open device - scan through usb busses looking for the right device, claim it and then open the device */ int OpenDevice( long board_address ) { if( board_address<0 || board_address>=K8055_MAX_DEV ) return K8055_ERROR; if( k8055d[board_address].dev_no!=0 ) return board_address; - int ret = open_device( &k8055d[board_address], board_address ); + int ret = k8055_open_device( &k8055d[board_address], board_address ); if ( ret != K8055_ERROR ) { curr_dev = &k8055d[board_address]; return ret; @@ -455,7 +455,7 @@ int OpenDevice( long board_address ) { } /* Close the Current device */ int CloseDevice() { - return close_device( curr_dev ); + return k8055_close_device( curr_dev ); } /* New function in version 2 of Velleman DLL, should return deviceno if OK */ long SetCurrentDevice( long deviceno ) { @@ -465,62 +465,62 @@ long SetCurrentDevice( long deviceno ) { return deviceno; } long ReadAnalogChannel( long channel ) { - return read_analog_channel( curr_dev, channel ); + return k8055_read_analog_channel( curr_dev, channel ); } int ReadAllAnalog( long* data1, long* data2 ) { - return read_all_analog( curr_dev, data1, data2 ); + return k8055_read_all_analog( curr_dev, data1, data2 ); } int OutputAnalogChannel( long channel, long data ) { - return output_analog_channel( curr_dev, channel, data ); + return k8055_output_analog_channel( curr_dev, channel, data ); } int OutputAllAnalog( long data1, long data2 ) { - return output_all_analog( curr_dev, data1, data2 ); + return k8055_output_all_analog( curr_dev, data1, data2 ); } int ClearAllAnalog() { - return clear_all_analog( curr_dev ); + return k8055_clear_all_analog( curr_dev ); } int ClearAnalogChannel( long channel ) { - return clear_analog_channel( curr_dev, channel ); + return k8055_clear_analog_channel( curr_dev, channel ); } int SetAnalogChannel( long channel ) { - return set_analog_channel( curr_dev, channel ); + return k8055_set_analog_channel( curr_dev, channel ); } int SetAllAnalog() { - return set_all_analog( curr_dev ); + return k8055_set_all_analog( curr_dev ); } int WriteAllDigital( long data ) { - return write_all_digital( curr_dev, data ); + return k8055_write_all_digital( curr_dev, data ); } int ClearDigitalChannel( long channel ) { - return clear_digital_channel( curr_dev, channel ); + return k8055_clear_digital_channel( curr_dev, channel ); } int ClearAllDigital() { - return clear_all_digital( curr_dev ); + return k8055_clear_all_digital( curr_dev ); } int SetDigitalChannel( long channel ) { - return set_digital_channel( curr_dev, channel ); + return k8055_set_digital_channel( curr_dev, channel ); } int SetAllDigital() { - return set_all_digital( curr_dev ); + return k8055_set_all_digital( curr_dev ); } int ReadDigitalChannel( long channel ) { - return read_digital_channel( curr_dev, channel ); + return k8055_read_digital_channel( curr_dev, channel ); } long ReadAllDigital() { - return read_all_digital( curr_dev ); + return k8055_read_all_digital( curr_dev ); } int ReadAllValues( long int* data1, long int* data2, long int* data3, long int* data4, long int* data5 ) { - return read_all_values( curr_dev, data1, data2, data3, data4, data5 ); + return k8055_read_all_values( curr_dev, data1, data2, data3, data4, data5 ); } int SetAllValues( int DigitalData, int AdData1, int AdData2 ) { - return set_all_values( curr_dev, DigitalData, AdData1, AdData2 ); + return k8055_set_all_values( curr_dev, DigitalData, AdData1, AdData2 ); } int ResetCounter( long counter ) { - return reset_counter( curr_dev, counter ); + return k8055_reset_counter( curr_dev, counter ); } long ReadCounter( long counter ) { - return read_counter( curr_dev, counter ); + return k8055_read_counter( curr_dev, counter ); } int SetCounterDebounceTime( long counter, long debounce_time ) { - return set_counter_debounce_time( curr_dev, counter, debounce_time ); + return k8055_set_counter_debounce_time( curr_dev, counter, debounce_time ); } diff --git a/libk8055/main.c b/libk8055/main.c index 4a22514..055d045 100644 --- a/libk8055/main.c +++ b/libk8055/main.c @@ -60,7 +60,7 @@ inline int str2int( char* text, int* i ) { } static void display_help ( char* params[] ) { - printf( "K8055 version %s MrBrain Build\n",version() ); + printf( "K8055 version %s MrBrain Build\n",k8055_version() ); printf( "Copyright (C) 2004 by Nicolas Sutre\n" ); printf( "Copyright (C) 2005 by Bob Dempsey\n" ); printf( "Copyright (C) 2005 by Julien Etelain and Edward Nys\n" ); @@ -111,7 +111,7 @@ int read_param( int argc, char* params[] ) { !str2int( params[i]+6,&dbt2 ) ) erreurParam = true; else if ( !strcmp( params[i],"-debug" ) ) { debug = 1; - set_debug_on(); + k8055_set_debug_on(); } else if ( !strcmp( params[i],"-reset1" ) ) resetcnt1 = true; else if ( !strcmp( params[i],"-reset2" ) ) resetcnt2 = true; else if ( !strcmp( params[i],"--help" ) ) { @@ -155,41 +155,41 @@ int main ( int argc,char* params[] ) { if ( debug ) usb_set_debug( 2 ); struct k8055_dev dev; - if ( open_device( &dev, ipid )<0 ) { + if ( k8055_open_device( &dev, ipid )<0 ) { printf( "Could not open the k8055 (port:%d)\nPlease ensure that the device is correctly connected.\n",ipid ); return ( EXIT_FAILURE ); } else { if ( resetcnt1 ) - reset_counter( &dev,1 ); + k8055_reset_counter( &dev,1 ); if ( resetcnt2 ) - reset_counter( &dev,2 ); + k8055_reset_counter( &dev,2 ); if ( dbt1 != -1 ) - set_counter_debounce_time( &dev,1,dbt1 ); + k8055_set_counter_debounce_time( &dev,1,dbt1 ); if ( dbt2 != -1 ) - set_counter_debounce_time( &dev,2,dbt1 ); + k8055_set_counter_debounce_time( &dev,2,dbt1 ); if ( ( ia1!=-1 ) && ( ia2!=-1 ) && ( id8!=-1 ) ) { - result = set_all_values( &dev,id8,ia1,ia2 ); + result = k8055_set_all_values( &dev,id8,ia1,ia2 ); if ( debug ) printf( "SetAllValues=%d - Digital:%d, analog1:%d, analog2:%d\n",result,id8,ia1,ia2 ); } else if ( ( id8 != -1 ) && ( ia1!=-1 ) ) { - result = set_all_values( &dev,id8,ia1,0 ); + result = k8055_set_all_values( &dev,id8,ia1,0 ); if ( debug ) printf( "SetAllValues=%d - Digital:%d, analog1:%d\n",result,id8,ia1 ); } else if ( ( id8 != -1 ) && ( ia2!=-1 ) ) { - result = set_all_values( &dev,id8,0,ia2 ); + result = k8055_set_all_values( &dev,id8,0,ia2 ); if ( debug ) printf( "SetAllValues=%d - Digital:%d, analog2:%d\n",result,id8,ia2 ); } else if ( ( ia1 != -1 ) && ( ia2!=-1 ) ) { - result = set_all_values( &dev,0,ia1,ia2 ); + result = k8055_set_all_values( &dev,0,ia1,ia2 ); if ( debug ) printf( "SetAllValues=%d - analog1:%d, analog2:%d\n",result,ia1,ia2 ); } else { if ( ia1!=-1 ) { - result=output_analog_channel( &dev,1,ia1 ); + result=k8055_output_analog_channel( &dev,1,ia1 ); if ( debug ) printf( "Set analog1:%d=>%d\n",ia1,result ); } if ( ia2!=-1 ) { - result=output_analog_channel( &dev,2,ia2 ); + result=k8055_output_analog_channel( &dev,2,ia2 ); if ( debug ) printf( "Set analog2:%d=>%d\n",ia2,result ); } if ( id8!=-1 ) { - result=write_all_digital( &dev,( long )id8 ); + result=k8055_write_all_digital( &dev,( long )id8 ); if ( debug ) printf( "Set digital:%d=>%d\n",id8,result ); } } @@ -198,11 +198,11 @@ int main ( int argc,char* params[] ) { if ( delay ) { while ( time_msec()-mstart < i*delay ); } - read_all_values( &dev,&d,&a1,&a2,&c1,&c2 ); + k8055_read_all_values( &dev,&d,&a1,&a2,&c1,&c2 ); lastcall = time_msec(); printf( "%d;%d;%d;%d;%d;%d\n", ( int )( lastcall-start ),( int )d, ( int )a1, ( int )a2,( int )c1,( int )c2 ); } - close_device( &dev ); + k8055_close_device( &dev ); } } return EXIT_SUCCESS; |