Skip to content

Commit

Permalink
analog input with same id shares value. bump to 1.5.6
Browse files Browse the repository at this point in the history
  • Loading branch information
camilo committed May 29, 2024
1 parent db1d29c commit bd7c82d
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 78 deletions.
2 changes: 1 addition & 1 deletion doc/Doxygen
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = "OS"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = v1.5.5
PROJECT_NUMBER = v1.5.6

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"maintainer": true
}
],
"version": "1.5.5",
"version": "1.5.6",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*"
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=QuarkTS
version=1.5.5
version=1.5.6
license=MIT
author=J. Camilo Gomez C. <[email protected]>
maintainer=J. Camilo Gomez C. <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required( VERSION 3.2 )
project( quarkts-cpp
VERSION 1.5.5
VERSION 1.5.6
DESCRIPTION "An open-source OS for small embedded applications"
LANGUAGES CXX )

Expand Down
6 changes: 3 additions & 3 deletions src/QuarkTS.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* @file QuarkTS.h
* @author J. Camilo Gomez C.
* @version 1.5.5
* @version 1.5.6
* @note This file is part of the QuarkTS++ distribution.
* @brief Global inclusion header
**/
Expand Down Expand Up @@ -41,8 +41,8 @@ This file is part of the QuarkTS++ OS distribution.
#ifndef QOS_CPP_H
#define QOS_CPP_H

#define QUARKTS_CPP_VERSION "1.5.5"
#define QUARKTS_CPP_VERNUM ( 155u )
#define QUARKTS_CPP_VERSION "1.5.6"
#define QUARKTS_CPP_VERNUM ( 156u )
#define QUARKTS_CPP_CAPTION "QuarkTS++ OS " QUARKTS_CPP_VERSION

#include "config/config.h"
Expand Down
59 changes: 36 additions & 23 deletions src/include/input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace qOS {
using eventCallback_t = void(*)( channel&, const event );

/*! @cond */
using channelStateFcn_t = void(*)( channel&, int );
using channelStateFcn_t = void(*)( channel& );
/*! @endcond */

/**
Expand All @@ -72,13 +72,16 @@ namespace qOS {
class channel : protected node {
private:
bool negate{ false };
int value;
int *ptrValue{ &value };

type channelType;
eventCallback_t cb[ static_cast<size_t>( input::event::MAX_EVENTS ) ] = { nullptr }; // skipcq: CXX-W2066
qOS::clock_t tChange{ 0U };
qOS::clock_t tSteadyOn{ 0xFFFFFFFFU };
qOS::clock_t tSteadyOff{ 0xFFFFFFFFU };
qOS::clock_t tSteadyBand{ 0xFFFFFFFFU };
uint8_t xChannel;
uint8_t number;
int riseThreshold{ 800 };
int fallThreshold{ 200 };
int hysteresis{ 20 };
Expand All @@ -104,17 +107,17 @@ namespace qOS {
}
}
channelStateFcn_t channelState{ nullptr };
static void digitalFallingEdgeState( channel& c, int value );
static void digitalRisingEdgeState( channel& c, int value );
static void digitalSteadyInHighState( channel& c, int value );
static void digitalSteadyInLowState( channel& c, int value );
static void digitalFallingEdgeState( channel& c );
static void digitalRisingEdgeState( channel& c );
static void digitalSteadyInHighState( channel& c );
static void digitalSteadyInLowState( channel& c );

static void analogFallingEdgeState( channel& c, int value );
static void analogRisingEdgeState( channel& c, int value );
static void analogInBandState( channel& c, int value );
static void analogSteadyInHighState( channel& c, int value );
static void analogSteadyInLowState( channel& c, int value );
static void analogSteadyInBandState( channel& c, int value );
static void analogFallingEdgeState( channel& c );
static void analogRisingEdgeState( channel& c );
static void analogInBandState( channel& c );
static void analogSteadyInHighState( channel& c );
static void analogSteadyInLowState( channel& c );
static void analogSteadyInBandState( channel& c );
public:
virtual ~channel() {}
/**
Expand All @@ -125,7 +128,7 @@ namespace qOS {
* @param[in] upperThreshold The upper threshold value.
* @param[in] h Hysteresis for the in-band transition.
*/
channel( const uint8_t inputChannel, const int lowerThreshold, const int upperThreshold, const int h = 20 ) : xChannel( inputChannel ), riseThreshold( upperThreshold ), fallThreshold( lowerThreshold ), hysteresis( h )
channel( const uint8_t inputChannel, const int lowerThreshold, const int upperThreshold, const int h = 20 ) : number( inputChannel ), riseThreshold( upperThreshold ), fallThreshold( lowerThreshold ), hysteresis( h )
{
channelType = input::type::ANALOG;
cbInit();
Expand All @@ -135,11 +138,10 @@ namespace qOS {
* @param[in] inputChannel The specified channel(pin) number to read.
* @param[in] invert To invert/negate the raw-reading.
*/
channel( uint8_t inputChannel, bool invert = false ) : negate( invert), xChannel( inputChannel )
channel( uint8_t inputChannel, bool invert = false ) : negate( invert), number( inputChannel )
{
channelType = input::type::DIGITAL;
cbInit();

}
/**
* @brief Set/Change the channel(pin) number.
Expand All @@ -151,7 +153,7 @@ namespace qOS {
bool retValue = false;

if ( inputChannel < 32U ) {
xChannel = inputChannel;
number = inputChannel;
retValue = true;
}

Expand All @@ -163,7 +165,7 @@ namespace qOS {
*/
inline uint8_t getChannel( void ) const
{
return xChannel;
return number;
}
/**
* @brief Get the channel type.
Expand All @@ -173,7 +175,6 @@ namespace qOS {
{
return channelType;
}

/**
* @brief Set the channel user-data.
* @param[in] A pointer to the user-data
Expand All @@ -190,6 +191,15 @@ namespace qOS {
{
return userData;
}
/**
* @brief Check if the channel value is shared with other channel
* with the same (pin) number.
* @return @c true if shared. Otherwise @c false.
*/
inline bool isShared( void ) const
{
return ( &value != ptrValue );
}
friend class watcher;
};

Expand All @@ -199,7 +209,8 @@ namespace qOS {
class watcher : protected node {
private:
eventCallback_t exception{ nullptr };
list nodes;
list digitalChannels;
list analogChannels;
qOS::timer waitDebounce;
qOS::duration_t debounceTime{ 100_ms };
channelReaderFcn_t digitalReader{ nullptr };
Expand Down Expand Up @@ -227,6 +238,11 @@ namespace qOS {
debounceTime( timeDebounce ), digitalReader( rDigital ), analogReader( rAnalog ) {}
/**
* @brief Add a channel to the watcher instance
* @note If the analog channel has channel-number equal to one of
* the channels already existing in the container, it will be
* marked as a shared channel. For shared channels the reader
* function will be invoked once and the value will be the same
* until the scan of all channels is completed.
* @param[in] c The input-Channel to watch
* @return @c true on success. Otherwise @c false.
*/
Expand All @@ -236,10 +252,7 @@ namespace qOS {
* @param[in] c The input-Channel to watch
* @return @c true on success. Otherwise @c false.
*/
bool remove( channel& c ) noexcept
{
return nodes.remove( &c );
}
bool remove( channel& c ) noexcept;
/**
* @brief Watch for the state and events for all channels
* registered inside the watcher instance (Non-Blocking call).
Expand Down
Loading

0 comments on commit bd7c82d

Please sign in to comment.