Skip to content

Commit 6746178

Browse files
author
camilo
committed
fix step event on input to prevent missing events. bump to 1.7.4
1 parent adf2218 commit 6746178

File tree

6 files changed

+41
-34
lines changed

6 files changed

+41
-34
lines changed

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"maintainer": true
1717
}
1818
],
19-
"version": "1.7.3",
19+
"version": "1.7.4",
2020
"license": "MIT",
2121
"frameworks": "arduino",
2222
"platforms": "*"

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=QuarkTS
2-
version=1.7.3
2+
version=1.7.4
33
license=MIT
44
author=J. Camilo Gomez C. <[email protected]>
55
maintainer=J. Camilo Gomez C. <[email protected]>

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required( VERSION 3.2 )
22
project( quarkts-cpp
3-
VERSION 1.7.3
3+
VERSION 1.7.4
44
DESCRIPTION "An open-source OS for small embedded applications"
55
LANGUAGES CXX )
66

src/QuarkTS.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* @file QuarkTS.h
33
* @author J. Camilo Gomez C.
4-
* @version 1.7.3
4+
* @version 1.7.4
55
* @note This file is part of the QuarkTS++ distribution.
66
* @brief Global inclusion header
77
**/
@@ -41,8 +41,8 @@ This file is part of the QuarkTS++ OS distribution.
4141
#ifndef QOS_CPP_H
4242
#define QOS_CPP_H
4343

44-
#define QUARKTS_CPP_VERSION "1.7.3"
45-
#define QUARKTS_CPP_VERNUM ( 173u )
44+
#define QUARKTS_CPP_VERSION "1.7.4"
45+
#define QUARKTS_CPP_VERNUM ( 174u )
4646
#define QUARKTS_CPP_CAPTION "QuarkTS++ OS " QUARKTS_CPP_VERSION
4747

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

6767
namespace qOS {
6868
namespace build {
69-
constexpr const uint32_t number = 4140;
69+
constexpr const uint32_t number = 4143;
7070
constexpr const char* date = __DATE__;
7171
constexpr const char* time = __TIME__;
7272
constexpr const char* std = "c++11";
@@ -76,7 +76,7 @@ namespace qOS {
7676
constexpr const uint8_t number = QUARKTS_CPP_VERNUM;
7777
constexpr const uint8_t mayor = 1U;
7878
constexpr const uint8_t minor = 7U;
79-
constexpr const uint8_t rev = 3U;
79+
constexpr const uint8_t rev = 4U;
8080
}
8181
namespace product {
8282
constexpr const char* author = "J. Camilo Gomez C.";

src/include/input.hpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ namespace qOS {
6565

6666

6767
using digitalValue_t = int;
68-
using analogValue_t = float;
68+
using analogValue_t = uint32_t;
6969

7070
/**
7171
* @brief A pointer to the wrapper function that reads the specific
@@ -332,12 +332,13 @@ namespace qOS {
332332
analogValue_t *ptrValue{ &value };
333333
analogReaderFcn_t reader{ nullptr };
334334
channelStateFcn_t channelState{ nullptr };
335-
analogValue_t high{ 800 };
336-
analogValue_t low{ 200 };
337-
analogValue_t last{ 0.0F };
338-
analogValue_t delta{ 1.0e+20F };
339-
analogValue_t step{ 1.0e+20F };
340-
analogValue_t hysteresis{ 20 };
335+
analogValue_t high{ 800U };
336+
analogValue_t low{ 200U };
337+
analogValue_t lastStep{ 0U };
338+
analogValue_t lastSampled{ 0U };
339+
analogValue_t delta{ 0xFFFFFFFFU };
340+
analogValue_t step{ 0xFFFFFFFFU };
341+
analogValue_t hysteresis{ 20U };
341342
qOS::clock_t tSteadyBand{ 0xFFFFFFFFU };
342343

343344
void updateReading( bool act ) noexcept override;
@@ -370,10 +371,11 @@ namespace qOS {
370371
* @param[in] upperThreshold The upper threshold value.
371372
* @param[in] h Hysteresis for the in-band transition.
372373
*/
373-
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 )
374-
{
375-
hysteresis = ( h < 0.0F ) ? -h : h;
376-
}
374+
analogChannel( const uint8_t inputChannel, const analogValue_t lowerThreshold, const analogValue_t upperThreshold, const analogValue_t h = 20 )
375+
: channel( inputChannel ),
376+
high( upperThreshold ),
377+
low( lowerThreshold ),
378+
hysteresis( h ) {}
377379
/**
378380
* @brief Get the channel type.
379381
* @return The channel type.

src/input.cpp

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,24 @@ void input::digitalChannel::updateReading( bool act ) noexcept
1717
void input::analogChannel::updateReading( bool act ) noexcept
1818
{
1919
value = ( isShared() ) ? ptrValue[ 0 ] : reader( number );
20-
if ( act ) {
21-
analogValue_t diff = value - last;
22-
diff = ( diff < 0.0F ) ? -diff : diff;
2320

21+
const analogValue_t currentStep = value/step;
22+
if ( currentStep != lastStep ) {
23+
const analogValue_t diff = ( currentStep > lastStep ) ? currentStep - lastStep
24+
: lastStep - currentStep;
25+
for ( analogValue_t i = 0; i < diff; ++i ) {
26+
dispatchEvent( input::event::STEP );
27+
}
28+
lastStep = currentStep;
29+
}
30+
31+
if ( act ) {
32+
analogValue_t diff = ( value > lastSampled ) ? value - lastSampled
33+
: lastSampled - value;
2434
if ( diff >= delta ) {
2535
dispatchEvent( input::event::DELTA );
2636
}
27-
if ( diff >= step ) {
28-
auto mult = static_cast<int>( diff/step );
29-
for ( int i = 0 ; i < mult; ++i ) {
30-
dispatchEvent( input::event::STEP );
31-
}
32-
}
33-
last = value;
37+
lastSampled = value;
3438
}
3539
}
3640
/*============================================================================*/
@@ -293,7 +297,7 @@ void input::digitalChannel::setInitalState( void ) noexcept
293297
/*============================================================================*/
294298
void input::analogChannel::setInitalState( void ) noexcept
295299
{
296-
const auto val = ( nullptr != reader ) ? reader( number ) : -1;
300+
const auto val = ( nullptr != reader ) ? reader( number ) : 0U;
297301

298302
if ( val > high ) {
299303
channelState = &input::analogChannel::highThresholdState;
@@ -304,7 +308,8 @@ void input::analogChannel::setInitalState( void ) noexcept
304308
else {
305309
channelState = &input::analogChannel::inBandState;
306310
}
307-
last = val;
311+
lastStep = val/step;
312+
lastSampled = val;
308313
}
309314
/*============================================================================*/
310315
bool input::watcher::add( input::channel& c ) noexcept
@@ -438,13 +443,13 @@ bool input::analogChannel::setParameter( const input::event e, const analogValue
438443
low = p;
439444
break;
440445
case input::event::IN_BAND:
441-
hysteresis = ( p < 0.0F ) ? -p : p;
446+
hysteresis = p;
442447
break;
443448
case input::event::DELTA:
444-
delta = ( p < 0.0F ) ? -p : p;
449+
delta = p;
445450
break;
446451
case input::event::STEP:
447-
step = ( p < 0.0F ) ? -p : p;
452+
step = p;
448453
break;
449454
default:
450455
retValue = false;

0 commit comments

Comments
 (0)