Instrument Neutral Distributed Interface INDI  2.0.2
gpdriver.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright(c) 2012 Jasem Mutlaq. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License as published by the Free
6  Software Foundation; either version 2 of the License, or (at your option)
7  any later version.
8 
9  This program is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 
19  The full GNU General Public License is included in this distribution in the
20  file called LICENSE.
21 *******************************************************************************/
22 
23 #include "gpdriver.h"
24 
26 {
27  //ctor
28  guideCMD[0] = 0;
29  debug = false;
30 }
31 
33 {
34  //dtor
35  // usb_close(usb_handle);
36 }
37 
39 {
40  dev = FindDevice(0x134A, 0x9020, 0);
41 
42  if (dev == nullptr)
43  {
44  IDLog("Error: No GPUSB device found\n");
45  return false;
46  }
47 
48  int rc = Open();
49 
50  return (rc != -1);
51 }
52 
54 {
55  Close();
56  return true;
57 }
58 
59 bool GPUSBDriver::startPulse(int direction)
60 {
61  int rc = 0;
62 
63  switch (direction)
64  {
65  case GPUSB_NORTH:
66  guideCMD[0] &= GPUSB_CLEAR_DEC;
67  guideCMD[0] |= (GPUSB_NORTH | GPUSB_LED_ON) & ~GPUSB_LED_RED;
68  break;
69 
70  case GPUSB_WEST:
71  guideCMD[0] &= GPUSB_CLEAR_RA;
72  guideCMD[0] |= (GPUSB_WEST | GPUSB_LED_ON) & ~GPUSB_LED_RED;
73  break;
74 
75  case GPUSB_SOUTH:
76  guideCMD[0] &= GPUSB_CLEAR_DEC;
77  guideCMD[0] |= GPUSB_SOUTH | GPUSB_LED_ON | GPUSB_LED_RED;
78  break;
79 
80  case GPUSB_EAST:
81  guideCMD[0] &= GPUSB_CLEAR_RA;
82  guideCMD[0] |= GPUSB_EAST | GPUSB_LED_ON | GPUSB_LED_RED;
83  break;
84  }
85 
86  if (debug)
87  IDLog("start command value is 0x%X\n", guideCMD[0]);
88 
89  rc = WriteBulk((unsigned char *)guideCMD, 1, 1000);
90 
91  if (debug)
92  IDLog("startPulse WriteBulk returns %d\n", rc);
93  if (rc == 1)
94  return true;
95 
96  return false;
97 }
98 
99 bool GPUSBDriver::stopPulse(int direction)
100 {
101  int rc = 0;
102 
103  switch (direction)
104  {
105  case GPUSB_NORTH:
106  if (debug)
107  IDLog("Stop North\n");
108  guideCMD[0] &= GPUSB_CLEAR_DEC;
109  break;
110 
111  case GPUSB_WEST:
112  if (debug)
113  IDLog("Stop West\n");
114  guideCMD[0] &= GPUSB_CLEAR_RA;
115  break;
116 
117  case GPUSB_SOUTH:
118  if (debug)
119  IDLog("Stop South\n");
120  guideCMD[0] &= GPUSB_CLEAR_DEC;
121  break;
122 
123  case GPUSB_EAST:
124  if (debug)
125  IDLog("Stop East\n");
126  guideCMD[0] &= GPUSB_CLEAR_RA;
127  break;
128  }
129 
130  if ((guideCMD[0] & GPUSB_NORTH) || (guideCMD[0] & GPUSB_WEST))
131  guideCMD[0] &= ~GPUSB_LED_RED;
132  else if ((guideCMD[0] & GPUSB_SOUTH) || (guideCMD[0] & GPUSB_EAST))
133  guideCMD[0] |= GPUSB_LED_RED;
134 
135  if ((guideCMD[0] & 0xF) == 0)
136  guideCMD[0] = 0;
137 
138  if (debug)
139  IDLog("stop command value is 0x%X\n", guideCMD[0]);
140 
141  rc = WriteBulk((unsigned char *)guideCMD, 1, 1000);
142 
143  if (debug)
144  IDLog("stopPulse WriteBulk returns %d\n", rc);
145  if (rc == 1)
146  return true;
147 
148  return false;
149 }
bool Connect()
Definition: gpdriver.cpp:38
virtual ~GPUSBDriver()
Definition: gpdriver.cpp:32
bool Disconnect()
Definition: gpdriver.cpp:53
bool stopPulse(int direction)
Definition: gpdriver.cpp:99
bool startPulse(int direction)
Definition: gpdriver.cpp:59
int WriteBulk(unsigned char *buf, int nbytes, int timeout)
libusb_device * dev
Definition: indiusbdevice.h:40
libusb_device * FindDevice(int, int, int)
@ GPUSB_CLEAR_RA
Definition: gpdriver.h:35
@ GPUSB_SOUTH
Definition: gpdriver.h:30
@ GPUSB_LED_RED
Definition: gpdriver.h:33
@ GPUSB_CLEAR_DEC
Definition: gpdriver.h:36
@ GPUSB_WEST
Definition: gpdriver.h:32
@ GPUSB_NORTH
Definition: gpdriver.h:29
@ GPUSB_EAST
Definition: gpdriver.h:31
@ GPUSB_LED_ON
Definition: gpdriver.h:34
void IDLog(const char *fmt,...)
Definition: indicom.c:316