27#define FOCUS_SETTINGS_TAB "Settings"
29static std::unique_ptr<FCUSB> fcusb(
new FCUSB());
30static const std::multimap<uint16_t, uint16_t> USBIDs =
54 for (
const auto &oneID : USBIDs)
56 if ( (handle =
hid_open(oneID.first, oneID.second,
nullptr)) !=
nullptr)
60 if (handle ==
nullptr)
71 return (handle !=
nullptr);
132 struct timeval curtime, diff;
133 gettimeofday(&curtime,
nullptr);
134 timersub(&timedMoveEnd, &curtime, &diff);
135 int timeleft = diff.tv_sec * 1000 + diff.tv_usec / 1000;
161 if (PWMScalerSP.
isUpdated(states, names, n))
163 PWMScalerSP.
update(states, names, n);
178bool FCUSB::getStatus()
181 uint8_t status[2] = {0};
183 int rc =
hid_read(handle, status, 2);
191 LOGF_DEBUG(
"RES <%#02X %#02X>", status[0], status[1]);
194 uint8_t motor = status[0] & 0x3;
196 if (motor == 0x3) motor = 0x2;
198 if (newMotorStatus != motorStatus)
200 motorStatus = newMotorStatus;
208 LOG_INFO(
"Motor is moving backwards.");
212 LOG_INFO(
"Motor is moving forward.");
218 uint8_t pwm = (status[0] & 0xC0) >> 6 ;
220 if (pwm == 0x3) pwm = 0x2;
222 if (newPWMStatus != pwmStatus)
224 pwmStatus = newPWMStatus;
262 bool rc = setStatus();
290 bool rc = setStatus();
334 bool rc = setStatus();
341 struct timeval duration_secs, current_time;
342 gettimeofday(¤t_time,
nullptr);
343 duration_secs.tv_sec = duration / 1000;
344 duration_secs.tv_usec = duration % 1000;
345 timeradd(¤t_time, &duration_secs, &timedMoveEnd);
356bool FCUSB::setStatus()
358 uint8_t command[2] = {0};
360 command[0] |= motorStatus;
362 command[0] |= (motorStatus ==
MOTOR_FWD) ? 0 : FC_LED_RED;
364 command[0] |= (motorStatus ==
MOTOR_OFF) ? 0 : FC_LED_ON;
366 command[0] |= (pwmStatus << 6);
368 command[1] = (motorStatus ==
MOTOR_OFF) ? 0 : static_cast<uint8_t>(targetSpeed);
370 LOGF_DEBUG(
"CMD <%#X %#X>", command[0], command[1]);
384 Focuser::saveConfigItems(fp);
386 PWMScalerSP.
save(fp);
399 static_cast<FCUSB *
>(context)->timedMoveCallback();
402void FCUSB::timedMoveCallback()
virtual bool initProperties() override
Initializes the default properties for the focuser device. Sets up standard INDI properties,...
virtual bool Disconnect() override
Disconnect from device.
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
const char * getDefaultName() override
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
virtual bool SetFocuserSpeed(int speed) override
SetFocuserSpeed Set Focuser speed.
virtual bool ReverseFocuser(bool enabled) override
ReverseFocuser Reverse focuser motion direction.
virtual bool saveConfigItems(FILE *fp) override
static void timedMoveHelper(void *context)
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 IPState MoveFocuser(FocusDirection dir, int speed, uint16_t duration) override
MoveFocuser the focuser in a particular direction with a specific speed for a finite duration.
virtual bool saveConfig(bool silent=false, const char *property=nullptr)
Save the current properties in a configuration file.
void addSimulationControl()
Add Simulation control to the driver.
void setVersion(uint16_t vMajor, uint16_t vMinor)
Set driver version information to be defined in DRIVER_INFO property as vMajor.vMinor.
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void defineProperty(INumberVectorProperty *property)
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.
INDI::PropertySwitch FocusReverseSP
void SetCapability(uint32_t cap)
FI::SetCapability sets the focuser capabilities. All capabilities must be initialized.
@ FOCUSER_HAS_VARIABLE_SPEED
INDI::PropertySwitch FocusMotionSP
INDI::PropertyNumber FocusSpeedNP
INDI::PropertyNumber FocusTimerNP
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,...
void setSupportedConnections(const uint8_t &value)
void setState(IPState state)
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
void save(FILE *f) const
save Save property to configuration file.
bool isNameMatch(const char *otherName) const
bool update(const ISState states[], const char *const names[], int n)
bool isUpdated(const ISState states[], const char *const names[], int n) const
int findOnSwitchIndex() const
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, ISRule rule, double timeout, IPState state)
const char * OPTIONS_TAB
OPTIONS_TAB Where all the driver's options are located. Those may include auxiliary controls,...
int IEAddTimer(int millisecs, IE_TCF *fp, void *p)
Register a new single-shot timer function, fp, to be called with ud as argument after ms.
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(hid_device *dev, unsigned char *data, size_t length)
Read an Input report from a HID device.
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.
#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,...)