Skip to content

Commit

Permalink
Add reverse support to starlight EFS focuser. Not tested on hardware
Browse files Browse the repository at this point in the history
  • Loading branch information
knro committed Dec 1, 2023
1 parent fc28d17 commit d11ac07
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 4 deletions.
2 changes: 1 addition & 1 deletion drivers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@
</device>
<device label="Starlight EFS" manufacturer="Starlight Instruments">
<driver name="SI EFS">indi_siefs_focus</driver>
<version>0.1</version>
<version>0.2</version>
</device>
<device label="Lacerta MFOC" manufacturer="Lacerta Optics">
<driver name="Lacerta MFOC">indi_lacerta_mfoc_focus</driver>
Expand Down
103 changes: 101 additions & 2 deletions drivers/focuser/si_efs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const std::map<SIEFS::SI_COMMANDS, std::string> SIEFS::CommandsMap =
{SIEFS::SI_FAST_IN, "Fast In"},
{SIEFS::SI_FAST_OUT, "Fast Out"},
{SIEFS::SI_HALT, "Halt"},
{SIEFS::SI_MOTOR_POLARITY, "Motor Polarity"},
};

const std::map<SIEFS::SI_MOTOR, std::string> SIEFS::MotorMap =
Expand All @@ -51,9 +52,13 @@ const std::map<SIEFS::SI_MOTOR, std::string> SIEFS::MotorMap =

SIEFS::SIEFS()
{
setVersion(0, 1);
setVersion(0, 2);

FI::SetCapability(FOCUSER_CAN_ABS_MOVE | FOCUSER_CAN_REL_MOVE | FOCUSER_CAN_ABORT | FOCUSER_CAN_SYNC);
FI::SetCapability(FOCUSER_CAN_ABS_MOVE |
FOCUSER_CAN_REL_MOVE |
FOCUSER_CAN_ABORT |
FOCUSER_CAN_SYNC |
FOCUSER_CAN_REVERSE);
setSupportedConnections(CONNECTION_NONE);
}

Expand Down Expand Up @@ -93,6 +98,10 @@ bool SIEFS::Connect()
FocusRelPosN[0].min = 0;
}

bool reversed = isReversed();
FocusReverseS[INDI_ENABLED].s = reversed ? ISS_ON : ISS_OFF;
FocusReverseS[INDI_DISABLED].s = reversed ? ISS_OFF : ISS_ON;
FocusReverseSP.s = IPS_OK;
SetTimer(getCurrentPollingPeriod());
}

Expand Down Expand Up @@ -539,3 +548,93 @@ bool SIEFS::SetFocuserMaxPosition(uint32_t ticks)

return rc;
}

bool SIEFS::ReverseFocuser(bool enabled)
{
return setReversed(enabled);
}

bool SIEFS::setReversed(bool enabled)
{
int rc = 0;
uint8_t command[2] = {0};
uint8_t response[2] = {0};

command[0] = SI_MOTOR_POLARITY;
command[1] = enabled ? 1 : 0;

LOGF_DEBUG("CMD <%02X> <%02X>", command[0], command[1]);

if (isSimulation())
rc = 1;
else
rc = hid_write(handle, command, 2);

if (rc < 0)
{
LOGF_ERROR("setReversed: Error writing to device (%s)", hid_error(handle));
return false;
}

if (isSimulation())
{
rc = 2;
response[0] = command[0];
// Normal
response[1] = 0;
}
else
rc = hid_read_timeout(handle, response, 2, SI_TIMEOUT);

if (rc < 0)
{
LOGF_ERROR("setReversed: Error reading from device (%s)", hid_error(handle));
return false;
}

LOGF_DEBUG("RES <%02X %02X>", response[0], response[1]);

return true;
}

bool SIEFS::isReversed()
{
int rc = 0;
uint8_t command[1] = {0};
uint8_t response[2] = {0};

command[0] = SI_MOTOR_POLARITY;

LOGF_DEBUG("CMD <%02X>", command[0]);

if (isSimulation())
rc = 1;
else
rc = hid_write(handle, command, 1);

if (rc < 0)
{
LOGF_ERROR("setReversed: Error writing to device (%s)", hid_error(handle));
return false;
}

if (isSimulation())
{
rc = 2;
response[0] = command[0];
// Normal
response[1] = 0;
}
else
rc = hid_read_timeout(handle, response, 2, SI_TIMEOUT);

if (rc < 0)
{
LOGF_ERROR("setReversed: Error reading from device (%s)", hid_error(handle));
return false;
}

LOGF_DEBUG("RES <%02X %02X>", response[0], response[1]);

return response[1] != 0;
}
9 changes: 8 additions & 1 deletion drivers/focuser/si_efs.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class SIEFS : public INDI::Focuser
SI_MAX_POS,
SI_FAST_IN = 0x11,
SI_FAST_OUT = 0x12,
SI_HALT = 0xFF
SI_HALT = 0xFF,
SI_MOTOR_POLARITY = 0x61
} SI_COMMANDS;


Expand Down Expand Up @@ -66,6 +67,8 @@ class SIEFS : public INDI::Focuser
virtual bool SyncFocuser(uint32_t ticks) override;
virtual bool SetFocuserMaxPosition(uint32_t ticks) override;

virtual bool ReverseFocuser(bool enabled) override;

private:
/**
* @brief setPosition Set Position (Either Absolute or Maximum)
Expand All @@ -91,6 +94,10 @@ class SIEFS : public INDI::Focuser
bool setMaxPosition(uint32_t ticks);
bool getMaxPosition(uint32_t *ticks);

// Polarity
bool isReversed();
bool setReversed(bool enabled);

bool sendCommand(SI_COMMANDS targetCommand);
bool getStatus();

Expand Down

0 comments on commit d11ac07

Please sign in to comment.