28#define POLLMS_OVERRIDE 1000
29#define FOCUSMASTER_TIMEOUT 1000
32#define FOCUS_SETTINGS_TAB "Settings"
45 handle =
hid_open(0x134A, 0x9030,
nullptr);
47 if (handle ==
nullptr)
49 LOG_ERROR(
"No FocusMaster focuser found.");
63 return (handle !=
nullptr);
75 return (
const char *)
"FocusMaster";
83 IUFillNumber(&SyncN[0],
"Ticks",
"",
"%.f", 0, 100000, 100., 0.);
133 float remaining = CalcTimeLeft(focusMoveStart, focusMoveRequest);
164 LOG_DEBUG(
"Focuser reached target position.");
179 if (!strcmp(FullMotionSP.
name, name))
197 if (strcmp(SyncNP.
name, name) == 0)
200 if (!sync(SyncN[0].value))
230 sendCommand(command);
232 gettimeofday(&focusMoveStart,
nullptr);
233 focusMoveRequest = duration / 1000.0;
237 usleep(duration * 1000);
261bool FocusMaster::sendCommand(
const uint8_t *command,
char *response)
267 LOGF_DEBUG(
"CMD <%#02X %#02X>", command[0], command[1]);
271 LOGF_ERROR(
"<%#02X %#02X>: Error writing to device %s", command[0], command[1],
hid_error(handle));
278bool FocusMaster::setPosition(uint32_t ticks)
284bool FocusMaster::getPosition(uint32_t *ticks)
299 bool rc = sendCommand(command);
321bool FocusMaster::sync(uint32_t ticks)
327float FocusMaster::CalcTimeLeft(timeval start,
float req)
335 gettimeofday(&now,
nullptr);
337 timesince = (double)(now.tv_sec * 1000.0 + now.tv_usec / 1000) - (double)(start.tv_sec * 1000.0 + start.tv_usec / 1000);
338 timesince = timesince / 1000;
339 timeleft = req - timesince;
const char * getDefaultName()
virtual bool initProperties() override
Initializes the default properties for the focuser device. Sets up standard INDI properties,...
bool Connect()
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
bool Disconnect()
Disconnect from device.
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks)
MoveFocuser the focuser to an relative position.
virtual IPState MoveFocuser(FocusDirection dir, int speed, uint16_t duration)
MoveFocuser the focuser in a particular direction with a specific speed for a finite duration.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Processes incoming new switch states from the client for this device. Handles updates to FocuserInter...
void TimerHit()
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
Processes incoming new number values from the client for this device. Handles updates to FocuserInter...
virtual bool AbortFocuser()
AbortFocuser all focus motion.
virtual bool updateProperties() override
Updates the state and definition of properties based on the current connection status....
virtual IPState MoveAbsFocuser(uint32_t targetTicks)
MoveFocuser the focuser to an absolute position.
void addSimulationControl()
Add Simulation control to the driver.
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void defineProperty(INumberVectorProperty *property)
int SetTimer(uint32_t ms)
Set a timer to call the function TimerHit after ms milliseconds.
INDI::PropertyNumber FocusRelPosNP
void SetCapability(uint32_t cap)
FI::SetCapability sets the focuser capabilities. All capabilities must be initialized.
INDI::PropertySwitch FocusMotionSP
INDI::PropertyNumber FocusTimerNP
INDI::PropertyNumber FocusAbsPosNP
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Processes incoming new switch states from the client for this device. Handles updates to FocuserInter...
virtual bool updateProperties() override
Updates the state and definition of properties based on the current connection status....
virtual bool initProperties() override
Initializes the default properties for the focuser device. Sets up standard INDI properties,...
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Processes incoming new number values from the client for this device. Handles updates to FocuserInter...
void setState(IPState state)
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
std::unique_ptr< FocusMaster > focusMaster(new FocusMaster())
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_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 IUFillNumberVector(INumberVectorProperty *nvp, INumber *np, int nnp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a number vector property. The vector's auxiliary elements will be set to NULL.
int IUFindOnSwitchIndex(const ISwitchVectorProperty *svp)
Returns the index of first ON switch it finds in the vector switch property.
void IUResetSwitch(ISwitchVectorProperty *svp)
Reset all switches in a switch vector property to OFF.
void IUFillSwitch(ISwitch *sp, const char *name, const char *label, ISState s)
Assign attributes for a switch property. The switch's auxiliary elements will be set to NULL.
void IUFillNumber(INumber *np, const char *name, const char *label, const char *format, double min, double max, double step, double value)
Assign attributes for a number property. The number's auxiliary elements will be set to NULL.
void IUFillSwitchVector(ISwitchVectorProperty *svp, ISwitch *sp, int nsp, const char *dev, const char *name, const char *label, const char *group, IPerm p, ISRule r, double timeout, IPState s)
Assign attributes for a switch vector property. The vector's auxiliary elements will be set to NULL.
int IUUpdateSwitch(ISwitchVectorProperty *svp, ISState *states, char *names[], int n)
Update all switches in a switch vector property.
void IDSetNumber(const INumberVectorProperty *nvp, const char *fmt,...)
void IDSetSwitch(const ISwitchVectorProperty *svp, const char *fmt,...)
int IUUpdateNumber(INumberVectorProperty *nvp, double values[], char *names[], int n)
Update all numbers in a number vector property.
#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,...)