| 1 |
/* |
| 2 |
DSUSB Driver for GPhoto |
| 3 |
|
| 4 |
Copyright (C) 2017 Jasem Mutlaq ([email protected]) |
| 5 |
|
| 6 |
This library is free software; you can redistribute it and/or |
| 7 |
modify it under the terms of the GNU Lesser General Public |
| 8 |
License as published by the Free Software Foundation; either |
| 9 |
version 2.1 of the License, or (at your option) any later version. |
| 10 |
|
| 11 |
This library is distributed in the hope that it will be useful, |
| 12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
Lesser General Public License for more details. |
| 15 |
|
| 16 |
You should have received a copy of the GNU Lesser General Public |
| 17 |
License along with this library; if not, write to the Free Software |
| 18 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 |
|
| 20 |
*/ |
| 21 |
|
| 22 |
#include "dsusbdriver.h" |
| 23 |
|
| 24 |
#include <indilogger.h> |
| 25 |
#include <unistd.h> |
| 26 |
#include <string.h> |
| 27 |
|
| 28 |
#define SHUTTER_ON 0x01 |
| 29 |
#define FOCUS_ON 0x02 |
| 30 |
#define LED_RED 0x10 |
| 31 |
#define LED_ON 0x20 |
| 32 |
|
| 33 |
DSUSBDriver::DSUSBDriver(const char *device) |
| 34 |
{ |
| 35 |
strncpy(this->device, device, MAXINDIDEVICE); |
| 36 |
|
| 37 |
DEBUGDEVICE(device, INDI::Logger::DBG_DEBUG, "Finding DSUSB 0x134A, 0x9021 ..."); |
| 38 |
// Try to see if it is DSUSB |
| 39 |
dev = FindDevice(0x134A, 0x9021, 0); |
| 40 |
// DSUSB2? |
| 41 |
if (dev == nullptr) |
| 42 |
{ |
| 43 |
DEBUGDEVICE(device, INDI::Logger::DBG_DEBUG, "Finding DSUSB 0x134A, 0x9026 ..."); |
| 44 |
dev = FindDevice(0x134A, 0x9026, 0); |
| 45 |
} |
| 46 |
|
| 47 |
if (dev) |
| 48 |
{ |
| 49 |
int rc = Open(); |
| 50 |
connected = (rc != -1); |
| 51 |
DEBUGDEVICE(device, INDI::Logger::DBG_DEBUG, "Connected to DSUSB!"); |
| 52 |
readState(); |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
bool DSUSBDriver::readState() |
| 57 |
{ |
| 58 |
int rc = ReadBulk(&infoByte, 1, 1000); |
| 59 |
DEBUGFDEVICE(device, INDI::Logger::DBG_DEBUG, "RC: %d - Info Byte: %#02X", rc, infoByte); |
| 60 |
|
| 61 |
return (rc == 1); |
| 62 |
} |
| 63 |
|
| 64 |
bool DSUSBDriver::openShutter() |
| 65 |
{ |
| 66 |
uint8_t command = 0; |
| 67 |
|
| 68 |
DEBUGDEVICE(device, INDI::Logger::DBG_DEBUG, "DSUSB Opening Shutter ..."); |
| 69 |
|
| 70 |
// First assert focus then assert shutter as per Doug recommendations from Shoestring Astronomy |
| 71 |
// LED = ON, COLOR = GREEN |
| 72 |
command = (LED_ON | FOCUS_ON); |
| 73 |
DEBUGDEVICE(device, INDI::Logger::DBG_DEBUG, "Asserting Focus ..."); |
| 74 |
DEBUGFDEVICE(device, INDI::Logger::DBG_DEBUG, "CMD <%#02X>", command); |
| 75 |
WriteBulk(&command, 1, 1000); |
| 76 |
|
| 77 |
// Wait 100 ms |
| 78 |
usleep(100000); |
| 79 |
|
| 80 |
// Assert Shutter |
| 81 |
command |= SHUTTER_ON; |
| 82 |
DEBUGDEVICE(device, INDI::Logger::DBG_DEBUG, "Asserting Shutter ..."); |
| 83 |
DEBUGFDEVICE(device, INDI::Logger::DBG_DEBUG, "CMD <%#02X>", command); |
| 84 |
WriteBulk(&command, 1, 1000); |
| 85 |
|
| 86 |
return true; |
| 87 |
} |
| 88 |
|
| 89 |
bool DSUSBDriver::closeShutter() |
| 90 |
{ |
| 91 |
uint8_t command = 0; |
| 92 |
|
| 93 |
DEBUGDEVICE(device, INDI::Logger::DBG_DEBUG, "DSUSB Closing Shutter ..."); |
| 94 |
|
| 95 |
// First deassert shutter then deassert focus as per Doug recommendations from Shoestring Astronomy |
| 96 |
// LED = ON, COLOR = RED |
| 97 |
command = (LED_ON | LED_RED | FOCUS_ON); |
| 98 |
DEBUGDEVICE(device, INDI::Logger::DBG_DEBUG, "Deasserting Shutter ..."); |
| 99 |
DEBUGFDEVICE(device, INDI::Logger::DBG_DEBUG, "CMD <%#02X>", command); |
| 100 |
WriteBulk(&command, 1, 1000); |
| 101 |
|
| 102 |
// Wait 100 ms |
| 103 |
usleep(100000); |
| 104 |
|
| 105 |
// Deassert Focus |
| 106 |
command = (LED_ON | LED_RED); |
| 107 |
DEBUGDEVICE(device, INDI::Logger::DBG_DEBUG, "Deasserting Focus ..."); |
| 108 |
DEBUGFDEVICE(device, INDI::Logger::DBG_DEBUG, "CMD <%#02X>", command); |
| 109 |
WriteBulk(&command, 1, 1000); |
| 110 |
|
| 111 |
return true; |
| 112 |
} |