mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-09-19 16:46:11 -04:00
0.1.6 AsyncAnalog
This commit is contained in:
parent
0ef1346f56
commit
f0f6fe32a1
@ -1,24 +1,15 @@
|
|||||||
//
|
//
|
||||||
// FILE: AsyncAnalog.cpp
|
// FILE: AsyncAnalog.cpp
|
||||||
// AUTHOR: Rob Tillaart
|
// AUTHOR: Rob Tillaart
|
||||||
// VERSION: 0.1.5
|
// VERSION: 0.1.6
|
||||||
// DATE: 2018-09-05
|
// DATE: 2018-09-05
|
||||||
// PURPOSE: async version of analogRead, prevent blocking wait
|
// PURPOSE: Async version of analogRead, prevent blocking wait
|
||||||
//
|
// URL: https://github.com/RobTillaart/AsyncAnalog
|
||||||
// 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
|
|
||||||
|
|
||||||
|
|
||||||
#include "AsyncAnalog.h"
|
#include "AsyncAnalog.h"
|
||||||
|
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_AVR)
|
#if defined(ARDUINO_ARCH_AVR)
|
||||||
|
|
||||||
AsyncAnalog::AsyncAnalog(const uint8_t pin)
|
AsyncAnalog::AsyncAnalog(const uint8_t pin)
|
||||||
@ -60,17 +51,18 @@ bool AsyncAnalog::ready()
|
|||||||
|
|
||||||
int AsyncAnalog::value()
|
int AsyncAnalog::value()
|
||||||
{
|
{
|
||||||
// we have to read ADCL first; doing so locks both ADCL
|
// ADCL has to be read first.
|
||||||
// and ADCH until ADCH is read. reading ADCL second would
|
// Doing so locks both ADCL and ADCH until ADCH is read.
|
||||||
// cause the results of each conversion to be discarded,
|
// Reading ADCL second would cause the results of each conversion to
|
||||||
// as ADCL and ADCH would be locked when it completed.
|
// be discarded as ADCL and ADCH would be locked when it completed.
|
||||||
int low = ADCL;
|
uint16_t lo = ADCL;
|
||||||
int high = ADCH;
|
uint16_t hi = ADCH;
|
||||||
// combine the two bytes
|
// Combine two parts.
|
||||||
return (high << 8) | low;
|
// _lastValue = (hi * 256) + lo;
|
||||||
|
return (hi * 256) + lo;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // ARDUINO_ARCH_AVR
|
#endif // ARDUINO_ARCH_AVR
|
||||||
|
|
||||||
|
|
||||||
// -- END OF FILE --
|
// -- END OF FILE --
|
||||||
|
@ -2,27 +2,28 @@
|
|||||||
//
|
//
|
||||||
// FILE: AsyncAnalog.h
|
// FILE: AsyncAnalog.h
|
||||||
// AUTHOR: Rob Tillaart
|
// AUTHOR: Rob Tillaart
|
||||||
// VERSION: 0.1.5
|
// VERSION: 0.1.6
|
||||||
// DATE: 2018-09-05
|
// DATE: 2018-09-05
|
||||||
// PURPOSE: async version of analogRead for AVR
|
// PURPOSE: Async version of analogRead for AVR
|
||||||
// URL: https://github.com/RobTillaart/AsyncAnalog
|
// URL: https://github.com/RobTillaart/AsyncAnalog
|
||||||
//
|
|
||||||
|
|
||||||
|
|
||||||
#if !defined(ARDUINO_ARCH_AVR)
|
#if !defined(ARDUINO_ARCH_AVR)
|
||||||
|
|
||||||
#error “AsyncAnalog library only supports boards with an AVR processor .”
|
#error “AsyncAnalog library only supports boards with an AVR processor .”
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
// (ARDUINO_ARCH_SAM) future
|
// (ARDUINO_ARCH_SAM) future
|
||||||
|
// (ARDUINO_ARCH_ESP32) future
|
||||||
|
// (ARDUINO_ARCH_ESP8266) future
|
||||||
|
|
||||||
|
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include "wiring_private.h"
|
#include "wiring_private.h"
|
||||||
#include "pins_arduino.h"
|
#include "pins_arduino.h"
|
||||||
|
|
||||||
#define ASYNCANALOG_LIB_VERSION (F("0.1.5"))
|
#define ASYNCANALOG_LIB_VERSION (F("0.1.6"))
|
||||||
|
|
||||||
|
|
||||||
class AsyncAnalog
|
class AsyncAnalog
|
||||||
@ -35,9 +36,11 @@ public:
|
|||||||
int value();
|
int value();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint8_t _pin;
|
uint8_t _pin;
|
||||||
|
// uint16_t _lastValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // defined(ARDUINO_ARCH_AVR)
|
||||||
|
|
||||||
// -- END OF FILE --
|
|
||||||
|
// -- END OF FILE --
|
||||||
|
36
libraries/AsyncAnalog/CHANGELOG.md
Normal file
36
libraries/AsyncAnalog/CHANGELOG.md
Normal 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()
|
||||||
|
|
@ -2,8 +2,11 @@
|
|||||||
[![Arduino CI](https://github.com/RobTillaart/AsyncAnalog/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
[![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)
|
[![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)
|
[![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)
|
[![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)
|
[![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
|
# AsyncAnalog
|
||||||
@ -13,7 +16,7 @@ Arduino Library for async reading of an analogue pin. **\[AVR ONLY\]**.
|
|||||||
|
|
||||||
## Description
|
## 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**
|
This means that the user must explicitly **start** the ADC, check if it is **ready**
|
||||||
and read out its **value**.
|
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.
|
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
|
As the UNO has only one ADC that is multiplexed, one can only read one analogue pin
|
||||||
in async way simultaneously.
|
in async way simultaneously.
|
||||||
|
|
||||||
**Use with care**
|
**Use with care**
|
||||||
|
|
||||||
|
|
||||||
## Interface
|
## Interface
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
#include "AsynAnalog,h"
|
||||||
|
```
|
||||||
|
|
||||||
- **AsyncAnalog(uint8_t pin)** constructor, defines the analogue pin to use.
|
- **AsyncAnalog(uint8_t pin)** constructor, defines the analogue pin to use.
|
||||||
- **void start()** triggers a new ADC reading.
|
- **void start()** triggers a new ADC reading.
|
||||||
@ -44,12 +52,29 @@ over Serial at 115200 baud.
|
|||||||
|
|
||||||
## Future
|
## Future
|
||||||
|
|
||||||
|
#### Must
|
||||||
|
|
||||||
|
#### Should
|
||||||
|
|
||||||
- improve documentation.
|
- improve documentation.
|
||||||
|
|
||||||
|
#### Could
|
||||||
|
|
||||||
- investigate the performance gain.
|
- investigate the performance gain.
|
||||||
- asyncAnalogTest2.ino is no good test.
|
- asyncAnalogTest2.ino is not a good test.
|
||||||
- create examples
|
- create examples
|
||||||
- real world examples preferred.
|
- real world examples preferred.
|
||||||
- investigate other platforms
|
- investigate other platforms
|
||||||
- fall back to normal analogRead for non AVR 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,
|
||||||
|
|
||||||
|
@ -15,9 +15,9 @@
|
|||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/RobTillaart/AsyncAnalog.git"
|
"url": "https://github.com/RobTillaart/AsyncAnalog.git"
|
||||||
},
|
},
|
||||||
"version": "0.1.5",
|
"version": "0.1.6",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"frameworks": "arduino",
|
"frameworks": "*",
|
||||||
"platforms": "*",
|
"platforms": "*",
|
||||||
"headers": "AsyncAnalog.h"
|
"headers": "AsyncAnalog.h"
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name=AsyncAnalog
|
name=AsyncAnalog
|
||||||
version=0.1.5
|
version=0.1.6
|
||||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||||
sentence=Arduino Library for async reading of an analog pin
|
sentence=Arduino Library for async reading of an analog pin
|
||||||
|
Loading…
Reference in New Issue
Block a user