Diffstat (limited to 'noncore/multimedia/camera/zcameraio.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/multimedia/camera/zcameraio.cpp | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/noncore/multimedia/camera/zcameraio.cpp b/noncore/multimedia/camera/zcameraio.cpp index b37ae8c..9af0c25 100644 --- a/noncore/multimedia/camera/zcameraio.cpp +++ b/noncore/multimedia/camera/zcameraio.cpp | |||
@@ -57,12 +57,13 @@ ZCameraIO::ZCameraIO() | |||
57 | void ZCameraIO::init() | 57 | void ZCameraIO::init() |
58 | { | 58 | { |
59 | if ( ZCameraIO::_instance ) | 59 | if ( ZCameraIO::_instance ) |
60 | ofatal << "Don't create more than one ZCameraIO instances." << oendl; | 60 | ofatal << "Don't create more than one ZCameraIO instances." << oendl; |
61 | else | 61 | else |
62 | { | 62 | { |
63 | _timer = new QTime(); | ||
63 | setReadMode( STATUS ); | 64 | setReadMode( STATUS ); |
64 | } | 65 | } |
65 | } | 66 | } |
66 | 67 | ||
67 | 68 | ||
68 | ZCameraIO::~ZCameraIO() | 69 | ZCameraIO::~ZCameraIO() |
@@ -80,14 +81,24 @@ bool ZCameraIO::isOpen() const | |||
80 | return _driver != -1; | 81 | return _driver != -1; |
81 | } | 82 | } |
82 | 83 | ||
83 | 84 | ||
84 | bool ZCameraIO::isShutterPressed() | 85 | bool ZCameraIO::isShutterPressed() |
85 | { | 86 | { |
86 | return _status[0] == 'S'; | 87 | if ( _timer->elapsed() < 1000 ) //TODO: make this customizable? |
87 | clearShutterLatch(); | 88 | { |
89 | clearShutterLatch(); | ||
90 | return false; | ||
91 | } | ||
92 | if ( _status[0] == 'S' ) | ||
93 | { | ||
94 | _timer->restart(); | ||
95 | clearShutterLatch(); | ||
96 | return true; | ||
97 | } | ||
98 | else return false; | ||
88 | } | 99 | } |
89 | 100 | ||
90 | 101 | ||
91 | bool ZCameraIO::isFinderReversed() const | 102 | bool ZCameraIO::isFinderReversed() const |
92 | { | 103 | { |
93 | return _status[1] == 'M'; | 104 | return _status[1] == 'M'; |
@@ -121,26 +132,34 @@ bool ZCameraIO::setCaptureFrame( int width, int height, int zoom, bool rot ) | |||
121 | return true; | 132 | return true; |
122 | } | 133 | } |
123 | return false; | 134 | return false; |
124 | } | 135 | } |
125 | 136 | ||
126 | 137 | ||
138 | bool ZCameraIO::setZoom( int zoom ) | ||
139 | { | ||
140 | return setCaptureFrame( _width, _height, zoom*256, _rot ); | ||
141 | } | ||
142 | |||
143 | |||
127 | void ZCameraIO::setReadMode( int mode ) | 144 | void ZCameraIO::setReadMode( int mode ) |
128 | { | 145 | { |
129 | char b[10]; | 146 | char b[10]; |
130 | sprintf( b, "M=%d", mode ); | 147 | sprintf( b, "M=%d", mode ); |
131 | write( b, mode <= 9 ? 3 : 4 ); | 148 | write( b, mode <= 9 ? 3 : 4 ); |
132 | if ( mode & 1 ) // STATUS bit is set | 149 | if ( mode & STATUS ) // STATUS bit is set |
150 | { | ||
133 | read( _status, 4 ); | 151 | read( _status, 4 ); |
152 | if ( isShutterPressed() ) emit shutterClicked(); | ||
153 | } | ||
134 | } | 154 | } |
135 | 155 | ||
136 | 156 | ||
137 | void ZCameraIO::clearShutterLatch() | 157 | void ZCameraIO::clearShutterLatch() |
138 | { | 158 | { |
139 | char b = 'B'; | 159 | write( "B", 1 ); |
140 | write( &b, 1 ); | ||
141 | } | 160 | } |
142 | 161 | ||
143 | 162 | ||
144 | bool ZCameraIO::read( char* b, int len ) | 163 | bool ZCameraIO::read( char* b, int len ) |
145 | { | 164 | { |
146 | #ifndef NO_TIMING | 165 | #ifndef NO_TIMING |
@@ -209,12 +228,13 @@ bool ZCameraIO::snapshot( QImage* image ) | |||
209 | } | 228 | } |
210 | } | 229 | } |
211 | 230 | ||
212 | return true; | 231 | return true; |
213 | } | 232 | } |
214 | 233 | ||
234 | |||
215 | bool ZCameraIO::snapshot( unsigned char* buf ) | 235 | bool ZCameraIO::snapshot( unsigned char* buf ) |
216 | { | 236 | { |
217 | setReadMode( IMAGE | XFLIP | YFLIP ); | 237 | setReadMode( IMAGE | XFLIP | YFLIP ); |
218 | 238 | ||
219 | read( (char*) buf, _readlen ); | 239 | read( (char*) buf, _readlen ); |
220 | 240 | ||
@@ -225,6 +245,20 @@ bool ZCameraIO::snapshot( unsigned char* buf ) | |||
225 | // TESTCODE */ | 245 | // TESTCODE */ |
226 | 246 | ||
227 | 247 | ||
228 | return true; | 248 | return true; |
229 | } | 249 | } |
230 | 250 | ||
251 | |||
252 | void ZCameraIO::captureFrame( int w, int h, int zoom, QImage* image ) | ||
253 | { | ||
254 | int pw = _width; | ||
255 | int ph = _height; | ||
256 | if ( _rot ) | ||
257 | setCaptureFrame( h, w, zoom*256, true ); | ||
258 | else | ||
259 | setCaptureFrame( w, h, zoom*256, false ); | ||
260 | snapshot( image ); | ||
261 | setCaptureFrame( pw, ph, _zoom, _rot ); | ||
262 | } | ||
263 | |||
264 | |||