85 lines
1.6 KiB
C++
85 lines
1.6 KiB
C++
/*****************************************************************************
|
|
|
|
source::worx libPiGPio
|
|
Copyright © 2022 c.holzheuer
|
|
chris@sourceworx.org
|
|
|
|
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.
|
|
|
|
Uses:
|
|
|
|
pigpiod_if2 by joan2937, pigpio @ abyz.me.uk
|
|
https://abyz.me.uk/rpi/pigpio
|
|
|
|
sigslot by 2017 Pierre-Antoine Lacaze
|
|
https://github.com/palacaze/sigslot
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
#ifndef PIGVALUE_H
|
|
#define PIGVALUE_H
|
|
|
|
|
|
#include <libpigpio.h>
|
|
|
|
//class rangeVal
|
|
|
|
template<class T>
|
|
class LIBPIGPIO_EXPORT pigValue
|
|
{
|
|
|
|
public:
|
|
|
|
sigslot::signal<T> sigValue;
|
|
|
|
pigValue() = default;
|
|
pigValue( T val )
|
|
: _value( val )
|
|
{
|
|
|
|
}
|
|
virtual ~pigValue() = default;
|
|
|
|
T value()
|
|
{
|
|
return _value;
|
|
}
|
|
|
|
void set_value( T value )
|
|
{
|
|
_value = value;
|
|
}
|
|
|
|
void change_value( T value )
|
|
{
|
|
set_value( value );
|
|
// emit ...
|
|
}
|
|
|
|
template< typename V >
|
|
void connect_value( V& listener )
|
|
{
|
|
//sigState.connect( [&](bool state) { T::change_state( state ); } );
|
|
sigValue.connect( &V::change_value, &listener );
|
|
}
|
|
/*
|
|
template< typename O >
|
|
void add_value_observer( O* target )
|
|
{
|
|
signal.connect( &O::on_value_changed, target );
|
|
}
|
|
*/
|
|
|
|
|
|
protected:
|
|
|
|
T _value = T();
|
|
|
|
};
|
|
|
|
#endif // PIGVALUE_H
|