summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-04-02 15:28:33 (UTC)
committer mickeyl <mickeyl>2003-04-02 15:28:33 (UTC)
commite9eeb493c75bfe6078f40952e85e859fb71fe970 (patch) (side-by-side diff)
tree2a6eedcdfbc3aa166d3f9d3cf317cfb7d8de7a52
parentf0d3ff51dde49f994783827051464920529024af (diff)
downloadopie-e9eeb493c75bfe6078f40952e85e859fb71fe970.zip
opie-e9eeb493c75bfe6078f40952e85e859fb71fe970.tar.gz
opie-e9eeb493c75bfe6078f40952e85e859fb71fe970.tar.bz2
implementation of camera API as described in the Sharp Camera API document nearly completed
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/camera/mainwindow.cpp7
-rw-r--r--noncore/multimedia/camera/zcameraio.cpp137
-rw-r--r--noncore/multimedia/camera/zcameraio.h35
3 files changed, 166 insertions, 13 deletions
diff --git a/noncore/multimedia/camera/mainwindow.cpp b/noncore/multimedia/camera/mainwindow.cpp
index 2cca9f9..4218232 100644
--- a/noncore/multimedia/camera/mainwindow.cpp
+++ b/noncore/multimedia/camera/mainwindow.cpp
@@ -21,4 +21,6 @@
#include <qlabel.h>
+#include <qdirectpainter_qws.h>
+
#include <qpe/resource.h>
#include <opie/ofiledialog.h>
@@ -47,4 +49,8 @@ CameraMainWindow::~CameraMainWindow()
void CameraMainWindow::clickedSnapShot()
{
+ QDirectPainter fb( l );
+ ZCameraIO::instance()->snapshot( fb.frameBuffer() );
+
+ /*
QImage i;
QPixmap p;
@@ -54,4 +60,5 @@ void CameraMainWindow::clickedSnapShot()
l->setPixmap( p );
}
+ */
}
diff --git a/noncore/multimedia/camera/zcameraio.cpp b/noncore/multimedia/camera/zcameraio.cpp
index e74136f..7343dca 100644
--- a/noncore/multimedia/camera/zcameraio.cpp
+++ b/noncore/multimedia/camera/zcameraio.cpp
@@ -22,4 +22,5 @@
#include <fcntl.h>
#include <unistd.h>
+#include <stdio.h>
#include <qimage.h>
@@ -29,12 +30,35 @@
ZCameraIO* ZCameraIO::_instance = 0;
+ZCameraIO* ZCameraIO::instance()
+{
+ if ( !ZCameraIO::_instance )
+ {
+ odebug << "Creating ZCameraIO::_instance" << oendl;
+ ZCameraIO::_instance = new ZCameraIO();
+ }
+ return ZCameraIO::_instance;
+}
+
+
ZCameraIO::ZCameraIO()
+ :_height( 0 ), _width( 0 ), _zoom( 0 ), _rot( 0 ), _readlen( 0 )
{
- _driver = open( "/dev/sharp_zdc", O_RDWR );
+ _driver = ::open( "/dev/sharp_zdc", O_RDWR );
if ( _driver == -1 )
oerr << "Can't open camera driver: " << strerror(errno) << oendl;
+ else
+ init();
+}
+
- ZCameraIO::_instance = this;
-};
+void ZCameraIO::init()
+{
+ if ( ZCameraIO::_instance )
+ ofatal << "Don't create more than one ZCameraIO instances." << oendl;
+ else
+ {
+ setReadMode( STATUS );
+ }
+}
@@ -42,5 +66,89 @@ ZCameraIO::~ZCameraIO()
{
if ( _driver != -1 )
- close( _driver );
+ ::close( _driver );
+}
+
+
+inline bool ZCameraIO::isOpen() const
+{
+ return _driver != -1;
+}
+
+
+inline bool ZCameraIO::isShutterPressed()
+{
+ return _status[0] == 'S';
+ clearShutterLatch();
+}
+
+
+inline bool ZCameraIO::isFinderReversed() const
+{
+ return _status[1] == 'M';
+}
+
+
+inline bool ZCameraIO::isCapturing() const
+{
+ return _status[2] == 'C';
+}
+
+
+inline bool ZCameraIO::isAvailable() const
+{
+ return _status[3] == 'A';
+}
+
+
+bool ZCameraIO::setCaptureFrame( int width, int height, int zoom, bool rot )
+{
+ char b[100];
+ sprintf( b, "%c=%d,%d,%d,%d", rot ? 'R':'S', width, height, zoom, width*2 );
+ if ( write( b ) )
+ {
+ _width = width;
+ _height = _height;
+ _zoom = zoom;
+ _rot = rot;
+ _readlen = 2 * _width * _height; // camera is fixed @ 16 bits per pixel
+ return true;
+ }
+ return false;
+}
+
+
+void ZCameraIO::setReadMode( int mode )
+{
+ char b[4];
+ sprintf( b, "M=%d", mode );
+ write( b, mode <= 9 ? 3 : 4 );
+ if ( mode & 1 ) // STATUS bit is set
+ read( _status, 4 );
+}
+
+
+void ZCameraIO::clearShutterLatch()
+{
+ char b = 'B';
+ write( &b, 1 );
+}
+
+
+bool ZCameraIO::read( char* b, int len )
+{
+ int rlen = ::read( _driver, b, len );
+ odebug << "read " << rlen << " from driver." << oendl;
+ return rlen == len;
+}
+
+
+bool ZCameraIO::write( char* buf, int len )
+{
+ if ( !len )
+ len = strlen( buf );
+
+ odebug << "writing '" << buf << "' to driver." << oendl;
+
+ return ::write( _driver, buf, len ) == len;
}
@@ -62,12 +170,11 @@ bool ZCameraIO::snapshot( QImage* image )
*/
- uchar buf[76800];
- uchar* bp = buf;
- uchar* p;
-
+ unsigned char buf[76800];
+ unsigned char* bp = buf;
+ unsigned char* p;
int fd = open( "/tmp/cam", O_RDONLY );
- if ( read( fd, buf, sizeof buf ) != sizeof buf )
- qDebug( "WARNING: couldn't read image!" );
+ if ( ::read( fd, buf, sizeof buf ) != sizeof buf )
+ owarn << "Couldn't read image from /dev/sharp_zdc" << oendl;
image->create( 240, 160, 16 );
@@ -88,2 +195,12 @@ bool ZCameraIO::snapshot( QImage* image )
return true;
}
+
+bool ZCameraIO::snapshot( uchar* buf )
+{
+ int fd = open( "/tmp/cam", O_RDONLY );
+ if ( ::read( fd, buf, 76800 ) != 76800 )
+ owarn << "Couldn't read image from /dev/sharp_zdc" << oendl;
+
+ return true;
+}
+
diff --git a/noncore/multimedia/camera/zcameraio.h b/noncore/multimedia/camera/zcameraio.h
index 1690aa6..bc4926b 100644
--- a/noncore/multimedia/camera/zcameraio.h
+++ b/noncore/multimedia/camera/zcameraio.h
@@ -22,14 +22,43 @@ class ZCameraIO
{
public:
- ZCameraIO();
virtual ~ZCameraIO();
- bool isOpen() const { return _driver != -1; };
+ enum ReadMode
+ {
+ IMAGE = 0, STATUS = 1,
+ FASTER = 0, BETTER = 2,
+ XNOFLIP = 0, XFLIP = 4,
+ YNOFLIP = 0, YFLIP = 8
+ };
+
+ bool setCaptureFrame( int w, int h, int zoom = 256, bool rot = true );
+ void setReadMode( int = IMAGE | XFLIP | YFLIP );
+
+ bool isShutterPressed(); // not const, because it calls clearShutterLatch
+ bool isAvailable() const;
+ bool isCapturing() const;
+ bool isFinderReversed() const;
+
+ bool isOpen() const;
bool snapshot( QImage* );
- static ZCameraIO* instance() { return _instance; };
+ bool snapshot( unsigned char* );
+ static ZCameraIO* instance();
+
+ protected:
+ ZCameraIO();
+ void clearShutterLatch();
+ void init();
+ bool read( char*, int );
+ bool write( char*, int = 0 );
private:
int _driver;
+ char _status[4];
static ZCameraIO* _instance;
+ int _height;
+ int _width;
+ int _zoom;
+ bool _rot;
+ int _readlen;
};