-rw-r--r-- | noncore/multimedia/camera/mainwindow.cpp | 7 | ||||
-rw-r--r-- | noncore/multimedia/camera/zcameraio.cpp | 137 | ||||
-rw-r--r-- | noncore/multimedia/camera/zcameraio.h | 35 |
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 | |||
@@ -1,57 +1,64 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved. | 2 | ** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Opie Environment. | 4 | ** This file is part of Opie Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | **********************************************************************/ | 14 | **********************************************************************/ |
15 | 15 | ||
16 | #include "mainwindow.h" | 16 | #include "mainwindow.h" |
17 | #include "zcameraio.h" | 17 | #include "zcameraio.h" |
18 | 18 | ||
19 | #include <qvbox.h> | 19 | #include <qvbox.h> |
20 | #include <qpushbutton.h> | 20 | #include <qpushbutton.h> |
21 | #include <qlabel.h> | 21 | #include <qlabel.h> |
22 | 22 | ||
23 | #include <qdirectpainter_qws.h> | ||
24 | |||
23 | #include <qpe/resource.h> | 25 | #include <qpe/resource.h> |
24 | #include <opie/ofiledialog.h> | 26 | #include <opie/ofiledialog.h> |
25 | 27 | ||
26 | CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags f ) | 28 | CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags f ) |
27 | :QMainWindow( parent, name, f ) | 29 | :QMainWindow( parent, name, f ) |
28 | { | 30 | { |
29 | QVBox* v = new QVBox( this ); | 31 | QVBox* v = new QVBox( this ); |
30 | l = new QLabel( v ); | 32 | l = new QLabel( v ); |
31 | l->setFixedSize( QSize( 240, 160 ) ); | 33 | l->setFixedSize( QSize( 240, 160 ) ); |
32 | QPushButton* p = new QPushButton( "Snapshot", v ); | 34 | QPushButton* p = new QPushButton( "Snapshot", v ); |
33 | connect( p, SIGNAL( clicked() ), this, SLOT( clickedSnapShot() ) ); | 35 | connect( p, SIGNAL( clicked() ), this, SLOT( clickedSnapShot() ) ); |
34 | v->show(); | 36 | v->show(); |
35 | l->show(); | 37 | l->show(); |
36 | p->show(); | 38 | p->show(); |
37 | setCentralWidget( v ); | 39 | setCentralWidget( v ); |
38 | 40 | ||
39 | }; | 41 | }; |
40 | 42 | ||
41 | 43 | ||
42 | CameraMainWindow::~CameraMainWindow() | 44 | CameraMainWindow::~CameraMainWindow() |
43 | { | 45 | { |
44 | } | 46 | } |
45 | 47 | ||
46 | 48 | ||
47 | void CameraMainWindow::clickedSnapShot() | 49 | void CameraMainWindow::clickedSnapShot() |
48 | { | 50 | { |
51 | QDirectPainter fb( l ); | ||
52 | ZCameraIO::instance()->snapshot( fb.frameBuffer() ); | ||
53 | |||
54 | /* | ||
49 | QImage i; | 55 | QImage i; |
50 | QPixmap p; | 56 | QPixmap p; |
51 | if ( ZCameraIO::instance()->snapshot( &i ) ) | 57 | if ( ZCameraIO::instance()->snapshot( &i ) ) |
52 | { | 58 | { |
53 | p.convertFromImage( i ); | 59 | p.convertFromImage( i ); |
54 | l->setPixmap( p ); | 60 | l->setPixmap( p ); |
55 | } | 61 | } |
62 | */ | ||
56 | } | 63 | } |
57 | 64 | ||
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 | |||
@@ -1,89 +1,206 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved. | 2 | ** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Opie Environment. | 4 | ** This file is part of Opie Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | **********************************************************************/ | 14 | **********************************************************************/ |
15 | 15 | ||
16 | #include "zcameraio.h" | 16 | #include "zcameraio.h" |
17 | 17 | ||
18 | #include <sys/types.h> | 18 | #include <sys/types.h> |
19 | #include <sys/stat.h> | 19 | #include <sys/stat.h> |
20 | #include <errno.h> | 20 | #include <errno.h> |
21 | #include <string.h> | 21 | #include <string.h> |
22 | #include <fcntl.h> | 22 | #include <fcntl.h> |
23 | #include <unistd.h> | 23 | #include <unistd.h> |
24 | #include <stdio.h> | ||
24 | 25 | ||
25 | #include <qimage.h> | 26 | #include <qimage.h> |
26 | 27 | ||
27 | #include <opie2/odebug.h> | 28 | #include <opie2/odebug.h> |
28 | 29 | ||
29 | ZCameraIO* ZCameraIO::_instance = 0; | 30 | ZCameraIO* ZCameraIO::_instance = 0; |
30 | 31 | ||
32 | ZCameraIO* ZCameraIO::instance() | ||
33 | { | ||
34 | if ( !ZCameraIO::_instance ) | ||
35 | { | ||
36 | odebug << "Creating ZCameraIO::_instance" << oendl; | ||
37 | ZCameraIO::_instance = new ZCameraIO(); | ||
38 | } | ||
39 | return ZCameraIO::_instance; | ||
40 | } | ||
41 | |||
42 | |||
31 | ZCameraIO::ZCameraIO() | 43 | ZCameraIO::ZCameraIO() |
44 | :_height( 0 ), _width( 0 ), _zoom( 0 ), _rot( 0 ), _readlen( 0 ) | ||
32 | { | 45 | { |
33 | _driver = open( "/dev/sharp_zdc", O_RDWR ); | 46 | _driver = ::open( "/dev/sharp_zdc", O_RDWR ); |
34 | if ( _driver == -1 ) | 47 | if ( _driver == -1 ) |
35 | oerr << "Can't open camera driver: " << strerror(errno) << oendl; | 48 | oerr << "Can't open camera driver: " << strerror(errno) << oendl; |
49 | else | ||
50 | init(); | ||
51 | } | ||
52 | |||
36 | 53 | ||
37 | ZCameraIO::_instance = this; | 54 | void ZCameraIO::init() |
38 | }; | 55 | { |
56 | if ( ZCameraIO::_instance ) | ||
57 | ofatal << "Don't create more than one ZCameraIO instances." << oendl; | ||
58 | else | ||
59 | { | ||
60 | setReadMode( STATUS ); | ||
61 | } | ||
62 | } | ||
39 | 63 | ||
40 | 64 | ||
41 | ZCameraIO::~ZCameraIO() | 65 | ZCameraIO::~ZCameraIO() |
42 | { | 66 | { |
43 | if ( _driver != -1 ) | 67 | if ( _driver != -1 ) |
44 | close( _driver ); | 68 | ::close( _driver ); |
69 | } | ||
70 | |||
71 | |||
72 | inline bool ZCameraIO::isOpen() const | ||
73 | { | ||
74 | return _driver != -1; | ||
75 | } | ||
76 | |||
77 | |||
78 | inline bool ZCameraIO::isShutterPressed() | ||
79 | { | ||
80 | return _status[0] == 'S'; | ||
81 | clearShutterLatch(); | ||
82 | } | ||
83 | |||
84 | |||
85 | inline bool ZCameraIO::isFinderReversed() const | ||
86 | { | ||
87 | return _status[1] == 'M'; | ||
88 | } | ||
89 | |||
90 | |||
91 | inline bool ZCameraIO::isCapturing() const | ||
92 | { | ||
93 | return _status[2] == 'C'; | ||
94 | } | ||
95 | |||
96 | |||
97 | inline bool ZCameraIO::isAvailable() const | ||
98 | { | ||
99 | return _status[3] == 'A'; | ||
100 | } | ||
101 | |||
102 | |||
103 | bool ZCameraIO::setCaptureFrame( int width, int height, int zoom, bool rot ) | ||
104 | { | ||
105 | char b[100]; | ||
106 | sprintf( b, "%c=%d,%d,%d,%d", rot ? 'R':'S', width, height, zoom, width*2 ); | ||
107 | if ( write( b ) ) | ||
108 | { | ||
109 | _width = width; | ||
110 | _height = _height; | ||
111 | _zoom = zoom; | ||
112 | _rot = rot; | ||
113 | _readlen = 2 * _width * _height; // camera is fixed @ 16 bits per pixel | ||
114 | return true; | ||
115 | } | ||
116 | return false; | ||
117 | } | ||
118 | |||
119 | |||
120 | void ZCameraIO::setReadMode( int mode ) | ||
121 | { | ||
122 | char b[4]; | ||
123 | sprintf( b, "M=%d", mode ); | ||
124 | write( b, mode <= 9 ? 3 : 4 ); | ||
125 | if ( mode & 1 ) // STATUS bit is set | ||
126 | read( _status, 4 ); | ||
127 | } | ||
128 | |||
129 | |||
130 | void ZCameraIO::clearShutterLatch() | ||
131 | { | ||
132 | char b = 'B'; | ||
133 | write( &b, 1 ); | ||
134 | } | ||
135 | |||
136 | |||
137 | bool ZCameraIO::read( char* b, int len ) | ||
138 | { | ||
139 | int rlen = ::read( _driver, b, len ); | ||
140 | odebug << "read " << rlen << " from driver." << oendl; | ||
141 | return rlen == len; | ||
142 | } | ||
143 | |||
144 | |||
145 | bool ZCameraIO::write( char* buf, int len ) | ||
146 | { | ||
147 | if ( !len ) | ||
148 | len = strlen( buf ); | ||
149 | |||
150 | odebug << "writing '" << buf << "' to driver." << oendl; | ||
151 | |||
152 | return ::write( _driver, buf, len ) == len; | ||
45 | } | 153 | } |
46 | 154 | ||
47 | 155 | ||
48 | bool ZCameraIO::snapshot( QImage* image ) | 156 | bool ZCameraIO::snapshot( QImage* image ) |
49 | { | 157 | { |
50 | /* | 158 | /* |
51 | 159 | ||
52 | char buf[76800]; | 160 | char buf[76800]; |
53 | 161 | ||
54 | write( _driver, "M=13", 4 ); | 162 | write( _driver, "M=13", 4 ); |
55 | write( _driver, "R=240,160,256,480", 17 ); | 163 | write( _driver, "R=240,160,256,480", 17 ); |
56 | write( _driver, "M=12", 4 ); | 164 | write( _driver, "M=12", 4 ); |
57 | 165 | ||
58 | int result = read( _driver, &buf, sizeof buf ); | 166 | int result = read( _driver, &buf, sizeof buf ); |
59 | 167 | ||
60 | return result == sizeof buf; | 168 | return result == sizeof buf; |
61 | 169 | ||
62 | */ | 170 | */ |
63 | 171 | ||
64 | uchar buf[76800]; | 172 | unsigned char buf[76800]; |
65 | uchar* bp = buf; | 173 | unsigned char* bp = buf; |
66 | uchar* p; | 174 | unsigned char* p; |
67 | |||
68 | 175 | ||
69 | int fd = open( "/tmp/cam", O_RDONLY ); | 176 | int fd = open( "/tmp/cam", O_RDONLY ); |
70 | if ( read( fd, buf, sizeof buf ) != sizeof buf ) | 177 | if ( ::read( fd, buf, sizeof buf ) != sizeof buf ) |
71 | qDebug( "WARNING: couldn't read image!" ); | 178 | owarn << "Couldn't read image from /dev/sharp_zdc" << oendl; |
72 | 179 | ||
73 | image->create( 240, 160, 16 ); | 180 | image->create( 240, 160, 16 ); |
74 | for ( int i = 0; i < 160; ++i ) | 181 | for ( int i = 0; i < 160; ++i ) |
75 | { | 182 | { |
76 | p = image->scanLine( i ); | 183 | p = image->scanLine( i ); |
77 | for ( int j = 0; j < 240; j++ ) | 184 | for ( int j = 0; j < 240; j++ ) |
78 | { | 185 | { |
79 | *p = *bp; | 186 | *p = *bp; |
80 | p++; | 187 | p++; |
81 | bp++; | 188 | bp++; |
82 | *p = *bp; | 189 | *p = *bp; |
83 | p++; | 190 | p++; |
84 | bp++; | 191 | bp++; |
85 | } | 192 | } |
86 | } | 193 | } |
87 | 194 | ||
88 | return true; | 195 | return true; |
89 | } | 196 | } |
197 | |||
198 | bool ZCameraIO::snapshot( uchar* buf ) | ||
199 | { | ||
200 | int fd = open( "/tmp/cam", O_RDONLY ); | ||
201 | if ( ::read( fd, buf, 76800 ) != 76800 ) | ||
202 | owarn << "Couldn't read image from /dev/sharp_zdc" << oendl; | ||
203 | |||
204 | return true; | ||
205 | } | ||
206 | |||
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 | |||
@@ -1,36 +1,65 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2003 Michael 'Mickey' Lauer. All rights reserved. | 2 | ** Copyright (C) 2003 Michael 'Mickey' Lauer. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Opie Environment. | 4 | ** This file is part of Opie Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | **********************************************************************/ | 14 | **********************************************************************/ |
15 | 15 | ||
16 | #ifndef ZCAMERAIO_H | 16 | #ifndef ZCAMERAIO_H |
17 | #define ZCAMERAIO_H | 17 | #define ZCAMERAIO_H |
18 | 18 | ||
19 | class QImage; | 19 | class QImage; |
20 | 20 | ||
21 | class ZCameraIO | 21 | class ZCameraIO |
22 | { | 22 | { |
23 | public: | 23 | public: |
24 | ZCameraIO(); | ||
25 | virtual ~ZCameraIO(); | 24 | virtual ~ZCameraIO(); |
26 | 25 | ||
27 | bool isOpen() const { return _driver != -1; }; | 26 | enum ReadMode |
27 | { | ||
28 | IMAGE = 0, STATUS = 1, | ||
29 | FASTER = 0, BETTER = 2, | ||
30 | XNOFLIP = 0, XFLIP = 4, | ||
31 | YNOFLIP = 0, YFLIP = 8 | ||
32 | }; | ||
33 | |||
34 | bool setCaptureFrame( int w, int h, int zoom = 256, bool rot = true ); | ||
35 | void setReadMode( int = IMAGE | XFLIP | YFLIP ); | ||
36 | |||
37 | bool isShutterPressed(); // not const, because it calls clearShutterLatch | ||
38 | bool isAvailable() const; | ||
39 | bool isCapturing() const; | ||
40 | bool isFinderReversed() const; | ||
41 | |||
42 | bool isOpen() const; | ||
28 | bool snapshot( QImage* ); | 43 | bool snapshot( QImage* ); |
29 | static ZCameraIO* instance() { return _instance; }; | 44 | bool snapshot( unsigned char* ); |
45 | static ZCameraIO* instance(); | ||
46 | |||
47 | protected: | ||
48 | ZCameraIO(); | ||
49 | void clearShutterLatch(); | ||
50 | void init(); | ||
51 | bool read( char*, int ); | ||
52 | bool write( char*, int = 0 ); | ||
30 | 53 | ||
31 | private: | 54 | private: |
32 | int _driver; | 55 | int _driver; |
56 | char _status[4]; | ||
33 | static ZCameraIO* _instance; | 57 | static ZCameraIO* _instance; |
58 | int _height; | ||
59 | int _width; | ||
60 | int _zoom; | ||
61 | bool _rot; | ||
62 | int _readlen; | ||
34 | }; | 63 | }; |
35 | 64 | ||
36 | #endif | 65 | #endif |