// 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); }