PIDUINO
Loading...
Searching...
No Matches
gpioconnector.h
1/* Copyright © 2018-2025 Pascal JEAN, All rights reserved.
2 * This file is part of the Piduino Library.
3 *
4 * The Piduino Library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 3 of the License, or (at your option) any later version.
8 *
9 * The Piduino Library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with the Piduino Library; if not, see <http://www.gnu.org/licenses/>.
16 */
17#pragma once
18
19#include <iostream>
20#include <vector>
21#include <piduino/gpiopin.h>
22
23namespace Piduino {
24
25 class Gpio;
26 class GpioDevice;
27
39 class Connector {
40
41 public:
42 friend class Pin;
43 friend class Gpio;
44
45 class Family {
46 public:
51 enum Id {
54 Unknown = -1
55 };
56
57 Family (Id i = Unknown) : _id (i), _columns (-1), _fnum (nullptr) {
58 setId (i);
59 }
60 virtual ~Family() {}
61
62 inline Id id() const {
63 return _id;
64 }
65
66 inline int columns() const {
67 return _columns;
68 }
69
70 inline const std::string &name() const {
71 return _name;
72 }
73
83 int pinNumber (int row, int column) const;
84
85 void setId (Id i);
86
87 private:
88 typedef int (* PinNumberFunc) (int row, int column, int columns);
92 std::string _name;
93 };
94
102 public:
103 std::string name;
105 int rows;
107 long long id;
108 std::vector<Pin::Descriptor> pin;
109 // -- functions
110 Descriptor (long long connectorId = -1, int connectorNumber = -1);
111 bool insert ();
112 bool hasPin (const Pin::Descriptor & p) const;
113 long long findId() const;
114 };
115
119 bool isOpen() const;
120
124 const std::string & name() const;
125
129 int number() const;
130
134 int size() const;
135
139 int rows() const;
140
144 int columns() const;
145
149 const Family & family() const;
150
154 long long id() const;
155
162 void setDebug (bool enable);
163
167 bool isDebug() const;
168
209 friend std::ostream& operator<< (std::ostream& os, const Connector * c);
210
214 Gpio * gpio() const;
215
216 //------------------------------------------------------------------------
217 // Accès aux broches
218 //------------------------------------------------------------------------
219
227 Pin & pin (int num) const;
228
248 const std::map<int, std::shared_ptr<Pin>> & pin ();
249
258 Connector (Gpio * parent, Descriptor * desc);
259
263 virtual ~Connector();
264
265 protected:
270
274 bool open();
275
279 void close();
280
290 int pinNumber (int row, int column) const;
291
296 void printHline (std::ostream & os) const;
297
302 void printTitle (std::ostream & os) const;
303
311 void printRow (std::ostream & os, int num) const;
312
316 inline void setId (int i) {
317 _descriptor->id = i;
318 }
319
320 private:
323 Descriptor * _descriptor; // descripteur
324 std::map<int, std::shared_ptr<Pin>> _pin; // toutes les broches
325 };
326}
331/* ========================================================================== */
Descripteur d'un connecteur.
Abstract base class for GPIO devices.
Definition gpiodevice.h:34
Classe Gpio.
Definition gpio.h:54
Describes a pin's type, numbering, and associated names.
Definition gpiopin.h:170
Represents a general-purpose input/output (GPIO) pin and its configuration.
Definition gpiopin.h:68
void printTitle(std::ostream &os) const
Affiche l'entête d'un tableau de broches.
int columns() const
Nombre de colonnes.
int(* PinNumberFunc)(int row, int column, int columns)
bool isDebug() const
Indique si le mode mise au point est actif.
std::map< int, std::shared_ptr< Pin > > _pin
Gpio * gpio() const
Accès au GPIO parent.
void setId(int i)
Modification identifiant en base de données.
const std::map< int, std::shared_ptr< Pin > > & pin()
Liste des broches du connecteur.
virtual ~Connector()
Destructeur.
bool open()
Ouverture.
const std::string & name() const
void printRow(std::ostream &os, int num) const
Affiche une ligne d'un tableau de broches Si le connecteur à 2 colonnes, les broches num et num+1 son...
int number() const
Numéro du connecteur sur la carte (commence à 1)
int rows() const
Nombre de lignes.
Connector(Gpio *parent, Descriptor *desc)
Constructeur.
int pinNumber(int row, int column) const
Calcul du numéro de broche.
const Family & family() const
Modèle du connecteur.
bool isOpen() const
Indique si ouvert.
void printHline(std::ostream &os) const
Affiche une ligne horizontale d'un tableau de broches.
Pin & pin(int num) const
Broche du connecteur.
const std::string & name() const
Nom du connecteur.
friend std::ostream & operator<<(std::ostream &os, const Connector *c)
Affiche toutes les informations sur le connecteur et ses broches.
void close()
Fermeture du GPIO.
GpioDevice * device() const
Accès à la couche matérielle.
bool hasPin(const Pin::Descriptor &p) const
int pinNumber(int row, int column) const
Calcul du numéro de broche.
bool insert()
Insertion dans la base de données.
long long id() const
Identifiant en base de données.
Descriptor(long long connectorId=-1, int connectorNumber=-1)
std::vector< Pin::Descriptor > pin
int size() const
Nombre de broches.
Descriptor * _descriptor
void setDebug(bool enable)
Active le mode mise au point.
@ Header2X
Connecteur Header à 2 rangées: 1 impaire, 1 paire (ie HE10)
@ Header1X
Connecteur Header à 1 rangée (SIL)
Global namespace for Piduino.
Definition board.h:28