Skip to content

Commit 257c96f

Browse files
committed
Can now turn LED off by calling setLedOn(OFF) for all controllers
Also renamed all enums, so they does not conflict with user code that easily
1 parent ec38c78 commit 257c96f

File tree

18 files changed

+296
-272
lines changed

18 files changed

+296
-272
lines changed

PS3BT.cpp

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,26 +49,26 @@ pBtd(p) // pointer to USB class instance - mandatory
4949
Reset();
5050
}
5151

52-
bool PS3BT::getButtonPress(Button b) {
53-
return (ButtonState & pgm_read_dword(&BUTTONS[(uint8_t)b]));
52+
bool PS3BT::getButtonPress(ButtonEnum b) {
53+
return (ButtonState & pgm_read_dword(&PS3_BUTTONS[(uint8_t)b]));
5454
}
5555

56-
bool PS3BT::getButtonClick(Button b) {
57-
uint32_t button = pgm_read_dword(&BUTTONS[(uint8_t)b]);
56+
bool PS3BT::getButtonClick(ButtonEnum b) {
57+
uint32_t button = pgm_read_dword(&PS3_BUTTONS[(uint8_t)b]);
5858
bool click = (ButtonClickState & button);
5959
ButtonClickState &= ~button; // Clear "click" event
6060
return click;
6161
}
6262

63-
uint8_t PS3BT::getAnalogButton(Button a) {
64-
return (uint8_t)(l2capinbuf[pgm_read_byte(&ANALOGBUTTONS[(uint8_t)a])]);
63+
uint8_t PS3BT::getAnalogButton(ButtonEnum a) {
64+
return (uint8_t)(l2capinbuf[pgm_read_byte(&PS3_ANALOG_BUTTONS[(uint8_t)a])]);
6565
}
6666

67-
uint8_t PS3BT::getAnalogHat(AnalogHat a) {
67+
uint8_t PS3BT::getAnalogHat(AnalogHatEnum a) {
6868
return (uint8_t)(l2capinbuf[(uint8_t)a + 15]);
6969
}
7070

71-
int16_t PS3BT::getSensor(Sensor a) {
71+
int16_t PS3BT::getSensor(SensorEnum a) {
7272
if(PS3Connected) {
7373
if(a == aX || a == aY || a == aZ || a == gZ)
7474
return ((l2capinbuf[(uint16_t)a] << 8) | l2capinbuf[(uint16_t)a + 1]);
@@ -85,7 +85,7 @@ int16_t PS3BT::getSensor(Sensor a) {
8585
return 0;
8686
}
8787

88-
double PS3BT::getAngle(Angle a) {
88+
double PS3BT::getAngle(AngleEnum a) {
8989
double accXval, accYval, accZval;
9090

9191
if(PS3Connected) {
@@ -112,7 +112,7 @@ double PS3BT::getAngle(Angle a) {
112112
return (atan2(accXval, accZval) + PI) * RAD_TO_DEG;
113113
}
114114

115-
double PS3BT::get9DOFValues(Sensor a) { // Thanks to Manfred Piendl
115+
double PS3BT::get9DOFValues(SensorEnum a) { // Thanks to Manfred Piendl
116116
if(!PS3MoveConnected)
117117
return 0;
118118
int16_t value = getSensor(a);
@@ -156,7 +156,7 @@ String PS3BT::getTemperature() {
156156
return "Error";
157157
}
158158

159-
bool PS3BT::getStatus(Status c) {
159+
bool PS3BT::getStatus(StatusEnum c) {
160160
return (l2capinbuf[(uint16_t)c >> 8] == ((uint8_t)c & 0xff));
161161
}
162162

@@ -544,7 +544,7 @@ void PS3BT::setRumbleOff() {
544544
HID_Command(HIDBuffer, HID_BUFFERSIZE);
545545
}
546546

547-
void PS3BT::setRumbleOn(Rumble mode) {
547+
void PS3BT::setRumbleOn(RumbleEnum mode) {
548548
uint8_t power[2] = {0xff, 0x00}; // Defaults to RumbleLow
549549
if(mode == RumbleHigh) {
550550
power[0] = 0x00;
@@ -566,18 +566,22 @@ void PS3BT::setLedRaw(uint8_t value) {
566566
HID_Command(HIDBuffer, HID_BUFFERSIZE);
567567
}
568568

569-
void PS3BT::setLedOff(LED a) {
570-
HIDBuffer[11] &= ~((uint8_t)((pgm_read_byte(&LEDS[(uint8_t)a]) & 0x0f) << 1));
569+
void PS3BT::setLedOff(LEDEnum a) {
570+
HIDBuffer[11] &= ~((uint8_t)((pgm_read_byte(&PS3_LEDS[(uint8_t)a]) & 0x0f) << 1));
571571
HID_Command(HIDBuffer, HID_BUFFERSIZE);
572572
}
573573

574-
void PS3BT::setLedOn(LED a) {
575-
HIDBuffer[11] |= (uint8_t)((pgm_read_byte(&LEDS[(uint8_t)a]) & 0x0f) << 1);
576-
HID_Command(HIDBuffer, HID_BUFFERSIZE);
574+
void PS3BT::setLedOn(LEDEnum a) {
575+
if(a == OFF)
576+
setLedRaw(0);
577+
else {
578+
HIDBuffer[11] |= (uint8_t)((pgm_read_byte(&PS3_LEDS[(uint8_t)a]) & 0x0f) << 1);
579+
HID_Command(HIDBuffer, HID_BUFFERSIZE);
580+
}
577581
}
578582

579-
void PS3BT::setLedToggle(LED a) {
580-
HIDBuffer[11] ^= (uint8_t)((pgm_read_byte(&LEDS[(uint8_t)a]) & 0x0f) << 1);
583+
void PS3BT::setLedToggle(LEDEnum a) {
584+
HIDBuffer[11] ^= (uint8_t)((pgm_read_byte(&PS3_LEDS[(uint8_t)a]) & 0x0f) << 1);
581585
HID_Command(HIDBuffer, HID_BUFFERSIZE);
582586
}
583587

@@ -602,7 +606,7 @@ void PS3BT::HIDMove_Command(uint8_t* data, uint8_t nbytes) {
602606
timerHID = millis();
603607
}
604608

605-
void PS3BT::moveSetBulb(uint8_t r, uint8_t g, uint8_t b) { //Use this to set the Color using RGB values
609+
void PS3BT::moveSetBulb(uint8_t r, uint8_t g, uint8_t b) { // Use this to set the Color using RGB values
606610
// Set the Bulb's values into the write buffer
607611
HIDMoveBuffer[3] = r;
608612
HIDMoveBuffer[4] = g;
@@ -611,7 +615,7 @@ void PS3BT::moveSetBulb(uint8_t r, uint8_t g, uint8_t b) { //Use this to set the
611615
HIDMove_Command(HIDMoveBuffer, HID_BUFFERSIZE);
612616
}
613617

614-
void PS3BT::moveSetBulb(Colors color) { //Use this to set the Color using the predefined colors in enum
618+
void PS3BT::moveSetBulb(ColorsEnum color) { // Use this to set the Color using the predefined colors in enum
615619
moveSetBulb((uint8_t)(color >> 16), (uint8_t)(color >> 8), (uint8_t)(color));
616620
}
617621

PS3BT.h

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -56,32 +56,34 @@ class PS3BT : public BluetoothService {
5656

5757
/** @name PS3 Controller functions */
5858
/**
59-
* getButtonPress(Button b) will return true as long as the button is held down.
59+
* getButtonPress(ButtonEnum b) will return true as long as the button is held down.
6060
*
61-
* While getButtonClick(Button b) will only return it once.
61+
* While getButtonClick(ButtonEnum b) will only return it once.
6262
*
63-
* So you instance if you need to increase a variable once you would use getButtonClick(Button b),
64-
* but if you need to drive a robot forward you would use getButtonPress(Button b).
63+
* So you instance if you need to increase a variable once you would use getButtonClick(ButtonEnum b),
64+
* but if you need to drive a robot forward you would use getButtonPress(ButtonEnum b).
65+
* @param b ::ButtonEnum to read.
66+
* @return getButtonPress(ButtonEnum b) will return a true as long as a button is held down, while getButtonClick(ButtonEnum b) will return true once for each button press.
6567
*/
66-
bool getButtonPress(Button b);
67-
bool getButtonClick(Button b);
68+
bool getButtonPress(ButtonEnum b);
69+
bool getButtonClick(ButtonEnum b);
6870
/**@}*/
6971
/** @name PS3 Controller functions */
7072
/**
7173
* Used to get the analog value from button presses.
72-
* @param a The ::Button to read.
74+
* @param a The ::ButtonEnum to read.
7375
* The supported buttons are:
7476
* ::UP, ::RIGHT, ::DOWN, ::LEFT, ::L1, ::L2, ::R1, ::R2,
7577
* ::TRIANGLE, ::CIRCLE, ::CROSS, ::SQUARE, and ::T.
7678
* @return Analog value in the range of 0-255.
7779
*/
78-
uint8_t getAnalogButton(Button a);
80+
uint8_t getAnalogButton(ButtonEnum a);
7981
/**
8082
* Used to read the analog joystick.
8183
* @param a ::LeftHatX, ::LeftHatY, ::RightHatX, and ::RightHatY.
8284
* @return Return the analog value in the range of 0-255.
8385
*/
84-
uint8_t getAnalogHat(AnalogHat a);
86+
uint8_t getAnalogHat(AnalogHatEnum a);
8587
/**
8688
* Used to read the sensors inside the Dualshock 3 and Move controller.
8789
* @param a
@@ -90,47 +92,47 @@ class PS3BT : public BluetoothService {
9092
* and a temperature sensor inside.
9193
* @return Return the raw sensor value.
9294
*/
93-
int16_t getSensor(Sensor a);
95+
int16_t getSensor(SensorEnum a);
9496
/**
9597
* Use this to get ::Pitch and ::Roll calculated using the accelerometer.
9698
* @param a Either ::Pitch or ::Roll.
9799
* @return Return the angle in the range of 0-360.
98100
*/
99-
double getAngle(Angle a);
101+
double getAngle(AngleEnum a);
100102
/**
101103
* Read the sensors inside the Move controller.
102104
* @param a ::aXmove, ::aYmove, ::aZmove, ::gXmove, ::gYmove, ::gZmove, ::mXmove, ::mYmove, and ::mXmove.
103105
* @return The value in SI units.
104106
*/
105-
double get9DOFValues(Sensor a);
107+
double get9DOFValues(SensorEnum a);
106108
/**
107-
* Get the ::Status from the controller.
108-
* @param c The ::Status you want to read.
109+
* Get the status from the controller.
110+
* @param c The ::StatusEnum you want to read.
109111
* @return True if correct and false if not.
110112
*/
111-
bool getStatus(Status c);
113+
bool getStatus(StatusEnum c);
112114
/**
113-
* Read all the available ::Status from the controller.
115+
* Read all the available ::StatusEnum from the controller.
114116
* @return One large string with all the information.
115117
*/
116118
String getStatusString();
117119
/**
118120
* Read the temperature from the Move controller.
119-
* @return The temperature in degrees celsius.
121+
* @return The temperature in degrees Celsius.
120122
*/
121123
String getTemperature();
122124

123-
/** Used to set all LEDs and ::Rumble off. */
125+
/** Used to set all LEDs and rumble off. */
124126
void setAllOff();
125-
/** Turn off ::Rumble. */
127+
/** Turn off rumble. */
126128
void setRumbleOff();
127129
/**
128-
* Turn on ::Rumble.
130+
* Turn on rumble.
129131
* @param mode Either ::RumbleHigh or ::RumbleLow.
130132
*/
131-
void setRumbleOn(Rumble mode);
133+
void setRumbleOn(RumbleEnum mode);
132134
/**
133-
* Turn on ::Rumble using custom duration and power.
135+
* Turn on rumble using custom duration and power.
134136
* @param rightDuration The duration of the right/low rumble effect.
135137
* @param rightPower The intensity of the right/low rumble effect.
136138
* @param leftDuration The duration of the left/high rumble effect.
@@ -139,8 +141,8 @@ class PS3BT : public BluetoothService {
139141
void setRumbleOn(uint8_t rightDuration, uint8_t rightPower, uint8_t leftDuration, uint8_t leftPower);
140142

141143
/**
142-
* Set LED value without using the ::LED enum.
143-
* @param value See: ::LED enum.
144+
* Set LED value without using ::LEDEnum.
145+
* @param value See: ::LEDEnum.
144146
*/
145147
void setLedRaw(uint8_t value);
146148

@@ -149,31 +151,31 @@ class PS3BT : public BluetoothService {
149151
setLedRaw(0);
150152
};
151153
/**
152-
* Turn the specific ::LED off.
153-
* @param a The ::LED to turn off.
154+
* Turn the specific LED off.
155+
* @param a The ::LEDEnum to turn off.
154156
*/
155-
void setLedOff(LED a);
157+
void setLedOff(LEDEnum a);
156158
/**
157-
* Turn the specific ::LED on.
158-
* @param a The ::LED to turn on.
159+
* Turn the specific LED on.
160+
* @param a The ::LEDEnum to turn on.
159161
*/
160-
void setLedOn(LED a);
162+
void setLedOn(LEDEnum a);
161163
/**
162-
* Toggle the specific ::LED.
163-
* @param a The ::LED to toggle.
164+
* Toggle the specific LED.
165+
* @param a The ::LEDEnum to toggle.
164166
*/
165-
void setLedToggle(LED a);
167+
void setLedToggle(LEDEnum a);
166168

167169
/**
168170
* Use this to set the Color using RGB values.
169171
* @param r,g,b RGB value.
170172
*/
171173
void moveSetBulb(uint8_t r, uint8_t g, uint8_t b);
172174
/**
173-
* Use this to set the color using the predefined colors in ::Colors.
175+
* Use this to set the color using the predefined colors in ::ColorsEnum.
174176
* @param color The desired color.
175177
*/
176-
void moveSetBulb(Colors color);
178+
void moveSetBulb(ColorsEnum color);
177179
/**
178180
* Set the rumble value inside the Move controller.
179181
* @param rumble The desired value in the range from 64-255.

0 commit comments

Comments
 (0)