ISR_Handler
system
system/ISR_Handler.h
system
stable
stable
Gestionnaire centralisé des interruptions matérielles (ISR). Cette classe implémente un singleton permettant : Elle simplifie la gestion des interruptions dans des projets embarqués structurés. /
Méthodes publiques
| Méthode | Description | Paramètres | Retour |
|---|---|---|---|
|
getInstance()
getInstance() {
|
Accès à l'instance unique du gestionnaire ISR. Implémentation du pattern Singleton. / | RéférenceRéférence vers l'instance unique de ISR_Handler. / |
|
|
attach()
attach(uint8_t pin, ISRCallback cb, PinStatus mode) {
|
Attache une interruption matérielle sur une broche. Cette méthode : pour un suivi ultérieur. / | pin: Numéro de la broche concernée. cb: Pointeur vers la fonction ISR. mode: Mode de déclenchement (RISING, FALLING, CHANGE, etc.). / |
|
|
attachInterrupt()
attachInterrupt(pin, cb, mode);
|
|||
|
push_back()
push_back({pin, cb, mode});
|
|||
|
listAttachedInterrupts()
listAttachedInterrupts() const {
|
Affiche la liste des interruptions attachées. Les informations sont envoyées sur la sortie série via l'objet Serial (debug). Affiche : / | ||
|
println()
println("=== ISR List ===");
|
|||
|
for()
for (const auto& rec : _isrList) {
|
|||
|
print()
print("Pin: ");
|
|||
|
print()
print(rec.pin);
|
|||
|
print()
print(" | Mode: ");
|
|||
|
switch()
switch (rec.mode) {
|
|||
|
print()
print("FALLING");
|
|||
|
print()
print("RISING");
|
|||
|
print()
print("CHANGE");
|
|||
|
print()
print("LOW");
|
|||
|
print()
print("HIGH");
|
|||
|
print()
print("UNKNOWN");
|
|||
|
println()
println();
|
Variables membres
ISR_Handler instance;
return instance;
uint8_t pin;
ISRCallback cb;
PinStatus mode;
Code source
#pragma once
#include <Arduino.h>
#include <vector>
#include "../StatusDevice.h"
/**
* @namespace crepp::system
* @brief Espace de noms système de la bibliothèque CREPP.
*/
namespace crepp::system {
/**
* @class ISR_Handler
* @brief Gestionnaire centralisé des interruptions matérielles (ISR).
*
* @details
* Cette classe implémente un singleton permettant :
* - d'attacher des interruptions matérielles Arduino,
* - de conserver une trace des ISR enregistrées,
* - de lister les interruptions attachées à des fins de debug.
*
* Elle simplifie la gestion des interruptions dans des projets
* embarqués structurés.
*
* @badge system
* @badge stable
*/
class ISR_Handler {
public:
/**
* @brief Type alias pour une fonction de callback d'interruption.
*/
using ISRCallback = void (*)();
/**
* @brief Accès à l'instance unique du gestionnaire ISR.
*
* @details
* Implémentation du pattern Singleton.
*
* @return Référence vers l'instance unique de ISR_Handler.
*/
static ISR_Handler& getInstance() {
static ISR_Handler instance;
return instance;
}
/**
* @brief Attache une interruption matérielle sur une broche.
*
* @details
* Cette méthode :
* - appelle attachInterrupt() d'Arduino,
* - enregistre l'interruption dans une liste interne
* pour un suivi ultérieur.
*
* @param pin Numéro de la broche concernée.
* @param cb Pointeur vers la fonction ISR.
* @param mode Mode de déclenchement (RISING, FALLING, CHANGE, etc.).
*/
void attach(uint8_t pin, ISRCallback cb, PinStatus mode) {
::attachInterrupt(pin, cb, mode);
_isrList.push_back({pin, cb, mode});
}
/**
* @brief Affiche la liste des interruptions attachées.
*
* @details
* Les informations sont envoyées sur la sortie série
* via l'objet Serial (debug).
*
* Affiche :
* - la broche,
* - le mode de déclenchement.
*/
void listAttachedInterrupts() const {
Serial.println("=== ISR List ===");
for (const auto& rec : _isrList) {
Serial.print("Pin: ");
Serial.print(rec.pin);
Serial.print(" | Mode: ");
switch (rec.mode) {
case FALLING: Serial.print("FALLING"); break;
case RISING: Serial.print("RISING"); break;
case CHANGE: Serial.print("CHANGE"); break;
case LOW: Serial.print("LOW"); break;
case HIGH: Serial.print("HIGH"); break;
default: Serial.print("UNKNOWN"); break;
}
Serial.println();
}
}
private:
/**
* @brief Constructeur privé (Singleton).
*/
ISR_Handler() = default;
/**
* @brief Constructeur de copie supprimé.
*/
ISR_Handler(const ISR_Handler&) = delete;
/**
* @brief Opérateur d'affectation supprimé.
*/
ISR_Handler& operator=(const ISR_Handler&) = delete;
/**
* @struct ISRRecord
* @brief Structure interne décrivant une ISR enregistrée.
*/
struct ISRRecord {
uint8_t pin; /**< Broche associée à l'interruption */
ISRCallback cb; /**< Fonction callback ISR */
PinStatus mode; /**< Mode de déclenchement */
};
/**
* @brief Liste des interruptions attachées.
*/
std::vector<ISRRecord> _isrList;
};
} // namespace crepp::system