27#define FOCUS_SETTINGS_TAB "Settings"
29static std::unique_ptr<SIEFS> siefs(
new SIEFS());
31const std::map<SIEFS::SI_COMMANDS, std::string> SIEFS::CommandsMap =
45const std::map<SIEFS::SI_MOTOR, std::string> SIEFS::MotorMap =
73 handle =
hid_open(0x04D8, 0xF056,
nullptr);
75 if (handle ==
nullptr)
82 uint32_t maximumPosition = 0;
83 bool rc = getMaxPosition(&maximumPosition);
101 bool reversed = isReversed();
108 return (handle !=
nullptr);
159 if (std::abs(simPosition -
static_cast<int32_t
>(targetPosition)) < 500)
178 LOG_DEBUG(
"Focuser reached target position.");
189 bool rc = setAbsPosition(targetTicks);
194 targetPosition = targetTicks;
210 int relative =
static_cast<int>(ticks);
212 int targetAbsPosition =
FocusAbsPosNP[0].getValue() + (relative * direction * reversed);
214 targetAbsPosition = std::min(
static_cast<uint32_t
>(
FocusMaxPosNP[0].getValue())
215 ,
static_cast<uint32_t
>(std::max(
static_cast<int>(
FocusAbsPosNP[0].getMin()), targetAbsPosition)));
220bool SIEFS::setPosition(uint32_t ticks, uint8_t cmdCode)
229 command[0] = cmdCode + 8;
230 command[1] = (ticks & 0x40000) >> 16;
232 LOGF_DEBUG(
"Set %s Position (%ld)", cmdCode == 0x20 ?
"Absolute" :
"Maximum", ticks);
233 LOGF_DEBUG(
"CMD <%02X %02X>", command[0], command[1]);
249 response[0] = cmdCode + 8;
250 response[1] = command[1];
261 LOGF_DEBUG(
"RES <%02X %02X>", response[0], response[1]);
264 command[0] = cmdCode;
266 command[1] = ticks & 0xFF;
268 command[2] = (ticks & 0xFF00) >> 8;
270 LOGF_DEBUG(
"CMD <%02X %02X %02X>", command[0], command[1], command[2]);
286 response[0] = command[0];
287 response[1] = command[1];
288 response[2] = command[2];
299 LOGF_DEBUG(
"RES <%02X %02X %02X>", response[0], response[1], response[2]);
301 targetPosition = ticks;
307bool SIEFS::getPosition(uint32_t *ticks, uint8_t cmdCode)
311 uint8_t command[1] = {0};
312 uint8_t response[3] = {0};
317 command[0] = cmdCode + 8;
319 LOGF_DEBUG(
"Get %s Position (High 4 bits)", cmdCode == 0x21 ?
"Absolute" :
"Maximum");
336 response[0] = command[0];
337 response[1] = simPosition >> 16;
348 LOGF_DEBUG(
"RES <%02X %02X>", response[0], response[1]);
351 pos = response[1] << 16;
354 command[0] = cmdCode;
356 LOGF_DEBUG(
"Get %s Position (Lower 16 bits)", cmdCode == 0x21 ?
"Absolute" :
"Maximum");
373 response[0] = command[0];
374 response[1] = simPosition & 0xFF;
375 response[2] = (simPosition & 0xFF00) >> 8;
386 LOGF_DEBUG(
"RES <%02X %02X %02X>", response[0], response[1], response[2]);
389 pos |= response[1] | response[2] << 8;
393 LOGF_DEBUG(
"%s Position: %ld", cmdCode == 0x21 ?
"Absolute" :
"Maximum", pos);
398bool SIEFS::setAbsPosition(uint32_t ticks)
400 return setPosition(ticks, 0x20);
403bool SIEFS::getAbsPosition(uint32_t *ticks)
405 return getPosition(ticks, 0x21);
408bool SIEFS::setMaxPosition(uint32_t ticks)
410 return setPosition(ticks, 0x22);
413bool SIEFS::getMaxPosition(uint32_t *ticks)
415 return getPosition(ticks, 0x23);
418bool SIEFS::sendCommand(SI_COMMANDS targetCommand)
421 uint8_t command[2] = {0};
422 uint8_t response[3] = {0};
425 command[1] = targetCommand;
427 LOGF_DEBUG(
"CMD <%02X %02X>", command[0], command[1]);
443 response[0] = command[0];
445 response[2] = command[1];
457 LOGF_DEBUG(
"RES <%02X %02X %02X>", response[0], response[1], response[2]);
459 if (response[1] == 0xFF)
461 LOG_ERROR(
"setStatus: Invalid state change.");
468bool SIEFS::getStatus()
471 uint8_t command[1] = {0};
472 uint8_t response[2] = {0};
492 response[0] = command[0];
493 response[1] = m_Motor;
507 LOGF_DEBUG(
"RES <%02X %02X>", response[0], response[1]);
509 m_Motor =
static_cast<SI_MOTOR>(response[1]);
510 if (MotorMap.count(m_Motor) > 0)
511 LOGF_DEBUG(
"State: %s", MotorMap.at(m_Motor).c_str());
514 LOGF_WARN(
"Warning: Unknown status (%d)", response[1]);
528 bool rc = setAbsPosition(ticks);
542 bool rc = setAbsPosition(ticks);
554 return setReversed(enabled);
557bool SIEFS::setReversed(
bool enabled)
560 uint8_t command[2] = {0};
561 uint8_t response[2] = {0};
564 command[1] = enabled ? 1 : 0;
566 LOGF_DEBUG(
"CMD <%02X> <%02X>", command[0], command[1]);
582 response[0] = command[0];
595 LOGF_DEBUG(
"RES <%02X %02X>", response[0], response[1]);
600bool SIEFS::isReversed()
603 uint8_t command[1] = {0};
604 uint8_t response[2] = {0};
624 response[0] = command[0];
637 LOGF_DEBUG(
"RES <%02X %02X>", response[0], response[1]);
639 return response[1] != 0;
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.
INDI::PropertyNumber FocusRelPosNP
INDI::PropertySwitch FocusReverseSP
void SetCapability(uint32_t cap)
FI::SetCapability sets the focuser capabilities. All capabilities must be initialized.
INDI::PropertyNumber FocusSyncNP
INDI::PropertyNumber FocusMaxPosNP
INDI::PropertyNumber FocusAbsPosNP
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
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 ReverseFocuser(bool enabled) override
ReverseFocuser Reverse focuser motion direction.
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
Initializes the default properties for the focuser device. Sets up standard INDI properties,...
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.
#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,...)