![](/media/cache/profiles/altb_JGUSAOG.jpg.50x50_q85.jpg)
corrections altb2
Lib_Misc/EncoderCounterIndex.cpp@3:8aa09988fa58, 2021-08-24 (annotated)
- Committer:
- altb2
- Date:
- Tue Aug 24 12:34:00 2021 +0000
- Revision:
- 3:8aa09988fa58
- Parent:
- 0:d2e117716219
corrected memory allocation in class
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
altb2 | 0:d2e117716219 | 1 | /* |
altb2 | 0:d2e117716219 | 2 | * EncoderCounterIndex.cpp |
altb2 | 0:d2e117716219 | 3 | * Copyright (c) 2018, ZHAW |
altb2 | 0:d2e117716219 | 4 | * All rights reserved. |
altb2 | 0:d2e117716219 | 5 | * |
altb2 | 0:d2e117716219 | 6 | * Created on: 13.08.2018 |
altb2 | 0:d2e117716219 | 7 | * Author: Marcel Honegger |
altb2 | 0:d2e117716219 | 8 | */ |
altb2 | 0:d2e117716219 | 9 | |
altb2 | 0:d2e117716219 | 10 | #include <stdint.h> |
altb2 | 0:d2e117716219 | 11 | #include "EncoderCounter.h" |
altb2 | 0:d2e117716219 | 12 | #include "EncoderCounterIndex.h" |
altb2 | 0:d2e117716219 | 13 | |
altb2 | 0:d2e117716219 | 14 | using namespace std; |
altb2 | 0:d2e117716219 | 15 | |
altb2 | 0:d2e117716219 | 16 | /** |
altb2 | 0:d2e117716219 | 17 | * Creates an object with an interrupt service routine to catch |
altb2 | 0:d2e117716219 | 18 | * the current encoder position when an index pulse is received. |
altb2 | 0:d2e117716219 | 19 | */ |
altb2 | 0:d2e117716219 | 20 | EncoderCounterIndex::EncoderCounterIndex(EncoderCounter& encoderCounter, InterruptIn& channelIndex) : encoderCounter(encoderCounter), channelIndex(channelIndex) { |
altb2 | 0:d2e117716219 | 21 | |
altb2 | 0:d2e117716219 | 22 | // attach interrupt |
altb2 | 0:d2e117716219 | 23 | |
altb2 | 0:d2e117716219 | 24 | channelIndex.rise(callback(this, &EncoderCounterIndex::rise)); |
altb2 | 0:d2e117716219 | 25 | } |
altb2 | 0:d2e117716219 | 26 | |
altb2 | 0:d2e117716219 | 27 | EncoderCounterIndex::~EncoderCounterIndex() {} |
altb2 | 0:d2e117716219 | 28 | |
altb2 | 0:d2e117716219 | 29 | int32_t EncoderCounterIndex::getPositionAtIndexPulse() { |
altb2 | 0:d2e117716219 | 30 | |
altb2 | 0:d2e117716219 | 31 | return positionAtIndexPulse; |
altb2 | 0:d2e117716219 | 32 | } |
altb2 | 0:d2e117716219 | 33 | |
altb2 | 0:d2e117716219 | 34 | void EncoderCounterIndex::rise() { |
altb2 | 0:d2e117716219 | 35 | |
altb2 | 0:d2e117716219 | 36 | positionAtIndexPulse = encoderCounter; |
altb2 | 0:d2e117716219 | 37 | channelIndex.rise(NULL); |
altb2 | 0:d2e117716219 | 38 | } |
altb2 | 0:d2e117716219 | 39 | |
altb2 | 0:d2e117716219 | 40 |