Loading...
Searching...
No Matches
BindJoystick.hpp
1#ifndef __BINDJOYSTICK_HPP
2#define __BINDJOYSTICK_HPP
3#include "BindView.hpp"
4#include "BindUtils.hpp"
57 class BindJoystick : public BindView
58{
59
60 public:
61 BindJoystick()
62 {
63 this->tag = tagIndex++;
64 }
65
66 int16_t x = 0;
67 int16_t y = 0;
68 uint8_t cmdId = 0;
69 int16_t dimSize = 200;
70 int16_t sX = 0;
71 int16_t sY = 0;
72 bool springed = true;
73
85 void setCallback(void (*callback)(int16_t, int16_t))
86 {
87 changeCallback = callback;
88 }
89
90 void invokeCallback(int16_t xIn, int16_t yIn)
91 {
92 this->sX = xIn;
93 this->sY = yIn;
94 if (changeCallback != nullptr)
95 {
96 changeCallback(xIn, yIn);
97 }
98 }
99
108 uint16_t getBytes(uint8_t *out) override
109 {
110 offset = 0;
111 copyAndOffset(out, &offset, &objID, sizeof(objID));
112 copyAndOffset(out, &offset, &x, sizeof(x));
113 copyAndOffset(out, &offset, &y, sizeof(y));
114 copyAndOffset(out, &offset, &tag, sizeof(tag));
115 copyAndOffset(out, &offset, &cmdId, sizeof(cmdId));
116 copyAndOffset(out, &offset, &dimSize, sizeof(dimSize));
117 copyAndOffset(out, &offset, &springed, sizeof(springed));
118 return offset;
119 }
120
121 private:
122 uint8_t objID = BIND_ID_JOYSTICK;
123 uint16_t offset = 0;
124 static int16_t tagIndex;
125 void (*changeCallback)(int16_t, int16_t) = nullptr;
126};
127
128#endif /* __BINDJOYSTICK_HPP */
BindJoystick
BindJoystick Class.
Definition BindJoystick.hpp:58
BindJoystick::sX
int16_t sX
The joystick's current X-axis position (internal).
Definition BindJoystick.hpp:70
BindJoystick::y
int16_t y
The y-coordinate position of the joystick on the screen.
Definition BindJoystick.hpp:67
BindJoystick::x
int16_t x
The x-coordinate position of the joystick on the screen.
Definition BindJoystick.hpp:66
BindJoystick::dimSize
int16_t dimSize
The dimensions (size) of the joystick.
Definition BindJoystick.hpp:69
BindJoystick::cmdId
uint8_t cmdId
Command identifier to add or refresh the joystick. See the notes for possible cmdId values.
Definition BindJoystick.hpp:68
BindJoystick::springed
bool springed
Indicates whether the joystick returns to the center automatically when released.
Definition BindJoystick.hpp:72
BindJoystick::setCallback
void setCallback(void(*callback)(int16_t, int16_t))
Set the Callback function for the joystick.
Definition BindJoystick.hpp:85
BindJoystick::getBytes
uint16_t getBytes(uint8_t *out) override
Serialize the joystick object into bytes.
Definition BindJoystick.hpp:108
BindJoystick::sY
int16_t sY
The joystick's current Y-axis position (internal).
Definition BindJoystick.hpp:71
BindView
Definition BindView.hpp:26