xref: /haiku/src/add-ons/media/media-add-ons/usb_webcam/CamSensor.h (revision 239222b2369c39dc52df52b0a7cdd6cc0a91bc92)
1 /*
2  * Copyright 2004-2008, François Revol, <revol@free.fr>.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _CAM_SENSOR_H
6 #define _CAM_SENSOR_H
7 
8 #include "CamDevice.h"
9 #include <Rect.h>
10 
11 // This class represents the camera's (cmos or whatever) sensor chip
12 class CamSensor
13 {
14 	public:
15 						CamSensor(CamDevice *_camera);
16 	virtual				~CamSensor();
17 
18 	virtual status_t	Probe(); // returns B_OK if found.
19 
20 	virtual status_t	InitCheck();
21 
22 	virtual status_t	Setup();
23 
24 	virtual const char*	Name();
25 
26 	virtual status_t	StartTransfer();
27 	virtual status_t	StopTransfer();
28 	virtual bool		TransferEnabled() const { return fTransferEnabled; };
29 
30 	virtual bool		IsBigEndian() const { return fIsBigEndian; };
31 	virtual bool		Use400kHz() const { return false; };
32 	virtual bool		UseRealIIC() const { return true; };
33 	virtual uint8		IICReadAddress() const { return 0; };
34 	virtual uint8		IICWriteAddress() const { return 0; };
35 
36 	virtual int			MaxWidth() const { return -1; };
37 	virtual int			MaxHeight() const { return -1; };
38 
39 	virtual status_t	AcceptVideoFrame(uint32 &width, uint32 &height);
40 	virtual status_t	SetVideoFrame(BRect rect);
41 	virtual BRect		VideoFrame() const { return fVideoFrame; };
42 	virtual status_t	SetVideoParams(float brightness, float contrast, float hue, float red, float green, float blue);
43 
44 	virtual void		AddParameters(BParameterGroup *group, int32 &index);
45 	virtual status_t	GetParameterValue(int32 id, bigtime_t *last_change, void *value, size_t *size);
46 	virtual status_t	SetParameterValue(int32 id, bigtime_t when, const void *value, size_t size);
47 
48 	CamDevice			*Device();
49 
50 #if 0
51 	// generic register-like access
52 	virtual status_t	WriteReg(uint16 address, uint8 *data, size_t count=1);
53 	virtual status_t	WriteReg8(uint16 address, uint8 data);
54 	virtual status_t	WriteReg16(uint16 address, uint16 data);
55 	virtual status_t	ReadReg(uint16 address, uint8 *data, size_t count=1, bool cached=false);
56 
57 	// I2C-like access
58 	virtual status_t	WriteIIC(uint8 address, uint8 *data, size_t count=1);
59 	virtual status_t	ReadIIC(uint8 address, uint8 *data);
60 #endif
61 	protected:
62 
63 	status_t			ProbeByIICSignature(const uint8 *regList,
64 											const uint8 *matchList,
65 											size_t count);
66 
67 		status_t		fInitStatus;
68 		bool			fIsBigEndian;
69 		bool			fTransferEnabled;
70 		BRect			fVideoFrame;
71 		int32			fFirstParameterID;
72 		bigtime_t		fLastParameterChanges;
73 	private:
74 		CamDevice		*fCamDevice;
75 };
76 
77 // internal modules
78 #define B_WEBCAM_DECLARE_SENSOR(sensorclass,sensorname) \
79 extern "C" CamSensor *Instantiate##sensorclass(CamDevice *cam); \
80 CamSensor *Instantiate##sensorclass(CamDevice *cam) \
81 { return new sensorclass(cam); };
82 
83 
84 #endif /* _CAM_SENSOR_H */
85