Skip to content

Commit

Permalink
add power management for ZWO cameras
Browse files Browse the repository at this point in the history
  • Loading branch information
kvangorkom committed Jul 31, 2024
1 parent 1daf282 commit 8cff766
Showing 1 changed file with 61 additions and 10 deletions.
71 changes: 61 additions & 10 deletions apps/asiCtrl/asiCtrl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ class asiCtrl : public MagAOXApp<>, public dev::stdCamera<asiCtrl>, public dev::
/** \name app::dev Configurations
*@{
*/
static constexpr bool c_stdCamera_tempControl = false; ///< app::dev config to tell stdCamera to expose temperature controls
static constexpr bool c_stdCamera_tempControl = true; ///< app::dev config to tell stdCamera to expose temperature controls

static constexpr bool c_stdCamera_temp = false; ///< app::dev config to tell stdCamera to expose temperature
static constexpr bool c_stdCamera_temp = true; ///< app::dev config to tell stdCamera to expose temperature

static constexpr bool c_stdCamera_readoutSpeed = false; ///< app::dev config to tell stdCamera to expose readout speed controls

Expand Down Expand Up @@ -246,7 +246,7 @@ class asiCtrl : public MagAOXApp<>, public dev::stdCamera<asiCtrl>, public dev::
inline
asiCtrl::asiCtrl() : MagAOXApp(MAGAOX_CURRENT_SHA1, MAGAOX_REPO_MODIFIED)
{
m_powerMgtEnabled = false;
m_powerMgtEnabled = true;

//m_acqBuff.memory_size = 0;
//m_acqBuff.memory = 0;
Expand Down Expand Up @@ -371,6 +371,7 @@ int asiCtrl::appStartup()
inline
int asiCtrl::appLogic()
{

//and run stdCamera's appLogic
if(dev::stdCamera<asiCtrl>::appLogic() < 0)
{
Expand All @@ -385,17 +386,18 @@ int asiCtrl::appLogic()

//state(stateCodes::READY);


if( state() == stateCodes::NOTCONNECTED || state() == stateCodes::NODEVICE || state() == stateCodes::ERROR)
{
m_reconfig = true; //Trigger a f.g. thread reconfig.

//Might have gotten here because of a power off.
if(MagAOXAppT::m_powerState == 0) return 0;
//if(MagAOXAppT::m_powerState == 0) return 0;
if(powerState() != 1 || powerStateTarget() != 1) return 0;

std::unique_lock<std::mutex> lock(m_indiMutex);
if(connect() < 0)
{
if(powerState() != 1 || powerStateTarget() != 1) return 0;
log<software_error>({__FILE__, __LINE__});
}

Expand Down Expand Up @@ -455,7 +457,6 @@ int asiCtrl::appLogic()
return 0;
}

BREADCRUMB
if(stdCamera<asiCtrl>::updateINDI() < 0)
{
return log<software_error,0>({__FILE__,__LINE__});
Expand All @@ -466,7 +467,6 @@ int asiCtrl::appLogic()
return log<software_error,0>({__FILE__,__LINE__});
}

BREADCRUMB
if(telemeter<asiCtrl>::appLogic() < 0)
{
log<software_error>({__FILE__, __LINE__});
Expand All @@ -475,7 +475,6 @@ int asiCtrl::appLogic()

}


//Fall through check?
return 0;

Expand Down Expand Up @@ -580,6 +579,7 @@ int asiCtrl::connect()
{
std::cerr << "Clearing\n";
free(m_imgBuff);
m_imgBuff = NULL;
//m_acqBuff.memory = NULL;
//m_acqBuff.memory_size = 0;
}
Expand All @@ -599,6 +599,7 @@ int asiCtrl::connect()

int numDevices = ASIGetNumOfConnectedCameras();

if(powerState() != 1 || powerStateTarget() != 1) return 0;

if(numDevices <= 0)
{
Expand Down Expand Up @@ -633,6 +634,10 @@ int asiCtrl::connect()

return 0;
}
else
{
if(powerState() != 1 || powerStateTarget() != 1) return 0;
}
}

state(stateCodes::NODEVICE);
Expand Down Expand Up @@ -717,6 +722,7 @@ int asiCtrl::setExpTime()
{

int rv = ASISetControlValue(m_camNum, ASI_EXPOSURE, m_expTimeSet * 1e6, ASI_FALSE);
sleep(1);

if(rv < 0)
{
Expand Down Expand Up @@ -792,7 +798,6 @@ int asiCtrl::configureAcquisition()

std::unique_lock<std::mutex> lock(m_indiMutex);


ASISetControlValue(m_camNum, ASI_HIGH_SPEED_MODE, 0, ASI_FALSE);
//ASISetControlValue(m_camNum, ASI_FLIP, ASI_FLIP_VERT, ASI_FALSE);

Expand Down Expand Up @@ -906,6 +911,24 @@ int asiCtrl::configureAcquisition()
//}
setEMGain();

rv = ASISetControlValue(m_camNum, ASI_BRIGHTNESS, 1, ASI_FALSE); // hard-coded for now, but should be an INDI property

if(rv < 0)
{
log<software_error>({__FILE__, __LINE__, "Error setting brightness!"});
return -1;
}


// TEMPORARY: HARD CODE HARDWARE BINNING !!!!
//rv = ASISetControlValue(m_camNum, ASI_HARDWARE_BIN, 2, ASI_FALSE);

if(rv < 0)
{
log<software_error>({__FILE__, __LINE__, "Error setting brightness!"});
return -1;
}

//Start continuous acquisition
//ASIStartVideoCapture(m_camNum);

Expand Down Expand Up @@ -939,15 +962,41 @@ int asiCtrl::startAcquisition()
inline
int asiCtrl::getTemp()
{
long asiTemp;
getASIParameter(asiTemp, ASI_TEMPERATURE);
m_ccdTemp = asiTemp / 10.0;
return 0;
}

inline
int asiCtrl::setTempSetPt()
{
int rv = ASISetControlValue(m_camNum, ASI_TARGET_TEMP, m_ccdTempSetpt , ASI_FALSE);
return 0;
}

inline
int asiCtrl::setTempControl()
{
if(m_tempControlStatusSet)
{
int rv = ASISetControlValue(m_camNum, ASI_COOLER_ON, ASI_TRUE , ASI_FALSE);
m_tempControlStatus = true;
m_tempControlStatusStr = "COOLING";
recordCamera();
log<text_log>("enabled temperature control");
return 0;
}
else
{
int rv = ASISetControlValue(m_camNum, ASI_COOLER_ON, ASI_FALSE , ASI_FALSE);
m_tempControlStatus = false;
m_tempControlStatusStr = "OFF";
recordCamera();
log<text_log>("disabled temperature control");
return 0;
}
}
inline
int asiCtrl::setReadoutSpeed()
{
Expand All @@ -962,7 +1011,7 @@ int asiCtrl::acquireAndCheckValid()
//long imgSize = width*height*(1 + (Image_type==ASI_IMG_RAW16));
//unsigned char* imgBuf = new unsigned char[imgSize];

ASIGetVideoData(m_camNum, m_imgBuff, m_imgSize, 500);
ASIGetVideoData(m_camNum, m_imgBuff, m_imgSize, 6000000); // really long time-out (100 minutes)

// timestamp
clock_gettime(CLOCK_REALTIME, &m_currImageTimestamp);
Expand Down Expand Up @@ -1006,6 +1055,8 @@ int asiCtrl::getAcquisitionState()

if(MagAOXAppT::m_powerState == 0) return 0;

if(powerState() != 1 || powerStateTarget() != 1) return -1;

if(m_running) state(stateCodes::OPERATING);
else state(stateCodes::READY);

Expand Down

0 comments on commit 8cff766

Please sign in to comment.