jerrym | f157933 | 2013-02-07 01:56:28 +0000 | [diff] [blame] | 1 | /*----------------------------------------------------------------------------*/
|
| 2 | /* Copyright (c) FIRST 2008. All Rights Reserved. */
|
| 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */
|
| 4 | /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
|
| 5 | /*----------------------------------------------------------------------------*/
|
| 6 |
|
| 7 | #ifndef __AXIS_CAMERA_H__
|
| 8 | #define __AXIS_CAMERA_H__
|
| 9 |
|
| 10 | #include <taskLib.h>
|
| 11 | #include <vxWorks.h>
|
| 12 | #include <sockLib.h>
|
| 13 | #include <inetLib.h>
|
| 14 |
|
| 15 | #include "Vision/AxisCameraParams.h"
|
| 16 | #if JAVA_CAMERA_LIB != 1
|
| 17 | #include "Vision/ColorImage.h"
|
| 18 | #include "Vision/HSLImage.h"
|
| 19 | #endif
|
| 20 | #include "nivision.h"
|
| 21 | #include <set>
|
| 22 | #include "Task.h"
|
| 23 |
|
| 24 | class PCVideoServer;
|
| 25 |
|
| 26 | /**
|
| 27 | * AxisCamera class.
|
| 28 | * This class handles everything about the Axis 206 FRC Camera.
|
| 29 | * It starts up 2 tasks each using a different connection to the camera:
|
| 30 | * - image reading task that reads images repeatedly from the camera
|
| 31 | * - parameter handler task in the base class that monitors for changes to
|
| 32 | * parameters and updates the camera
|
| 33 | */
|
| 34 | class AxisCamera : public AxisCameraParams
|
| 35 | {
|
| 36 | private:
|
| 37 | explicit AxisCamera(const char *cameraIP);
|
| 38 | public:
|
| 39 | virtual ~AxisCamera();
|
| 40 | static AxisCamera& GetInstance(const char *cameraIP = NULL);
|
| 41 | static void DeleteInstance();
|
| 42 |
|
| 43 | bool IsFreshImage();
|
| 44 | SEM_ID GetNewImageSem();
|
| 45 |
|
| 46 | int GetImage(Image *imaqImage);
|
| 47 | #if JAVA_CAMERA_LIB != 1
|
| 48 | int GetImage(ColorImage *image);
|
| 49 | HSLImage *GetImage();
|
| 50 | #endif
|
| 51 |
|
| 52 | int CopyJPEG(char **destImage, int &destImageSize, int &destImageBufferSize);
|
| 53 |
|
| 54 | private:
|
| 55 | static int s_ImageStreamTaskFunction(AxisCamera *thisPtr);
|
| 56 | int ImageStreamTaskFunction();
|
| 57 |
|
| 58 | int ReadImagesFromCamera();
|
| 59 | void UpdatePublicImageFromCamera(char *imgBuffer, int imgSize);
|
| 60 |
|
| 61 | virtual void RestartCameraTask();
|
| 62 |
|
| 63 | static AxisCamera *_instance;
|
| 64 | int m_cameraSocket;
|
| 65 | typedef std::set<SEM_ID> SemSet_t;
|
| 66 | SemSet_t m_newImageSemSet;
|
| 67 |
|
| 68 | char* m_protectedImageBuffer;
|
| 69 | int m_protectedImageBufferLength;
|
| 70 | int m_protectedImageSize;
|
| 71 | SEM_ID m_protectedImageSem;
|
| 72 | bool m_freshImage;
|
| 73 |
|
| 74 | Task m_imageStreamTask;
|
| 75 |
|
| 76 | PCVideoServer *m_videoServer;
|
| 77 | };
|
| 78 |
|
| 79 | #if JAVA_CAMERA_LIB == 1
|
| 80 | #ifdef __cplusplus
|
| 81 | extern "C" {
|
| 82 | #endif
|
| 83 | void AxisCameraStart(const char *IPAddress);
|
| 84 | int AxisCameraGetImage(Image *image);
|
| 85 | void AxisCameraDeleteInstance();
|
| 86 | int AxisCameraFreshImage();
|
| 87 |
|
| 88 | // Mid-stream gets & writes
|
| 89 | void AxisCameraWriteBrightness(int brightness);
|
| 90 | int AxisCameraGetBrightness();
|
| 91 | void AxisCameraWriteWhiteBalance(AxisCameraParams::WhiteBalance_t whiteBalance);
|
| 92 | AxisCameraParams::WhiteBalance_t AxisCameraGetWhiteBalance();
|
| 93 | void AxisCameraWriteColorLevel(int colorLevel);
|
| 94 | int AxisCameraGetColorLevel();
|
| 95 | void AxisCameraWriteExposureControl(AxisCameraParams::Exposure_t exposure);
|
| 96 | AxisCameraParams::Exposure_t AxisCameraGetExposureControl();
|
| 97 | void AxisCameraWriteExposurePriority(int exposurePriority);
|
| 98 | int AxisCameraGetExposurePriority();
|
| 99 | void AxisCameraWriteMaxFPS(int maxFPS);
|
| 100 | int AxisCameraGetMaxFPS();
|
| 101 |
|
| 102 | // New-Stream gets & writes
|
| 103 | void AxisCameraWriteResolution(AxisCameraParams::Resolution_t resolution);
|
| 104 | AxisCameraParams::Resolution_t AxisCameraGetResolution();
|
| 105 | void AxisCameraWriteCompression(int compression);
|
| 106 | int AxisCameraGetCompression();
|
| 107 | void AxisCameraWriteRotation(AxisCameraParams::Rotation_t rotation);
|
| 108 | AxisCameraParams::Rotation_t AxisCameraGetRotation();
|
| 109 | #ifdef __cplusplus
|
| 110 | }
|
| 111 | #endif
|
| 112 | #endif // JAVA_CAMERA_LIB == 1
|
| 113 |
|
| 114 | #endif
|