Skip to content

Commit

Permalink
Modify data format
Browse files Browse the repository at this point in the history
  • Loading branch information
YanMinge committed Oct 8, 2016
1 parent 445097e commit 2b5e7bd
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
8 changes: 4 additions & 4 deletions makeblock/examples/Me_PS2/MePS2Test/MePS2Test.ino
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
* @brief Description: this file is sample code for MePS2.
*
* Function List:
* 1. int MePS2::MeAnalog(uint8_t button);
* 1. int16_t MePS2::MeAnalog(uint8_t button);
* 2. boolean MePS2::ButtonPressed(uint8_t button);
* 3. void MePS2::loop(void);
*
* \par History:
* <pre>
* `<Author>` `<Time>` `<Version>` `<Descr>`
* Scott wang 2016/09/18 1.0.0 Build the lib.
* Scott wang 2016/09/19 1.0.1 Revise the rocker.
* Scott 2016/09/23 1.0.2 Add BUTTON_L and BUTTON_R.
* Scott wang 2016/09/19 1.0.1 Revise the rocker.
* Scott 2016/09/23 1.0.2 Add BUTTON_L and BUTTON_R.
* </pre>
*/

Expand All @@ -31,7 +31,7 @@ void setup() {

void loop() {
MePS2.loop();
if (MePS2.ButtonPressed(UP))
if (MePS2.ButtonPressed(UP))
{
Serial.println("UP is pressed!");
}
Expand Down
30 changes: 21 additions & 9 deletions makeblock/src/MePS2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* \brief Driver for MePS2 handle device.
* @file MePS2.cpp
* @author MakeBlock
* @version V1.0.3
* @date 2016/09/23
* @version V1.0.4
* @date 2016/10/08
* @brief Driver for MePS2 device.
*
* \par Copyright
Expand All @@ -24,12 +24,12 @@
* This file is a drive for Me PS2 handle device, The MePS2 inherited the
* MeSerial class from SoftwareSerial.
*
*\par Method List:
* 1. int8_t MePS2::readBuffer(int16_t index);
* \par Method List:
* 1. uint8_t MePS2::readBuffer(int16_t index);
* 2. void MePS2::writeBuffer(int16_t index,uint8_t c);
* 3. void MePS2::readSerial(void);
* 4. boolean MePS2::readjoystick(void);
* 5. int MePS2::MeAnalog(uint8_t button);
* 5. int16_t MePS2::MeAnalog(uint8_t button);
* 6. boolean MePS2::ButtonPressed(uint8_t button);
* 7. void MePS2::loop(void);
*
Expand All @@ -39,7 +39,8 @@
* Scott wang 2016/09/18 1.0.0 Build the new lib.
* Scott 2016/09/20 1.0.1 Correct the receive error.
* Scott 2016/09/22 1.0.2 Correct the connect error.
* Scott 2016/09/23 1.0.3 Add BUTTON_L and BUTTON_R.
* Scott 2016/09/23 1.0.3 Add BUTTON_L and BUTTON_R.
* Mark Yan 2016/10/08 1.0.4 Modify data format.
* </pre>
*
* @example MePS2Test.ino
Expand Down Expand Up @@ -250,6 +251,7 @@ boolean MePS2::readjoystick(void)
* \param[in]
* Button
* \par Output
* None
* \par Return
* Analog value(-128~127). if none return 0.
Expand All @@ -258,17 +260,27 @@ boolean MePS2::readjoystick(void)
*/
int16_t MePS2::MeAnalog(uint8_t button)
{
int16_t result;
if (!_isReady)
{
return (-999);
return (ANALOG_ERROR);
}
else
{
if(button == MePS2_RX || button == MePS2_RY || button == MePS2_LX || button == MePS2_LY)
{
return (ps2_data_list[button]-128);
int16_t = 2*(ps2_data_list[button]-128);
if(result == -256)
{
result = -255;
}
else if(result == 254)
{
result == 255;
}
return result;
}
else
else
{
return SET_ANALOG_VALUE;
}
Expand Down
19 changes: 11 additions & 8 deletions makeblock/src/MePS2.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* \brief Driver for MePS2 handle device.
* @file MePS2.h
* @author MakeBlock
* @version V1.0.1
* @date 2016/09/23
* @version V1.0.4
* @date 2016/10/08
* @brief Header for MePS2.cpp module
*
* \par Copyright
Expand All @@ -25,19 +25,22 @@
* MeSerial class from SoftwareSerial.
*
* \par Method List:
* 1. int8_t MePS2::readBuffer(int16_t index);
* 1. uint8_t MePS2::readBuffer(int16_t index);
* 2. void MePS2::writeBuffer(int16_t index,uint8_t c);
* 3. void MePS2::readSerial(void);
* 4. boolean MePS2::readjoystick(void);
* 5. int MePS2::MeAnalog(uint8_t button);
* 5. int16_t MePS2::MeAnalog(uint8_t button);
* 6. boolean MePS2::ButtonPressed(uint8_t button);
* 7. void MePS2::loop(void);
*
* \par History:
* <pre>
* `<Author>` `<Time>` `<Version>` `<Descr>`
* Scott wang 2016/09/18 1.0.0 build the new lib.
* Scott 2016/09/23 1.0.1 Add BUTTON_L and BUTTON_R.
* Scott wang 2016/09/18 1.0.0 Build the new lib.
* Scott 2016/09/20 1.0.1 Correct the receive error.
* Scott 2016/09/22 1.0.2 Correct the connect error.
* Scott 2016/09/23 1.0.3 Add BUTTON_L and BUTTON_R.
* Mark Yan 2016/10/08 1.0.4 Modify data format.
* </pre>
*
*/
Expand Down Expand Up @@ -77,7 +80,7 @@
#define BUTTON_L 20
#define BUTTON_R 21
#define SET_ANALOG_VALUE 0
#define ANALOG_ERROR -999
#define ANALOG_ERROR 0

/**
* Class: MePS2
Expand Down

0 comments on commit 2b5e7bd

Please sign in to comment.