27 #define PERFECTSTAR_TIMEOUT 1000
29 #define FOCUS_SETTINGS_TAB "Settings"
32 static std::unique_ptr<PerfectStar> perfectStar(
new PerfectStar());
50 handle =
hid_open(0x04D8, 0xF812,
nullptr);
52 if (handle ==
nullptr)
54 LOG_ERROR(
"No PerfectStar focuser found.");
60 return (handle !=
nullptr);
76 return (
const char *)
"PerfectStar";
147 if (std::abs((int64_t)simPosition - (int64_t)targetPosition) < 500)
166 LOG_DEBUG(
"Focuser reached target position.");
177 LOG_INFO(
"Focuser reached home position.");
237 bool rc = setPosition(targetTicks);
242 targetPosition = targetTicks;
261 bool PerfectStar::setPosition(uint32_t ticks)
264 unsigned char command[3];
265 unsigned char response[3];
271 command[1] = (ticks & 0x40000) >> 16;
274 LOGF_DEBUG(
"CMD (%02X %02X)", command[0], command[1]);
291 response[1] = command[1];
302 LOGF_DEBUG(
"RES (%02X %02X)", response[0], response[1]);
307 command[1] = ticks & 0xFF;
309 command[2] = (ticks & 0xFF00) >> 8;
311 LOGF_DEBUG(
"CMD (%02X %02X %02X)", command[0], command[1], command[2]);
327 response[0] = command[0];
328 response[1] = command[1];
329 response[2] = command[2];
340 LOGF_DEBUG(
"RES (%02X %02X %02X)", response[0], response[1], response[2]);
342 targetPosition = ticks;
348 bool PerfectStar::getPosition(uint32_t *ticks)
352 unsigned char command[1];
353 unsigned char response[3];
377 response[0] = command[0];
378 response[1] = simPosition >> 16;
389 LOGF_DEBUG(
"RES (%02X %02X)", response[0], response[1]);
392 pos = response[1] << 16;
397 LOG_DEBUG(
"Get Position (Lower 16 bits)");
414 response[0] = command[0];
415 response[1] = simPosition & 0xFF;
416 response[2] = (simPosition & 0xFF00) >> 8;
427 LOGF_DEBUG(
"RES (%02X %02X %02X)", response[0], response[1], response[2]);
430 pos |= response[1] | response[2] << 8;
439 bool PerfectStar::setStatus(PS_STATUS targetStatus)
442 unsigned char command[2];
443 unsigned char response[3];
446 command[1] = (targetStatus ==
PS_HALT) ? 0xFF : targetStatus;
448 LOGF_DEBUG(
"CMD (%02X %02X)", command[0], command[1]);
464 response[0] = command[0];
466 response[2] = command[1];
467 status = targetStatus;
488 LOGF_DEBUG(
"RES (%02X %02X %02X)", response[0], response[1], response[2]);
490 if (response[1] == 0xFF)
492 LOG_ERROR(
"setStatus: Invalid state change.");
499 bool PerfectStar::getStatus(PS_STATUS *currentStatus)
502 unsigned char command[1];
503 unsigned char response[2];
523 response[0] = command[0];
524 response[1] = status;
538 LOGF_DEBUG(
"RES (%02X %02X)", response[0], response[1]);
548 *currentStatus =
PS_IN;
568 LOGF_WARN(
"Warning: Unknown status (%d)", response[1]);
584 bool rc = setPosition(ticks);
const char * getDeviceName() const
void addSimulationControl()
Add Simulation control to the driver.
uint32_t getCurrentPollingPeriod() const
getCurrentPollingPeriod Return the current polling period.
bool isSimulation() const
int SetTimer(uint32_t ms)
Set a timer to call the function TimerHit after ms milliseconds.
INumberVectorProperty FocusAbsPosNP
INumberVectorProperty FocusRelPosNP
void SetCapability(uint32_t cap)
FI::SetCapability sets the focuser capabilities. All capabilities must be initialized.
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
void setSupportedConnections(const uint8_t &value)
setConnection Set Focuser connection mode. Child class should call this in the constructor before Foc...
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveFocuser the focuser to an absolute position.
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
virtual bool SyncFocuser(uint32_t ticks) override
SyncFocuser Set current position to ticks without moving the focuser.
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
virtual bool Disconnect() override
Disconnect from device.
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
const char * getDefaultName() override
hid_device * hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number)
Open a HID device using a Vendor ID (VID), Product ID (PID) and optionally a serial number.
int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t length, int milliseconds)
Read an Input report from a HID device with timeout.
int HID_API_EXPORT hid_write(hid_device *dev, const unsigned char *data, size_t length)
Write an Output report to a HID device.
void HID_API_EXPORT hid_close(hid_device *dev)
Close a HID device.
HID_API_EXPORT const wchar_t *HID_API_CALL hid_error(hid_device *dev)
Get a string describing the last error which occurred.
int HID_API_EXPORT hid_exit(void)
Finalize the HIDAPI library.
void IDSetNumber(const INumberVectorProperty *nvp, const char *fmt,...)
#define LOGF_WARN(fmt,...)
#define LOGF_DEBUG(fmt,...)
#define LOG_ERROR(txt)
Shorter logging macros. In order to use these macros, the function (or method) "getDeviceName()" must...
#define LOGF_ERROR(fmt,...)
#define PERFECTSTAR_TIMEOUT