mirror of
https://github.com/shakemid/pcsensor-temper.git
synced 2025-01-21 17:18:16 +01:00
Fix indent to 4 spaces
This commit is contained in:
parent
3519bbbd47
commit
cc37eec1cf
1 changed files with 209 additions and 228 deletions
53
pcsensor.c
53
pcsensor.c
|
@ -112,28 +112,23 @@ libusb_device_handle* setup_libusb_access() {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
usb_detach(lvr_winusb, INTERFACE1);
|
||||
|
||||
|
||||
usb_detach(lvr_winusb, INTERFACE2);
|
||||
|
||||
|
||||
if (libusb_set_configuration(lvr_winusb, 0x01) < 0) {
|
||||
fprintf(stderr, "Could not set configuration 1\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
// Microdia tiene 2 interfaces
|
||||
int errno;
|
||||
if ( ( errno = libusb_claim_interface(lvr_winusb, INTERFACE1) ) != 0) {
|
||||
fprintf(stderr, "Could not claim interface. Error:%d\n", errno);
|
||||
int s;
|
||||
if ( ( s = libusb_claim_interface(lvr_winusb, INTERFACE1) ) != 0) {
|
||||
fprintf(stderr, "Could not claim interface. Error:%d\n", s);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ( ( errno = libusb_claim_interface(lvr_winusb, INTERFACE2) ) != 0) {
|
||||
fprintf(stderr, "Could not claim interface. Error:%d\n", errno);
|
||||
if ( ( s = libusb_claim_interface(lvr_winusb, INTERFACE2) ) != 0) {
|
||||
fprintf(stderr, "Could not claim interface. Error:%d\n", s);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -160,12 +155,10 @@ void ini_control_transfer(libusb_device_handle *dev) {
|
|||
char question[] = { 0x01,0x01 };
|
||||
|
||||
r = libusb_control_transfer(dev, 0x21, 0x09, 0x0201, 0x00, (char *) question, 2, timeout);
|
||||
if( r < 0 )
|
||||
{
|
||||
if( r < 0 ) {
|
||||
perror("USB control write"); bad("USB write failed");
|
||||
}
|
||||
|
||||
|
||||
if(debug) {
|
||||
for (i=0;i<reqIntLen; i++) printf("%02x ",question[i] & 0xFF);
|
||||
printf("\n");
|
||||
|
@ -180,8 +173,7 @@ void control_transfer(libusb_device_handle *dev, const char *pquestion) {
|
|||
memcpy(question, pquestion, sizeof question);
|
||||
|
||||
r = libusb_control_transfer(dev, 0x21, 0x09, 0x0200, 0x01, (char *) question, reqIntLen, timeout);
|
||||
if( r < 0 )
|
||||
{
|
||||
if( r < 0 ) {
|
||||
perror("USB control write"); bad("USB write failed");
|
||||
}
|
||||
|
||||
|
@ -192,21 +184,21 @@ void control_transfer(libusb_device_handle *dev, const char *pquestion) {
|
|||
}
|
||||
|
||||
void interrupt_transfer(libusb_device_handle *dev) {
|
||||
|
||||
int r,s,i;
|
||||
char answer[reqIntLen];
|
||||
char question[reqIntLen];
|
||||
int transferred;
|
||||
|
||||
for (i=0;i<reqIntLen; i++) question[i]=i;
|
||||
|
||||
s = libusb_interrupt_transfer(dev, endpoint_Int_out, question, reqIntLen, &r, timeout);
|
||||
if( r < 0 )
|
||||
{
|
||||
if( r < 0 ) {
|
||||
fprintf(stderr, "USB write failed:%d", s);
|
||||
perror("USB interrupt write"); bad("USB write failed");
|
||||
}
|
||||
|
||||
s = libusb_interrupt_transfer(dev, endpoint_Int_in, answer, reqIntLen, &r, timeout);
|
||||
if( r != reqIntLen )
|
||||
{
|
||||
if( r != reqIntLen ) {
|
||||
fprintf(stderr, "USB read failed:%d", s);
|
||||
perror("USB interrupt read"); bad("USB read failed");
|
||||
}
|
||||
|
@ -219,14 +211,12 @@ void interrupt_transfer(libusb_device_handle *dev) {
|
|||
}
|
||||
|
||||
void interrupt_read(libusb_device_handle *dev) {
|
||||
|
||||
int r,s,i;
|
||||
unsigned char answer[reqIntLen];
|
||||
bzero(answer, reqIntLen);
|
||||
|
||||
s = libusb_interrupt_transfer(dev, endpoint_Int_in, answer, reqIntLen, &r, timeout);
|
||||
if( r != reqIntLen )
|
||||
{
|
||||
if( r != reqIntLen ) {
|
||||
fprintf(stderr, "USB read failed: %d\n", s);
|
||||
perror("USB interrupt read"); bad("USB read failed");
|
||||
}
|
||||
|
@ -239,19 +229,16 @@ void interrupt_read(libusb_device_handle *dev) {
|
|||
}
|
||||
|
||||
void interrupt_read_temperatura(libusb_device_handle *dev, float *tempInC, float *tempOutC) {
|
||||
|
||||
int r,s,i, temperature;
|
||||
unsigned char answer[reqIntLen];
|
||||
bzero(answer, reqIntLen);
|
||||
|
||||
s = libusb_interrupt_transfer(dev, endpoint_Int_in, answer, reqIntLen, &r, timeout);
|
||||
if( r != reqIntLen )
|
||||
{
|
||||
if( r != reqIntLen ) {
|
||||
fprintf(stderr, "USB read failed: %d\n", s);
|
||||
perror("USB interrupt read"); bad("USB read failed");
|
||||
}
|
||||
|
||||
|
||||
if(debug) {
|
||||
for (i=0;i<reqIntLen; i++) printf("%02x ",answer[i] & 0xFF);
|
||||
|
||||
|
@ -269,22 +256,19 @@ void interrupt_read_temperatura(libusb_device_handle *dev, float *tempInC, float
|
|||
}
|
||||
|
||||
void bulk_transfer(libusb_device_handle *dev) {
|
||||
|
||||
int r,s,i;
|
||||
char answer[reqBulkLen];
|
||||
|
||||
s = libusb_bulk_transfer(dev, endpoint_Bulk_out, NULL, 0, &r, timeout);
|
||||
if( r < 0 )
|
||||
{
|
||||
if( r < 0 ) {
|
||||
perror("USB bulk write"); bad("USB write failed");
|
||||
}
|
||||
|
||||
s = libusb_bulk_transfer(dev, endpoint_Bulk_in, answer, reqBulkLen, &r, timeout);
|
||||
if( r != reqBulkLen )
|
||||
{
|
||||
if( r != reqBulkLen ) {
|
||||
perror("USB bulk read"); bad("USB read failed");
|
||||
}
|
||||
|
||||
|
||||
if(debug) {
|
||||
for (i=0;i<reqBulkLen; i++) printf("%02x ",answer[i] & 0xFF);
|
||||
}
|
||||
|
@ -300,7 +284,6 @@ void ex_program(int sig) {
|
|||
}
|
||||
|
||||
int main( int argc, char **argv) {
|
||||
|
||||
libusb_device_handle *lvr_winusb = NULL;
|
||||
float tempInC;
|
||||
float tempOutC;
|
||||
|
@ -378,7 +361,6 @@ int main( int argc, char **argv) {
|
|||
|
||||
(void) signal(SIGINT, ex_program);
|
||||
|
||||
|
||||
ini_control_transfer(lvr_winusb);
|
||||
|
||||
control_transfer(lvr_winusb, uTemperatura );
|
||||
|
@ -391,7 +373,6 @@ int main( int argc, char **argv) {
|
|||
interrupt_read(lvr_winusb);
|
||||
interrupt_read(lvr_winusb);
|
||||
|
||||
|
||||
do {
|
||||
control_transfer(lvr_winusb, uTemperatura );
|
||||
interrupt_read_temperatura(lvr_winusb, &tempInC, &tempOutC);
|
||||
|
|
Loading…
Add table
Reference in a new issue