32static std::unique_ptr<MoonLite> moonLite(
new MoonLite());
58 TemperatureNP[0].
fill(
"TEMPERATURE",
"Celsius",
"%6.2f", -50, 70., 0., 0.);
63 TemperatureSettingNP[Calibration].
fill(
"Calibration",
"",
"%6.2f", -100, 100, 0.5, 0);
64 TemperatureSettingNP[Coefficient].
fill(
"Coefficient",
"",
"%6.2f", -100, 100, 0.5, 0);
104 LOG_INFO(
"MoonLite parameters updated, focuser ready for use.");
121 LOG_INFO(
"MoonLite is online. Getting focus parameters...");
126 "Error retrieving data from MoonLite, please ensure MoonLite controller is powered and the port is correct.");
137 bool success =
false;
139 for (
int i = 0; i < 3; i++)
153bool MoonLite::readStepMode()
155 char res[ML_RES] = {0};
157 if (sendCommand(
":GH#", res) ==
false)
160 if (strcmp(res,
"FF#") == 0)
162 else if (strcmp(res,
"00#") == 0)
166 LOGF_ERROR(
"Unknown error: focuser step value (%s)", res);
173bool MoonLite::readVersion()
175 char res[ML_RES] = {0};
177 if (sendCommand(
":GV#", res,
true, 2) ==
false)
180 LOGF_INFO(
"Detected firmware version %c.%c", res[0], res[1]);
185bool MoonLite::readTemperature()
187 char res[ML_RES] = {0};
191 if (sendCommand(
":GT#", res) ==
false)
195 int rc = sscanf(res,
"%X", &temp);
198 TemperatureNP[0].setValue(
static_cast<int16_t
>(temp) / 2.0);
201 LOGF_ERROR(
"Unknown error: focuser temperature value (%s)", res);
208bool MoonLite::readTemperatureCoefficient()
210 char res[ML_RES] = {0};
212 if (sendCommand(
":GC#", res) ==
false)
215 uint8_t coefficient = 0;
216 int rc = sscanf(res,
"%hhX", &coefficient);
219 TemperatureSettingNP[1].setValue(
static_cast<int8_t
>(coefficient) / 2.0);
222 LOGF_ERROR(
"Unknown error: focuser temperature coefficient value (%s)", res);
229bool MoonLite::readPosition()
231 char res[ML_RES] = {0};
233 if (sendCommand(
":GP#", res) ==
false)
237 int rc = sscanf(res,
"%X#", &pos);
243 LOGF_ERROR(
"Unknown error: focuser position value (%s)", res);
250bool MoonLite::readSpeed()
252 char res[ML_RES] = {0};
254 if (sendCommand(
":GD#", res) ==
false)
258 int rc = sscanf(res,
"%hX#", &speed);
262 int focus_speed = -1;
272 LOGF_ERROR(
"Unknown error: focuser speed value (%s)", res);
279bool MoonLite::isMoving()
281 char res[ML_RES] = {0};
283 if (sendCommand(
":GI#", res) ==
false)
287 if (strstr(res,
"1#"))
289 else if (strstr(res,
"0#"))
292 LOGF_ERROR(
"Unknown error: isMoving value (%s)", res);
296bool MoonLite::setTemperatureCalibration(
double calibration)
298 char cmd[ML_RES] = {0};
299 uint8_t hex =
static_cast<int8_t
>(calibration * 2) & 0xFF;
300 snprintf(
cmd, ML_RES,
":PO%02X#", hex);
301 return sendCommand(
cmd);
304bool MoonLite::setTemperatureCoefficient(
double coefficient)
306 char cmd[ML_RES] = {0};
307 uint8_t hex =
static_cast<int8_t
>(coefficient * 2) & 0xFF;
308 snprintf(
cmd, ML_RES,
":SC%02X#", hex);
309 return sendCommand(
cmd);
314 char cmd[ML_RES] = {0};
315 snprintf(
cmd, ML_RES,
":SP%04X#", ticks);
316 return sendCommand(
cmd);
321 char cmd[ML_RES] = {0};
322 snprintf(
cmd, ML_RES,
":SN%04X#", position);
324 if (sendCommand(
cmd) ==
false)
327 if (sendCommand(
":FG#") ==
false)
333bool MoonLite::setStepMode(FocusStepMode mode)
335 char cmd[ML_RES] = {0};
337 return sendCommand(
cmd);
340bool MoonLite::setSpeed(
int speed)
342 char cmd[ML_RES] = {0};
345 snprintf(
cmd, ML_RES,
":SD%02X#", hex_value);
346 return sendCommand(
cmd);
349bool MoonLite::setTemperatureCompensation(
bool enable)
351 char cmd[ML_RES] = {0};
352 snprintf(
cmd, ML_RES,
":%c#", enable ?
'+' :
'-');
353 return sendCommand(
cmd);
365 StepModeSP.
update(states, names, n);
369 if (current_mode == target_mode)
394 TemperatureCompensateSP.
update(states, names, n);
396 bool rc = setTemperatureCompensation((TemperatureCompensateSP[
INDI_ENABLED].getState() ==
ISS_ON));
401 TemperatureCompensateSP.
reset();
403 TemperatureCompensateSP.
apply();
408 TemperatureCompensateSP.
apply();
423 TemperatureSettingNP.
update(values, names, n);
424 if (!setTemperatureCalibration(TemperatureSettingNP[Calibration].getValue()) ||
425 !setTemperatureCoefficient(TemperatureSettingNP[Coefficient].getValue()))
428 TemperatureSettingNP.
apply();
433 TemperatureSettingNP.
apply();
441void MoonLite::GetFocusParams()
446 if (readTemperature())
447 TemperatureNP.
apply();
449 if (readTemperatureCoefficient())
450 TemperatureSettingNP.
apply();
461 return setSpeed(speed);
466 if (speed !=
static_cast<int>(
FocusSpeedNP[0].getValue()))
468 if (!setSpeed(speed))
485 static_cast<MoonLite *
>(context)->timedMoveCallback();
488void MoonLite::timedMoveCallback()
502 targetPos = targetTicks;
513 int32_t offset = ((dir ==
FOCUS_INWARD) ? -1 : 1) *
static_cast<int32_t
>(ticks);
515 newPosition = std::max(
static_cast<int32_t
>(
FocusAbsPosNP[0].getMin()),
533 bool rc = readPosition();
539 lastPos =
static_cast<uint32_t
>(
FocusAbsPosNP[0].getValue());
543 rc = readTemperature();
546 if (std::abs(lastTemperature - TemperatureNP[0].getValue()) >= 0.5)
548 TemperatureNP.
apply();
549 lastTemperature =
static_cast<uint32_t
>(TemperatureNP[0].getValue());
561 lastPos =
static_cast<uint32_t
>(
FocusAbsPosNP[0].getValue());
562 LOG_INFO(
"Focuser reached requested position.");
571 return sendCommand(
":FQ#");
576 Focuser::saveConfigItems(fp);
583bool MoonLite::sendCommand(
const char *
cmd,
char * res,
bool silent,
int nret)
585 int nbytes_written = 0, nbytes_read = 0, rc = -1;
587 tcflush(
PortFD, TCIOFLUSH);
596 LOGF_ERROR(
"Serial write error: %s.", errstr);
626 tcflush(
PortFD, TCIOFLUSH);
void setDefaultPollingPeriod(uint32_t msec)
setDefaultPollingPeriod Change the default polling period to call TimerHit() function in 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.
int SetTimer(uint32_t ms)
Set a timer to call the function TimerHit after ms milliseconds.
void addDebugControl()
Add Debug control to the driver.
INDI::PropertyNumber FocusRelPosNP
void SetCapability(uint32_t cap)
FI::SetCapability sets the focuser capabilities. All capabilities must be initialized.
@ FOCUSER_HAS_VARIABLE_SPEED
INDI::PropertyNumber FocusSpeedNP
INDI::PropertyNumber FocusTimerNP
INDI::PropertyNumber FocusMaxPosNP
INDI::PropertyNumber FocusAbsPosNP
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,...
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Processes incoming new number values from the client for this device. Handles updates to FocuserInter...
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.
const char * getName() const
bool isNameMatch(const char *otherName) const
bool update(const double values[], const char *const names[], int n)
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, double timeout, IPState state)
bool update(const ISState states[], const char *const names[], int n)
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)
virtual IPState MoveFocuser(FocusDirection dir, int speed, uint16_t duration) override
MoveFocuser Move focuser in a specific direction and speed for period of time.
virtual bool saveConfigItems(FILE *fp) override
static void timedMoveHelper(void *context)
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual bool SetFocuserSpeed(int speed) override
SetFocuserSpeed Set Focuser speed.
const char * getDefaultName() override
virtual bool SyncFocuser(uint32_t ticks) override
SyncFocuser Set the supplied position as the current focuser position.
virtual bool Handshake() override
Handshake Try to communicate with Focuser and see if there is a valid response.
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
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 IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveAbsFocuser Move to an absolute target position.
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,...
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Processes incoming new number values from the client for this device. Handles updates to FocuserInter...
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveRelFocuser Move focuser for a relative amount of ticks in a specific direction.
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
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 tty_read(int fd, char *buf, int nbytes, int timeout, int *nbytes_read)
read buffer from terminal
int tty_write_string(int fd, const char *buf, int *nbytes_written)
Writes a null terminated string to fd.
void tty_error_msg(int err_code, char *err_msg, int err_msg_len)
Retrieve the tty error message.
int tty_nread_section(int fd, char *buf, int nsize, char stop_char, int timeout, int *nbytes_read)
read buffer from terminal with a delimiter
Implementations for common driver routines.
#define LOGF_INFO(fmt,...)
#define LOGF_DEBUG(fmt,...)
#define LOGF_ERROR(fmt,...)