diff --git a/drivers/ccd/guide_simulator.cpp b/drivers/ccd/guide_simulator.cpp index cf1fd6aa38..bbe51d9c10 100644 --- a/drivers/ccd/guide_simulator.cpp +++ b/drivers/ccd/guide_simulator.cpp @@ -48,8 +48,8 @@ GuideSim::GuideSim() bool GuideSim::SetupParms() { int nbuf; - SetCCDParams(SimulatorSettingsN[0].value, SimulatorSettingsN[1].value, 16, SimulatorSettingsN[2].value, - SimulatorSettingsN[3].value); + SetCCDParams(SimulatorSettingsNP[SIM_XRES].getValue(), SimulatorSettingsNP[SIM_YRES].getValue(), 16, SimulatorSettingsNP[SIM_XSIZE].getValue(), + SimulatorSettingsNP[SIM_YRES].getValue()); if (HasCooler()) { @@ -58,20 +58,20 @@ bool GuideSim::SetupParms() } // Kwiq - maxnoise = SimulatorSettingsN[8].value; - skyglow = SimulatorSettingsN[9].value; - maxval = SimulatorSettingsN[4].value; - bias = SimulatorSettingsN[5].value; - limitingmag = SimulatorSettingsN[7].value; - saturationmag = SimulatorSettingsN[6].value; - OAGoffset = SimulatorSettingsN[10].value; // An oag is offset this much from center of scope position (arcminutes); - polarError = SimulatorSettingsN[11].value; - polarDrift = SimulatorSettingsN[12].value; - rotationCW = SimulatorSettingsN[13].value; + maxnoise = SimulatorSettingsNP[SIM_NOISE].getValue(); + skyglow = SimulatorSettingsNP[SIM_SKYGLOW].getValue(); + maxval = SimulatorSettingsNP[SIM_MAXVAL].getValue(); + bias = SimulatorSettingsNP[SIM_BIAS].getValue(); + limitingmag = SimulatorSettingsNP[SIM_BIAS].getValue(); + saturationmag = SimulatorSettingsNP[SIM_SATURATION].getValue(); + OAGoffset = SimulatorSettingsNP[SIM_OAGOFFSET].getValue(); // An oag is offset this much from center of scope position (arcminutes); + polarError = SimulatorSettingsNP[SIM_POLAR].getValue(); + polarDrift = SimulatorSettingsNP[SIM_POLARDRIFT].getValue(); + rotationCW = SimulatorSettingsNP[SIM_ROTATION].getValue(); // Kwiq++ - king_gamma = SimulatorSettingsN[14].value * 0.0174532925; - king_theta = SimulatorSettingsN[15].value * 0.0174532925; - TimeFactor = SimulatorSettingsN[16].value; + king_gamma = SimulatorSettingsNP[SIM_KING_GAMMA].getValue() * 0.0174532925; + king_theta = SimulatorSettingsNP[SIM_KING_THETA].getValue() * 0.0174532925; + TimeFactor = SimulatorSettingsNP[SIM_TIME_FACTOR].getValue(); nbuf = PrimaryCCD.getXRes() * PrimaryCCD.getYRes() * PrimaryCCD.getBPP() / 8; //nbuf += 512; @@ -117,47 +117,47 @@ bool GuideSim::initProperties() CaptureFormat format = {"INDI_MONO", "Mono", 16, true}; addCaptureFormat(format); - IUFillNumber(&SimulatorSettingsN[0], "SIM_XRES", "CCD X resolution", "%4.0f", 0, 8192, 0, 1280); - IUFillNumber(&SimulatorSettingsN[1], "SIM_YRES", "CCD Y resolution", "%4.0f", 0, 8192, 0, 1024); - IUFillNumber(&SimulatorSettingsN[2], "SIM_XSIZE", "CCD X Pixel Size", "%4.2f", 0, 60, 0, 2.4); - IUFillNumber(&SimulatorSettingsN[3], "SIM_YSIZE", "CCD Y Pixel Size", "%4.2f", 0, 60, 0, 2.4); - IUFillNumber(&SimulatorSettingsN[4], "SIM_MAXVAL", "CCD Maximum ADU", "%4.0f", 0, 65000, 0, 65000); - IUFillNumber(&SimulatorSettingsN[5], "SIM_BIAS", "CCD Bias", "%4.0f", 0, 6000, 0, 10); - IUFillNumber(&SimulatorSettingsN[6], "SIM_SATURATION", "Saturation Mag", "%4.1f", 0, 20, 0, 1.0); - IUFillNumber(&SimulatorSettingsN[7], "SIM_LIMITINGMAG", "Limiting Mag", "%4.1f", 0, 20, 0, 17.0); - IUFillNumber(&SimulatorSettingsN[8], "SIM_NOISE", "CCD Noise", "%4.0f", 0, 6000, 0, 10); - IUFillNumber(&SimulatorSettingsN[9], "SIM_SKYGLOW", "Sky Glow (magnitudes)", "%4.1f", 0, 6000, 0, 19.5); - IUFillNumber(&SimulatorSettingsN[10], "SIM_OAGOFFSET", "Oag Offset (arcminutes)", "%4.1f", 0, 6000, 0, 0); - IUFillNumber(&SimulatorSettingsN[11], "SIM_POLAR", "PAE (arcminutes)", "%4.1f", -600, 600, 0, - 0); /* PAE = Polar Alignment Error */ - IUFillNumber(&SimulatorSettingsN[12], "SIM_POLARDRIFT", "PAE Drift (minutes)", "%4.1f", 0, 6000, 0, 0); - IUFillNumber(&SimulatorSettingsN[13], "SIM_ROTATION", "Rotation CW (degrees)", "%4.1f", -360, 360, 0, 0); - IUFillNumber(&SimulatorSettingsN[14], "SIM_KING_GAMMA", "(CP,TCP), deg", "%4.1f", 0, 10, 0, 0); - IUFillNumber(&SimulatorSettingsN[15], "SIM_KING_THETA", "hour hangle, deg", "%4.1f", 0, 360, 0, 0); - IUFillNumber(&SimulatorSettingsN[16], "SIM_TIME_FACTOR", "Time Factor (x)", "%.2f", 0.01, 100, 0, 1); - - IUFillNumberVector(&SimulatorSettingsNP, SimulatorSettingsN, 17, getDeviceName(), "SIMULATOR_SETTINGS", - "Config", SIMULATOR_TAB, IP_RW, 60, IPS_IDLE); + SimulatorSettingsNP[SIM_XRES].fill("SIM_XRES", "CCD X resolution", "%4.0f", 0, 8192, 0, 1280); + SimulatorSettingsNP[SIM_YRES].fill("SIM_YRES", "CCD Y resolution", "%4.0f", 0, 8192, 0, 1024); + SimulatorSettingsNP[SIM_XSIZE].fill("SIM_XSIZE", "CCD X Pixel Size", "%4.2f", 0, 60, 0, 2.4); + SimulatorSettingsNP[SIM_YSIZE].fill("SIM_YSIZE", "CCD Y Pixel Size", "%4.2f", 0, 60, 0, 2.4); + SimulatorSettingsNP[SIM_MAXVAL].fill("SIM_MAXVAL", "CCD Maximum ADU", "%4.0f", 0, 65000, 0, 65000); + SimulatorSettingsNP[SIM_BIAS].fill("SIM_BIAS", "CCD Bias", "%4.0f", 0, 6000, 0, 10); + SimulatorSettingsNP[SIM_SATURATION].fill("SIM_SATURATION", "Saturation Mag", "%4.1f", 0, 20, 0, 1.0); + SimulatorSettingsNP[SIM_LIMITINGMAG].fill("SIM_LIMITINGMAG", "Limiting Mag", "%4.1f", 0, 20, 0, 17.0); + SimulatorSettingsNP[SIM_NOISE].fill("SIM_NOISE", "CCD Noise", "%4.0f", 0, 6000, 0, 10); + SimulatorSettingsNP[SIM_SKYGLOW].fill("SIM_SKYGLOW", "Sky Glow (magnitudes)", "%4.1f", 0, 6000, 0, 19.5); + SimulatorSettingsNP[SIM_OAGOFFSET].fill("SIM_OAGOFFSET", "Oag Offset (arcminutes)", "%4.1f", 0, 6000, 0, 0); + SimulatorSettingsNP[SIM_POLAR].fill("SIM_POLAR", "PAE (arcminutes)", "%4.1f", -600, 600, 0, + 0); /* PAE = Polar Alignment Error */ + SimulatorSettingsNP[SIM_POLARDRIFT].fill("SIM_POLARDRIFT", "PAE Drift (minutes)", "%4.1f", 0, 6000, 0, 0); + SimulatorSettingsNP[SIM_ROTATION].fill("SIM_ROTATION", "Rotation CW (degrees)", "%4.1f", -360, 360, 0, 0); + SimulatorSettingsNP[SIM_KING_GAMMA].fill("SIM_KING_GAMMA", "(CP,TCP), deg", "%4.1f", 0, 10, 0, 0); + SimulatorSettingsNP[SIM_KING_THETA].fill("SIM_KING_THETA", "hour hangle, deg", "%4.1f", 0, 360, 0, 0); + SimulatorSettingsNP[SIM_TIME_FACTOR].fill("SIM_TIME_FACTOR", "Time Factor (x)", "%.2f", 0.01, 100, 0, 1); + + SimulatorSettingsNP.fill(getDeviceName(), "SIMULATOR_SETTINGS", + "Config", SIMULATOR_TAB, IP_RW, 60, IPS_IDLE); // RGB Simulation - IUFillSwitch(&SimulateRgbS[0], "SIMULATE_YES", "Yes", ISS_OFF); - IUFillSwitch(&SimulateRgbS[1], "SIMULATE_NO", "No", ISS_ON); - IUFillSwitchVector(&SimulateRgbSP, SimulateRgbS, 2, getDeviceName(), "SIMULATE_RGB", "Simulate RGB", + SimulateRgbSP[SIMULATE_YES].fill("SIMULATE_YES", "Yes", ISS_OFF); + SimulateRgbSP[SIMULATE_NO].fill("SIMULATE_NO", "No", ISS_ON); + SimulateRgbSP.fill(getDeviceName(), "SIMULATE_RGB", "Simulate RGB", SIMULATOR_TAB, IP_RW, ISR_1OFMANY, 60, IPS_IDLE); - IUFillSwitch(&CoolerS[0], "COOLER_ON", "ON", ISS_OFF); - IUFillSwitch(&CoolerS[1], "COOLER_OFF", "OFF", ISS_ON); - IUFillSwitchVector(&CoolerSP, CoolerS, 2, getDeviceName(), "CCD_COOLER", "Cooler", MAIN_CONTROL_TAB, IP_WO, - ISR_1OFMANY, 0, IPS_IDLE); + CoolerSP[COOLER_ON].fill("COOLER_ON", "ON", ISS_OFF); + CoolerSP[COOLER_OFF].fill("COOLER_OFF", "OFF", ISS_ON); + CoolerSP.fill(getDeviceName(), "CCD_COOLER", "Cooler", MAIN_CONTROL_TAB, IP_WO, + ISR_1OFMANY, 0, IPS_IDLE); // CCD Gain - IUFillNumber(&GainN[0], "GAIN", "Gain", "%.f", 0, 100, 10, 50); - IUFillNumberVector(&GainNP, GainN, 1, getDeviceName(), "CCD_GAIN", "Gain", MAIN_CONTROL_TAB, IP_RW, 60, IPS_IDLE); + GainNP[0].fill("GAIN", "Gain", "%.f", 0, 100, 10, 50); + GainNP.fill(getDeviceName(), "CCD_GAIN", "Gain", MAIN_CONTROL_TAB, IP_RW, 60, IPS_IDLE); - IUFillNumber(&EqPEN[0], "RA_PE", "RA (hh:mm:ss)", "%010.6m", 0, 24, 0, 0); - IUFillNumber(&EqPEN[1], "DEC_PE", "DEC (dd:mm:ss)", "%010.6m", -90, 90, 0, 0); - IUFillNumberVector(&EqPENP, EqPEN, 2, getDeviceName(), "EQUATORIAL_PE", "EQ PE", SIMULATOR_TAB, IP_RW, 60, - IPS_IDLE); + EqPENP[RA_PE].fill("RA_PE", "RA (hh:mm:ss)", "%010.6m", 0, 24, 0, 0); + EqPENP[DEC_PE].fill("DEC_PE", "DEC (dd:mm:ss)", "%010.6m", -90, 90, 0, 0); + EqPENP.fill(getDeviceName(), "EQUATORIAL_PE", "EQ PE", SIMULATOR_TAB, IP_RW, 60, + IPS_IDLE); // Timeout ToggleTimeoutSP[INDI_ENABLED].fill("INDI_ENABLED", "Enabled", ISS_OFF); @@ -215,9 +215,9 @@ void GuideSim::ISGetProperties(const char * dev) { INDI::CCD::ISGetProperties(dev); - defineProperty(&SimulatorSettingsNP); - defineProperty(&EqPENP); - defineProperty(&SimulateRgbSP); + defineProperty(SimulatorSettingsNP); + defineProperty(EqPENP); + defineProperty(SimulateRgbSP); defineProperty(ToggleTimeoutSP); } @@ -228,9 +228,9 @@ bool GuideSim::updateProperties() if (isConnected()) { if (HasCooler()) - defineProperty(&CoolerSP); + defineProperty(CoolerSP); - defineProperty(&GainNP); + defineProperty(GainNP); SetupParms(); @@ -243,9 +243,9 @@ bool GuideSim::updateProperties() else { if (HasCooler()) - deleteProperty(CoolerSP.name); + deleteProperty(CoolerSP.getName()); - deleteProperty(GainNP.name); + deleteProperty(GainNP.getName()); } return true; @@ -260,10 +260,10 @@ int GuideSim::SetTemperature(double temperature) return 1; } - CoolerS[0].s = ISS_ON; - CoolerS[1].s = ISS_OFF; - CoolerSP.s = IPS_BUSY; - IDSetSwitch(&CoolerSP, nullptr); + CoolerSP[COOLER_ON].setState(ISS_ON); + CoolerSP[COOLER_OFF].setState(ISS_OFF); + CoolerSP.setState(IPS_BUSY); + CoolerSP.apply(); return 0; } @@ -369,10 +369,10 @@ void GuideSim::TimerHit() // Above 20, cooler is off if (TemperatureN[0].value >= 20) { - CoolerS[0].s = ISS_OFF; - CoolerS[0].s = ISS_ON; - CoolerSP.s = IPS_IDLE; - IDSetSwitch(&CoolerSP, nullptr); + CoolerSP[COOLER_ON].setState(ISS_OFF); + CoolerSP[COOLER_OFF].setState(ISS_ON); + CoolerSP.setState(IPS_IDLE); + CoolerSP.apply(); } } @@ -392,7 +392,7 @@ int GuideSim::DrawCcdFrame(INDI::CCDChip * targetChip) else exposure_time = ExposureRequest; - exposure_time *= (1 + sqrt(GainN[0].value)); + exposure_time *= (1 + sqrt(GainNP[0].getValue())); auto targetFocalLength = ScopeInfoNP[FocalLength].getValue() > 0 ? ScopeInfoNP[FocalLength].getValue() : snoopedFocalLength; @@ -597,7 +597,7 @@ int GuideSim::DrawCcdFrame(INDI::CCDChip * targetChip) // remember it is the center of the simulated image double J2_mnt_d_rar = king_gamma * sin(J2decr) * sin(JnHAr - king_theta) / cos(J2decr); double J2_mnt_rar = rar - J2_mnt_d_rar - ; // rad = currentRA * 15.0; rar = rad * 0.0174532925; currentRA = J2000Pos.ra / 15.0; + ; // rad = currentRA * 15.0; rar = rad * 0.0174532925; currentRA = J2000Pos.ra / 15.0; // Imagine the HA axis points to HA=0, dec=89deg, then in the mount's coordinate // system a star at true dec = 88 is seen at 89 deg in the mount's system @@ -605,7 +605,7 @@ int GuideSim::DrawCcdFrame(INDI::CCDChip * targetChip) // and set it to 87 deg then the real location is at 88 deg. double J2_mnt_d_decr = king_gamma * cos(JnHAr - king_theta); double J2_mnt_decr = decr + J2_mnt_d_decr - ; // decr = cameradec * 0.0174532925; cameradec = currentDE + OAGoffset / 60; currentDE = J2000Pos.dec; + ; // decr = cameradec * 0.0174532925; cameradec = currentDE + OAGoffset / 60; currentDE = J2000Pos.dec; // IDLog("raw mod ra : %8.3f, dec: %8.3f (degree)\n", J2_mnt_rar / 0.0174532925, J2_mnt_decr / 0.0174532925 ); if (J2_mnt_decr > M_PI / 2.) { @@ -1001,54 +1001,54 @@ bool GuideSim::ISNewNumber(const char * dev, const char * name, double values[], if (dev != nullptr && strcmp(dev, getDeviceName()) == 0) { - if (!strcmp(name, GainNP.name)) + if (GainNP.isNameMatch(name)) { - IUUpdateNumber(&GainNP, values, names, n); - GainNP.s = IPS_OK; - IDSetNumber(&GainNP, nullptr); + GainNP.update(values, names, n); + GainNP.setState(IPS_OK); + GainNP.apply(); return true; } if (strcmp(name, "SIMULATOR_SETTINGS") == 0) { - IUUpdateNumber(&SimulatorSettingsNP, values, names, n); - SimulatorSettingsNP.s = IPS_OK; + SimulatorSettingsNP.update(values, names, n); + SimulatorSettingsNP.setState(IPS_OK); // Reset our parameters now SetupParms(); - IDSetNumber(&SimulatorSettingsNP, nullptr); - - maxnoise = SimulatorSettingsN[8].value; - skyglow = SimulatorSettingsN[9].value; - maxval = SimulatorSettingsN[4].value; - bias = SimulatorSettingsN[5].value; - limitingmag = SimulatorSettingsN[7].value; - saturationmag = SimulatorSettingsN[6].value; - OAGoffset = SimulatorSettingsN[10].value; - polarError = SimulatorSettingsN[11].value; - polarDrift = SimulatorSettingsN[12].value; - rotationCW = SimulatorSettingsN[13].value; + SimulatorSettingsNP.apply(); + + maxnoise = SimulatorSettingsNP[SIM_NOISE].getValue(); + skyglow = SimulatorSettingsNP[SIM_SKYGLOW].getValue(); + maxval = SimulatorSettingsNP[SIM_MAXVAL].getValue(); + bias = SimulatorSettingsNP[SIM_BIAS].getValue(); + limitingmag = SimulatorSettingsNP[SIM_LIMITINGMAG].getValue(); + saturationmag = SimulatorSettingsNP[SIM_SATURATION].getValue(); + OAGoffset = SimulatorSettingsNP[SIM_OAGOFFSET].getValue(); + polarError = SimulatorSettingsNP[SIM_POLAR].getValue(); + polarDrift = SimulatorSettingsNP[SIM_POLARDRIFT].getValue(); + rotationCW = SimulatorSettingsNP[SIM_ROTATION].getValue(); // Kwiq++ - king_gamma = SimulatorSettingsN[14].value * 0.0174532925; - king_theta = SimulatorSettingsN[15].value * 0.0174532925; - TimeFactor = SimulatorSettingsN[16].value; + king_gamma = SimulatorSettingsNP[SIM_KING_GAMMA].getValue() * 0.0174532925; + king_theta = SimulatorSettingsNP[SIM_KING_THETA].getValue() * 0.0174532925; + TimeFactor = SimulatorSettingsNP[SIM_TIME_FACTOR].getValue(); return true; } // Record PE EQ to simulate different position in the sky than actual mount coordinate // This can be useful to simulate Periodic Error or cone error or any arbitrary error. - if (!strcmp(name, EqPENP.name)) + if (EqPENP.isNameMatch(name)) { - IUUpdateNumber(&EqPENP, values, names, n); - EqPENP.s = IPS_OK; + EqPENP.update(values, names, n); + EqPENP.setState(IPS_OK); - INDI::IEquatorialCoordinates epochPos { EqPEN[AXIS_RA].value, EqPEN[AXIS_DE].value }, J2000Pos { 0, 0 }; + INDI::IEquatorialCoordinates epochPos { EqPENP[AXIS_RA].getValue(), EqPENP[AXIS_DE].getValue() }, J2000Pos { 0, 0 }; INDI::ObservedToJ2000(&epochPos, ln_get_julian_from_sys(), &J2000Pos); currentRA = J2000Pos.rightascension; currentDE = J2000Pos.declination; usePE = true; - IDSetNumber(&EqPENP, nullptr); + EqPENP.apply(); return true; } } @@ -1061,43 +1061,43 @@ bool GuideSim::ISNewSwitch(const char * dev, const char * name, ISState * states if (dev != nullptr && strcmp(dev, getDeviceName()) == 0) { - if (!strcmp(name, SimulateRgbSP.name)) + if (SimulateRgbSP.isNameMatch(name)) { - IUUpdateSwitch(&SimulateRgbSP, states, names, n); - int index = IUFindOnSwitchIndex(&SimulateRgbSP); + SimulateRgbSP.update(states, names, n); + int index = SimulateRgbSP.findOnSwitchIndex(); if (index == -1) { - SimulateRgbSP.s = IPS_ALERT; + SimulateRgbSP.setState(IPS_ALERT); LOG_INFO("Cannot determine whether RGB simulation should be switched on or off."); - IDSetSwitch(&SimulateRgbSP, nullptr); + SimulateRgbSP.apply(); return false; } simulateRGB = index == 0; setRGB(simulateRGB); - SimulateRgbS[0].s = simulateRGB ? ISS_ON : ISS_OFF; - SimulateRgbS[1].s = simulateRGB ? ISS_OFF : ISS_ON; - SimulateRgbSP.s = IPS_OK; - IDSetSwitch(&SimulateRgbSP, nullptr); + SimulateRgbSP[SIMULATE_YES].setState(simulateRGB ? ISS_ON : ISS_OFF); + SimulateRgbSP[SIMULATE_NO].setState(simulateRGB ? ISS_OFF : ISS_ON); + SimulateRgbSP.setState(IPS_OK); + SimulateRgbSP.apply(); return true; } - if (strcmp(name, CoolerSP.name) == 0) + if (CoolerSP.isNameMatch(name)) { - IUUpdateSwitch(&CoolerSP, states, names, n); + CoolerSP.update(states, names, n); - if (CoolerS[0].s == ISS_ON) - CoolerSP.s = IPS_BUSY; + if (CoolerSP[COOLER_ON].getState() == ISS_ON) + CoolerSP.setState(IPS_BUSY); else { - CoolerSP.s = IPS_IDLE; + CoolerSP.setState(IPS_IDLE); TemperatureRequest = 20; TemperatureNP.s = IPS_BUSY; } - IDSetSwitch(&CoolerSP, nullptr); + CoolerSP.apply(); return true; } @@ -1176,13 +1176,13 @@ bool GuideSim::saveConfigItems(FILE * fp) // Save CCD Simulator Config - IUSaveConfigNumber(fp, &SimulatorSettingsNP); + SimulatorSettingsNP.save(fp); // Gain - IUSaveConfigNumber(fp, &GainNP); + GainNP.save(fp); // RGB - IUSaveConfigSwitch(fp, &SimulateRgbSP); + SimulateRgbSP.save(fp); return true; } @@ -1292,5 +1292,5 @@ void GuideSim::addFITSKeywords(INDI::CCDChip *targetChip, std::vector &fitsKeywords) override; - virtual void activeDevicesUpdated() override; - virtual int SetTemperature(double temperature) override; - virtual bool UpdateCCDFrame(int x, int y, int w, int h) override; - virtual bool UpdateCCDBin(int hor, int ver) override; - - virtual bool StartStreaming() override; - virtual bool StopStreaming() override; - - private: - - float CalcTimeLeft(timeval, float); - bool SetupParms(); - - // Turns on/off Bayer RGB simulation. - void setRGB(bool onOff); - - double TemperatureRequest { 0 }; - - float ExposureRequest { 0 }; - struct timeval ExpStart - { - 0, 0 - }; - - - int testvalue { 0 }; - bool ShowStarField { true }; - int bias { 1500 }; - int maxnoise { 20 }; - int maxval { 65000 }; - int maxpix { 0 }; - int minpix { 65000 }; - float skyglow { 40 }; - float limitingmag { 11.5 }; - float saturationmag { 2 }; - float seeing { 3.5 }; - float ImageScalex { 1.0 }; - float ImageScaley { 1.0 }; - // An oag is offset this much from center of scope position (arcminutes) - float OAGoffset { 0 }; - double rotationCW { 0 }; - float TimeFactor { 1 }; - - bool simulateRGB { false }; - - // our zero point calcs used for drawing stars - float k { 0 }; - float z { 0 }; - - bool AbortPrimaryFrame { false }; - - /// Guide rate is 7 arcseconds per second - float GuideRate { 7 }; - - /// Our PEPeriod is 8 minutes and we have a 22 arcsecond swing - float PEPeriod { 8 * 60 }; - float PEMax { 11 }; - - double currentRA { 0 }; - double currentDE { 0 }; - bool usePE { false }; - time_t RunStart; - - float guideNSOffset {0}; - float guideWEOffset {0}; - - float polarError { 0 }; - float polarDrift { 0 }; - float king_gamma = { 0 }; - float king_theta = { 0 }; - - int streamPredicate; - pthread_t primary_thread; - bool terminateThread; - - // And this lives in our simulator settings page - - INumberVectorProperty SimulatorSettingsNP; - INumber SimulatorSettingsN[17]; - - ISwitchVectorProperty SimulateRgbSP; - ISwitch SimulateRgbS[2]; - - INumberVectorProperty EqPENP; - INumber EqPEN[2]; - - ISwitch CoolerS[2]; - ISwitchVectorProperty CoolerSP; - - INumber GainN[1]; - INumberVectorProperty GainNP; - - INDI::PropertySwitch ToggleTimeoutSP {2}; - - static constexpr const char *SIMULATOR_TAB {"Simulator Settings"}; + virtual IPState GuideNorth(uint32_t) override; + virtual IPState GuideSouth(uint32_t) override; + virtual IPState GuideEast(uint32_t) override; + virtual IPState GuideWest(uint32_t) override; + + virtual bool saveConfigItems(FILE *fp) override; + virtual void addFITSKeywords(INDI::CCDChip *targetChip, std::vector &fitsKeywords) override; + virtual void activeDevicesUpdated() override; + virtual int SetTemperature(double temperature) override; + virtual bool UpdateCCDFrame(int x, int y, int w, int h) override; + virtual bool UpdateCCDBin(int hor, int ver) override; + + virtual bool StartStreaming() override; + virtual bool StopStreaming() override; + +private: + + float CalcTimeLeft(timeval, float); + bool SetupParms(); + + // Turns on/off Bayer RGB simulation. + void setRGB(bool onOff); + + double TemperatureRequest { 0 }; + + float ExposureRequest { 0 }; + struct timeval ExpStart + { + 0, 0 + }; + + + int testvalue { 0 }; + bool ShowStarField { true }; + int bias { 1500 }; + int maxnoise { 20 }; + int maxval { 65000 }; + int maxpix { 0 }; + int minpix { 65000 }; + float skyglow { 40 }; + float limitingmag { 11.5 }; + float saturationmag { 2 }; + float seeing { 3.5 }; + float ImageScalex { 1.0 }; + float ImageScaley { 1.0 }; + // An oag is offset this much from center of scope position (arcminutes) + float OAGoffset { 0 }; + double rotationCW { 0 }; + float TimeFactor { 1 }; + + bool simulateRGB { false }; + + // our zero point calcs used for drawing stars + float k { 0 }; + float z { 0 }; + + bool AbortPrimaryFrame { false }; + + /// Guide rate is 7 arcseconds per second + float GuideRate { 7 }; + + /// Our PEPeriod is 8 minutes and we have a 22 arcsecond swing + float PEPeriod { 8 * 60 }; + float PEMax { 11 }; + + double currentRA { 0 }; + double currentDE { 0 }; + bool usePE { false }; + time_t RunStart; + + float guideNSOffset {0}; + float guideWEOffset {0}; + + float polarError { 0 }; + float polarDrift { 0 }; + float king_gamma = { 0 }; + float king_theta = { 0 }; + + int streamPredicate; + pthread_t primary_thread; + bool terminateThread; + + // And this lives in our simulator settings page + + INDI::PropertyNumber SimulatorSettingsNP {17}; + enum + { + SIM_XRES, + SIM_YRES, + SIM_XSIZE, + SIM_YSIZE, + SIM_MAXVAL, + SIM_BIAS, + SIM_SATURATION, + SIM_LIMITINGMAG, + SIM_NOISE, + SIM_SKYGLOW, + SIM_OAGOFFSET, + SIM_POLAR, + SIM_POLARDRIFT, + SIM_ROTATION, + SIM_KING_GAMMA, + SIM_KING_THETA, + SIM_TIME_FACTOR + }; + + INDI::PropertySwitch SimulateRgbSP {2}; + enum + { + SIMULATE_YES, + SIMULATE_NO + }; + + INDI::PropertyNumber EqPENP {2}; + enum + { + RA_PE, + DEC_PE + }; + + INDI::PropertySwitch CoolerSP {2}; + enum + { + COOLER_ON, + COOLER_OFF + }; + + INDI::PropertyNumber GainNP {1}; + + INDI::PropertySwitch ToggleTimeoutSP {2}; + + static constexpr const char *SIMULATOR_TAB {"Simulator Settings"}; }; diff --git a/drivers/focuser/focus_simulator.cpp b/drivers/focuser/focus_simulator.cpp index d20f12f359..2f0ee73d1e 100644 --- a/drivers/focuser/focus_simulator.cpp +++ b/drivers/focuser/focus_simulator.cpp @@ -69,7 +69,7 @@ void FocusSim::ISGetProperties(const char *dev) INDI::Focuser::ISGetProperties(dev); - defineProperty(&ModeSP); + defineProperty(ModeSP); loadConfig(true, "Mode"); } @@ -80,28 +80,28 @@ bool FocusSim::initProperties() { INDI::Focuser::initProperties(); - IUFillNumber(&SeeingN[0], "SIM_SEEING", "arcseconds", "%4.2f", 0, 60, 0, 3.5); - IUFillNumberVector(&SeeingNP, SeeingN, 1, getDeviceName(), "SEEING_SETTINGS", "Seeing", MAIN_CONTROL_TAB, IP_RW, 60, - IPS_IDLE); + SeeingNP[0].fill("SIM_SEEING", "arcseconds", "%4.2f", 0, 60, 0, 3.5); + SeeingNP.fill(getDeviceName(), "SEEING_SETTINGS", "Seeing", MAIN_CONTROL_TAB, IP_RW, 60, + IPS_IDLE); - IUFillNumber(&FWHMN[0], "SIM_FWHM", "arcseconds", "%4.2f", 0, 60, 0, 7.5); - IUFillNumberVector(&FWHMNP, FWHMN, 1, getDeviceName(), "FWHM", "FWHM", MAIN_CONTROL_TAB, IP_RO, 60, IPS_IDLE); + FWHMNP[0].fill("SIM_FWHM", "arcseconds", "%4.2f", 0, 60, 0, 7.5); + FWHMNP.fill(getDeviceName(), "FWHM", "FWHM", MAIN_CONTROL_TAB, IP_RO, 60, IPS_IDLE); - IUFillNumber(&TemperatureN[0], "TEMPERATURE", "Celsius", "%6.2f", -50., 70., 0., 0.); - IUFillNumberVector(&TemperatureNP, TemperatureN, 1, getDeviceName(), "FOCUS_TEMPERATURE", "Temperature", + TemperatureNP[0].fill("TEMPERATURE", "Celsius", "%6.2f", -50., 70., 0., 0.); + TemperatureNP.fill(getDeviceName(), "FOCUS_TEMPERATURE", "Temperature", MAIN_CONTROL_TAB, IP_RW, 0, IPS_IDLE); DelayNP[0].fill("DELAY_VALUE", "Value (uS)", "%.f", 0, 60000, 100, 100); DelayNP.fill(getDeviceName(), "DELAY", "Delay", OPTIONS_TAB, IP_RW, 60, IPS_IDLE); - IUFillSwitch(&ModeS[MODE_ALL], "All", "All", ISS_ON); - IUFillSwitch(&ModeS[MODE_ABSOLUTE], "Absolute", "Absolute", ISS_OFF); - IUFillSwitch(&ModeS[MODE_RELATIVE], "Relative", "Relative", ISS_OFF); - IUFillSwitch(&ModeS[MODE_TIMER], "Timer", "Timer", ISS_OFF); - IUFillSwitchVector(&ModeSP, ModeS, MODE_COUNT, getDeviceName(), "Mode", "Mode", MAIN_CONTROL_TAB, IP_RW, - ISR_1OFMANY, 60, IPS_IDLE); + ModeSP[MODE_ALL].fill("All", "All", ISS_ON); + ModeSP[MODE_ABSOLUTE].fill("Absolute", "Absolute", ISS_OFF); + ModeSP[MODE_RELATIVE].fill("Relative", "Relative", ISS_OFF); + ModeSP[MODE_TIMER].fill("Timer", "Timer", ISS_OFF); + ModeSP.fill(getDeviceName(), "Mode", "Mode", MAIN_CONTROL_TAB, IP_RW, + ISR_1OFMANY, 60, IPS_IDLE); - initTicks = sqrt(FWHMN[0].value - SeeingN[0].value) / 0.75; + initTicks = sqrt(FWHMNP[0].getValue() - SeeingNP[0].getValue()) / 0.75; FocusSpeedN[0].min = 1; FocusSpeedN[0].max = 5; @@ -124,16 +124,16 @@ bool FocusSim::updateProperties() if (isConnected()) { - defineProperty(&SeeingNP); - defineProperty(&FWHMNP); - defineProperty(&TemperatureNP); + defineProperty(SeeingNP); + defineProperty(FWHMNP); + defineProperty(TemperatureNP); defineProperty(DelayNP); } else { - deleteProperty(SeeingNP.name); - deleteProperty(FWHMNP.name); - deleteProperty(TemperatureNP.name); + deleteProperty(SeeingNP.getName()); + deleteProperty(FWHMNP.getName()); + deleteProperty(TemperatureNP.getName()); deleteProperty(DelayNP); } @@ -148,39 +148,40 @@ bool FocusSim::ISNewSwitch(const char *dev, const char *name, ISState *states, c if (dev != nullptr && strcmp(dev, getDeviceName()) == 0) { // Modes - if (strcmp(ModeSP.name, name) == 0) + if (ModeSP.isNameMatch(name)) { - IUUpdateSwitch(&ModeSP, states, names, n); + ModeSP.update(states, names, n); uint32_t cap = 0; - int index = IUFindOnSwitchIndex(&ModeSP); + int index = ModeSP.findOnSwitchIndex(); switch (index) { - case MODE_ALL: - cap = FOCUSER_CAN_ABS_MOVE | FOCUSER_CAN_REL_MOVE | FOCUSER_HAS_VARIABLE_SPEED; - break; - - case MODE_ABSOLUTE: - cap = FOCUSER_CAN_ABS_MOVE; - break; - - case MODE_RELATIVE: - cap = FOCUSER_CAN_REL_MOVE; - break; - - case MODE_TIMER: - cap = FOCUSER_HAS_VARIABLE_SPEED; - break; - - default: - ModeSP.s = IPS_ALERT; - IDSetSwitch(&ModeSP, "Unknown mode index %d", index); - return true; + case MODE_ALL: + cap = FOCUSER_CAN_ABS_MOVE | FOCUSER_CAN_REL_MOVE | FOCUSER_HAS_VARIABLE_SPEED; + break; + + case MODE_ABSOLUTE: + cap = FOCUSER_CAN_ABS_MOVE; + break; + + case MODE_RELATIVE: + cap = FOCUSER_CAN_REL_MOVE; + break; + + case MODE_TIMER: + cap = FOCUSER_HAS_VARIABLE_SPEED; + break; + + default: + ModeSP.setState(IPS_ALERT); + LOG_INFO("Unknown mode index"); + ModeSP.apply(); + return true; } FI::SetCapability(cap); - ModeSP.s = IPS_OK; - IDSetSwitch(&ModeSP, nullptr); + ModeSP.setState(IPS_OK); + ModeSP.apply(); return true; } } @@ -197,19 +198,19 @@ bool FocusSim::ISNewNumber(const char *dev, const char *name, double values[], c { if (strcmp(name, "SEEING_SETTINGS") == 0) { - SeeingNP.s = IPS_OK; - IUUpdateNumber(&SeeingNP, values, names, n); + SeeingNP.setState(IPS_OK); + SeeingNP.update(values, names, n); - IDSetNumber(&SeeingNP, nullptr); + SeeingNP.apply(); return true; } if (strcmp(name, "FOCUS_TEMPERATURE") == 0) { - TemperatureNP.s = IPS_OK; - IUUpdateNumber(&TemperatureNP, values, names, n); + TemperatureNP.setState(IPS_OK); + TemperatureNP.update(values, names, n); - IDSetNumber(&TemperatureNP, nullptr); + TemperatureNP.apply(); return true; } @@ -234,7 +235,7 @@ bool FocusSim::ISNewNumber(const char *dev, const char *name, double values[], c IPState FocusSim::MoveFocuser(FocusDirection dir, int speed, uint16_t duration) { double mid = (FocusAbsPosN[0].max - FocusAbsPosN[0].min) / 2; - int mode = IUFindOnSwitchIndex(&ModeSP); + int mode = ModeSP.findOnSwitchIndex(); double targetTicks = ((dir == FOCUS_INWARD) ? -1 : 1) * (speed * duration); internalTicks += targetTicks; @@ -254,10 +255,10 @@ IPState FocusSim::MoveFocuser(FocusDirection dir, int speed, uint16_t duration) double ticks = initTicks + (internalTicks - mid) / 5000.0; - FWHMN[0].value = 0.5625 * ticks * ticks + SeeingN[0].value; + FWHMNP[0].setValue(0.5625 * ticks * ticks + SeeingNP[0].getValue()); LOGF_DEBUG("TIMER Current internal ticks: %g FWHM ticks: %g FWHM: %g", internalTicks, ticks, - FWHMN[0].value); + FWHMNP[0].getValue()); if (mode == MODE_ALL) { @@ -265,10 +266,10 @@ IPState FocusSim::MoveFocuser(FocusDirection dir, int speed, uint16_t duration) IDSetNumber(&FocusAbsPosNP, nullptr); } - if (FWHMN[0].value < SeeingN[0].value) - FWHMN[0].value = SeeingN[0].value; + if (FWHMNP[0].getValue() < SeeingNP[0].getValue()) + FWHMNP[0].setValue(SeeingNP[0].getValue()); - IDSetNumber(&FWHMNP, nullptr); + FWHMNP.apply(); return IPS_OK; } @@ -290,15 +291,15 @@ IPState FocusSim::MoveAbsFocuser(uint32_t targetTicks) FocusAbsPosN[0].value = targetTicks; - FWHMN[0].value = 0.5625 * ticks * ticks + SeeingN[0].value; + FWHMNP[0].setValue(0.5625 * ticks * ticks + SeeingNP[0].getValue()); LOGF_DEBUG("ABS Current internal ticks: %g FWHM ticks: %g FWHM: %g", internalTicks, ticks, - FWHMN[0].value); + FWHMNP[0].getValue()); - if (FWHMN[0].value < SeeingN[0].value) - FWHMN[0].value = SeeingN[0].value; + if (FWHMNP[0].getValue() < SeeingNP[0].getValue()) + FWHMNP[0].setValue(SeeingNP[0].getValue()); - IDSetNumber(&FWHMNP, nullptr); + FWHMNP.apply(); return IPS_OK; } diff --git a/drivers/focuser/focus_simulator.h b/drivers/focuser/focus_simulator.h index 21a07118e9..22b73792ea 100644 --- a/drivers/focuser/focus_simulator.h +++ b/drivers/focuser/focus_simulator.h @@ -34,61 +34,58 @@ */ class FocusSim : public INDI::Focuser { - public: - FocusSim(); - virtual ~FocusSim() override = default; +public: + FocusSim(); + virtual ~FocusSim() override = default; - const char *getDefaultName() override; + const char *getDefaultName() override; - void ISGetProperties(const char *dev) override; - virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override; - virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override; + void ISGetProperties(const char *dev) override; + virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override; + virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override; - protected: +protected: - bool initProperties() override; - bool updateProperties() override; + bool initProperties() override; + bool updateProperties() override; - bool Connect() override; - bool Disconnect() override; + bool Connect() override; + bool Disconnect() override; - virtual IPState MoveFocuser(FocusDirection dir, int speed, uint16_t duration) override; - virtual IPState MoveAbsFocuser(uint32_t targetTicks) override; - virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override; - virtual bool SetFocuserSpeed(int speed) override; + virtual IPState MoveFocuser(FocusDirection dir, int speed, uint16_t duration) override; + virtual IPState MoveAbsFocuser(uint32_t targetTicks) override; + virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override; + virtual bool SetFocuserSpeed(int speed) override; - virtual bool SetFocuserBacklash(int32_t steps) override; - virtual bool SetFocuserBacklashEnabled(bool enabled) override; + virtual bool SetFocuserBacklash(int32_t steps) override; + virtual bool SetFocuserBacklashEnabled(bool enabled) override; - virtual bool saveConfigItems(FILE *fp) override; + virtual bool saveConfigItems(FILE *fp) override; - private: - double internalTicks { 0 }; - double initTicks { 0 }; +private: + double internalTicks { 0 }; + double initTicks { 0 }; - // Seeing in arcseconds - INumberVectorProperty SeeingNP; - INumber SeeingN[1]; + // Seeing in arcseconds + INDI::PropertyNumber SeeingNP {1}; - // FWHM to be used by CCD driver to draw 'fuzzy' stars - INumberVectorProperty FWHMNP; - INumber FWHMN[1]; + // FWHM to be used by CCD driver to draw 'fuzzy' stars + INDI::PropertyNumber FWHMNP {1}; - // Temperature in celcius degrees - INumberVectorProperty TemperatureNP; - INumber TemperatureN[1]; + // Temperature in celcius degrees + INDI::PropertyNumber TemperatureNP {1}; - INDI::PropertyNumber DelayNP {1}; + INDI::PropertyNumber DelayNP {1}; - // Current mode of Focus simulator for testing purposes - enum - { - MODE_ALL, - MODE_ABSOLUTE, - MODE_RELATIVE, - MODE_TIMER, - MODE_COUNT - }; - ISwitchVectorProperty ModeSP; - ISwitch ModeS[MODE_COUNT]; + // Current mode of Focus simulator for testing purposes + enum + { + MODE_ALL, + MODE_ABSOLUTE, + MODE_RELATIVE, + MODE_TIMER, + MODE_COUNT + }; + INDI::PropertySwitch ModeSP {4}; + // ISwitch ModeS[MODE_COUNT]; };