Subversion Repositories seema-scanner

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 jakw 1
/*
2
 * usb.cpp
3
 *
4
 * This module has the wrapper functions to access USB driver functions.
5
 *
6
 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
7
 * ALL RIGHTS RESERVED
8
 *
9
*/
10
 
11
//#ifdef Q_OS_WIN32
12
//#include <setupapi.h>
13
//#endif
14
//#include <QMessageBox>
15
//#include <QTimer>
16
#include "usb.h"
17
//#include <stdio.h>
18
//#include <stdlib.h>
19
#include "hidapi.h"
20
 
21
/***************************************************
22
*                  GLOBAL VARIABLES
23
****************************************************/
24
static hid_device *DeviceHandle;	//Handle to write
25
//In/Out buffers equal to HID endpoint size + 1
26
//First byte is for Windows internal use and it is always 0
27
unsigned char OutputBuffer[USB_MAX_PACKET_SIZE+1];
28
unsigned char InputBuffer[USB_MAX_PACKET_SIZE+1];
29
 
30
static bool USBConnected = false;      //Boolean true when device is connected
31
 
32
bool USB_IsConnected()
33
{
34
    return USBConnected;
35
}
36
 
37
int USB_Init(void)
38
{
39
    return hid_init();
40
}
41
 
42
int USB_Exit(void)
43
{
44
    return hid_exit();
45
}
46
 
47
int USB_Open()
48
{
49
    // Open the device using the VID, PID,
50
    // and optionally the Serial number.
51
    DeviceHandle = hid_open(MY_VID, MY_PID, NULL);
52
 
53
    if(DeviceHandle == NULL)
54
    {
55
        USBConnected = false;
56
        return -1;
57
    }
58
    USBConnected = true;
59
    return 0;
60
}
61
 
62
int USB_Write()
63
{
64
    if(DeviceHandle == NULL)
65
        return -1;
66
 
67
    return hid_write(DeviceHandle, OutputBuffer, USB_MIN_PACKET_SIZE+1);
68
 
69
}
70
 
71
int USB_Read()
72
{
73
    if(DeviceHandle == NULL)
74
        return -1;
75
 
76
    return hid_read_timeout(DeviceHandle, InputBuffer, USB_MIN_PACKET_SIZE+1, 2000);
77
}
78
 
79
int USB_Close()
80
{
81
    hid_close(DeviceHandle);
82
    USBConnected = false;
83
 
84
    return 0;
85
}
86