summaryrefslogtreecommitdiff
path: root/noncore/multimedia/camera/zcameraio.cpp
Unidiff
Diffstat (limited to 'noncore/multimedia/camera/zcameraio.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/camera/zcameraio.cpp137
1 files changed, 127 insertions, 10 deletions
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
@@ -21,6 +21,7 @@
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
@@ -28,20 +29,127 @@
28 29
29ZCameraIO* ZCameraIO::_instance = 0; 30ZCameraIO* ZCameraIO::_instance = 0;
30 31
32ZCameraIO* 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
31ZCameraIO::ZCameraIO() 43ZCameraIO::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; 54void 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
41ZCameraIO::~ZCameraIO() 65ZCameraIO::~ZCameraIO()
42{ 66{
43 if ( _driver != -1 ) 67 if ( _driver != -1 )
44 close( _driver ); 68 ::close( _driver );
69}
70
71
72inline bool ZCameraIO::isOpen() const
73{
74 return _driver != -1;
75}
76
77
78inline bool ZCameraIO::isShutterPressed()
79{
80 return _status[0] == 'S';
81 clearShutterLatch();
82}
83
84
85inline bool ZCameraIO::isFinderReversed() const
86{
87 return _status[1] == 'M';
88}
89
90
91inline bool ZCameraIO::isCapturing() const
92{
93 return _status[2] == 'C';
94}
95
96
97inline bool ZCameraIO::isAvailable() const
98{
99 return _status[3] == 'A';
100}
101
102
103bool 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
120void 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
130void ZCameraIO::clearShutterLatch()
131{
132 char b = 'B';
133 write( &b, 1 );
134}
135
136
137bool 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
145bool 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
@@ -61,14 +169,13 @@ bool ZCameraIO::snapshot( QImage* image )
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 )
@@ -87,3 +194,13 @@ bool ZCameraIO::snapshot( QImage* image )
87 194
88 return true; 195 return true;
89} 196}
197
198bool 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