|
| 1 | +#include <libflipro.h> |
| 2 | +#include <stdio.h> |
| 3 | +#include <stdlib.h> |
| 4 | +#include <string.h> |
| 5 | +#include <unistd.h> |
| 6 | + |
| 7 | +#define FLI_MAX_SUPPORTED_CAMERAS 4 |
| 8 | + |
| 9 | +static void save_merged_file(const char *fileName, void *buffer, size_t size) |
| 10 | +{ |
| 11 | + FILE *fp = fopen(fileName, "wb"); |
| 12 | + if (fp) |
| 13 | + { |
| 14 | + fwrite(buffer, 1, size, fp); |
| 15 | + fclose(fp); |
| 16 | + printf("Saved merged image to %s\n", fileName); |
| 17 | + } |
| 18 | + else |
| 19 | + { |
| 20 | + perror("Error saving file"); |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +int main() |
| 25 | +{ |
| 26 | + FPRODEVICEINFO camerasDeviceInfo[FLI_MAX_SUPPORTED_CAMERAS]; |
| 27 | + uint32_t detectedCamerasCount = FLI_MAX_SUPPORTED_CAMERAS; |
| 28 | + int32_t result = FPROCam_GetCameraList(camerasDeviceInfo, &detectedCamerasCount); |
| 29 | + |
| 30 | + if (result < 0 || detectedCamerasCount == 0) |
| 31 | + { |
| 32 | + printf("No FLI cameras found.\n"); |
| 33 | + return -1; |
| 34 | + } |
| 35 | + |
| 36 | + printf("Found %u FLI cameras.\n", detectedCamerasCount); |
| 37 | + |
| 38 | + int32_t cameraHandle = -1; |
| 39 | + result = FPROCam_Open(&camerasDeviceInfo[0], &cameraHandle); |
| 40 | + if (result < 0) |
| 41 | + { |
| 42 | + printf("Failed to open camera.\n"); |
| 43 | + return -1; |
| 44 | + } |
| 45 | + |
| 46 | + printf("Camera opened successfully.\n"); |
| 47 | + |
| 48 | + // Set 1 second exposure |
| 49 | + result = FPROCtrl_SetExposure(cameraHandle, 1e9, 0, false); |
| 50 | + if (result < 0) |
| 51 | + { |
| 52 | + printf("Failed to set exposure.\n"); |
| 53 | + FPROCam_Close(cameraHandle); |
| 54 | + return -1; |
| 55 | + } |
| 56 | + |
| 57 | + printf("Exposure set to 1 second.\n"); |
| 58 | + |
| 59 | + uint32_t frameSize = FPROFrame_ComputeFrameSize(cameraHandle); |
| 60 | + uint8_t *frameBuffer = (uint8_t *)malloc(frameSize); |
| 61 | + if (!frameBuffer) |
| 62 | + { |
| 63 | + printf("Failed to allocate frame buffer.\n"); |
| 64 | + FPROCam_Close(cameraHandle); |
| 65 | + return -1; |
| 66 | + } |
| 67 | + |
| 68 | + FPROUNPACKEDIMAGES fproUnpacked; |
| 69 | + memset(&fproUnpacked, 0, sizeof(fproUnpacked)); |
| 70 | + fproUnpacked.bMergedImageRequest = true; |
| 71 | + fproUnpacked.eMergeFormat = FPRO_IMAGE_FORMAT::IFORMAT_FITS; |
| 72 | + |
| 73 | + result = FPROFrame_CaptureStart(cameraHandle, 1); |
| 74 | + if (result < 0) |
| 75 | + { |
| 76 | + printf("Failed to start capture.\n"); |
| 77 | + free(frameBuffer); |
| 78 | + FPROCam_Close(cameraHandle); |
| 79 | + return -1; |
| 80 | + } |
| 81 | + |
| 82 | + printf("Capture started, waiting for image...\n"); |
| 83 | + |
| 84 | + result = FPROFrame_GetVideoFrameUnpacked(cameraHandle, frameBuffer, &frameSize, 2000, &fproUnpacked, nullptr); |
| 85 | + FPROFrame_CaptureAbort(cameraHandle); |
| 86 | + |
| 87 | + if (result >= 0) |
| 88 | + { |
| 89 | + printf("Image received.\n"); |
| 90 | + if (fproUnpacked.pMergedImage) |
| 91 | + { |
| 92 | + save_merged_file("merged_image.fits", fproUnpacked.pMergedImage, fproUnpacked.uiMergedBufferSize); |
| 93 | + } |
| 94 | + else |
| 95 | + { |
| 96 | + printf("Merged image buffer is null.\n"); |
| 97 | + } |
| 98 | + } |
| 99 | + else |
| 100 | + { |
| 101 | + printf("Failed to get frame: %d\n", result); |
| 102 | + } |
| 103 | + |
| 104 | + FPROFrame_FreeUnpackedBuffers(&fproUnpacked); |
| 105 | + free(frameBuffer); |
| 106 | + FPROCam_Close(cameraHandle); |
| 107 | + |
| 108 | + printf("Camera closed.\n"); |
| 109 | + |
| 110 | + return 0; |
| 111 | +} |
0 commit comments