2 Copyright (C) 2010 by Juan Carlos Torres <jucato@kdemail.net>
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of
7 the License or (at your option) version 3 or any later version
8 accepted by the membership of KDE e.V. (or its successor appro-
9 ved by the membership of KDE e.V.), which shall act as a proxy
10 defined in Section 14 of version 3 of the license.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see http://www.gnu.org/licenses/.
25 #include <QtCore/QObject>
26 #include <QtCore/QString>
27 #include <QtCore/QList>
28 #include <QtDBus/QDBusArgument>
43 const QDBusArgument& operator<<(QDBusArgument& arg, const Property& change);
44 const QDBusArgument& operator>>(QDBusArgument& arg, const Property& change);
47 * @brief Qt-based class for accessing the N900 camera and flash LEDs
49 * This class provides easy access to the N900's camera and flash LED
50 * functionality, specifically initializing the camera and controlling
51 * the LED torch and flash modes. It also reports on the status of
55 // TODO: Implement torch functionality
56 class Camera : public QObject
62 * Error codes for easier error message handling
66 NoError = 0, /**< No error */
67 GenericError = -1 /**< Generic Error */
70 Camera(QObject* parent = 0);
74 * Opens a character device connected to the camera
75 * and gets a file descriptor.
77 * @param device Device name, normally /dev/video0
78 * @return @c int Identifying the file descriptor
79 * @return @c int -1 Of opening the device was unsuccessful
81 static int open(char* device);
84 * Closes the character device connected to the camera.
86 * @return @c int 0 If closing the device was successful
87 * @return @c int -1 If closing the device was unsuccessful
92 * Initializes the camera. This specifically does the following:
93 * @li Get and set the cropping properties
94 * @li Set the camera data format
95 * @li Allocate memory-mapped buffers
97 * @return @c int 0 If initialization was successful
98 * @return @c int -1 If initialization was unsuccessful
103 * Deinitializes the camera, freeing any allocated memory
104 * used during initialization.
106 * @return @c int 0 If deinitialization was successful
107 * @return @c int -1 If deinitialization was unsuccessful
112 * Returns the current set flash intensity. This
113 * is different from the torch intensity used in
116 * @return @c int The current flash intensity
118 int flashIntensity() const;
121 * Returns the strobe timeout. Used only in strobe mode.
123 * @return @c quint32 Current timeout in microseconds
125 quint32 timeout() const;
128 * Convenience function to create a D-Bus connection
129 * to listen for changes in the camera shutter status.
131 void registerDbusWatcher();
134 * Function to manually query the status of the camera
135 * shutter using D-Bus and HAL.
137 * @return @c true If the camera shutter is open
138 * @return @c false If the camera shutter is closed
140 bool isShutterOpen() const;
145 * Starts or stops camera data streaming. Used to block
146 * and unblock the camera while using the flash.
148 * @param stream Whether streaming is on (@c true) or off (@c false)
150 * @return @c int 0 If starting or stopping the stream was successful
151 * @return @c int 1 If starting or stopping the stream was unsuccessful
153 int stream(bool stream);
156 * Flash the LED in strobe mode. This will only flash
157 * the LED once. Repetition must be controlled by the
158 * client of this class.
160 * @return @c int 0 If strobing was successful
161 * @return @c int -1 If strobing was unsuccessful
166 * Sets the intensity of the LED in flash mode.
168 * @param intensity intensity in mA. Valid values range
169 * from 215 to 500 only
171 * @return @c int 0 If setting the flash intensity was successful
172 * @return @c int -1 If setting the flash intensity was unsuccessful
174 int setFlashIntensity(int intensity);
177 * Sets the strobe timeout. Used only in strobe mode.
179 * @param timeout Timeout in microseconds. Valid values range
180 * from 54600 to 820000 only
182 int setTimeout(quint32 timeout);
185 * Slot that is called when the camera shutter status
186 * changes, that is, when it is opened or closed. Internally
187 * calls @ref isShutterOpen() to get the current shutter
188 * status and emits the @ref shutterStateChanged() signal.
190 * @param numUpdates Unused parameter to match the signal signature
191 * @param updates Unused parameter to match the signal signature
193 void shutterPropertyModified(int numUpdates, QList<Property> updates);
197 * Signal to notify change in the camera shutter status.
198 * Users of this class should connect to this to monitor
201 * @param open Determines whether the shutter is open (@c true)
202 * or closed (@c false).
204 void shutterStateChanged(bool open);
207 static char m_deviceName[15];
210 quint32 m_numBuffers;
211 struct buffer* m_buffers;