diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2011-06-06 07:01:09 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2011-06-06 07:01:09 +0200 |
commit | b019e00751a521524a5a3f8869cbf0f152ded52e (patch) | |
tree | 6e3406f6b695ea80ffb1e38edd7b52497c732257 | |
parent | 1dcf7f69f49dd11108c01c97025bfc1abd3b75d2 (diff) | |
download | k8055-b019e00751a521524a5a3f8869cbf0f152ded52e.zip k8055-b019e00751a521524a5a3f8869cbf0f152ded52e.tar.gz |
rename k8055_digital_x to k8055_digital_input_x, add k8055_digital_output_x, same for analog
-rw-r--r-- | libk8055/k8055++.h | 21 | ||||
-rw-r--r-- | libk8055/k8055.h | 41 | ||||
-rw-r--r-- | libk8055/libk8055.c | 46 | ||||
-rw-r--r-- | libk8055/libk8055.cpp | 56 |
4 files changed, 119 insertions, 45 deletions
diff --git a/libk8055/k8055++.h b/libk8055/k8055++.h index b924f65..0f3a024 100644 --- a/libk8055/k8055++.h +++ b/libk8055/k8055++.h @@ -35,13 +35,20 @@ class K8055 { int read( void ); int write( void ); - int digital_1( void ); - int digital_2( void ); - int digital_3( void ); - int digital_4( void ); - int digital_5( void ); - int analog_1( void ); - int analog_2( void ); + int digital_output_1( void ); + int digital_output_2( void ); + int digital_output_3( void ); + int digital_output_4( void ); + int digital_output_5( void ); + int analog_output_1( void ); + int analog_output_2( void ); + int digital_input_1( void ); + int digital_input_2( void ); + int digital_input_3( void ); + int digital_input_4( void ); + int digital_input_5( void ); + int analog_input_1( void ); + int analog_input_2( void ); int counter_1( void ); int counter_2( void ); diff --git a/libk8055/k8055.h b/libk8055/k8055.h index d1f8359..259d00b 100644 --- a/libk8055/k8055.h +++ b/libk8055/k8055.h @@ -42,19 +42,29 @@ extern "C" { unsigned char data_in[PACKET_LEN+1]; unsigned char data_out[PACKET_LEN+1]; }; + /* create/destroy struct */ struct k8055_dev* k8055_alloc( void ); void k8055_free( struct k8055_dev* dev ); - + /* read data_in / write data_out */ int k8055_read( struct k8055_dev* dev ); int k8055_write( struct k8055_dev* dev ); - int k8055_digital_1( struct k8055_dev* dev ); - int k8055_digital_2( struct k8055_dev* dev ); - int k8055_digital_3( struct k8055_dev* dev ); - int k8055_digital_4( struct k8055_dev* dev ); - int k8055_digital_5( struct k8055_dev* dev ); - int k8055_analog_1( struct k8055_dev* dev ); - int k8055_analog_2( struct k8055_dev* dev ); + /* access output data */ + int k8055_digital_output_1( struct k8055_dev* dev ); + int k8055_digital_output_2( struct k8055_dev* dev ); + int k8055_digital_output_3( struct k8055_dev* dev ); + int k8055_digital_output_4( struct k8055_dev* dev ); + int k8055_digital_output_5( struct k8055_dev* dev ); + int k8055_analog_output_1( struct k8055_dev* dev ); + int k8055_analog_output_2( struct k8055_dev* dev ); + /* access input data */ + int k8055_digital_input_1( struct k8055_dev* dev ); + int k8055_digital_input_2( struct k8055_dev* dev ); + int k8055_digital_input_3( struct k8055_dev* dev ); + int k8055_digital_input_4( struct k8055_dev* dev ); + int k8055_digital_input_5( struct k8055_dev* dev ); + int k8055_analog_input_1( struct k8055_dev* dev ); + int k8055_analog_input_2( struct k8055_dev* dev ); int k8055_counter_1( struct k8055_dev* dev ); int k8055_counter_2( struct k8055_dev* dev ); @@ -66,24 +76,25 @@ extern "C" { int k8055_open_device( struct k8055_dev* dev, int board_address ); int k8055_close_device( struct k8055_dev* dev ); + /* analog outputs */ int k8055_set_analog_channel( struct k8055_dev* dev, int channel ); int k8055_clear_analog_channel( struct k8055_dev* dev, int channel ); - int k8055_read_analog_channel( struct k8055_dev* dev, int channel ); int k8055_write_analog_channel( struct k8055_dev* dev ,int channel, int data ); - int k8055_set_all_analog( struct k8055_dev* dev ); int k8055_clear_all_analog( struct k8055_dev* dev ); - int k8055_read_all_analog( struct k8055_dev* dev, int* data1, int* data2 ); int k8055_write_all_analog( struct k8055_dev* dev, int data1, int data2 ); - + /* analog inputs */ + int k8055_read_analog_channel( struct k8055_dev* dev, int channel ); + int k8055_read_all_analog( struct k8055_dev* dev, int* data1, int* data2 ); + /* digital outputs */ int k8055_set_digital_channel( struct k8055_dev* dev, int channel ); int k8055_clear_digital_channel( struct k8055_dev* dev, int channel ); - int k8055_read_digital_channel( struct k8055_dev* dev, int channel ); - int k8055_set_all_digital( struct k8055_dev* dev ); int k8055_clear_all_digital( struct k8055_dev* dev ); - int k8055_read_all_digital( struct k8055_dev* dev ); int k8055_write_all_digital( struct k8055_dev* dev, int data ); + /* digital inputs */ + int k8055_read_digital_channel( struct k8055_dev* dev, int channel ); + int k8055_read_all_digital( struct k8055_dev* dev ); int k8055_set_all_values( struct k8055_dev* dev, int d_data, int a_data1, int a_data2 ); int k8055_read_all_values( struct k8055_dev* dev, int* data1, int* data2, int* data3, int* data4, int* data5 ); diff --git a/libk8055/libk8055.c b/libk8055/libk8055.c index 09691b1..4853cc3 100644 --- a/libk8055/libk8055.c +++ b/libk8055/libk8055.c @@ -143,31 +143,59 @@ int k8055_write( struct k8055_dev* dev ) { return K8055_ERROR; } -int k8055_digital_1( struct k8055_dev* dev ) { +int k8055_digital_output_1( struct k8055_dev* dev ) { + return ( ( dev->data_out[DIGITAL_OUT_OFFSET] ) & 0x01 ); +} + +int k8055_digital_output_2( struct k8055_dev* dev ) { + return ( ( dev->data_out[DIGITAL_OUT_OFFSET] >> 1 ) & 0x01 ); +} + +int k8055_digital_output_3( struct k8055_dev* dev ) { + return ( ( dev->data_out[DIGITAL_OUT_OFFSET] >> 2 ) & 0x01 ); +} + +int k8055_digital_output_4( struct k8055_dev* dev ) { + return ( ( dev->data_out[DIGITAL_OUT_OFFSET] >> 3 ) & 0x01 ); +} + +int k8055_digital_output_5( struct k8055_dev* dev ) { + return ( ( dev->data_out[DIGITAL_OUT_OFFSET] >> 4 ) & 0x01 ); +} + +int k8055_analog_output_1( struct k8055_dev* dev ) { + return dev->data_out[ANALOG_1_OFFSET]; +} + +int k8055_analog_output_2( struct k8055_dev* dev ) { + return dev->data_out[ANALOG_2_OFFSET]; +} + +int k8055_digital_input_1( struct k8055_dev* dev ) { return ( ( dev->data_in[DIGITAL_INP_OFFSET] >> 4 ) & 0x01 ); } -int k8055_digital_2( struct k8055_dev* dev ) { +int k8055_digital_input_2( struct k8055_dev* dev ) { return ( ( dev->data_in[DIGITAL_INP_OFFSET] >> 5 ) & 0x01 ); } -int k8055_digital_3( struct k8055_dev* dev ) { +int k8055_digital_input_3( struct k8055_dev* dev ) { return ( ( dev->data_in[DIGITAL_INP_OFFSET] ) & 0x01 ); } -int k8055_digital_4( struct k8055_dev* dev ) { +int k8055_digital_input_4( struct k8055_dev* dev ) { return ( ( dev->data_in[DIGITAL_INP_OFFSET] >> 6 ) & 0x01 ); } -int k8055_digital_5( struct k8055_dev* dev ) { +int k8055_digital_input_5( struct k8055_dev* dev ) { return ( ( dev->data_in[DIGITAL_INP_OFFSET] >> 7 ) & 0x01 ); } -int k8055_analog_1( struct k8055_dev* dev ) { +int k8055_analog_input_1( struct k8055_dev* dev ) { return dev->data_in[ANALOG_1_OFFSET]; } -int k8055_analog_2( struct k8055_dev* dev ) { +int k8055_analog_input_2( struct k8055_dev* dev ) { return dev->data_in[ANALOG_2_OFFSET]; } @@ -179,14 +207,14 @@ int k8055_counter_2( struct k8055_dev* dev ) { return dev->data_in[COUNTER_2_OFFSET]; } -/* If device is owned by some kernel driver, try to disconnect it and claim the device*/ +/* If device is owned by some kernel driver, try to disconnect it and clanalog_inputm the device*/ static int k8055_takeover_device( libusb_device_handle* handle, int interface ) { char driver_name[STR_BUFF]; memset( driver_name, 0, STR_BUFF ); int ret = K8055_ERROR; assert( handle != NULL ); if( libusb_detach_kernel_driver( handle, interface )!=0 ) { - if( debug ) fprintf( stderr, "usb_detach_kernel_driver failure\n" ); + if( debug ) fprintf( stderr, "usb_detach_kernel_driver fanalog_inputlure\n" ); } if ( libusb_claim_interface( handle, interface )!=0 ) { if( debug ) fprintf( stderr, "usb_claim_interface failure\n" ); diff --git a/libk8055/libk8055.cpp b/libk8055/libk8055.cpp index 5c6aa2b..f537676 100644 --- a/libk8055/libk8055.cpp +++ b/libk8055/libk8055.cpp @@ -39,32 +39,60 @@ int K8055::write( void ) { return k8055_write( &dev ); } -int K8055::digital_1( void ) { - return k8055_digital_1( &dev ); +int K8055::digital_output_1( void ) { + return k8055_digital_output_1( &dev ); } -int K8055::digital_2( void ) { - return k8055_digital_2( &dev ); +int K8055::digital_output_2( void ) { + return k8055_digital_output_2( &dev ); } -int K8055::digital_3( void ) { - return k8055_digital_3( &dev ); +int K8055::digital_output_3( void ) { + return k8055_digital_output_3( &dev ); } -int K8055::digital_4( void ) { - return k8055_digital_4( &dev ); +int K8055::digital_output_4( void ) { + return k8055_digital_output_4( &dev ); } -int K8055::digital_5( void ) { - return k8055_digital_5( &dev ); +int K8055::digital_output_5( void ) { + return k8055_digital_output_5( &dev ); } -int K8055::analog_1( void ) { - return k8055_analog_1( &dev ); +int K8055::analog_output_1( void ) { + return k8055_analog_output_1( &dev ); } -int K8055::analog_2( void ) { - return k8055_analog_2( &dev ); +int K8055::analog_output_2( void ) { + return k8055_analog_input_2( &dev ); +} + +int K8055::digital_input_1( void ) { + return k8055_digital_input_1( &dev ); +} + +int K8055::digital_input_2( void ) { + return k8055_digital_input_2( &dev ); +} + +int K8055::digital_input_3( void ) { + return k8055_digital_input_3( &dev ); +} + +int K8055::digital_input_4( void ) { + return k8055_digital_input_4( &dev ); +} + +int K8055::digital_input_5( void ) { + return k8055_digital_input_5( &dev ); +} + +int K8055::analog_input_1( void ) { + return k8055_analog_input_1( &dev ); +} + +int K8055::analog_input_2( void ) { + return k8055_analog_input_2( &dev ); } int K8055::counter_1( void ) { |