summaryrefslogtreecommitdiff
path: root/2003/i/buzz
diff options
context:
space:
mode:
Diffstat (limited to '2003/i/buzz')
-rw-r--r--2003/i/buzz/src/camera/GNUmakefile16
-rw-r--r--2003/i/buzz/src/camera/camera.cc48
-rw-r--r--2003/i/buzz/src/camera/camera.h23
-rw-r--r--2003/i/buzz/src/camera/test_camera.cc14
4 files changed, 101 insertions, 0 deletions
diff --git a/2003/i/buzz/src/camera/GNUmakefile b/2003/i/buzz/src/camera/GNUmakefile
new file mode 100644
index 0000000..56aaef9
--- /dev/null
+++ b/2003/i/buzz/src/camera/GNUmakefile
@@ -0,0 +1,16 @@
+SRCDIR = ..
+CXXFLAGS = -Wall -g
+CPPFLAGS = -I$(SRCDIR) -I/usr/pkg/include
+LDFLAGS = -L/usr/pkg/lib
+LDADD = -lnetpbm
+
+TARGETS = test_camera
+test_camera_SOURCES = camera.cc test_camera.cc $(SRCDIR)/vision/vision.a $(SRCDIR)/erreur/erreur.a
+
+all: $(TARGETS)
+
+test_camera: $(test_camera_SOURCES:%.cc=%.o)
+ $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $^ $(LDADD)
+
+clean:
+ rm -f $(TARGETS) *.o
diff --git a/2003/i/buzz/src/camera/camera.cc b/2003/i/buzz/src/camera/camera.cc
new file mode 100644
index 0000000..3982c7e
--- /dev/null
+++ b/2003/i/buzz/src/camera/camera.cc
@@ -0,0 +1,48 @@
+// camera.cc
+// buzz - Programme du robot Efrei Robotique I1-I2 2003
+// Copyright (C) 2003 Nicolas Schodet
+//
+#include "camera.h"
+#include "erreur/erreur.h"
+#include "kernel/pbus.h"
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <iostream> // Debug.
+
+#define CAM_FILE "/dev/robotcam"
+
+// Constructeur.
+Camera::Camera ()
+{
+ // Ouvre le périphérique.
+ m_fd = open (CAM_FILE, O_RDONLY);
+ if (m_fd == -1)
+ throw ErreurFatale ("Impossible d'ouvrir le périphérique de la"
+ " camera.\n");
+ // Paramètre la taille de frame.
+ m_frameSize = m_w * m_h;
+ ioctl (m_fd, CAM_SETFRAMESIZE, m_frameSize);
+ // Lance le dma ?
+ unsigned int image;
+ ::read (m_fd, &image, 0);
+ char t;
+ cin >> t;
+}
+
+// Destructeur.
+Camera::~Camera ()
+{
+ // Ferme le périphérique de camera.
+ close (m_fd);
+}
+
+// Lit une image.
+void
+Camera::read (unsigned char *image) const
+{
+ int r;
+ // Lit les données sur la camera.
+ r = ::read (m_fd, image, m_frameSize);
+ cout << "camera read " << r << endl;
+}
diff --git a/2003/i/buzz/src/camera/camera.h b/2003/i/buzz/src/camera/camera.h
new file mode 100644
index 0000000..5c15a88
--- /dev/null
+++ b/2003/i/buzz/src/camera/camera.h
@@ -0,0 +1,23 @@
+#ifndef camera_h
+#define camera_h
+// camera.h
+// buzz - Programme du robot Efrei Robotique I1-I2 2003
+// Copyright (C) 2003 Nicolas Schodet
+
+class Camera
+{
+ int m_fd;
+ static const int m_w = 352, m_h = 280;
+ int m_frameSize;
+ public:
+ // Constructeur.
+ Camera ();
+ // Destructeur.
+ ~Camera ();
+ // Lit une image.
+ void read (unsigned char *image) const;
+ // Lit la taille.
+ void getSize (int &w, int &h) const { w = m_w; h = m_h; }
+};
+
+#endif // camera_h
diff --git a/2003/i/buzz/src/camera/test_camera.cc b/2003/i/buzz/src/camera/test_camera.cc
new file mode 100644
index 0000000..130d53e
--- /dev/null
+++ b/2003/i/buzz/src/camera/test_camera.cc
@@ -0,0 +1,14 @@
+// test_camera.cc
+// buzz - Programme du robot Efrei Robotique I1-I2 2003
+// Copyright (C) 2003 Nicolas Schodet
+//
+#include "camera.h"
+#include "vision/image.h"
+
+int
+main (int argc, char **argv)
+{
+ Camera cam;
+ Image image (cam, 0);
+ image.dump (argc == 2 ? argv[1] : "test.ppm");
+}