Open FFBoard
Open source force feedback firmware
EncoderLocal.h
Go to the documentation of this file.
1/*
2 * EncoderLocal.h
3 *
4 * Created on: 02.02.2020
5 * Author: Yannick
6 */
7
8#ifndef ENCODERLOCAL_H_
9#define ENCODERLOCAL_H_
10
11#include "cppmain.h"
12#include <Encoder.h>
13#include "constants.h"
14#include "ExtiHandler.h"
15#include "TimerHandler.h"
16#include "CommandHandler.h"
17#include "PersistentStorage.h"
18
19#ifdef LOCALENCODER
20extern TIM_HandleTypeDef TIM_ENC;
21
22
23
25 enum class EncoderLocal_commands : uint32_t{
27 };
28public:
29 static bool inUse;
32 static bool isCreatable() {return !inUse;};
33
35 virtual ~EncoderLocal();
36
38
39 void registerCommands();
40
41 int32_t getPos();
42 void setPos(int32_t pos);
43 //void setOffset(int32_t offset);
44 void setPeriod(uint32_t period);
45 void overflowCallback();
46 void exti(uint16_t GPIO_Pin) override;
47 void timerElapsed(TIM_HandleTypeDef* htim);
48
49 int32_t getTimerCount();
50
51 void setCpr(uint32_t cpr); // Encoder counts per rotation
52
53 CommandStatus command(const ParsedCommand& cmd,std::vector<CommandReply>& replies);
54 std::string getHelpstring(){return "Local ABN encoder\n";}
55 void saveFlash(); // Write to flash here
56 void restoreFlash(); // Load from flash
57
58 //const ClassType getClassType() override {return ClassType::Encoder;};
59private:
60 TIM_HandleTypeDef* htim;
61 int16_t offset = 0;
62 int32_t pos = 0; // Extra position counter for overflows
63 uint32_t indexpos = 0;
64
65 bool indexHit = false;
66 bool useIndex = false;
67};
68#endif
69#endif /* ENCODERLOCAL_H_ */
CommandStatus
EncoderType
Definition: Encoder.h:27
TIM_HandleTypeDef TIM_ENC
uint32_t cpr
Definition: Encoder.h:53
int32_t getTimerCount()
int32_t getPos()
void setPos(int32_t pos)
static bool isCreatable()
Definition: EncoderLocal.h:32
virtual ~EncoderLocal()
void exti(uint16_t GPIO_Pin) override
void timerElapsed(TIM_HandleTypeDef *htim)
void setPeriod(uint32_t period)
static bool inUse
Definition: EncoderLocal.h:29
const ClassIdentifier getInfo()
Command handlers always have class infos. Works well with ChoosableClass.
void registerCommands()
static ClassIdentifier info
Definition: EncoderLocal.h:30
void saveFlash()
void restoreFlash()
int16_t offset
Definition: EncoderLocal.h:61
TIM_HandleTypeDef * htim
Definition: EncoderLocal.h:60
void overflowCallback()
EncoderType getEncoderType()
CommandStatus command(const ParsedCommand &cmd, std::vector< CommandReply > &replies)
uint32_t indexpos
Definition: EncoderLocal.h:63
void setCpr(uint32_t cpr)
std::string getHelpstring()
Definition: EncoderLocal.h:54
int32_t pos
Definition: EncoderLocal.h:62