27 #define FOCUS_SETTINGS_TAB "Settings"
29 static std::unique_ptr<FCUSB> fcusb(
new FCUSB());
30 static 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;
159 if (strcmp(PWMScalerSP.
name, name) == 0)
177 bool FCUSB::getStatus()
180 uint8_t status[2] = {0};
182 int rc =
hid_read(handle, status, 2);
190 LOGF_DEBUG(
"RES <%#02X %#02X>", status[0], status[1]);
193 uint8_t motor = status[0] & 0x3;
195 if (motor == 0x3) motor = 0x2;
197 if (newMotorStatus != motorStatus)
199 motorStatus = newMotorStatus;
207 LOG_INFO(
"Motor is moving backwards.");
211 LOG_INFO(
"Motor is moving forward.");
217 uint8_t pwm = (status[0] & 0xC0) >> 6 ;
219 if (pwm == 0x3) pwm = 0x2;
221 if (newPWMStatus != pwmStatus)
223 pwmStatus = newPWMStatus;
240 PWMScalerS[pwmStatus].s =
ISS_ON;
261 bool rc = setStatus();
289 bool rc = setStatus();
333 bool rc = setStatus();
340 struct timeval duration_secs, current_time;
341 gettimeofday(¤t_time,
nullptr);
342 duration_secs.tv_sec = duration / 1000;
343 duration_secs.tv_usec = duration % 1000;
344 timeradd(¤t_time, &duration_secs, &timedMoveEnd);
355 bool FCUSB::setStatus()
357 uint8_t command[2] = {0};
359 command[0] |= motorStatus;
361 command[0] |= (motorStatus ==
MOTOR_FWD) ? 0 : FC_LED_RED;
363 command[0] |= (motorStatus ==
MOTOR_OFF) ? 0 : FC_LED_ON;
365 command[0] |= (pwmStatus << 6);
367 command[1] = (motorStatus ==
MOTOR_OFF) ? 0 :
static_cast<uint8_t
>(targetSpeed);
369 LOGF_DEBUG(
"CMD <%#X %#X>", command[0], command[1]);
383 Focuser::saveConfigItems(fp);
398 static_cast<FCUSB *
>(context)->timedMoveCallback();
401 void FCUSB::timedMoveCallback()
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
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
saveConfigItems Saves the Device Port and Focuser Presets in the configuration file
static void timedMoveHelper(void *context)
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
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.
const char * getDeviceName() const
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.
ISwitchVectorProperty FocusMotionSP
INumberVectorProperty FocusSpeedNP
INumberVectorProperty FocusTimerNP
void SetCapability(uint32_t cap)
FI::SetCapability sets the focuser capabilities. All capabilities must be initialized.
@ FOCUSER_HAS_VARIABLE_SPEED
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
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.
void setSupportedConnections(const uint8_t &value)
setConnection Set Focuser connection mode. Child class should call this in the constructor before Foc...
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.
int HID_API_EXPORT hid_read(hid_device *dev, unsigned char *data, size_t length)
Read an Input report from a HID device.
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 IUSaveConfigSwitch(FILE *fp, const ISwitchVectorProperty *svp)
Add a switch vector property value to the configuration file.
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 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,...)
#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,...)