Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: USBDevice mbed-rtos mbed
Fork of JoyStick by
AnalogInFiltered.cpp@5:a0bb17c379ce, 2016-06-22 (annotated)
- Committer:
- rvt
- Date:
- Wed Jun 22 12:50:16 2016 +0000
- Revision:
- 5:a0bb17c379ce
- Parent:
- 2:ae7a31a3c618
Latest
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| rvt | 0:33bc88c4ab31 | 1 | #include "AnalogInFiltered.h" |
| rvt | 0:33bc88c4ab31 | 2 | |
| rvt | 0:33bc88c4ab31 | 3 | |
| rvt | 5:a0bb17c379ce | 4 | AnalogInFiltered::AnalogInFiltered(AnalogFilterInterface *filter, PinName pin, int fuzzyFactor) : _ain(new AnalogIn(pin)), _fuzzyFactor(fuzzyFactor), _filter(filter), _lastValue(0) { |
| rvt | 0:33bc88c4ab31 | 5 | } |
| rvt | 0:33bc88c4ab31 | 6 | |
| rvt | 0:33bc88c4ab31 | 7 | AnalogInFiltered::~AnalogInFiltered() { |
| rvt | 0:33bc88c4ab31 | 8 | delete(_ain); |
| rvt | 0:33bc88c4ab31 | 9 | } |
| rvt | 0:33bc88c4ab31 | 10 | |
| rvt | 5:a0bb17c379ce | 11 | void AnalogInFiltered::setData (long d) { |
| rvt | 0:33bc88c4ab31 | 12 | _filter->setData(_ain->read_u16() - 32768); |
| rvt | 0:33bc88c4ab31 | 13 | } |
| rvt | 0:33bc88c4ab31 | 14 | |
| rvt | 5:a0bb17c379ce | 15 | long AnalogInFiltered::getData() const { |
| rvt | 2:ae7a31a3c618 | 16 | return _filter->getData(); |
| rvt | 2:ae7a31a3c618 | 17 | } |
| rvt | 0:33bc88c4ab31 | 18 | |
| rvt | 2:ae7a31a3c618 | 19 | |
| rvt | 2:ae7a31a3c618 | 20 | bool AnalogInFiltered::getIsChanged() { |
| rvt | 2:ae7a31a3c618 | 21 | // _filter->setData(_ain->read_u16() - 32768); |
| rvt | 2:ae7a31a3c618 | 22 | if (abs(_filter->getData() - _lastValue) > _fuzzyFactor) { |
| rvt | 0:33bc88c4ab31 | 23 | _lastValue = _filter->getData(); |
| rvt | 0:33bc88c4ab31 | 24 | return true; |
| rvt | 0:33bc88c4ab31 | 25 | } |
| rvt | 0:33bc88c4ab31 | 26 | return false; |
| rvt | 0:33bc88c4ab31 | 27 | } |
| rvt | 0:33bc88c4ab31 | 28 | |
| rvt | 2:ae7a31a3c618 | 29 | int AnalogInFiltered::getFuzzyFactor() { |
| rvt | 2:ae7a31a3c618 | 30 | return _fuzzyFactor; |
| rvt | 2:ae7a31a3c618 | 31 | } |
