summaryrefslogtreecommitdiff
path: root/2003/i/buzz/src/camera/camera.cc
diff options
context:
space:
mode:
Diffstat (limited to '2003/i/buzz/src/camera/camera.cc')
-rw-r--r--2003/i/buzz/src/camera/camera.cc35
1 files changed, 33 insertions, 2 deletions
diff --git a/2003/i/buzz/src/camera/camera.cc b/2003/i/buzz/src/camera/camera.cc
index 5bc6920..fb1fe2d 100644
--- a/2003/i/buzz/src/camera/camera.cc
+++ b/2003/i/buzz/src/camera/camera.cc
@@ -6,6 +6,7 @@
#include "erreur/erreur.h"
#include "kernel/pbus.h"
#include "config/config.h"
+#include "date/date.h"
#include <fcntl.h>
#include <unistd.h>
@@ -15,6 +16,8 @@
#define CAM_FILE "/dev/robotcam"
+#define CAMERA_DEBUG
+
// Constructeur.
Camera::Camera ()
{
@@ -36,25 +39,33 @@ Camera::Camera ()
{
rc.getId ();
m_w = rc.getNum ();
+#ifdef CAMERA_DEBUG
cout << "camera width " << m_w << endl;
+#endif // CAMERA_DEBUG
}
else if (rc.isId ("height"))
{
rc.getId ();
m_h = rc.getNum ();
+#ifdef CAMERA_DEBUG
cout << "camera height " << m_h << endl;
+#endif // CAMERA_DEBUG
}
else if (rc.isId ("depth"))
{
rc.getId ();
m_d = rc.getNum ();
+#ifdef CAMERA_DEBUG
cout << "camera depth " << m_d << endl;
+#endif // CAMERA_DEBUG
}
else if (rc.isId ("cut"))
{
rc.getId ();
m_cut = rc.getNum ();
+#ifdef CAMERA_DEBUG
cout << "camera cut " << m_cut << endl;
+#endif // CAMERA_DEBUG
}
else if (rc.isId ("setup"))
{
@@ -62,14 +73,17 @@ Camera::Camera ()
addr = rc.getNum ();
data = rc.getNum ();
param.addr = addr; param.data = data;
+#ifdef CAMERA_DEBUG
cout << "camera sccbwrite 0x" << hex << addr << " 0x" << data <<
endl;
+#endif // CAMERA_DEBUG
ioctl (m_fd, CAM_SCCBWRITE, &param);
}
else
rc.noId ();
}
// Affiche les paramètres.
+#ifdef CAMERA_DEBUG
cout << hex << "camera sccbdump";
for (addr = 0; addr < 0x50; ++addr)
{
@@ -81,6 +95,8 @@ Camera::Camera ()
}
cout << endl << dec;
+#endif // CAMERA_DEBUG
+ m_lastRead = 0;
// Paramètre la taille de frame.
int hcount = m_w * m_d;
ioctl (m_fd, CAM_SETHCOUNT, &hcount);
@@ -97,28 +113,42 @@ Camera::~Camera ()
// Lit une image.
int
-Camera::read (unsigned char *image) const
+Camera::read (unsigned char *image)
{
int r;
+ int t = Date::getInstance ().start ();
+ // Attention, pas trops vite.
+ if (m_lastRead + 100 > t)
+ return 0;
+ m_lastRead = t;
// Lit les données sur la camera.
if (m_cut)
r = ::read (m_fd, image, m_cut);
if (!m_cut || r)
r = ::read (m_fd, image, m_frameSize - m_cut);
+#ifdef CAMERA_DEBUG
cout << "camera read " << r << endl;
+#endif // CAMERA_DEBUG
return r;
}
// Lit une image en RGB.
int
-Camera::readRGB (unsigned char *rgb) const
+Camera::readRGB (unsigned char *rgb)
{
int ret;
+ int t = Date::getInstance ().start ();
+ // Attention, pas trops vite.
+ if (m_lastRead + 100 > t)
+ return 0;
+ m_lastRead = t;
// Alloue de la mémoire.
unsigned char *image = new unsigned char[m_frameSize];
// Lit les données sur la camera.
ret = ::read (m_fd, image, m_frameSize);
+#ifdef CAMERA_DEBUG
cout << "camera read " << ret << endl;
+#endif // CAMERA_DEBUG
if (!ret) return 0;
// Positions de débuts.
unsigned char *r, *g, *b;
@@ -135,6 +165,7 @@ Camera::readRGB (unsigned char *rgb) const
*rgb++ = *b;
b += 4;
}
+ delete image;
return ret - m_cut;
}