summaryrefslogtreecommitdiffstats
path: root/libk8055
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2011-03-01 10:37:03 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2011-03-01 10:37:03 +0100
commit685999a84dad1fa51e28eb8c676e53fb3a856375 (patch)
treea8255b12b359eef55332ee00ba14a35e93f87040 /libk8055
parent4ac9d96b5ca74c03020282d1c486e0eecad58d73 (diff)
downloadk8055-685999a84dad1fa51e28eb8c676e53fb3a856375.zip
k8055-685999a84dad1fa51e28eb8c676e53fb3a856375.tar.gz
set k8055_read and k8055_write public, add data_in access functions
Diffstat (limited to 'libk8055')
-rw-r--r--libk8055/k8055.h19
-rw-r--r--libk8055/libk8055.c12
2 files changed, 22 insertions, 9 deletions
diff --git a/libk8055/k8055.h b/libk8055/k8055.h
index 37a70af..121c757 100644
--- a/libk8055/k8055.h
+++ b/libk8055/k8055.h
@@ -25,12 +25,31 @@ extern "C" {
#define PACKET_LEN 8
+#define DIGITAL_INP_OFFSET 0
+#define DIGITAL_OUT_OFFSET 1
+#define ANALOG_1_OFFSET 2
+#define ANALOG_2_OFFSET 3
+#define COUNTER_1_OFFSET 4
+#define COUNTER_2_OFFSET 6
+
struct k8055_dev {
int dev_no;
struct usb_dev_handle* device_handle;
unsigned char data_in[PACKET_LEN+1];
unsigned char data_out[PACKET_LEN+1];
};
+ int k8055_read( struct k8055_dev* dev );
+ int k8055_write( struct k8055_dev* dev );
+
+ int k8055_digital_1( struct k8055_dev* dev ) { return ( ( dev->data_in[DIGITAL_INP_OFFSET] >> 4 ) & 0x01 ); }
+ int k8055_digital_2( struct k8055_dev* dev ) { return ( ( dev->data_in[DIGITAL_INP_OFFSET] >> 5 ) & 0x01 ); }
+ int k8055_digital_3( struct k8055_dev* dev ) { return ( ( dev->data_in[DIGITAL_INP_OFFSET] ) & 0x01 ); }
+ int k8055_digital_4( struct k8055_dev* dev ) { return ( ( dev->data_in[DIGITAL_INP_OFFSET] >> 6 ) & 0x01 ); }
+ int k8055_digital_5( struct k8055_dev* dev ) { return ( ( dev->data_in[DIGITAL_INP_OFFSET] >> 7 ) & 0x01 ); }
+ int k8055_analog_1( struct k8055_dev* dev ) { return dev->data_in[ANALOG_1_OFFSET]; }
+ int k8055_analog_2( struct k8055_dev* dev ) { return dev->data_in[ANALOG_2_OFFSET]; }
+ int k8055_counter_1( struct k8055_dev* dev ) { return dev->data_in[COUNTER_1_OFFSET]; }
+ int k8055_counter_2( struct k8055_dev* dev ) { return dev->data_in[COUNTER_2_OFFSET]; }
char* k8055_version( void );
void k8055_set_debug_on( void );
diff --git a/libk8055/libk8055.c b/libk8055/libk8055.c
index 6d85c06..536507e 100644
--- a/libk8055/libk8055.c
+++ b/libk8055/libk8055.c
@@ -99,13 +99,7 @@
#define USB_TIMEOUT 20
#define K8055_ERROR -1
-#define DIGITAL_INP_OFFSET 0
-#define DIGITAL_OUT_OFFSET 1
-#define ANALOG_1_OFFSET 2
-#define ANALOG_2_OFFSET 3
-#define COUNTER_1_OFFSET 4
-#define COUNTER_2_OFFSET 6
-
+#define CMD_OFFSET 0
#define CMD_RESET 0x00
#define CMD_SET_DEBOUNCE_1 0x01
#define CMD_SET_DEBOUNCE_2 0x01
@@ -117,7 +111,7 @@
static int debug = 0;
/* Actual read of data from the device endpoint, retry READ_RETRY times if not responding ok */
-static int k8055_read( struct k8055_dev* dev ) {
+int k8055_read( struct k8055_dev* dev ) {
if( dev->dev_no==0 ) return K8055_ERROR;
for( int i=0; i<READ_RETRY; i++ ) {
int read_status = usb_interrupt_read( dev->device_handle, USB_INP_EP, ( char* )dev->data_in, PACKET_LEN, USB_TIMEOUT );
@@ -128,7 +122,7 @@ static int k8055_read( struct k8055_dev* dev ) {
}
/* Actual write of data to the device endpont, retry WRITE_RETRY times if not reponding correctly */
-static int k8055_write( struct k8055_dev* dev ) {
+int k8055_write( struct k8055_dev* dev ) {
if( dev->dev_no == 0 ) return K8055_ERROR;
for( int i=0; i<WRITE_RETRY; i++ ) {
int write_status = usb_interrupt_write( dev->device_handle, USB_OUT_EP, ( char* )dev->data_out, PACKET_LEN, USB_TIMEOUT );