Skip to content

Commit

Permalink
Support setting autodew aggression (indilib#1992) (indilib#2006)
Browse files Browse the repository at this point in the history
  • Loading branch information
ijessen authored Feb 28, 2024
1 parent 2a4e2e1 commit 2a66a0f
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
52 changes: 50 additions & 2 deletions drivers/auxiliary/pegasus_ppba.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ bool PegasusPPBA::initProperties()
IUFillSwitchVector(&AutoDewSP, AutoDewS, 2, getDeviceName(), "AUTO_DEW", "Auto Dew", DEW_TAB, IP_RW, ISR_1OFMANY, 60,
IPS_IDLE);

IUFillNumber(&AutoDewSettingsN[AUTO_DEW_AGGRESSION], "AGGRESSION", "Aggresiveness (%)", "%.2f", 0, 100, 10, 0);
IUFillNumberVector(&AutoDewSettingsNP, AutoDewSettingsN, 1, getDeviceName(), "AUTO_DEW_SETTINGS", "Auto Dew Settings", DEW_TAB, IP_RW, 60, IPS_IDLE);


// Dew PWM
IUFillNumber(&DewPWMN[DEW_PWM_A], "DEW_A", "Dew A (%)", "%.2f", 0, 100, 10, 0);
IUFillNumber(&DewPWMN[DEW_PWM_B], "DEW_B", "Dew B (%)", "%.2f", 0, 100, 10, 0);
Expand Down Expand Up @@ -213,8 +217,11 @@ bool PegasusPPBA::updateProperties()

// Dew
defineProperty(&AutoDewSP);
defineProperty(&AutoDewSettingsNP);
defineProperty(&DewPWMNP);

getAutoDewAggression();

// Focuser
if (m_HasExternalMotor)
{
Expand All @@ -227,6 +234,7 @@ bool PegasusPPBA::updateProperties()

// Firmware
defineProperty(&FirmwareTP);
sendFirmware();

setupComplete = true;
}
Expand All @@ -244,6 +252,7 @@ bool PegasusPPBA::updateProperties()

// Dew
deleteProperty(AutoDewSP.name);
deleteProperty(AutoDewSettingsNP.name);
deleteProperty(DewPWMNP.name);

if (m_HasExternalMotor)
Expand Down Expand Up @@ -295,8 +304,7 @@ bool PegasusPPBA::Handshake()
{
tcflush(PortFD, TCIOFLUSH);
tty_write_string(PortFD, command, &nbytes_written);
stopChar = 0xA;
tty_rc = tty_nread_section(PortFD, response, PEGASUS_LEN, stopChar, 1, &nbytes_read);
tty_rc = tty_nread_section(PortFD, response, PEGASUS_LEN, 0xA, 1, &nbytes_read);
}

if (tty_rc != TTY_OK)
Expand Down Expand Up @@ -506,6 +514,16 @@ bool PegasusPPBA::ISNewNumber(const char * dev, const char * name, double values
return true;
}

// Auto Dew Settings
if (!strcmp(name, AutoDewSettingsNP.name))
{
AutoDewSettingsNP.s = setAutoDewAggression(static_cast<uint8_t>(values[AUTO_DEW_AGGRESSION] / 100.0 * 255.0)) ? IPS_OK : IPS_ALERT;
if (AutoDewSettingsNP.s == IPS_OK)
IUUpdateNumber(&AutoDewSettingsNP, values, names, n);
IDSetNumber(&AutoDewSettingsNP, nullptr);
return true;
}

// Focuser Settings
if (!strcmp(name, FocuserSettingsNP.name))
{
Expand Down Expand Up @@ -593,6 +611,18 @@ bool PegasusPPBA::setAutoDewEnabled(bool enabled)
return false;
}

bool PegasusPPBA::setAutoDewAggression(uint8_t value)
{
char cmd[PEGASUS_LEN] = {0}, res[PEGASUS_LEN] = {0};
snprintf(cmd, PEGASUS_LEN, "PD:%d", value);
if (sendCommand(cmd, res))
{
return (!strcmp(res, cmd));
}

return false;
}

bool PegasusPPBA::setPowerOnBoot()
{
char cmd[PEGASUS_LEN] = {0}, res[PEGASUS_LEN] = {0};
Expand Down Expand Up @@ -632,6 +662,7 @@ bool PegasusPPBA::saveConfigItems(FILE * fp)
}
WI::saveConfigItems(fp);
IUSaveConfigSwitch(fp, &AutoDewSP);
IUSaveConfigNumber(fp, &AutoDewSettingsNP);
return true;
}

Expand Down Expand Up @@ -791,6 +822,23 @@ bool PegasusPPBA::getConsumptionData()
return false;
}

bool PegasusPPBA::getAutoDewAggression()
{
char res[PEGASUS_LEN] = {0};
if (sendCommand("DA", res))
{

uint32_t value = 0;
sscanf(res, "%*[^:]:%d", &value);
AutoDewSettingsN[AUTO_DEW_AGGRESSION].value = 100 * value / 255;
}
else
AutoDewSettingsNP.s = IPS_ALERT;

IDSetNumber(&AutoDewSettingsNP, nullptr);
return AutoDewSettingsNP.s != IPS_ALERT;
}

bool PegasusPPBA::getMetricsData()
{
char res[PEGASUS_LEN] = {0};
Expand Down
9 changes: 9 additions & 0 deletions drivers/auxiliary/pegasus_ppba.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ class PegasusPPBA : public INDI::DefaultDevice, public INDI::FocuserInterface, p

// Dew
bool setAutoDewEnabled(bool enabled);
bool setAutoDewAggression(uint8_t value);
bool getAutoDewAggression();
bool setDewPWM(uint8_t id, uint8_t value);

// Focuser
Expand Down Expand Up @@ -212,6 +214,13 @@ class PegasusPPBA : public INDI::DefaultDevice, public INDI::FocuserInterface, p
ISwitch AutoDewS[2];
ISwitchVectorProperty AutoDewSP;

INumber AutoDewSettingsN[1];
INumberVectorProperty AutoDewSettingsNP;
enum
{
AUTO_DEW_AGGRESSION
};

// Dew PWM
INumber DewPWMN[2];
INumberVectorProperty DewPWMNP;
Expand Down

0 comments on commit 2a66a0f

Please sign in to comment.