Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5698e1e

Browse files
committed
Updated with first set of CR changes on the Zephyr side
1 parent01a30a5 commit5698e1e

File tree

2 files changed

+51
-25
lines changed

2 files changed

+51
-25
lines changed

‎libraries/Camera/src/camera.cpp‎

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,18 @@ uint32_t FrameBuffer::getBufferSize() {
3232
if (this->vbuf) {
3333
returnthis->vbuf->bytesused;
3434
}
35+
return0;
3536
}
3637

3738
uint8_t*FrameBuffer::getBuffer() {
3839
if (this->vbuf) {
3940
returnthis->vbuf->buffer;
4041
}
42+
returnnullptr;
4143
}
4244

43-
Camera::Camera() : vdev(NULL), byte_swap(false), yuv_to_gray(false) {
45+
Camera::Camera() : vdev(NULL), byte_swap(false), yuv_to_gray(false),
46+
snapshot_mode(CONFIG_VIDEO_BUFFER_POOL_NUM_MAX <=1) {
4447
for (size_t i =0; i <ARRAY_SIZE(this->vbuf); i++) {
4548
this->vbuf[i] =NULL;
4649
}
@@ -95,6 +98,7 @@ bool Camera::begin(uint32_t width, uint32_t height, uint32_t crop_width, uint32_
9598

9699
// Set format.
97100
staticstructvideo_format fmt = {
101+
.type = VIDEO_BUF_TYPE_OUTPUT,
98102
.pixelformat = pixformat,
99103
.width = width,
100104
.height = height,
@@ -124,6 +128,16 @@ bool Camera::begin(uint32_t width, uint32_t height, uint32_t crop_width, uint32_
124128
// this should compute the sizes needed.
125129
video_get_format(this->vdev, &fmt);
126130

131+
132+
// If we are in snapshot mode, try starting the video stream with no buffers
133+
// to tell it that we want snapshot...
134+
if (snapshot_mode) {
135+
if (video_stream_start(this->vdev, VIDEO_BUF_TYPE_OUTPUT)) {
136+
Serial.println("Snapshot mode Failed to start capture");
137+
//return false;
138+
}
139+
}
140+
127141
// Allocate video buffers.
128142
for (size_t i =0; i <ARRAY_SIZE(this->vbuf); i++) {
129143
this->vbuf[i] =video_buffer_aligned_alloc(fmt.pitch * fmt.height,
@@ -137,11 +151,12 @@ bool Camera::begin(uint32_t width, uint32_t height, uint32_t crop_width, uint32_
137151
}
138152

139153
// Start video capture
140-
if (video_stream_start(this->vdev, VIDEO_BUF_TYPE_OUTPUT)) {
141-
Serial.println("Failed to start capture");
142-
returnfalse;
143-
}
144-
154+
if (!snapshot_mode) {
155+
if (video_stream_start(this->vdev, VIDEO_BUF_TYPE_OUTPUT)) {
156+
Serial.println("Failed to start capture");
157+
returnfalse;
158+
}
159+
}
145160
returntrue;
146161
}
147162

@@ -179,7 +194,7 @@ bool Camera::releaseFrame(FrameBuffer &fb) {
179194

180195
int ret;
181196
//printk("Camera::ReleaseFrame called\n");
182-
if (ret =video_enqueue(this->vdev, fb.vbuf)) {
197+
if ((ret =video_enqueue(this->vdev, fb.vbuf)) !=0) {
183198
printk("Failed to enqueue buffer %d\n", ret);
184199
returnfalse;
185200
}
@@ -226,22 +241,28 @@ int Camera::getSelection(struct video_selection *sel) {
226241
*
227242
* @param snapshot_mode pointer to Turn Snaphsot mode on or off..
228243
*/
229-
intCamera::getSnapshotMode(bool *snapshot_mode) {
230-
#if DT_HAS_CHOSEN(zephyr_camera)
231-
this->vdev =DEVICE_DT_GET(DT_CHOSEN(zephyr_camera));
232-
#endif
233-
returnvideo_get_snapshot_mode(vdev, snapshot_mode);
244+
boolCamera::getSnapshotMode() {
245+
return snapshot_mode;
234246
}
235247

236248
/**
237-
* @brief Function pointer type for video_set_snapshot_mode()
249+
* @brief returns if snapshot mode is turned on or off.
250+
*
251+
* Must be called before begin to take effect.
252+
*
253+
* @param snap_shot mode if true.
238254
*
239-
* @param snapshot_mode Turn Snaphsot mode on or off..
255+
* @retval 0 is successful.
240256
*/
241-
intCamera::setSnapshotMode(bool snapshot_mode) {
242-
#if DT_HAS_CHOSEN(zephyr_camera)
243-
this->vdev =DEVICE_DT_GET(DT_CHOSEN(zephyr_camera));
244-
#endif
245-
returnvideo_set_snapshot_mode(vdev, snapshot_mode);
257+
intCamera::setSnapshotMode(bool snap_shot) {
258+
if (snap_shot) {
259+
snapshot_mode = snap_shot;
260+
return0;
261+
}else {
262+
#if CONFIG_VIDEO_BUFFER_POOL_NUM_MAX <= 1
263+
return -EINVAL;
264+
#endif
265+
snapshot_mode = snap_shot;
266+
return0;
267+
}
246268
}
247-

‎libraries/Camera/src/camera.h‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class Camera {
7575
conststructdevice *vdev;
7676
bool byte_swap;
7777
bool yuv_to_gray;
78+
bool snapshot_mode;
7879
structvideo_buffer *vbuf[CONFIG_VIDEO_BUFFER_POOL_NUM_MAX];
7980

8081
public:
@@ -182,16 +183,20 @@ class Camera {
182183
/**
183184
* @brief returns if snapshot mode is turned on or off.
184185
*
185-
* @param snapshot_mode pointer to Turn Snaphsotmodeon or off..
186+
* @retval true if in snapshotmodefalse otherwise.
186187
*/
187-
intgetSnapshotMode(bool *snapshot_mode);
188+
boolgetSnapshotMode();
188189

189190
/**
190-
* @brief Function pointer type for video_set_snapshot_mode()
191+
* @brief returns if snapshot mode is turned on or off.
192+
*
193+
* Must be called before begin to take effect.
194+
*
195+
* @param snap_shot mode if true.
191196
*
192-
* @param snapshot_mode Turn Snaphsot mode on or off..
197+
* @retval 0 is successful.
193198
*/
194-
intsetSnapshotMode(boolsnapshot_mode);
199+
intsetSnapshotMode(boolsnap_shot);
195200
};
196201

197202
#endif// __CAMERA_H__

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp