X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fcamera.h;fp=src%2Fcamera.h;h=6a6e973bcc2c750ff35d5b91302bacb35bd7a95a;hb=120855b88a15f731db18b063e69aa59d7bf36d6f;hp=0000000000000000000000000000000000000000;hpb=a40214477d6687456277c31f725bf2a72a66bfb2;p=flashstrobe diff --git a/src/camera.h b/src/camera.h new file mode 100644 index 0000000..6a6e973 --- /dev/null +++ b/src/camera.h @@ -0,0 +1,215 @@ +/* + Copyright (C) 2010 by Juan Carlos Torres + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of + the License or (at your option) version 3 or any later version + accepted by the membership of KDE e.V. (or its successor appro- + ved by the membership of KDE e.V.), which shall act as a proxy + defined in Section 14 of version 3 of the license. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see http://www.gnu.org/licenses/. +*/ + + +#ifndef CAMERA_H +#define CAMERA_H + +#include +#include +#include +#include + +struct buffer +{ + void* start; + size_t length; +}; + +struct Property +{ + QString name; + bool added; + bool removed; +}; + +const QDBusArgument& operator<<(QDBusArgument& arg, const Property& change); +const QDBusArgument& operator>>(QDBusArgument& arg, const Property& change); + +/** + * @brief Qt-based class for accessing the N900 camera and flash LEDs + * + * This class provides easy access to the N900's camera and flash LED + * functionality, specifically initializing the camera and controlling + * the LED torch and flash modes. It also reports on the status of + * the camera shutter. + * + */ +// TODO: Implement torch functionality +class Camera : public QObject +{ + Q_OBJECT + + public: + /** + * Error codes for easier error message handling + */ + enum ErrorCode + { + NoError = 0, /**< No error */ + GenericError = -1 /**< Generic Error */ + }; + + Camera(QObject* parent = 0); + ~Camera(); + + /** + * Opens a character device connected to the camera + * and gets a file descriptor. + * + * @param device Device name, normally /dev/video0 + * @return @c int Identifying the file descriptor + * @return @c int -1 Of opening the device was unsuccessful + */ + static int open(char* device); + + /** + * Closes the character device connected to the camera. + * + * @return @c int 0 If closing the device was successful + * @return @c int -1 If closing the device was unsuccessful + */ + int close(); + + /** + * Initializes the camera. This specifically does the following: + * @li Get and set the cropping properties + * @li Set the camera data format + * @li Allocate memory-mapped buffers + * + * @return @c int 0 If initialization was successful + * @return @c int -1 If initialization was unsuccessful + */ + int init(); + + /** + * Deinitializes the camera, freeing any allocated memory + * used during initialization. + * + * @return @c int 0 If deinitialization was successful + * @return @c int -1 If deinitialization was unsuccessful + */ + int deinit(); + + /** + * Returns the current set flash intensity. This + * is different from the torch intensity used in + * torch modes. + * + * @return @c int The current flash intensity + */ + int flashIntensity() const; + + /** + * Returns the strobe timeout. Used only in strobe mode. + * + * @return @c quint32 Current timeout in microseconds + */ + quint32 timeout() const; + + /** + * Convenience function to create a D-Bus connection + * to listen for changes in the camera shutter status. + */ + void registerDbusWatcher(); + + /** + * Function to manually query the status of the camera + * shutter using D-Bus and HAL. + * + * @return @c true If the camera shutter is open + * @return @c false If the camera shutter is closed + */ + bool isShutterOpen() const; + + public slots: + + /** + * Starts or stops camera data streaming. Used to block + * and unblock the camera while using the flash. + * + * @param stream Whether streaming is on (@c true) or off (@c false) + * + * @return @c int 0 If starting or stopping the stream was successful + * @return @c int 1 If starting or stopping the stream was unsuccessful + */ + int stream(bool stream); + + /** + * Flash the LED in strobe mode. This will only flash + * the LED once. Repetition must be controlled by the + * client of this class. + * + * @return @c int 0 If strobing was successful + * @return @c int -1 If strobing was unsuccessful + */ + int strobe(); + + /** + * Sets the intensity of the LED in flash mode. + * + * @param intensity intensity in mA. Valid values range + * from 215 to 500 only + * + * @return @c int 0 If setting the flash intensity was successful + * @return @c int -1 If setting the flash intensity was unsuccessful + */ + int setFlashIntensity(int intensity); + + /** + * Sets the strobe timeout. Used only in strobe mode. + * + * @param timeout Timeout in microseconds. Valid values range + * from 54600 to 820000 only + */ + int setTimeout(quint32 timeout); + + /** + * Slot that is called when the camera shutter status + * changes, that is, when it is opened or closed. Internally + * calls @ref isShutterOpen() to get the current shutter + * status and emits the @ref shutterStateChanged() signal. + * + * @param numUpdates Unused parameter to match the signal signature + * @param updates Unused parameter to match the signal signature + */ + void shutterPropertyModified(int numUpdates, QList updates); + + signals: + /** + * Signal to notify change in the camera shutter status. + * Users of this class should connect to this to monitor + * the shutter state. + * + * @param open Determines whether the shutter is open (@c true) + * or closed (@c false). + */ + void shutterStateChanged(bool open); + + private: + static char m_deviceName[15]; + static int m_fd; + + quint32 m_numBuffers; + struct buffer* m_buffers; + +}; + +#endif