33 #define MICROTOUCH_TIMEOUT 3
35 static std::unique_ptr<Microtouch> microTouch(
new Microtouch());
59 IUFillNumber(&TemperatureN[0],
"TEMPERATURE",
"Celsius",
"%6.2f", -50, 70., 0., 0.);
69 IUFillNumber(&TemperatureSettingN[0],
"Calibration",
"",
"%6.2f", -20, 20, 0.01, 0);
70 IUFillNumber(&TemperatureSettingN[1],
"Coefficient",
"",
"%6.2f", -20, 20, 0.01, 0);
122 LOG_INFO(
"Microtouch parameters updated, focuser ready for use.");
140 tcflush(
PortFD, TCIOFLUSH);
144 LOG_INFO(
"Microtouch is online. Getting focus parameters...");
148 LOG_INFO(
"Error retrieving data from Microtouch, please ensure Microtouch controller is "
149 "powered and the port is correct.");
158 bool Microtouch::Ack()
160 return updatePosition();
163 bool Microtouch::updateTemperature()
167 short int ttemp = 0, tcoeff = 0;
168 double raw_temp = 0, raw_coeff = 0, tcomp_coeff = 0;
172 ttemp = ((
short int)resp[1] << 8 | ((
short int)resp[2] & 0xff));
173 raw_temp = ((double)ttemp) / 16;
175 tcoeff = ((
short int)resp[5] << 8 | ((
short int)resp[4] & 0xff));
176 raw_coeff = ((double)tcoeff) / 16;
178 tcomp_coeff = (double)(((
double)WriteCmdGetInt(
CMD_GET_COEFF)) / 128);
180 LOGF_DEBUG(
"updateTemperature : RESP (%02X %02X %02X %02X %02X %02X)", resp[0], resp[1],
181 resp[2], resp[3], resp[4], resp[5]);
183 TemperatureN[0].value = raw_temp + raw_coeff;
184 TemperatureSettingN[0].value = raw_coeff;
185 TemperatureSettingN[1].value = tcomp_coeff;
190 bool Microtouch::updatePosition()
196 FocusAbsPosN[0].value =
static_cast<double>(
static_cast<uint8_t
>(read[2]) << 8 |
static_cast<uint8_t
>(read[1]));
203 bool Microtouch::updateSpeed()
250 bool Microtouch::updateMotorSpeed()
257 MotorSpeedS[0].s =
ISS_ON;
259 MotorSpeedS[1].s =
ISS_ON;
269 bool Microtouch::isMoving()
274 bool Microtouch::setTemperatureCalibration(
double calibration)
279 bool Microtouch::setTemperatureCoefficient(
double coefficient)
281 int tcoeff = (int)(coefficient * 128);
283 LOGF_DEBUG(
"Setting new temperaturecoefficient : %d.", tcoeff);
287 LOG_ERROR(
"setTemperatureCoefficient error: Setting temperaturecoefficient failed.");
313 LOGF_DEBUG(
"MoveFocuser to Position: %d", position);
317 LOGF_ERROR(
"Requested position value out of bound: %d", position);
323 bool Microtouch::setMotorSpeed(
char speed)
333 bool Microtouch::setSpeed(
unsigned short speed)
356 bool Microtouch::setTemperatureCompensation(
bool enable)
376 if (strcmp(MotorSpeedSP.
name, name) == 0)
385 if (current_mode == target_mode)
391 if (target_mode == 0)
399 MotorSpeedS[current_mode].s =
ISS_ON;
410 if (strcmp(TemperatureCompensateSP.
name, name) == 0)
415 bool rc = setTemperatureCompensation((TemperatureCompensateS[0].s ==
ISS_ON));
421 TemperatureCompensateS[last_index].s =
ISS_ON;
426 TemperatureCompensateSP.
s =
IPS_OK;
460 if (strcmp(name, TemperatureSettingNP.
name) == 0)
463 if (!setTemperatureCalibration(TemperatureSettingN[0].value) ||
464 !setTemperatureCoefficient(TemperatureSettingN[1].value))
471 TemperatureSettingNP.
s =
IPS_OK;
493 void Microtouch::GetFocusParams()
495 if (updatePosition())
498 if (updateTemperature())
507 if (updateMotorSpeed())
515 rc = setSpeed(speed);
520 currentSpeed = speed;
530 if (speed != (
int)currentSpeed)
532 bool rc = setSpeed(speed);
538 gettimeofday(&focusMoveStart,
nullptr);
539 focusMoveRequest = duration / 1000.0;
548 usleep(duration * 1000);
558 targetPos = targetTicks;
574 double newPosition = 0;
600 bool rc = updatePosition();
611 rc = updateTemperature();
614 if (fabs(lastTemperature - TemperatureN[0].value) >= 0.01)
617 lastTemperature = TemperatureN[0].value;
623 float remaining = CalcTimeLeft(focusMoveStart, focusMoveRequest);
644 LOG_INFO(
"Focuser reached requested position.");
661 float Microtouch::CalcTimeLeft(timeval start,
float req)
669 gettimeofday(&now,
nullptr);
672 (double)(now.tv_sec * 1000.0 + now.tv_usec / 1000) - (double)(start.tv_sec * 1000.0 + start.tv_usec / 1000);
673 timesince = timesince / 1000;
674 timeleft = req - timesince;
678 bool Microtouch::WriteCmd(
char cmd)
680 int nbytes_written = 0, rc = -1;
683 tcflush(
PortFD, TCIOFLUSH);
696 bool Microtouch::WriteCmdGetResponse(
char cmd,
char *readbuffer,
char numbytes)
698 int nbytes_read = 0, rc = -1;
706 LOGF_ERROR(
"WriteCmdGetResponse error: %s.", errstr);
716 char Microtouch::WriteCmdGetByte(
char cmd)
720 if (WriteCmdGetResponse(
cmd, read, 2))
722 LOGF_DEBUG(
"WriteCmdGetByte : %02x %02x ", read[0], read[1]);
729 bool Microtouch::WriteCmdSetByte(
char cmd,
char val)
731 int nbytes_written = 0, rc = -1;
733 char write_buffer[2];
735 write_buffer[0] =
cmd;
736 write_buffer[1] = val;
738 LOGF_DEBUG(
"WriteCmdSetByte : CMD %02x %02x ", write_buffer[0], write_buffer[1]);
740 tcflush(
PortFD, TCIOFLUSH);
745 LOGF_ERROR(
"WriteCmdSetByte error: %s.", errstr);
751 bool Microtouch::WriteCmdSetShortInt(
char cmd,
short int val)
753 int nbytes_written = 0, rc = -1;
755 char write_buffer[3];
757 write_buffer[0] =
cmd;
758 write_buffer[1] = val & 0xFF;
759 write_buffer[2] = val >> 8;
761 LOGF_DEBUG(
"WriteCmdSetShortInt : %02x %02x %02x ", write_buffer[0], write_buffer[1],
764 tcflush(
PortFD, TCIOFLUSH);
769 LOGF_ERROR(
"WriteCmdSetShortInt error: %s.", errstr);
775 int Microtouch::WriteCmdGetInt(
char cmd)
779 if (WriteCmdGetResponse(
cmd, read, 5))
780 return ((
unsigned char)read[4] << 24 | (
unsigned char)read[3] << 16 | (
unsigned char)read[2] << 8 |
781 (
unsigned char)read[1]);
786 bool Microtouch::WriteCmdSetInt(
char cmd,
int val)
788 int nbytes_written = 0, rc = -1;
790 char write_buffer[5];
792 write_buffer[0] =
cmd;
793 write_buffer[1] = val & 0xFF;
794 write_buffer[2] = val >> 8;
795 write_buffer[3] = val >> 16;
796 write_buffer[4] = val >> 24;
798 LOGF_DEBUG(
"WriteCmdSetInt : %02x %02x %02x %02x %02x ", write_buffer[0], write_buffer[1],
799 write_buffer[2], write_buffer[3], write_buffer[4]);
801 tcflush(
PortFD, TCIOFLUSH);
806 LOGF_ERROR(
"WriteCmdSetInt error: %s.", errstr);
812 bool Microtouch::WriteCmdSetIntAsDigits(
char cmd,
int val)
814 int nbytes_written = 0, rc = -1;
816 char write_buffer[5];
818 write_buffer[0] =
cmd;
819 write_buffer[1] = val % 10;
820 write_buffer[2] = (val / 10) % 10;
821 write_buffer[3] = (val / 100) % 10;
822 write_buffer[4] = (val / 1000);
824 LOGF_DEBUG(
"WriteCmdSetIntAsDigits : CMD (%02x %02x %02x %02x %02x) ", write_buffer[0],
825 write_buffer[1], write_buffer[2], write_buffer[3], write_buffer[4]);
827 tcflush(
PortFD, TCIOFLUSH);
832 LOGF_ERROR(
"WriteCmdSetIntAsDigits error: %s.", errstr);
void setDefaultBaudRate(BaudRate newRate)
setDefaultBaudRate Set default baud rate. The default baud rate is 9600 unless otherwise changed by t...
const char * getDeviceName() const
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.
INumberVectorProperty FocusSpeedNP
INumberVectorProperty FocusAbsPosNP
INumberVectorProperty FocusRelPosNP
INumberVectorProperty FocusTimerNP
void SetCapability(uint32_t cap)
FI::SetCapability sets the focuser capabilities. All capabilities must be initialized.
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.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Connection::Serial * serialConnection
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveFocuser the focuser to an absolute position.
virtual bool Handshake() override
perform handshake with device to check communication
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
const char * getDefaultName() override
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.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool SetFocuserSpeed(int speed) override
SetFocuserSpeed Set Focuser speed.
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
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.
virtual bool SyncFocuser(uint32_t ticks) override
SyncFocuser Set current position to ticks without moving the focuser.
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
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 tty_write(int fd, const char *buf, int nbytes, int *nbytes_written)
Writes a buffer to fd.
int tty_read(int fd, char *buf, int nbytes, int timeout, int *nbytes_read)
read buffer from terminal
void tty_error_msg(int err_code, char *err_msg, int err_msg_len)
Retrieve the tty error message.
Implementations for common driver routines.
void IUFillNumberVector(INumberVectorProperty *nvp, INumber *np, int nnp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a number vector property. The vector's auxiliary elements will be set to NULL.
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 IUFillNumber(INumber *np, const char *name, const char *label, const char *format, double min, double max, double step, double value)
Assign attributes for a number property. The number'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,...)
int IUUpdateNumber(INumberVectorProperty *nvp, double values[], char *names[], int n)
Update all numbers in a number vector property.
#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,...)
#define MICROTOUCH_TIMEOUT
#define CMD_SET_TEMP_OFFSET
#define CMD_GET_TEMPERATURE
#define CMD_RESET_POSITION
#define CMD_SET_MOTOR_SPEED
#define CMD_GET_MOTOR_SPEED
#define CMD_UPDATE_POSITION
#define FOCUS_MOTORSPEED_NORMAL
#define FOCUS_MOTORSPEED_FAST