Skip to content

Commit

Permalink
fix step event on input to prevent missing events. bump to 1.7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
camilo committed Jun 14, 2024
1 parent adf2218 commit 6746178
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 34 deletions.
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.7.3",
"version": "1.7.4",
"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.7.3
version=1.7.4
license=MIT
author=J. Camilo Gomez C. <kmilo17pet@gmail.com>
maintainer=J. Camilo Gomez C. <kmilo17pet@gmail.com>
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.7.3
VERSION 1.7.4
DESCRIPTION "An open-source OS for small embedded applications"
LANGUAGES CXX )

Expand Down
10 changes: 5 additions & 5 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.7.3
* @version 1.7.4
* @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.7.3"
#define QUARKTS_CPP_VERNUM ( 173u )
#define QUARKTS_CPP_VERSION "1.7.4"
#define QUARKTS_CPP_VERNUM ( 174u )
#define QUARKTS_CPP_CAPTION "QuarkTS++ OS " QUARKTS_CPP_VERSION

#include "config/config.h"
Expand All @@ -66,7 +66,7 @@ This file is part of the QuarkTS++ OS distribution.

namespace qOS {
namespace build {
constexpr const uint32_t number = 4140;
constexpr const uint32_t number = 4143;
constexpr const char* date = __DATE__;
constexpr const char* time = __TIME__;
constexpr const char* std = "c++11";
Expand All @@ -76,7 +76,7 @@ namespace qOS {
constexpr const uint8_t number = QUARKTS_CPP_VERNUM;
constexpr const uint8_t mayor = 1U;
constexpr const uint8_t minor = 7U;
constexpr const uint8_t rev = 3U;
constexpr const uint8_t rev = 4U;
}
namespace product {
constexpr const char* author = "J. Camilo Gomez C.";
Expand Down
24 changes: 13 additions & 11 deletions src/include/input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace qOS {


using digitalValue_t = int;
using analogValue_t = float;
using analogValue_t = uint32_t;

/**
* @brief A pointer to the wrapper function that reads the specific
Expand Down Expand Up @@ -332,12 +332,13 @@ namespace qOS {
analogValue_t *ptrValue{ &value };
analogReaderFcn_t reader{ nullptr };
channelStateFcn_t channelState{ nullptr };
analogValue_t high{ 800 };
analogValue_t low{ 200 };
analogValue_t last{ 0.0F };
analogValue_t delta{ 1.0e+20F };
analogValue_t step{ 1.0e+20F };
analogValue_t hysteresis{ 20 };
analogValue_t high{ 800U };
analogValue_t low{ 200U };
analogValue_t lastStep{ 0U };
analogValue_t lastSampled{ 0U };
analogValue_t delta{ 0xFFFFFFFFU };
analogValue_t step{ 0xFFFFFFFFU };
analogValue_t hysteresis{ 20U };
qOS::clock_t tSteadyBand{ 0xFFFFFFFFU };

void updateReading( bool act ) noexcept override;
Expand Down Expand Up @@ -370,10 +371,11 @@ namespace qOS {
* @param[in] upperThreshold The upper threshold value.
* @param[in] h Hysteresis for the in-band transition.
*/
analogChannel( const uint8_t inputChannel, const analogValue_t lowerThreshold, const analogValue_t upperThreshold, const analogValue_t h = 0.1F ) : channel( inputChannel ), high( upperThreshold ), low( lowerThreshold )
{
hysteresis = ( h < 0.0F ) ? -h : h;
}
analogChannel( const uint8_t inputChannel, const analogValue_t lowerThreshold, const analogValue_t upperThreshold, const analogValue_t h = 20 )
: channel( inputChannel ),
high( upperThreshold ),
low( lowerThreshold ),
hysteresis( h ) {}
/**
* @brief Get the channel type.
* @return The channel type.
Expand Down
35 changes: 20 additions & 15 deletions src/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,24 @@ void input::digitalChannel::updateReading( bool act ) noexcept
void input::analogChannel::updateReading( bool act ) noexcept
{
value = ( isShared() ) ? ptrValue[ 0 ] : reader( number );
if ( act ) {
analogValue_t diff = value - last;
diff = ( diff < 0.0F ) ? -diff : diff;

const analogValue_t currentStep = value/step;
if ( currentStep != lastStep ) {
const analogValue_t diff = ( currentStep > lastStep ) ? currentStep - lastStep
: lastStep - currentStep;
for ( analogValue_t i = 0; i < diff; ++i ) {
dispatchEvent( input::event::STEP );
}
lastStep = currentStep;
}

if ( act ) {
analogValue_t diff = ( value > lastSampled ) ? value - lastSampled
: lastSampled - value;
if ( diff >= delta ) {
dispatchEvent( input::event::DELTA );
}
if ( diff >= step ) {
auto mult = static_cast<int>( diff/step );
for ( int i = 0 ; i < mult; ++i ) {
dispatchEvent( input::event::STEP );
}
}
last = value;
lastSampled = value;
}
}
/*============================================================================*/
Expand Down Expand Up @@ -293,7 +297,7 @@ void input::digitalChannel::setInitalState( void ) noexcept
/*============================================================================*/
void input::analogChannel::setInitalState( void ) noexcept
{
const auto val = ( nullptr != reader ) ? reader( number ) : -1;
const auto val = ( nullptr != reader ) ? reader( number ) : 0U;

if ( val > high ) {
channelState = &input::analogChannel::highThresholdState;
Expand All @@ -304,7 +308,8 @@ void input::analogChannel::setInitalState( void ) noexcept
else {
channelState = &input::analogChannel::inBandState;
}
last = val;
lastStep = val/step;
lastSampled = val;
}
/*============================================================================*/
bool input::watcher::add( input::channel& c ) noexcept
Expand Down Expand Up @@ -438,13 +443,13 @@ bool input::analogChannel::setParameter( const input::event e, const analogValue
low = p;
break;
case input::event::IN_BAND:
hysteresis = ( p < 0.0F ) ? -p : p;
hysteresis = p;
break;
case input::event::DELTA:
delta = ( p < 0.0F ) ? -p : p;
delta = p;
break;
case input::event::STEP:
step = ( p < 0.0F ) ? -p : p;
step = p;
break;
default:
retValue = false;
Expand Down

0 comments on commit 6746178

Please sign in to comment.