Exemple #1
0
bool Camera_DSIClass::Capture(int duration, usImage& img, int options, const wxRect& subframe)
{
    MeadeCam->SetGain((unsigned int) (GuideCameraGain * 63 / 100));
    MeadeCam->SetExposureTime(duration);

    if (img.Init(MeadeCam->GetWidth(), MeadeCam->GetHeight()))
    {
        DisconnectWithAlert(CAPT_FAIL_MEMORY);
        return true;
    }

    bool retval = MeadeCam->GetImage(img.ImageData, true);
    if (!retval)
        return true;

// The AbortImage method does not appear to work with the DSI camera.  If abort is called and the thread is terminated, the
// pending image is still downloaded and PHD2 will crash
#if AbortActuallyWorks
    CameraWatchdog watchdog(duration, GetTimeoutMs());

    // wait for image to finish and d/l
    while (!MeadeCam->ImageReady)
    {
        wxMilliSleep(20);
        if (WorkerThread::InterruptRequested())
        {
            MeadeCam->AbortImage();
            return true;
        }
        if (watchdog.Expired())
        {
            MeadeCam->AbortImage();
            DisconnectWithAlert(CAPT_FAIL_TIMEOUT);
            return true;
        }
    }
#else // handle the pending image download, regardless

    // We also need to prevent the thread from being killed when phd2 is closed
    WorkerThreadKillGuard _guard;

    if (duration > 100) {
        wxMilliSleep(duration - 100); // wait until near end of exposure, nicely
    }
    bool still_going = true;
    while (still_going) {  // wait for image to finish and d/l
        wxMilliSleep(20);
        still_going = !(MeadeCam->ImageReady);
    }

#endif // end of waiting for the image

    if (options & CAPTURE_SUBTRACT_DARK) SubtractDark(img);

    if (options & CAPTURE_RECON)
    {
        if (MeadeCam->IsColor)
            QuickLRecon(img);
        if (MeadeCam->IsDsiII)
            SquarePixels(img, 8.6, 8.3);
        else if (!MeadeCam->IsDsiIII)           // Original DSI
            SquarePixels(img, 9.6, 7.5);
    }

    return false;
}
Exemple #2
0
bool Camera_INDIClass::Capture(int duration, usImage& img, int options, const wxRect& subframeArg)
{
    if (Connected) {

        bool takeSubframe = UseSubframes;
        wxRect subframe(subframeArg);

        // we can set the exposure time directly in the camera
        if (expose_prop) {
            if (Binning != m_curBinning)
            {
                FullSize = wxSize(m_maxSize.x / Binning, m_maxSize.y / Binning);
                binning_x->value = Binning;
                binning_y->value = Binning;
                sendNewNumber(binning_prop);
                m_curBinning = Binning;
            }

            if (subframe.width <= 0 || subframe.height <= 0)
            {
                takeSubframe = false;
            }

            // Program the size
            if (!takeSubframe)
            {
                subframe = wxRect(0, 0, FullSize.GetWidth(), FullSize.GetHeight());
            }

            if (subframe != m_roi)
            {
                frame_x->value = subframe.x*Binning;
                frame_y->value = subframe.y*Binning;
                frame_width->value = subframe.width*Binning;
                frame_height->value = subframe.height*Binning;
                sendNewNumber(frame_prop);
                m_roi = subframe;
            }
            //printf("Exposing for %d(ms)\n", duration);

            // set the exposure time, this immediately start the exposure
            expose_prop->np->value = (double)duration/1000;
            sendNewNumber(expose_prop);

            modal = true;  // will be reset when the image blob is received

            unsigned long loopwait = duration > 100 ? 10 : 1;

            CameraWatchdog watchdog(duration, GetTimeoutMs());

            while (modal) {
                wxMilliSleep(loopwait);
                if (WorkerThread::TerminateRequested())
                    return true;
                if (watchdog.Expired())
                {
                    DisconnectWithAlert(CAPT_FAIL_TIMEOUT);
                    return true;
                }
            }
        }
        // for video camera without exposure time setting
        else if (video_prop) {
            takeSubframe = false;
            //printf("Enabling video capture\n");
            ISwitch *v_on = IUFindSwitch(video_prop,"ON");
            ISwitch *v_off = IUFindSwitch(video_prop,"OFF");
            v_on->s = ISS_ON;
            v_off->s = ISS_OFF;
            // start capture, every video frame is received as a blob
            sendNewSwitch(video_prop);

            // wait the required time
            wxMilliSleep(duration); // TODO : add the frames received during exposure

            //printf("Stop video capture\n");
            v_on->s = ISS_OFF;
            v_off->s = ISS_ON;
            sendNewSwitch(video_prop);
        }
        else {
            return true;
        }

        //printf("Exposure end\n");

        if (strcmp(cam_bp->format, ".fits") == 0) {
            //printf("Processing fits file\n");
            // for CCD camera
            if ( ! ReadFITS(img,takeSubframe,subframe) ) {
                if (options & CAPTURE_SUBTRACT_DARK) {
                    //printf("Subtracting dark\n");
                    SubtractDark(img);
                }
                if (options & CAPTURE_RECON) {
                    if (PixSizeX != PixSizeY) SquarePixels(img, PixSizeX, PixSizeY);
                }
                return false;
            } else {
                return true;
            }
        } else if (strcmp(cam_bp->format, ".stream") == 0) {
            //printf("Processing stream file\n");
            // for video camera
            return ReadStream(img);
        } else {
            pFrame->Alert(_("Unknown image format: ") + wxString::FromAscii(cam_bp->format));
            return true;
        }

    }
    else {
        // in case the camera is not connected
        return true;
    }
    // we must never go here
    return true;
}