7#include "indicamerachip.h"
12#include "indi_debug.h"
17CameraChip::CameraChip(
ISD::Camera *camera, ChipType type): m_Camera(camera), m_Type(
type) {}
19FITSView *CameraChip::getImageView(FITSMode imageType)
33 return calibrationImage;
45void CameraChip::setImageView(FITSView *image, FITSMode imageType)
62 calibrationImage = image;
74 imageData = image->imageData();
77bool CameraChip::getFrameMinMax(
int *minX,
int *maxX,
int *minY,
int *maxY,
int *minW,
int *maxW,
int *minH,
int *maxH)
79 INumberVectorProperty *frameProp =
nullptr;
84 frameProp = m_Camera->getNumber(
"CCD_FRAME");
88 frameProp = m_Camera->getNumber(
"GUIDER_FRAME");
92 if (frameProp ==
nullptr)
95 INumber *arg = IUFindNumber(frameProp,
"X");
105 arg = IUFindNumber(frameProp,
"Y");
115 arg = IUFindNumber(frameProp,
"WIDTH");
125 arg = IUFindNumber(frameProp,
"HEIGHT");
138bool CameraChip::setImageInfo(uint16_t width, uint16_t height,
double pixelX,
double pixelY, uint8_t bitdepth)
140 INumberVectorProperty *ccdInfoProp =
nullptr;
145 ccdInfoProp = m_Camera->getNumber(
"CCD_INFO");
149 ccdInfoProp = m_Camera->getNumber(
"GUIDER_INFO");
153 if (ccdInfoProp ==
nullptr)
156 ccdInfoProp->np[0].value = width;
157 ccdInfoProp->np[1].value = height;
158 ccdInfoProp->np[2].value = std::hypotf(pixelX, pixelY);
159 ccdInfoProp->np[3].value = pixelX;
160 ccdInfoProp->np[4].value = pixelY;
161 ccdInfoProp->np[5].value = bitdepth;
163 m_Camera->sendNewProperty(ccdInfoProp);
168bool CameraChip::getImageInfo(uint16_t &width, uint16_t &height,
double &pixelX,
double &pixelY, uint8_t &bitdepth)
170 INumberVectorProperty *ccdInfoProp =
nullptr;
175 ccdInfoProp = m_Camera->getNumber(
"CCD_INFO");
179 ccdInfoProp = m_Camera->getNumber(
"GUIDER_INFO");
183 if (ccdInfoProp ==
nullptr)
186 width = ccdInfoProp->np[0].value;
187 height = ccdInfoProp->np[1].value;
188 pixelX = ccdInfoProp->np[2].value;
189 pixelY = ccdInfoProp->np[3].value;
190 bitdepth = ccdInfoProp->np[5].value;
195bool CameraChip::getBayerInfo(uint16_t &offsetX, uint16_t &offsetY,
QString &pattern)
197 ITextVectorProperty * bayerTP = m_Camera->getText(
"CCD_CFA");
203 pattern =
QString(bayerTP->tp[2].text);
208bool CameraChip::getFrame(
int *x,
int *y,
int *w,
int *h)
210 INumberVectorProperty *frameProp =
nullptr;
215 frameProp = m_Camera->getNumber(
"CCD_FRAME");
219 frameProp = m_Camera->getNumber(
"GUIDER_FRAME");
223 if (frameProp ==
nullptr)
226 INumber *arg = IUFindNumber(frameProp,
"X");
233 arg = IUFindNumber(frameProp,
"Y");
239 arg = IUFindNumber(frameProp,
"WIDTH");
245 arg = IUFindNumber(frameProp,
"HEIGHT");
254bool CameraChip::resetFrame()
256 INumberVectorProperty *frameProp =
nullptr;
261 frameProp = m_Camera->getNumber(
"CCD_FRAME");
265 frameProp = m_Camera->getNumber(
"GUIDER_FRAME");
269 if (frameProp ==
nullptr)
272 INumber *xarg = IUFindNumber(frameProp,
"X");
273 INumber *yarg = IUFindNumber(frameProp,
"Y");
274 INumber *warg = IUFindNumber(frameProp,
"WIDTH");
275 INumber *harg = IUFindNumber(frameProp,
"HEIGHT");
277 if (xarg && yarg && warg && harg)
279 if (!std::fabs(xarg->value - xarg->min) &&
280 !std::fabs(yarg->value - yarg->min) &&
281 !std::fabs(warg->value - warg->max) &&
282 !std::fabs(harg->value - harg->max))
285 xarg->value = xarg->min;
286 yarg->value = yarg->min;
287 warg->value = warg->max;
288 harg->value = harg->max;
290 m_Camera->sendNewProperty(frameProp);
297bool CameraChip::setFrame(
int x,
int y,
int w,
int h,
bool force)
299 INumberVectorProperty *frameProp =
nullptr;
304 frameProp = m_Camera->getNumber(
"CCD_FRAME");
308 frameProp = m_Camera->getNumber(
"GUIDER_FRAME");
312 if (frameProp ==
nullptr)
315 INumber *xarg = IUFindNumber(frameProp,
"X");
316 INumber *yarg = IUFindNumber(frameProp,
"Y");
317 INumber *warg = IUFindNumber(frameProp,
"WIDTH");
318 INumber *harg = IUFindNumber(frameProp,
"HEIGHT");
320 if (xarg && yarg && warg && harg)
323 !std::fabs(xarg->value - x) &&
324 !std::fabs(yarg->value - y) &&
325 !std::fabs(warg->value - w) &&
326 !std::fabs(harg->value - h))
334 m_Camera->sendNewProperty(frameProp);
341bool CameraChip::capture(
double exposure)
344 INumberVectorProperty *expProp =
nullptr;
349 expProp = m_Camera->getNumber(
"CCD_EXPOSURE");
353 expProp = m_Camera->getNumber(
"GUIDER_EXPOSURE");
357 if (expProp ==
nullptr)
362 if (Options::forceDSLRPresets())
365 if (!exposurePresets.
isEmpty())
368 QPair<double, double> minmax = m_Camera->getExposurePresetsMinMax();
371 if (exposure > min && exposure < max)
374 double closestMatch = exposure;
375 for (
const auto &oneValue : exposurePresets.
values())
377 double newDiff = std::fabs(exposure - oneValue);
380 closestMatch = oneValue;
385 qCDebug(KSTARS_INDI) <<
"Requested exposure" << exposure <<
"closes match is" << closestMatch;
386 exposure = closestMatch;
394 strcpy(n.name, expProp->np[0].name);
397 std::unique_ptr<INumberVectorProperty> newExpProp(
new INumberVectorProperty());
398 strncpy(newExpProp->device, expProp->device, MAXINDIDEVICE);
399 strncpy(newExpProp->name, expProp->name, MAXINDINAME);
400 strncpy(newExpProp->label, expProp->label, MAXINDILABEL);
404 m_Camera->sendNewProperty(newExpProp.get());
409bool CameraChip::abortExposure()
411 if (!m_Camera)
return false;
412 ISwitchVectorProperty *abortProp =
nullptr;
417 abortProp = m_Camera->getSwitch(
"CCD_ABORT_EXPOSURE");
421 abortProp = m_Camera->getSwitch(
"GUIDER_ABORT_EXPOSURE");
425 if (abortProp ==
nullptr)
428 ISwitch *abort = IUFindSwitch(abortProp,
"ABORT");
430 if (abort ==
nullptr)
435 m_Camera->sendNewProperty(abortProp);
439bool CameraChip::canBin()
const
441 return CanBin && m_Camera->getEncodingFormat() !=
QLatin1String(
"Native");
444void CameraChip::setCanBin(
bool value)
449bool CameraChip::canSubframe()
const
451 return CanSubframe && m_Camera->getEncodingFormat() !=
QLatin1String(
"Native");
454void CameraChip::setCanSubframe(
bool value)
458bool CameraChip::canAbort()
const
463void CameraChip::setCanAbort(
bool value)
473int CameraChip::getISOIndex()
const
475 auto isoProp = m_Camera->getSwitch(
"CCD_ISO");
480 return isoProp->findOnSwitchIndex();
483bool CameraChip::getISOValue(
QString &value)
const
485 auto index = getISOIndex();
486 auto list = getISOList();
496bool CameraChip::setISOIndex(
int value)
498 auto isoProp = m_Camera->getSwitch(
"CCD_ISO");
504 isoProp->at(value)->setState(ISS_ON);
506 m_Camera->sendNewProperty(isoProp);
515 auto isoProp = m_Camera->getSwitch(
"CCD_ISO");
520 for (
const auto &it : *isoProp)
521 isoList << it.getLabel();
526bool CameraChip::isCapturing()
528 if (!m_Camera)
return false;
529 INumberVectorProperty *expProp =
nullptr;
534 expProp = m_Camera->getNumber(
"CCD_EXPOSURE");
538 expProp = m_Camera->getNumber(
"GUIDER_EXPOSURE");
542 if (expProp ==
nullptr)
545 return (expProp->s == IPS_BUSY);
548bool CameraChip::setFrameType(
const QString &name)
550 CCDFrameType fType = FRAME_LIGHT;
552 if (name ==
"FRAME_LIGHT" || name ==
"Light")
554 else if (name ==
"FRAME_DARK" || name ==
"Dark")
556 else if (name ==
"FRAME_BIAS" || name ==
"Bias")
558 else if (name ==
"FRAME_FLAT" || name ==
"Flat")
562 qCWarning(KSTARS_INDI) <<
name <<
" frame type is unknown." ;
566 return setFrameType(fType);
569bool CameraChip::setFrameType(CCDFrameType fType)
571 ISwitchVectorProperty *frameProp =
nullptr;
573 if (m_Type == PRIMARY_CCD)
574 frameProp = m_Camera->getSwitch(
"CCD_FRAME_TYPE");
576 frameProp = m_Camera->getSwitch(
"GUIDER_FRAME_TYPE");
577 if (frameProp ==
nullptr)
580 ISwitch *ccdFrame =
nullptr;
582 if (fType == FRAME_LIGHT)
583 ccdFrame = IUFindSwitch(frameProp,
"FRAME_LIGHT");
584 else if (fType == FRAME_DARK)
585 ccdFrame = IUFindSwitch(frameProp,
"FRAME_DARK");
586 else if (fType == FRAME_BIAS)
587 ccdFrame = IUFindSwitch(frameProp,
"FRAME_BIAS");
588 else if (fType == FRAME_FLAT)
589 ccdFrame = IUFindSwitch(frameProp,
"FRAME_FLAT");
591 if (ccdFrame ==
nullptr)
594 if (ccdFrame->s == ISS_ON)
597 if (fType != FRAME_LIGHT)
598 captureMode = FITS_CALIBRATE;
600 IUResetSwitch(frameProp);
601 ccdFrame->s = ISS_ON;
603 m_Camera->sendNewProperty(frameProp);
608CCDFrameType CameraChip::getFrameType()
610 CCDFrameType fType = FRAME_LIGHT;
611 ISwitchVectorProperty *frameProp =
nullptr;
613 if (m_Type == PRIMARY_CCD)
614 frameProp = m_Camera->getSwitch(
"CCD_FRAME_TYPE");
616 frameProp = m_Camera->getSwitch(
"GUIDER_FRAME_TYPE");
618 if (frameProp ==
nullptr)
621 ISwitch *ccdFrame =
nullptr;
623 ccdFrame = IUFindOnSwitch(frameProp);
625 if (ccdFrame ==
nullptr)
627 qCWarning(KSTARS_INDI) <<
"ISD:CCD Cannot find active frame in CCD!";
631 if (!strcmp(ccdFrame->name,
"FRAME_LIGHT"))
633 else if (!strcmp(ccdFrame->name,
"FRAME_DARK"))
635 else if (!strcmp(ccdFrame->name,
"FRAME_FLAT"))
637 else if (!strcmp(ccdFrame->name,
"FRAME_BIAS"))
643bool CameraChip::setBinning(CCDBinType binType)
648 return setBinning(1, 1);
650 return setBinning(2, 2);
652 return setBinning(3, 3);
654 return setBinning(4, 4);
660CCDBinType CameraChip::getBinning()
662 CCDBinType binType = SINGLE_BIN;
663 INumberVectorProperty *binProp =
nullptr;
668 binProp = m_Camera->getNumber(
"CCD_BINNING");
672 binProp = m_Camera->getNumber(
"GUIDER_BINNING");
676 if (binProp ==
nullptr)
679 INumber *horBin =
nullptr, *verBin =
nullptr;
681 horBin = IUFindNumber(binProp,
"HOR_BIN");
682 verBin = IUFindNumber(binProp,
"VER_BIN");
684 if (!horBin || !verBin)
687 switch (
static_cast<int>(horBin->value))
690 binType = DOUBLE_BIN;
694 binType = TRIPLE_BIN;
698 binType = QUADRAPLE_BIN;
708bool CameraChip::getBinning(
int *bin_x,
int *bin_y)
710 INumberVectorProperty *binProp =
nullptr;
716 binProp = m_Camera->getNumber(
"CCD_BINNING");
720 binProp = m_Camera->getNumber(
"GUIDER_BINNING");
724 if (binProp ==
nullptr)
727 INumber *horBin =
nullptr, *verBin =
nullptr;
729 horBin = IUFindNumber(binProp,
"HOR_BIN");
730 verBin = IUFindNumber(binProp,
"VER_BIN");
732 if (!horBin || !verBin)
735 *bin_x = horBin->value;
736 *bin_y = verBin->value;
741bool CameraChip::getMaxBin(
int *max_xbin,
int *max_ybin)
743 if (!max_xbin || !max_ybin)
746 INumberVectorProperty *binProp =
nullptr;
748 *max_xbin = *max_ybin = 1;
753 binProp = m_Camera->getNumber(
"CCD_BINNING");
757 binProp = m_Camera->getNumber(
"GUIDER_BINNING");
761 if (binProp ==
nullptr)
764 INumber *horBin =
nullptr, *verBin =
nullptr;
766 horBin = IUFindNumber(binProp,
"HOR_BIN");
767 verBin = IUFindNumber(binProp,
"VER_BIN");
769 if (!horBin || !verBin)
772 *max_xbin = horBin->max;
773 *max_ybin = verBin->max;
778bool CameraChip::setBinning(
int bin_x,
int bin_y)
780 INumberVectorProperty *binProp =
nullptr;
785 binProp = m_Camera->getNumber(
"CCD_BINNING");
789 binProp = m_Camera->getNumber(
"GUIDER_BINNING");
793 if (binProp ==
nullptr)
796 INumber *horBin = IUFindNumber(binProp,
"HOR_BIN");
797 INumber *verBin = IUFindNumber(binProp,
"VER_BIN");
799 if (!horBin || !verBin)
802 if (!std::fabs(horBin->value - bin_x) && !std::fabs(verBin->value - bin_y))
805 if (bin_x > horBin->max || bin_y > verBin->max)
808 horBin->value = bin_x;
809 verBin->value = bin_y;
811 m_Camera->sendNewProperty(binProp);
Camera class controls an INDI Camera device.
ISD is a collection of INDI Standard Devices.
QString name(GameStandardAction id)
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
qsizetype count() const const
bool isEmpty() const const
bool isEmpty() const const
QList< T > values() const const
int toInt(bool *ok, int base) const const