0.1.6 AsyncAnalog

This commit is contained in:
Rob Tillaart 2023-10-17 19:46:28 +02:00
parent 0ef1346f56
commit f0f6fe32a1
6 changed files with 94 additions and 38 deletions

View File

@ -1,24 +1,15 @@
//
// FILE: AsyncAnalog.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.5
// VERSION: 0.1.6
// DATE: 2018-09-05
// PURPOSE: async version of analogRead, prevent blocking wait
//
// backgrounder
// https://www.avrfreaks.net/forum/tut-c-newbies-guide-avr-adc?name=PNphpBB2&file=viewtopic&t=56429
//
// HISTORY:
// 0.1.0 2018-09-05 initial version, based upon analogRead()
// 0.1.1 2020-03-26 minor refactor
// 0.1.2 2020-05-27 update library.json
// 0.1.3 2020-12-12 added Arduino CI, minor fixes
// 0.1.4 2020-12-12 update Arduino CI, minor fixes
// 0.1.5 2021-12-13 update library.json, license, readme
// PURPOSE: Async version of analogRead, prevent blocking wait
// URL: https://github.com/RobTillaart/AsyncAnalog
#include "AsyncAnalog.h"
#if defined(ARDUINO_ARCH_AVR)
AsyncAnalog::AsyncAnalog(const uint8_t pin)
@ -60,17 +51,18 @@ bool AsyncAnalog::ready()
int AsyncAnalog::value()
{
// we have to read ADCL first; doing so locks both ADCL
// and ADCH until ADCH is read. reading ADCL second would
// cause the results of each conversion to be discarded,
// as ADCL and ADCH would be locked when it completed.
int low = ADCL;
int high = ADCH;
// combine the two bytes
return (high << 8) | low;
// ADCL has to be read first.
// Doing so locks both ADCL and ADCH until ADCH is read.
// Reading ADCL second would cause the results of each conversion to
// be discarded as ADCL and ADCH would be locked when it completed.
uint16_t lo = ADCL;
uint16_t hi = ADCH;
// Combine two parts.
// _lastValue = (hi * 256) + lo;
return (hi * 256) + lo;
}
#endif // ARDUINO_ARCH_AVR
#endif // ARDUINO_ARCH_AVR
// -- END OF FILE --
// -- END OF FILE --

View File

@ -2,27 +2,28 @@
//
// FILE: AsyncAnalog.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.5
// VERSION: 0.1.6
// DATE: 2018-09-05
// PURPOSE: async version of analogRead for AVR
// PURPOSE: Async version of analogRead for AVR
// URL: https://github.com/RobTillaart/AsyncAnalog
//
#if !defined(ARDUINO_ARCH_AVR)
#error “AsyncAnalog library only supports boards with an AVR processor .”
#else
// (ARDUINO_ARCH_SAM) future
// (ARDUINO_ARCH_ESP32) future
// (ARDUINO_ARCH_ESP8266) future
#include "Arduino.h"
#include "wiring_private.h"
#include "pins_arduino.h"
#define ASYNCANALOG_LIB_VERSION (F("0.1.5"))
#define ASYNCANALOG_LIB_VERSION (F("0.1.6"))
class AsyncAnalog
@ -35,9 +36,11 @@ public:
int value();
private:
uint8_t _pin;
uint8_t _pin;
// uint16_t _lastValue;
};
#endif
#endif // defined(ARDUINO_ARCH_AVR)
// -- END OF FILE --
// -- END OF FILE --

View File

@ -0,0 +1,36 @@
# Change Log AsyncAnalog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.1.6] - 2023-10-17
- update readme.md
- add changelog.md
- minor edits
## [0.1.5] - 2021-12-13
- update library.json
- update license
- update readme.md
## [0.1.4] - 2020-12-12
- update Arduino CI
- minor fixes
## [0.1.3] - 2020-12-12
- added Arduino CI
- minor fixes
## [0.1.2] - 2020-05-27
- update library.json
## [0.1.1] - 2020-03-26
- minor refactor
## [0.1.0] - 2018-09-05
- initial version, based upon analogRead()

View File

@ -2,8 +2,11 @@
[![Arduino CI](https://github.com/RobTillaart/AsyncAnalog/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![Arduino-lint](https://github.com/RobTillaart/AsyncAnalog/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/AsyncAnalog/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/AsyncAnalog/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/AsyncAnalog/actions/workflows/jsoncheck.yml)
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/AsyncAnalog.svg)](https://github.com/RobTillaart/AsyncAnalog/issues)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/AsyncAnalog/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/AsyncAnalog.svg?maxAge=3600)](https://github.com/RobTillaart/AsyncAnalog/releases)
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/AsyncAnalog.svg)](https://registry.platformio.org/libraries/robtillaart/AsyncAnalog)
# AsyncAnalog
@ -13,7 +16,7 @@ Arduino Library for async reading of an analogue pin. **\[AVR ONLY\]**.
## Description
AsyncAnalog is a library to read the analogue port of an AVR in an asynchronous way.
AsyncAnalog is a library to read the analogue port of an **AVR** in an asynchronous way.
This means that the user must explicitly **start** the ADC, check if it is **ready**
and read out its **value**.
@ -22,13 +25,18 @@ By using this class, the user prevents the (~112 uSec) blocking of the
The library works only for AVR boards now, other platforms might be supported in the future.
**WARNING**
As the UNO has only one ADC that is multiplexed, one can only read one analogue pin
in async way simultaneously.
**Use with care**
## Interface
## Interface
```cpp
#include "AsynAnalog,h"
```
- **AsyncAnalog(uint8_t pin)** constructor, defines the analogue pin to use.
- **void start()** triggers a new ADC reading.
@ -44,12 +52,29 @@ over Serial at 115200 baud.
## Future
#### Must
#### Should
- improve documentation.
#### Could
- investigate the performance gain.
- asyncAnalogTest2.ino is no good test.
- asyncAnalogTest2.ino is not a good test.
- create examples
- real world examples preferred.
- investigate other platforms
- fall back to normal analogRead for non AVR platforms ?
-
- better have specific code per platform.
#### Wont
## Support
If you appreciate my libraries, you can support the development and maintenance.
Improve the quality of the libraries by providing issues and Pull Requests, or
donate through PayPal or GitHub sponsors.
Thank you,

View File

@ -15,9 +15,9 @@
"type": "git",
"url": "https://github.com/RobTillaart/AsyncAnalog.git"
},
"version": "0.1.5",
"version": "0.1.6",
"license": "MIT",
"frameworks": "arduino",
"frameworks": "*",
"platforms": "*",
"headers": "AsyncAnalog.h"
}

View File

@ -1,5 +1,5 @@
name=AsyncAnalog
version=0.1.5
version=0.1.6
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino Library for async reading of an analog pin