summaryrefslogtreecommitdiff
path: root/2004/i/nono/src/io/gpio_param.cc
diff options
context:
space:
mode:
authorschodet2004-05-19 13:15:12 +0000
committerschodet2004-05-19 13:15:12 +0000
commit43cbee25345ca2a8c6e4a950ad8d5e91375d0527 (patch)
treed192ae91d040d4f441bd593787faf7701d97acae /2004/i/nono/src/io/gpio_param.cc
parenta489a86584e82b33821aa2b7287af145e36f4f83 (diff)
Plein de trucs.
Diffstat (limited to '2004/i/nono/src/io/gpio_param.cc')
-rw-r--r--2004/i/nono/src/io/gpio_param.cc126
1 files changed, 126 insertions, 0 deletions
diff --git a/2004/i/nono/src/io/gpio_param.cc b/2004/i/nono/src/io/gpio_param.cc
new file mode 100644
index 0000000..0b6b024
--- /dev/null
+++ b/2004/i/nono/src/io/gpio_param.cc
@@ -0,0 +1,126 @@
+// gpio_param.cc
+// nono - programme du robot 2004. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// Robot APB Team/Efrei 2004.
+// Web: http://assos.efrei.fr/robot/
+// Email: robot AT efrei DOT fr
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+// }}}
+#include "gpio_param.h"
+#include "config/config.h"
+
+/// Constructeur.
+GpioParam::GpioParam (Gpio &gpio)
+ : gpio_ (gpio)
+{
+ Config rc ("rc/gpio");
+ std::string name, io;
+ int n;
+ while (!rc.eof ())
+ {
+ if (rc.isId ("io"))
+ {
+ rc.getId ();
+ rc.getId (name);
+ if (rc.isId ())
+ {
+ rc.getId (io);
+ n = gpio.getByName (io);
+ if (n == -1)
+ throw std::runtime_error
+ (std::string ("gpio param: no io named ") + io);
+ }
+ else
+ {
+ rc >> n;
+ }
+ names_[name] = n;
+ }
+ else
+ rc.noId ();
+ }
+}
+
+/// Change plusieurs sorties.
+void
+GpioParam::set (int n, unsigned int bits, int nb)
+{
+ gpio_.set (n, bits, nb);
+}
+
+/// Change une sortie.
+void
+GpioParam::set (int n, unsigned int bit)
+{
+ gpio_.set (n, bit);
+}
+
+/// Lit plusieurs entrées.
+unsigned int
+GpioParam::get (int n, int nb)
+{
+ return gpio_.get (n, nb);
+}
+
+/// Lit une entrée.
+unsigned int
+GpioParam::get (int n)
+{
+ return gpio_.get (n);
+}
+
+/// Change la direction de plusieurs I/O.
+void
+GpioParam::dir (int n, unsigned int bits, int nb)
+{
+ gpio_.dir (n, bits, nb);
+}
+
+/// Change la direction d'un I/O (1 pour I, 0 pour O).
+void
+GpioParam::dir (int n, unsigned int bit)
+{
+ gpio_.dir (n, bit);
+}
+
+/// Met à jour.
+void
+GpioParam::update (void)
+{
+ gpio_.update ();
+}
+
+/// Récupère le nombre d'entrées/sorties.
+int
+GpioParam::getNbIo (void) const
+{
+ return gpio_.getNbIo ();
+}
+
+/// Récupère une entrée/sortie par son nom.
+int
+GpioParam::getByName (const std::string &name) const
+{
+ Names::const_iterator i = names_.find (name);
+ if (i != names_.end ())
+ return i->second;
+ else
+ return gpio_.getByName (name);
+}
+