27 #define FOCUS_SETTINGS_TAB "Settings"
29 static std::unique_ptr<SIEFS> siefs(
new SIEFS());
31 const std::map<SIEFS::SI_COMMANDS, std::string> SIEFS::CommandsMap =
44 const std::map<SIEFS::SI_MOTOR, std::string> SIEFS::MotorMap =
68 handle =
hid_open(0x04D8, 0xF056,
nullptr);
70 if (handle ==
nullptr)
77 uint32_t maximumPosition = 0;
78 bool rc = getMaxPosition(&maximumPosition);
99 return (handle !=
nullptr);
150 if (std::abs(simPosition -
static_cast<int32_t
>(targetPosition)) < 500)
169 LOG_DEBUG(
"Focuser reached target position.");
180 bool rc = setAbsPosition(targetTicks);
185 targetPosition = targetTicks;
201 int relative =
static_cast<int>(ticks);
203 int targetAbsPosition =
FocusAbsPosN[0].value + (relative * direction * reversed);
211 bool SIEFS::setPosition(uint32_t ticks, uint8_t cmdCode)
220 command[0] = cmdCode + 8;
221 command[1] = (ticks & 0x40000) >> 16;
223 LOGF_DEBUG(
"Set %s Position (%ld)", cmdCode == 0x20 ?
"Absolute" :
"Maximum", ticks);
224 LOGF_DEBUG(
"CMD <%02X %02X>", command[0], command[1]);
240 response[0] = cmdCode + 8;
241 response[1] = command[1];
252 LOGF_DEBUG(
"RES <%02X %02X>", response[0], response[1]);
255 command[0] = cmdCode;
257 command[1] = ticks & 0xFF;
259 command[2] = (ticks & 0xFF00) >> 8;
261 LOGF_DEBUG(
"CMD <%02X %02X %02X>", command[0], command[1], command[2]);
277 response[0] = command[0];
278 response[1] = command[1];
279 response[2] = command[2];
290 LOGF_DEBUG(
"RES <%02X %02X %02X>", response[0], response[1], response[2]);
292 targetPosition = ticks;
298 bool SIEFS::getPosition(uint32_t *ticks, uint8_t cmdCode)
302 uint8_t command[1] = {0};
303 uint8_t response[3] = {0};
308 command[0] = cmdCode + 8;
310 LOGF_DEBUG(
"Get %s Position (High 4 bits)", cmdCode == 0x21 ?
"Absolute" :
"Maximum");
327 response[0] = command[0];
328 response[1] = simPosition >> 16;
339 LOGF_DEBUG(
"RES <%02X %02X>", response[0], response[1]);
342 pos = response[1] << 16;
345 command[0] = cmdCode;
347 LOGF_DEBUG(
"Get %s Position (Lower 16 bits)", cmdCode == 0x21 ?
"Absolute" :
"Maximum");
364 response[0] = command[0];
365 response[1] = simPosition & 0xFF;
366 response[2] = (simPosition & 0xFF00) >> 8;
377 LOGF_DEBUG(
"RES <%02X %02X %02X>", response[0], response[1], response[2]);
380 pos |= response[1] | response[2] << 8;
384 LOGF_DEBUG(
"%s Position: %ld", cmdCode == 0x21 ?
"Absolute" :
"Maximum", pos);
389 bool SIEFS::setAbsPosition(uint32_t ticks)
391 return setPosition(ticks, 0x20);
394 bool SIEFS::getAbsPosition(uint32_t *ticks)
396 return getPosition(ticks, 0x21);
399 bool SIEFS::setMaxPosition(uint32_t ticks)
401 return setPosition(ticks, 0x22);
404 bool SIEFS::getMaxPosition(uint32_t *ticks)
406 return getPosition(ticks, 0x23);
409 bool SIEFS::sendCommand(SI_COMMANDS targetCommand)
412 uint8_t command[2] = {0};
413 uint8_t response[3] = {0};
416 command[1] = targetCommand;
418 LOGF_DEBUG(
"CMD <%02X %02X>", command[0], command[1]);
434 response[0] = command[0];
436 response[2] = command[1];
448 LOGF_DEBUG(
"RES <%02X %02X %02X>", response[0], response[1], response[2]);
450 if (response[1] == 0xFF)
452 LOG_ERROR(
"setStatus: Invalid state change.");
459 bool SIEFS::getStatus()
462 uint8_t command[1] = {0};
463 uint8_t response[2] = {0};
483 response[0] = command[0];
484 response[1] = m_Motor;
498 LOGF_DEBUG(
"RES <%02X %02X>", response[0], response[1]);
500 m_Motor =
static_cast<SI_MOTOR>(response[1]);
501 if (MotorMap.count(m_Motor) > 0)
502 LOGF_DEBUG(
"State: %s", MotorMap.at(m_Motor).c_str());
505 LOGF_WARN(
"Warning: Unknown status (%d)", response[1]);
519 bool rc = setAbsPosition(ticks);
533 bool rc = setAbsPosition(ticks);
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.
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 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...
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveFocuser the focuser to an absolute position.
virtual bool SetFocuserMaxPosition(uint32_t ticks) override
SetFocuserMaxPosition Update focuser maximum position. It only updates the PresetNP property limits.
virtual bool SyncFocuser(uint32_t ticks) override
SyncFocuser Set current position to ticks without moving the focuser.
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
virtual bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
virtual bool Disconnect() override
Disconnect from device.
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,...)