From 8138c9a431aee3b71898067f2189ea5893017e8b Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Thu, 12 Dec 2019 15:26:02 +0100 Subject: [PATCH 01/58] Remove led class --- include/Led.h | 15 --------------- src/Led.cpp | 13 ------------- 2 files changed, 28 deletions(-) delete mode 100644 include/Led.h delete mode 100644 src/Led.cpp diff --git a/include/Led.h b/include/Led.h deleted file mode 100644 index b8b024c..0000000 --- a/include/Led.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef Led_h -#define Led_h - -#include - -class Led { - public: - Led(int pin); - void Blink(int led_delay); - - private: - int output_pin; // Each Led instance has a output pin -}; - -#endif \ No newline at end of file diff --git a/src/Led.cpp b/src/Led.cpp deleted file mode 100644 index 56c00b3..0000000 --- a/src/Led.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include - -Led::Led(int pin) { - pinMode(pin, OUTPUT); // Specify that pin is a output - output_pin = pin; -} - -void Led::Blink(int led_delay) { - digitalWrite(output_pin, HIGH); // Set 3.3V at output_pin - delay(led_delay); // Wait half the period - digitalWrite(output_pin, LOW); // Pull output_pin to GND - delay(led_delay); // Wait half the period -} \ No newline at end of file From 1dbd99214f2833eef7fb1a88056701b86f8b7261 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Thu, 12 Dec 2019 15:26:11 +0100 Subject: [PATCH 02/58] Add clang format config --- .clang-format | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..4a88ce1 --- /dev/null +++ b/.clang-format @@ -0,0 +1,7 @@ +--- +BasedOnStyle: LLVM +--- +Language: Cpp +DerivePointerAlignment: false +PointerAlignment: Left +--- From a490fb2a4fb5fb7c94a9464dbe3a612fdb8a8c17 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Thu, 12 Dec 2019 18:03:24 +0100 Subject: [PATCH 03/58] Remove unused variable --- include/WirelessConnection.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/WirelessConnection.h b/include/WirelessConnection.h index 009065c..58fb733 100644 --- a/include/WirelessConnection.h +++ b/include/WirelessConnection.h @@ -22,7 +22,6 @@ void setupWiFi() WiFi.begin(ssid, password); Serial.print("\nConnecting to "); Serial.println(ssid); - uint8_t i = 0; while (WiFi.status() != WL_CONNECTED) { delay(500); From 5da50250d0f35775b8feb6881b5372e502aa337b Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Thu, 12 Dec 2019 18:06:12 +0100 Subject: [PATCH 04/58] WIP: Add first design new state machine --- include/Screen.h | 2 +- include/StateMachine.h | 155 ---- include/state.h | 58 ++ include/state_machine.h | 36 + src/Screen.cpp | 2 +- src/StateMachine.cpp | 1762 --------------------------------------- src/main.cpp | 57 +- src/state_machine.cpp | 45 + 8 files changed, 177 insertions(+), 1940 deletions(-) delete mode 100644 include/StateMachine.h create mode 100644 include/state.h create mode 100644 include/state_machine.h delete mode 100644 src/StateMachine.cpp create mode 100644 src/state_machine.cpp diff --git a/include/Screen.h b/include/Screen.h index e14d22c..d7c772f 100644 --- a/include/Screen.h +++ b/include/Screen.h @@ -39,7 +39,7 @@ class Screen void initialize(); void clear(); void reset(); - void draw_image(int addr_hi, int addr_lo); + void draw_image(word addr_hi, word addr_lo); private: SoftwareSerial * m_serial; diff --git a/include/StateMachine.h b/include/StateMachine.h deleted file mode 100644 index adeb519..0000000 --- a/include/StateMachine.h +++ /dev/null @@ -1,155 +0,0 @@ -#ifndef STATEMACHINE_H -#define STATEMACHINE_H - -#include -#include -#include -#include "SD_sector_addresses.h" - -enum class State { HomeSitStart, - HomeSitStartSelected, - HomeSitStartActivated, - StandUp, - StandUpSelected, - StandUpActivated, - TurnOffStart, - // TurnOffStartSelected, - // TurnOffStartActivated, - HomeStandStart, - HomeStandStartSelected, - HomeStandStartActivated, - - Sit, - SitSelected, - SitActivated, - HomeSit, - HomeSitSelected, - HomeSitActivated, - HomeStand, - HomeStandSelected, - HomeStandActivated, - TurnOff, - // TurnOffSelected, - // TurnOffActivated, - - Walk, - WalkSmall, - WalkNormal, - WalkLarge, - WalkSmallSelected, - WalkNormalSelected, - // WalkLargeSelected, - WalkSmallActivated, - WalkNormalActivated, - // WalkLargeActivated, - SingleStep, - SingleStepSmall, - SingleStepNormal, - SingleStepLarge, - SingleStepSmallSelected, - SingleStepNormalSelected, - // SingleStepLargeSelected, - SingleStepSmallActivated, - SingleStepNormalActivated, - // SingleStepLargeActivated, - SideStep, - SideStepLeft, - SideStepRight, - SideStepLeftNormal, - SideStepLeftNormalSelected, - SideStepLeftNormalActivated, - SideStepLeftSmall, - SideStepLeftSmallSelected, - SideStepLeftSmallActivated, - SideStepRightNormal, - SideStepRightNormalSelected, - SideStepRightNormalActivated, - SideStepRightSmall, - SideStepRightSmallSelected, - SideStepRightSmallActivated, - - Sofa, - SofaSit, - SofaSitSelected, - SofaSitActivated, - SofaStandUp, - SofaStandUpSelected, - SofaStandUpActivated, - - TiltedPath, - TiltedPathStartHomeToMin5, - TiltedPathStartHomeToMin5Selected, - TiltedPathStartHomeToMin5Activated, - FirstStartStep, - FirstStartStepActivated, - SecondStartStep, - SecondStartStepActivated, - HomeStandToMin10, - HomeStandToMin10Activated, - TiltedPathMiddleStep, - TiltedPathMiddleStepActivated, - HomeStandToMin5, - HomeStandToMin5Activated, - FirstEndStep, - FirstEndStepActivated, - SecondEndStep, - SecondEndStepActivated, - HomeForWalk25, - HomeForWalk25Activated, - - Stairs, - StairsUp, - StairsUpSelected, - StairsUpActivated, - StairsDown, - StairsDownSelected, - StairsDownActivated, - // StairsDownFinal, - // StairsDownFinalSelected, - // StairsDownFinalActivated, - - WalkObstacle, - WalkObstacleSmall, - WalkObstacleNormal, - WalkObstacleLarge, - WalkObstacleSmallSelected, // same image as WalkSmallSelected - WalkObstacleNormalSelected, // same image as WalkNormalSelected - // WalkObstacleLargeSelected, // same image as WalkLargeSelected - WalkObstacleSmallActivated, // same image as WalkSmallActivated - WalkObstacleNormalActivated, // same image as WalkNormalActivated - // WalkObstacleLargeActivated, // same image as WalkLargeActivated - SingleStepObstacle, - SingleStepObstacleSmall, - SingleStepObstacleNormal, - SingleStepObstacleLarge, - SingleStepObstacleSmallSelected, // same image as SingleStepSmallSelected - SingleStepObstacleNormalSelected, // same image as SingleStepNormalSelected - // SingleStepObstacleLargeSelected, // same image as SignleStepLargeSelected - SingleStepObstacleSmallActivated, // same image as SingleStepSmallActivated - SingleStepObstacleNormalActivated}; // same image as SingleStepNormalActivated - // SingleStepObstacleLargeActivated}; // same image as SingleStepLargeActivated - - - -class StateMachine -{ -private: - State currentState; - State rememberStateWIB; - State rememberStateSit; - State rememberStateObstacle; - State rememberStateObstacleWIB; - std::map stateToGaitMapping; - -public: - StateMachine(); - void updateState(String joystickState = "NEUTRAL", String joystickPress = "NEUTRAL", String rockerState = "NEUTRAL", String triggerPress = "NEUTRAL"); - int * getScreenImage(); - State getCurrentState(); - std::string getGaitNameOfState(State state); -}; - - - - -#endif // STATEMACHINE_H \ No newline at end of file diff --git a/include/state.h b/include/state.h new file mode 100644 index 0000000..492b413 --- /dev/null +++ b/include/state.h @@ -0,0 +1,58 @@ +#ifndef INPUT_DEVICE_STATE_H +#define INPUT_DEVICE_STATE_H +#include + +#include + +class AbstractState { +public: + virtual AbstractState* left() = 0; + virtual AbstractState* right() = 0; + virtual AbstractState* up() = 0; + virtual AbstractState* down() = 0; + + virtual AbstractState* back() = 0; + virtual AbstractState* select() = 0; + virtual AbstractState* activate() = 0; +}; + +class State { +public: + State(const word address_hi = 0, const word address_lo = 0, + const std::string& gait = "") + : gait_(gait), image_address_hi_(address_hi), + image_address_lo_(address_lo), left_(this), right_(this), up_(this), + down_(this) {} + + const std::string& getGaitName() const { return this->gait_; } + + void getImage(word& image_address_hi, word& image_address_lo) const { + image_address_hi = this->image_address_hi_; + image_address_lo = this->image_address_lo_; + }; + + State* left() const { return this->left_; } + State* right() const { return this->right_; } + State* up() const { return this->up_; } + State* down() const { return this->down_; } + + State* back() const { return this->back_; } + State* select() const { return this->select_; } + State* activate() const { return this->activate_; } + +private: + std::string gait_; + const word image_address_hi_; + const word image_address_lo_; + + State* left_ = nullptr; + State* right_ = nullptr; + State* up_ = nullptr; + State* down_ = nullptr; + + State* back_ = nullptr; + State* select_ = nullptr; + State* activate_ = nullptr; +}; + +#endif // INPUT_DEVICE_STATE_H diff --git a/include/state_machine.h b/include/state_machine.h new file mode 100644 index 0000000..eb4f2fb --- /dev/null +++ b/include/state_machine.h @@ -0,0 +1,36 @@ +#ifndef INPUT_DEVICE_STATE_MACHINE_H +#define INPUT_DEVICE_STATE_MACHINE_H +#include "SD_sector_addresses.h" +#include "state.h" + +#include + +#include +#include +#include + +class StateMachine { +public: + StateMachine(); + + const std::string& getCurrentGaitName() const; + + void getCurrentImage(word& address_hi, word& address_lo) const; + + bool left(); + bool right(); + bool up(); + bool down(); + + bool back(); + bool select(); + bool activate(); + +private: + bool setCurrentState(State* new_state); + + std::vector states_; + State* current_state_ = nullptr; +}; + +#endif // INPUT_DEVICE_STATE_MACHINE_H diff --git a/src/Screen.cpp b/src/Screen.cpp index 63abd21..a217397 100644 --- a/src/Screen.cpp +++ b/src/Screen.cpp @@ -43,7 +43,7 @@ void Screen::reset(){ sleep(3); }; -void Screen::draw_image(int addr_hi, int addr_lo){ +void Screen::draw_image(word addr_hi, word addr_lo){ if((millis() - m_lastDrawTime)*1000 > m_waitTimeUs){ m_screen->media_SetSector(addr_hi, addr_lo); m_screen->media_Image(0,0); diff --git a/src/StateMachine.cpp b/src/StateMachine.cpp deleted file mode 100644 index c4edd04..0000000 --- a/src/StateMachine.cpp +++ /dev/null @@ -1,1762 +0,0 @@ -#include - -// Constructor -StateMachine::StateMachine() -{ - this->currentState = State::HomeSitStart; - this->rememberStateObstacle = State::Sofa; - this->rememberStateObstacleWIB = State::TiltedPath; - stateToGaitMapping[State::HomeSitStartActivated] = "home_sit"; - stateToGaitMapping[State::StandUpActivated] = "gait_stand"; - stateToGaitMapping[State::HomeStandStartActivated] = "home_stand"; - - stateToGaitMapping[State::WalkNormalActivated] = "gait_walk"; - stateToGaitMapping[State::WalkSmallActivated] = "gait_walk_small"; - stateToGaitMapping[State::SingleStepNormalActivated] = "gait_single_step_normal"; - stateToGaitMapping[State::SingleStepSmallActivated] = "gait_single_step_small"; - - stateToGaitMapping[State::SitActivated] = "gait_sit"; - stateToGaitMapping[State::HomeSitActivated] = "home_sit"; - stateToGaitMapping[State::HomeStandActivated] = "home_stand"; - - stateToGaitMapping[State::WalkObstacleNormalActivated] = "gait_walk"; - stateToGaitMapping[State::WalkObstacleSmallActivated] = "gait_walk_small"; - stateToGaitMapping[State::SingleStepObstacleNormalActivated] = "gait_single_step_normal"; - stateToGaitMapping[State::SingleStepObstacleSmallActivated] = "gait_single_step_small"; - - stateToGaitMapping[State::SofaSitActivated] = "gait_sofa_sit"; - stateToGaitMapping[State::SofaStandUpActivated] = "gait_sofa_stand"; - - stateToGaitMapping[State::StairsUpActivated] = "gait_stairs_up"; - stateToGaitMapping[State::StairsDownActivated] = "gait_stairs_down"; - - stateToGaitMapping[State::SideStepLeftNormalActivated] = "gait_side_step_left"; - stateToGaitMapping[State::SideStepRightNormalActivated] = "gait_side_step_right"; - stateToGaitMapping[State::SideStepLeftSmallActivated] = "gait_side_step_left_small"; - stateToGaitMapping[State::SideStepRightSmallActivated] = "gait_side_step_right_small"; - - stateToGaitMapping[State::TiltedPathStartHomeToMin5Activated] = "gait_set_ankle_from_2_5_to_min5"; - stateToGaitMapping[State::FirstStartStepActivated] = "gait_tilted_path_first_starting_step"; - stateToGaitMapping[State::SecondStartStepActivated] = "gait_tilted_path_second_starting_step"; - stateToGaitMapping[State::HomeStandToMin10Activated] = "gait_set_ankle_from_min5_to_min10"; - stateToGaitMapping[State::TiltedPathMiddleStepActivated] = "gait_tilted_path_middle_step"; - stateToGaitMapping[State::HomeStandToMin5Activated] = "gait_set_ankle_from_min10_to_min5"; - stateToGaitMapping[State::FirstEndStepActivated] = "gait_tilted_path_first_ending_step"; - stateToGaitMapping[State::SecondEndStepActivated] = "gait_tilted_path_second_ending_step"; - stateToGaitMapping[State::HomeForWalk25Activated] = "gait_set_ankle_from_min5_to_2_5"; -} - -State StateMachine::getCurrentState(){ - return this->currentState; -} - -std::string StateMachine::getGaitNameOfState(State state){ - if(stateToGaitMapping.count(state) > 0){ - return stateToGaitMapping[state]; - } - return ""; -} - -// Updates the current state based on the button inputs -void StateMachine::updateState(String joystickState, String joystickPress, String rockerState, String triggerPress){ - switch (this->currentState) - { - //Start menu - //Scroll - case State::HomeSitStart: - if(joystickState == "RIGHT"){ - this->currentState = State::StandUp; - } - else if(joystickState == "LEFT"){ - this->currentState = State::TurnOffStart; - } - else if(joystickPress == "PUSH"){ - this->currentState = State::HomeSitStartSelected; - } - break; - case State::StandUp: - if(joystickState == "RIGHT"){ - this->currentState = State::HomeStandStart; - } - else if(joystickState == "LEFT"){ - this->currentState = State::HomeSitStart; - } - else if(joystickPress == "PUSH"){ - this->currentState = State::StandUpSelected; - } - break; - case State::HomeStandStart: - if(joystickState == "RIGHT"){ - this->currentState = State::TurnOffStart; - } - else if(joystickState == "LEFT"){ - this->currentState = State::StandUp; - } - else if(joystickPress == "PUSH"){ - this->currentState = State::HomeStandStartSelected; - } - break; - case State::TurnOffStart: - if(joystickState =="RIGHT"){ - this->currentState = State::HomeSitStart; - } - else if(joystickState == "LEFT"){ - this->currentState = State::HomeStandStart; - } - break; - - //Selected - case State::HomeSitStartSelected: - if(triggerPress == "PUSH"){ - this->currentState = State::HomeSitStartActivated; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::HomeSitStart; - } - break; - case State::StandUpSelected: - if(triggerPress == "PUSH"){ - this->currentState = State::StandUpActivated; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::StandUp; - } - break; - case State::HomeStandStartSelected: - if(triggerPress == "PUSH"){ - this->currentState = State::HomeStandStartActivated; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::HomeStandStart; - } - break; - - - //Activated - case State::HomeSitStartActivated: - if(triggerPress == "EXIT_GAIT"){ - this->currentState = State::StandUp; //Automatically - } - break; - case State::StandUpActivated: - if(triggerPress == "EXIT_GAIT"){ - this->currentState = State::Walk; //Automatically - } - break; - case State::HomeStandStartActivated: - if(triggerPress == "EXIT_GAIT"){ - this->currentState = State::Walk; //Automatically - } - break; - - - //Sit menu - //Scroll - case State::Sit: - if(joystickState == "RIGHT"){ - this->currentState = State::HomeSit; - } - else if(joystickState == "LEFT"){ - this->currentState = State::TurnOff; - } - else if(joystickPress == "PUSH"){ - this->currentState = State::SitSelected; - } - else if(joystickState == "UP"){ - this->currentState = State::Walk; - - } - break; - - case State::HomeSit: - if(joystickState == "RIGHT"){ - this->currentState = State::HomeStand; - } - else if(joystickState == "LEFT"){ - this->currentState = State::Sit; - } - else if(joystickPress == "PUSH"){ - this->currentState = State::HomeSitSelected; - } - else if(joystickState == "UP"){ - this->currentState = State::Walk; - } - break; - - case State::HomeStand: - if(joystickState == "RIGHT"){ - this->currentState = State::TurnOff; - } - else if(joystickState == "LEFT"){ - this->currentState = State::HomeSit; - } - else if(joystickPress == "PUSH"){ - this->currentState = State::HomeStandSelected; - } - else if(joystickState == "UP"){ - this->currentState = State::Walk; - } - break; - case State::TurnOff: - if(joystickState == "RIGHT"){ - this->currentState = State::Sit; - } - else if(joystickState =="LEFT"){ - this->currentState = State::HomeStand; - } - else if(joystickState == "UP"){ - this->currentState = State::Walk; - } - break; - - //Selected - case State::SitSelected: - if(triggerPress == "PUSH"){ - this->currentState = State::SitActivated; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::Sit; - } - break; - case State::HomeSitSelected: - if(triggerPress == "PUSH"){ - this->currentState = State::HomeSitActivated; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::HomeSit; - } - break; - - case State::HomeStandSelected: - if(triggerPress == "PUSH"){ - this->currentState = State::HomeStandActivated; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::HomeStand; - } - break; - - - //Activated - case State::SitActivated: - if(triggerPress == "EXIT_GAIT"){ - this->currentState = State::StandUp; //Automatically - } - break; - case State::HomeSitActivated: - if(triggerPress = "EXIT_GAIT"){ - this->currentState = State::StandUp; //Automatically - } - break; - case State::HomeStandActivated: - if(triggerPress = "EXIT_GAIT"){ - this->currentState = State::Walk; //Automatically - } - break; - - - //WIB menu - //Scroll - case State::Walk: - if(joystickState == "RIGHT"){ - this->currentState = State::SingleStep; - } - else if(joystickState == "LEFT"){ - this->currentState = State::SideStep; - } - else if(joystickPress == "PUSH"){ - this->currentState = State::WalkNormal; - } - else if(joystickState =="UP"){ - this->currentState = rememberStateObstacle; - } - else if(joystickState == "DOWN"){ - this->currentState = State::Sit; - } - break; - case State::SingleStep: - if(joystickState == "RIGHT"){ - this->currentState = State::SideStep; - } - else if(joystickState == "LEFT"){ - this->currentState = State::Walk; - } - else if(joystickPress == "PUSH"){ - this->currentState = State::SingleStepNormal; - } - else if(joystickState =="UP"){ - this->currentState = rememberStateObstacle; - } - else if(joystickState == "DOWN"){ - this->currentState = State::Sit; - } - break; - case State::SideStep: - if(joystickState == "RIGHT"){ - this->currentState = State::Walk; - } - else if(joystickState == "LEFT"){ - this->currentState = State::SingleStep; - } - else if(joystickPress == "PUSH"){ - this->currentState = State::SideStepLeft; - } - else if(joystickState =="UP"){ - this->currentState = rememberStateObstacle; - } - else if(joystickState == "DOWN"){ - this->currentState = State::Sit; - } - break; - - //Choose step size - case State::WalkNormal: - if(rockerState == "DOWN"){ - this->currentState = State::WalkSmall; - } - else if(rockerState =="UP"){ - this->currentState = State::WalkLarge; - } - else if(joystickState =="RIGHT"){ - this->currentState = State::WalkLarge; - } - else if(joystickState =="LEFT"){ - this->currentState = State::WalkSmall; - } - else if(joystickPress == "PUSH"){ - this->currentState = State::WalkNormalSelected; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::Walk; - } - else if(joystickState =="UP"){ - this->currentState = rememberStateObstacle; - } - else if(joystickState == "DOWN"){ - this->currentState = State::Sit; - } - break; - case State::WalkSmall: - if(rockerState =="UP"){ - this->currentState = State::WalkNormal; - } - else if (joystickState == "RIGHT"){ - this->currentState = State::WalkNormal; - } - else if(joystickPress == "PUSH"){ - this->currentState = State::WalkSmallSelected; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::Walk; - } - else if(joystickState =="UP"){ - this->currentState = rememberStateObstacle; - } - else if(joystickState == "DOWN"){ - this->currentState = State::Sit; - } - break; - case State::WalkLarge: - if(rockerState =="DOWN"){ - this->currentState = State::WalkNormal; - } - else if (joystickState == "LEFT"){ - this->currentState = State::WalkNormal; - } - // else if(joystickPress == "PUSH"){ - // this->currentState = State::WalkLargeSelected; - // } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::Walk; - } - else if(joystickState =="UP"){ - this->currentState = rememberStateObstacle; - } - else if(joystickState == "DOWN"){ - this->currentState = State::Sit; - } - break; - case State::SingleStepNormal: - if(rockerState == "DOWN"){ - this->currentState = State::SingleStepSmall; - } - else if(joystickState == "LEFT"){ - this->currentState = State::SingleStepSmall; - } - else if(rockerState =="UP"){ - this->currentState = State::SingleStepLarge; - } - else if(joystickState == "RIGHT"){ - this->currentState = State::SingleStepLarge; - } - else if(joystickPress == "PUSH"){ - this->currentState = State::SingleStepNormalSelected; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::SingleStep; - } - else if(joystickState =="UP"){ - this->currentState = rememberStateObstacle; - } - else if(joystickState == "DOWN"){ - this->currentState = State::Sit; - } - break; - case State::SingleStepSmall: - if(rockerState =="UP"){ - this->currentState = State::SingleStepNormal; - } - else if(joystickState == "RIGHT"){ - this->currentState = State::SingleStepNormal; - } - else if(joystickPress == "PUSH"){ - this->currentState = State::SingleStepSmallSelected; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::SingleStep; - } - else if(joystickState =="UP"){ - this->currentState = rememberStateObstacle; - } - else if(joystickState == "DOWN"){ - this->currentState = State::Sit; - } - break; - case State::SingleStepLarge: - if(rockerState =="DOWN"){ - this->currentState = State::SingleStepNormal; - } - else if(joystickState == "LEFT"){ - this->currentState = State::SingleStepNormal; - } - // else if(joystickPress == "PUSH"){ - // this->currentState = State::SingleStepLargeSelected; - // } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::SingleStep; - } - else if(joystickState =="UP"){ - this->currentState = rememberStateObstacle; - } - else if(joystickState == "DOWN"){ - this->currentState = State::Sit; - } - break; - case State::SideStepLeft: - if (joystickState == "LEFT"){ - this->currentState = State::SideStepRight; - } - else if (joystickState == "RIGHT"){ - this->currentState = State::SideStepRight; - } - else if(joystickPress == "PUSH"){ - this->currentState = State::SideStepLeftNormal; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::SideStep; - } - else if(joystickState =="UP"){ - this->currentState = rememberStateObstacle; - } - else if(joystickState == "DOWN"){ - this->currentState = State::Sit; - } - break; - - case State::SideStepRight: - if (joystickState == "LEFT"){ - this->currentState = State::SideStepLeft; - } - else if (joystickState == "RIGHT"){ - this->currentState = State::SideStepLeft; - } - else if(joystickPress == "PUSH"){ - this->currentState = State::SideStepRightNormal; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::SideStep; - } - else if(joystickState =="UP"){ - this->currentState = rememberStateObstacle; - } - else if(joystickState == "DOWN"){ - this->currentState = State::Sit; - } - break; - - case State::SideStepLeftNormal: - if (joystickState == "LEFT"){ - this->currentState = State::SideStepLeftSmall; - } - else if (joystickState == "RIGHT"){ - this->currentState = State::SideStepLeftSmall; - } - else if(joystickPress == "PUSH"){ - this->currentState = State::SideStepLeftNormalSelected; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::SideStepLeft; - } - break; - - case State::SideStepLeftSmall: - if (joystickState == "LEFT"){ - this->currentState = State::SideStepLeftNormal; - } - else if (joystickState == "RIGHT"){ - this->currentState = State::SideStepLeftNormal; - } - else if(joystickPress == "PUSH"){ - this->currentState = State::SideStepLeftSmallSelected; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::SideStepLeft; - } - break; - - case State::SideStepRightNormal: - if (joystickState == "LEFT"){ - this->currentState = State::SideStepRightSmall; - } - else if (joystickState == "RIGHT"){ - this->currentState = State::SideStepRightSmall; - } - else if(joystickPress == "PUSH"){ - this->currentState = State::SideStepRightNormalSelected; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::SideStepRight; - } - break; - - case State::SideStepRightSmall: - if (joystickState == "LEFT"){ - this->currentState = State::SideStepRightNormal; - } - else if (joystickState == "RIGHT"){ - this->currentState = State::SideStepRightNormal; - } - else if(joystickPress == "PUSH"){ - this->currentState = State::SideStepRightSmallSelected; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::SideStepRight; - } - break; - - - - //Selected - case State::WalkSmallSelected: - if(triggerPress == "PUSH"){ - this->currentState = State::WalkSmallActivated; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::WalkSmall; - } - break; - case State::WalkNormalSelected: - if(triggerPress == "PUSH"){ - this->currentState = State::WalkNormalActivated; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::WalkNormal; - } - break; - // case State::WalkLargeSelected: - // if(triggerPress == "PUSH"){ - // this->currentState = State::WalkLargeActivated; - // } - // else if(joystickPress == "DOUBLE"){ - // this->currentState = State::WalkLarge; - // } - // break; - case State::SingleStepSmallSelected: - if(triggerPress == "PUSH"){ - this->currentState = State::SingleStepSmallActivated; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::SingleStepSmall; - } - break; - case State::SingleStepNormalSelected: - if(triggerPress == "PUSH"){ - this->currentState = State::SingleStepNormalActivated; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::SingleStepNormal; - } - break; - // case State::SingleStepLargeSelected: - // if(triggerPress == "PUSH"){ - // this->currentState = State::SingleStepLargeActivated; - // } - // else if(joystickPress == "DOUBLE"){ - // this->currentState = State::SingleStepLarge; - // } - // break; - case State::SideStepLeftNormalSelected: - if(triggerPress == "PUSH"){ - this->currentState = State::SideStepLeftNormalActivated; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::SideStepLeftNormal; - } - break; - - case State::SideStepLeftSmallSelected: - if(triggerPress == "PUSH"){ - this->currentState = State::SideStepLeftSmallActivated; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::SideStepLeftSmall; - } - break; - - case State::SideStepRightNormalSelected: - if(triggerPress == "PUSH"){ - this->currentState = State::SideStepRightNormalActivated; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::SideStepRightNormal; - } - break; - - case State::SideStepRightSmallSelected: - if(triggerPress == "PUSH"){ - this->currentState = State::SideStepRightSmallActivated; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::SideStepRightSmall; - } - break; - - - //Activated - case State::WalkSmallActivated: - if(triggerPress == "EXIT_GAIT"){ - this->currentState = State::Walk; //Automatically - } - break; - case State::WalkNormalActivated: - if(triggerPress == "EXIT_GAIT"){ - this->currentState = State::Walk; //Automatically - } - break; - // case State::WalkLargeActivated: - // if(triggerPress == "EXIT_GAIT"){ - // this->currentState = State::Walk; //Automatically - // } - // break; - case State::SingleStepSmallActivated: - if(triggerPress == "EXIT_GAIT"){ - this->currentState = State::SingleStep; //Automatically - } - break; - case State::SingleStepNormalActivated: - if(triggerPress == "EXIT_GAIT"){ - this->currentState = State::SingleStep; //Automatically - } - break; - // case State::SingleStepLargeActivated: - // if(triggerPress == "EXIT_GAIT"){ - // this->currentState = State::SingleStep; //Automatically - // } - // break; - case State::SideStepLeftNormalActivated: - if(triggerPress == "EXIT_GAIT"){ - this->currentState = State::SideStep; //Automatically - } - break; - case State::SideStepLeftSmallActivated: - if(triggerPress == "EXIT_GAIT"){ - this->currentState = State::SideStep; //Automatically - } - break; - case State::SideStepRightSmallActivated: - if(triggerPress == "EXIT_GAIT"){ - this->currentState = State::SideStep; //Automatically - } - break; - case State::SideStepRightNormalActivated: - if(triggerPress == "EXIT_GAIT"){ - this->currentState = State::SideStep; //Automatically - } - break; - - //Obstacle menu - //Scroll - case State::Sofa: - if(joystickState == "RIGHT"){ - this->currentState = State::Stairs; - } - else if(joystickState == "LEFT"){ - this->currentState = State::TiltedPath; - } - else if(joystickPress == "PUSH"){ - this->currentState = State::SofaSit; - } - else if(joystickState =="DOWN"){ - this->rememberStateObstacle = currentState; - this->currentState = State::Walk; - } - break; - - case State::Stairs: - if(joystickState == "RIGHT"){ - this->currentState = State::TiltedPath; - } - else if(joystickState == "LEFT"){ - this->currentState = State::Sofa; - } - else if(joystickPress == "PUSH"){ - this->currentState = State::StairsUp; - } - else if(joystickState =="DOWN"){ - this->rememberStateObstacle = currentState; - this->currentState = State::Walk; - } - break; - - case State::TiltedPath: - if(joystickState == "RIGHT"){ - this->currentState = State::Sofa; - } - else if(joystickState == "LEFT"){ - this->currentState = State::Stairs; - } - else if(joystickPress == "PUSH"){ - this->currentState = State::TiltedPathStartHomeToMin5; - } - else if(joystickState =="DOWN"){ - this->rememberStateObstacle = currentState; - this->currentState = State::Walk; - } - break; - - - //Submenu obstacles - //Sofa - case State::SofaSit: - if(joystickPress == "PUSH"){ - this->currentState = State::SofaSitSelected; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::Sofa; - } - else if(joystickState == "RIGHT"){ - this->currentState = State::SofaStandUp; - } - else if(joystickState == "LEFT"){ - this->currentState = State::SofaStandUp; - } - break; - - case State::SofaStandUp: - if(triggerPress == "PUSH"){ - this->currentState = State::SofaStandUpActivated; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::Sofa; - } - else if(joystickState == "RIGHT"){ - this->currentState = State::SofaSit; - } - else if(joystickState == "LEFT"){ - this->currentState = State::SofaSit; - } - break; - - case State::SofaSitSelected: - if(triggerPress == "PUSH"){ - this->currentState = State::SofaSitActivated; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::SofaSit; - } - break; - - case State::SofaSitActivated: - if(triggerPress == "EXIT_GAIT"){ - this->currentState = State::SofaStandUp; //Automatically - } - break; - - // case State::SofaStandUpSelected: - // if(triggerPress == "PUSH"){ - // this->currentState = State::SofaStandUpActivated; - // } - // else if(joystickPress == "DOUBLE"){ - // this->currentState = State::SofaStandUp; - // } - // break; - - case State::SofaStandUpActivated: - if(triggerPress == "EXIT_GAIT"){ - this->currentState = State::WalkObstacle; //Automatically - this->rememberStateObstacleWIB = State::Stairs; - } - break; - - - - - //Stairs - case State::StairsUp: - if(joystickPress == "PUSH"){ - this->currentState = State::StairsUpSelected; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::Stairs; - } - else if(joystickState == "RIGHT"){ - this->currentState = State::StairsDown; - } - else if(joystickState == "LEFT"){ - this->currentState = State::StairsDown; // old: this->currentState = State::StairsDownFinal; - } - break; - - case State::StairsDown: - if(joystickPress == "PUSH"){ - this->currentState = State::StairsDownSelected; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::Stairs; - } - else if(joystickState == "RIGHT"){ - this->currentState = State::StairsUp; // old: this->currentState = State::StairsDownFinal; - } - else if(joystickState == "LEFT"){ - this->currentState = State::StairsUp; - } - break; - - case State::StairsUpSelected: - if(triggerPress == "PUSH"){ - this->currentState = State::StairsUpActivated; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::StairsUp; - } - break; - - case State::StairsUpActivated: - if(triggerPress == "EXIT_GAIT"){ - this->rememberStateObstacleWIB = State::StairsDown; - this->currentState = State::WalkObstacle; //Automatically - } - break; - case State::StairsDownSelected: - if(triggerPress == "PUSH"){ - this->currentState = State::StairsDownActivated; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::StairsDown; - } - break; - - case State::StairsDownActivated: - if(triggerPress == "EXIT_GAIT"){ - this->currentState = State::WalkObstacle; //Automatically - this->rememberStateObstacleWIB = State::TiltedPath; - } - break; - // case State::StairsDownFinalSelected: - // if(triggerPress == "PUSH"){ - // this->currentState = State::StairsDownFinalActivated; - // } - // else if(joystickPress == "DOUBLE"){ - // this->currentState = State::StairsDownFinal; - // } - // break; - // case State::StairsDownFinalActivated: - // if(triggerPress == "EXIT_GAIT"){ - // this->rememberStateObstacleWIB = State::TiltedPath; - // this->currentState = State::WalkObstacle; //Automatically - // } - // break; - - - - // case State::StairsDownFinal: - // if(joystickPress == "PUSH"){ - // this->currentState = State::StairsDownFinalSelected; - // } - // else if(joystickPress == "DOUBLE"){ - // this->currentState = State::Stairs; - // } - // else if(joystickState == "RIGHT"){ - // this->currentState = State::StairsUp; - // } - // else if(joystickState == "LEFT"){ - // this->currentState = State::StairsDown; - // } - // break; - - //Selected and activated submenus - - //Tilted Path - case State::TiltedPathStartHomeToMin5: // first home ankles to -5 before going on the tilted path - if(joystickPress == "PUSH"){ - this->currentState = State::TiltedPathStartHomeToMin5Selected; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::TiltedPath; - } - else if(joystickState == "LEFT"){ - this->currentState = State::HomeForWalk25; - } - else if(joystickState == "RIGHT"){ - this->currentState = State::FirstStartStep; - } - break; - - case State::TiltedPathStartHomeToMin5Selected: // we want the first gait to be selected & activated, to others only need to be triggered - if(triggerPress == "PUSH"){ - this->currentState = State::TiltedPathStartHomeToMin5Activated; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::TiltedPathStartHomeToMin5; - } - break; - - case State::TiltedPathStartHomeToMin5Activated: - if(triggerPress == "EXIT_GAIT"){ - this->currentState = State::FirstStartStep; //Automatically - } - break; - - - case State::FirstStartStep: // first step on the tilted path - if(triggerPress == "PUSH"){ - this->currentState = State::FirstStartStepActivated; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::TiltedPath; - } - else if(joystickState == "LEFT"){ - this->currentState = State::TiltedPathStartHomeToMin5; - } - else if(joystickState == "RIGHT"){ - this->currentState = State::SecondStartStep; - } - break; - - case State::FirstStartStepActivated: - if(triggerPress == "EXIT_GAIT"){ - this->currentState = State::SecondStartStep; //Automatically - } - break; - - - - case State::SecondStartStep: // second step on tilted path, after this gait we will stand on the middle part - if(triggerPress == "PUSH"){ - this->currentState = State::SecondStartStepActivated; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::TiltedPath; - } - else if(joystickState == "LEFT"){ - this->currentState = State::FirstStartStep; - } - else if(joystickState == "RIGHT"){ - this->currentState = State::HomeStandToMin10; - } - break; - - case State::SecondStartStepActivated: - if(triggerPress == "EXIT_GAIT"){ - this->currentState = State::HomeStandToMin10; //Automatically - } - break; - - - case State::HomeStandToMin10: // before doing side steps on the middle part we have to home to an ankle position -10 - if(triggerPress == "PUSH"){ - this->currentState = State::HomeStandToMin10Activated; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::TiltedPath; - } - else if(joystickState == "LEFT"){ - this->currentState = State::SecondStartStep; - } - else if(joystickState == "RIGHT"){ - this->currentState = State::TiltedPathMiddleStep; - } - break; - - case State::HomeStandToMin10Activated: - if(triggerPress == "EXIT_GAIT"){ - this->currentState = State::TiltedPathMiddleStep; //Automatically - } - break; - - - case State::TiltedPathMiddleStep: // after activating a side step for the middle part you can do this action again, when you are at the end you have to push the joystick to the right. - if(triggerPress == "PUSH"){ - this->currentState = State::TiltedPathMiddleStepActivated; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::TiltedPath; - } - else if(joystickState == "LEFT"){ - this->currentState = State::HomeStandToMin10; - } - else if(joystickState == "RIGHT"){ - this->currentState = State::HomeStandToMin5; - } - break; - - case State::TiltedPathMiddleStepActivated: - if(triggerPress == "EXIT_GAIT"){ - this->currentState = State::TiltedPathMiddleStep; //Automatically - } - break; - - case State::HomeStandToMin5: // before going off the tilted path we have to home ankles to -5 - if(triggerPress == "PUSH"){ - this->currentState = State::HomeStandToMin5Activated; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::TiltedPath; - } - else if(joystickState == "LEFT"){ - this->currentState = State::TiltedPathMiddleStep; - } - else if(joystickState == "RIGHT"){ - this->currentState = State::FirstEndStep; - } - break; - - case State::HomeStandToMin5Activated: - if(triggerPress == "EXIT_GAIT"){ - this->currentState = State::FirstEndStep; //Automatically - } - break; - - case State::FirstEndStep: // first step for the end of the tilted path - if(triggerPress == "PUSH"){ - this->currentState = State::FirstEndStepActivated; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::TiltedPath; - } - else if(joystickState == "LEFT"){ - this->currentState = State::HomeStandToMin5; - } - else if(joystickState == "RIGHT"){ - this->currentState = State::SecondEndStep; - } - break; - - case State::FirstEndStepActivated: - if(triggerPress == "EXIT_GAIT"){ - this->currentState = State::SecondEndStep; //Automatically - } - break; - - case State::SecondEndStep: // second step for the end of the tilted path - if(triggerPress == "PUSH"){ - this->currentState = State::SecondEndStepActivated; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::TiltedPath; - } - else if(joystickState == "LEFT"){ - this->currentState = State::FirstEndStep; - } - else if(joystickState == "RIGHT"){ - this->currentState = State::HomeForWalk25; - } - break; - - case State::SecondEndStepActivated: - if(triggerPress == "EXIT_GAIT"){ - this->currentState = State::HomeForWalk25; //Automatically - } - break; - - case State::HomeForWalk25: // We are now finished with the tilted path, but before we can walk we have to set ankles back to 2.5 for walking -> home. - if(triggerPress == "PUSH"){ - this->currentState = State::HomeForWalk25Activated; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::TiltedPath; - } - else if(joystickState == "LEFT"){ - this->currentState = State::SecondEndStep; - } - else if(joystickState == "RIGHT"){ - this->currentState = State::TiltedPathStartHomeToMin5; - } - break; - - case State::HomeForWalk25Activated: - if(triggerPress == "EXIT_GAIT"){ - this->currentState = State::WalkObstacle; //Automatically - this->rememberStateObstacleWIB = State::Sofa; - } - break; - - - //Walk in between obstacles - case State::WalkObstacle: - if(joystickPress == "PUSH"){ - this->currentState = State::WalkObstacleNormal; - } - else if(joystickState == "RIGHT"){ - this->currentState = State::SingleStepObstacle; - } - break; - case State::SingleStepObstacle: - if(joystickPress == "PUSH"){ - this->currentState = State::SingleStepObstacleNormal; - } - else if(joystickState == "RIGHT"){ - this->currentState = rememberStateObstacleWIB; - } - else if(joystickState == "LEFT"){ - this->currentState = State::WalkObstacle; - } - break; - - //Choose step size - case State::WalkObstacleNormal: - if(rockerState == "DOWN"){ - this->currentState = State::WalkObstacleSmall; - } - else if(joystickState == "LEFT"){ - this->currentState = State::WalkObstacleSmall; - } - else if(rockerState =="UP"){ - this->currentState = State::WalkObstacleLarge; - } - else if(joystickState == "RIGHT"){ - this->currentState = State::WalkObstacleLarge; - } - else if(joystickPress == "PUSH"){ - this->currentState = State::WalkObstacleNormalSelected; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::WalkObstacle; - } - break; - case State::WalkObstacleSmall: - if(rockerState =="UP"){ - this->currentState = State::WalkObstacleNormal; - } - else if(joystickState == "RIGHT"){ - this->currentState = State::WalkObstacleNormal; - } - else if(joystickPress == "PUSH"){ - this->currentState = State::WalkObstacleSmallSelected; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::WalkObstacle; - } - break; - case State::WalkObstacleLarge: - if(rockerState =="DOWN"){ - this->currentState = State::WalkObstacleNormal; - } - else if(joystickState == "LEFT"){ - this->currentState = State::WalkObstacleNormal; - } - // else if(joystickPress == "PUSH"){ - // this->currentState = State::WalkObstacleLargeSelected; - // } - else if(joystickState == "DOUBLE"){ - this->currentState = State::WalkObstacle; - } - break; - case State::SingleStepObstacleNormal: - if(rockerState == "DOWN"){ - this->currentState = State::SingleStepObstacleSmall; - } - else if(rockerState =="UP"){ - this->currentState = State::SingleStepObstacleLarge; - } - else if(joystickState == "LEFT"){ - this->currentState = State::SingleStepObstacleSmall; - } - else if(joystickState == "RIGHT"){ - this->currentState = State::SingleStepObstacleLarge; - } - else if(joystickPress == "PUSH"){ - this->currentState = State::SingleStepObstacleNormalSelected; - } - else if(joystickState == "DOUBLE"){ - this->currentState = State::SingleStepObstacle; - } - break; - case State::SingleStepObstacleSmall: - if(rockerState =="UP"){ - this->currentState = State::SingleStepObstacleNormal; - } - else if(joystickState == "RIGHT"){ - this->currentState = State::SingleStepObstacleNormal; - } - else if(joystickPress == "PUSH"){ - this->currentState = State::SingleStepObstacleSmallSelected; - } - else if(joystickState == "DOUBLE"){ - this->currentState = State::SingleStepObstacle; - } - break; - case State::SingleStepObstacleLarge: - if(rockerState =="DOWN"){ - this->currentState = State::SingleStepObstacleNormal; - } - else if (joystickState == "LEFT"){ - this->currentState = State::SingleStepObstacleNormal; - } - // else if(joystickPress == "PUSH"){ - // this->currentState = State::SingleStepObstacleLargeSelected; - // } - else if(joystickState == "DOUBLE"){ - this->currentState = State::SingleStepObstacle; - } - break; - - - //Selected - case State::WalkObstacleSmallSelected: - if(triggerPress == "PUSH"){ - this->currentState = State::WalkObstacleSmallActivated; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::WalkObstacleSmall; - } - break; - case State::WalkObstacleNormalSelected: - if(triggerPress == "PUSH"){ - this->currentState = State::WalkObstacleNormalActivated; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::WalkObstacleNormal; - } - break; - // case State::WalkObstacleLargeSelected: - // if(triggerPress == "PUSH"){ - // this->currentState = State::WalkObstacleLargeActivated; - // } - // else if(joystickPress == "DOUBLE"){ - // this->currentState = State::WalkObstacleLarge; - // } - // break; - case State::SingleStepObstacleSmallSelected: - if(triggerPress == "PUSH"){ - this->currentState = State::SingleStepObstacleSmallActivated; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::SingleStepObstacleSmall; - } - break; - case State::SingleStepObstacleNormalSelected: - if(triggerPress == "PUSH"){ - this->currentState = State::SingleStepObstacleNormalActivated; - } - else if(joystickPress == "DOUBLE"){ - this->currentState = State::SingleStepObstacleNormal; - } - break; - // case State::SingleStepObstacleLargeSelected: - // if(triggerPress == "PUSH"){ - // this->currentState = State::SingleStepObstacleLargeActivated; - // } - // else if(joystickPress == "DOUBLE"){ - // this->currentState = State::SingleStepObstacleLarge; - // } - // break; - - //Activated - case State::WalkObstacleSmallActivated: - if(triggerPress == "EXIT_GAIT"){ - this->currentState = State::SingleStepObstacle; //Automatically - } - break; - case State::WalkObstacleNormalActivated: - if(triggerPress == "EXIT_GAIT"){ - this->currentState = State::SingleStepObstacle; //Automatically - } - break; - // case State::WalkObstacleLargeActivated: - // if(triggerPress == "EXIT_GAIT"){ - // this->currentState = State::SingleStepObstacle; //Automatically - // } - // break; - case State::SingleStepObstacleSmallActivated: - if(triggerPress == "EXIT_GAIT"){ - this->currentState = rememberStateObstacleWIB; //Automatically - } - break; - case State::SingleStepObstacleNormalActivated: - if(triggerPress == "EXIT_GAIT"){ - this->currentState = rememberStateObstacleWIB; //Automatically - } - break; - // case State::SingleStepObstacleLargeActivated: - // if(triggerPress == "EXIT_GAIT"){ - // this->currentState = rememberStateObstacleWIB; //Automatically - // } - // break; - - default: - break; - } -} - - -// Return the SD addresses of the image that should be drawn in the current state -int * StateMachine::getScreenImage(){ - static int currentSdAddresses[2] = {0, 0}; - switch (this->currentState) - { - //Start menu - case State::HomeSitStart: - currentSdAddresses[0] = HomeSitStart_Hi; - currentSdAddresses[1] = HomeSitStart_Lo; - break; - case State::HomeSitStartSelected: - currentSdAddresses[0] = HomeSitStartSelected_Hi; - currentSdAddresses[1] = HomeSitStartSelected_Lo; - break; - case State::HomeSitStartActivated: - currentSdAddresses[0] = HomeSitStartActivated_Hi; - currentSdAddresses[1] = HomeSitStartActivated_Lo; - break; - case State::StandUp: - currentSdAddresses[0] = StandUp_Hi; - currentSdAddresses[1] = StandUp_Lo; - break; - case State::StandUpSelected: - currentSdAddresses[0] = StandUpSelected_Hi; - currentSdAddresses[1] = StandUpSelected_Lo; - break; - case State::StandUpActivated: - currentSdAddresses[0] = StandUpActivated_Hi; - currentSdAddresses[1] = StandUpActivated_Lo; - break; - case State::HomeStandStart: - currentSdAddresses[0] = HomeStandStart_Hi; - currentSdAddresses[1] = HomeStandStart_Lo; - break; - case State::HomeStandStartSelected: - currentSdAddresses[0] = HomeStandStartSelected_Hi; - currentSdAddresses[1] = HomeStandStartSelected_Lo; - break; - case State::HomeStandStartActivated: - currentSdAddresses[0] = HomeStandStartActivated_Hi; - currentSdAddresses[1] = HomeStandStartActivated_Lo; - break; - case State::TurnOffStart: - currentSdAddresses[0] = TurnOffStart_Hi; - currentSdAddresses[1] = TurnOffStart_Lo; - break; - - - - //Sit menu - case State::Sit: - currentSdAddresses[0] = Sit_Hi; - currentSdAddresses[1] = Sit_Lo; - break; - case State::SitSelected: - currentSdAddresses[0] = SitSelected_Hi; - currentSdAddresses[1] = SitSelected_Lo; - break; - case State::SitActivated: - currentSdAddresses[0] = SitActivated_Hi; - currentSdAddresses[1] = SitActivated_Lo; - break; - case State::HomeSit: - currentSdAddresses[0] = HomeSit_Hi; - currentSdAddresses[1] = HomeSit_Lo; - break; - case State::HomeSitSelected: - currentSdAddresses[0] = HomeSitSelected_Hi; - currentSdAddresses[1] = HomeSitSelected_Lo; - break; - case State::HomeSitActivated: - currentSdAddresses[0] = HomeSitActivated_Hi; - currentSdAddresses[1] = HomeSitActivated_Lo; - break; - case State::HomeStand: - currentSdAddresses[0] = HomeStand_Hi; - currentSdAddresses[1] = HomeStand_Lo; - break; - case State::HomeStandSelected: - currentSdAddresses[0] = HomeStandSelected_Hi; - currentSdAddresses[1] = HomeStandSelected_Lo; - break; - case State::HomeStandActivated: - currentSdAddresses[0] = HomeStandActivated_Hi; - currentSdAddresses[1] = HomeStandActivated_Lo; - break; - case State::TurnOff: - currentSdAddresses[0] = TurnOff_Hi; - currentSdAddresses[1] = TurnOff_Lo; - break; - - - //Obstacle menu - case State::Sofa: - currentSdAddresses[0] = Sofa_Hi; - currentSdAddresses[1] = Sofa_Lo; - break; - case State::SofaSit: - currentSdAddresses[0] = SofaSit_Hi; - currentSdAddresses[1] = SofaSit_Lo; - break; - case State::SofaSitSelected: - currentSdAddresses[0] = SofaSitSelected_Hi; - currentSdAddresses[1] = SofaSitSelected_Lo; - break; - case State::SofaSitActivated: - currentSdAddresses[0] = SofaSitActivated_Hi; - currentSdAddresses[1] = SofaSitActivated_Lo; - break; - case State::SofaStandUp: - currentSdAddresses[0] = SofaStandUp_Hi; - currentSdAddresses[1] = SofaStandUp_Lo; - break; - case State::SofaStandUpSelected: - currentSdAddresses[0] = SofaStandUpSelected_Hi; - currentSdAddresses[1] = SofaStandUpSelected_Lo; - break; - case State::SofaStandUpActivated: - currentSdAddresses[0] = SofaStandUpActivated_Hi; - currentSdAddresses[1] = SofaStandUpActivated_Lo; - break; - - - case State::TiltedPath: - currentSdAddresses[0] = TiltedPath_Hi; - currentSdAddresses[1] = TiltedPath_Lo; - break; - case State::TiltedPathStartHomeToMin5: - currentSdAddresses[0] = TiltedPathStartHomeToMin5_Hi; - currentSdAddresses[1] = TiltedPathStartHomeToMin5_Lo; - break; - case State::TiltedPathStartHomeToMin5Selected: - currentSdAddresses[0] = TiltedPathStartHomeToMin5Selected_Hi; - currentSdAddresses[1] = TiltedPathStartHomeToMin5Selected_Lo; - break; - case State::TiltedPathStartHomeToMin5Activated: - currentSdAddresses[0] = TiltedPathStartHomeToMin5Activated_Hi; - currentSdAddresses[1] = TiltedPathStartHomeToMin5Activated_Lo; - break; - case State::FirstStartStep: - currentSdAddresses[0] = FirstStartStep_Hi; - currentSdAddresses[1] = FirstStartStep_Lo; - break; - case State::FirstStartStepActivated: - currentSdAddresses[0] = FirstStartStepActivated_Hi; - currentSdAddresses[1] = FirstStartStepActivated_Lo; - break; - case State::SecondStartStep: - currentSdAddresses[0] = SecondStartStep_Hi; - currentSdAddresses[1] = SecondStartStep_Lo; - break; - case State::SecondStartStepActivated: - currentSdAddresses[0] = SecondStartStepActivated_Hi; - currentSdAddresses[1] = SecondStartStepActivated_Lo; - break; - case State::HomeStandToMin10: - currentSdAddresses[0] = HomeStandToMin10_Hi; - currentSdAddresses[1] = HomeStandToMin10_Lo; - break; - case State::HomeStandToMin10Activated: - currentSdAddresses[0] = HomeStandToMin10Activated_Hi; - currentSdAddresses[1] = HomeStandToMin10Activated_Lo; - break; - case State::TiltedPathMiddleStep: - currentSdAddresses[0] = TiltedPathMiddleStep_Hi; - currentSdAddresses[1] = TiltedPathMiddleStep_Lo; - break; - case State::TiltedPathMiddleStepActivated: - currentSdAddresses[0] = TiltedPathMiddleStepActivated_Hi; - currentSdAddresses[1] = TiltedPathMiddleStepActivated_Lo; - break; - case State::HomeStandToMin5: - currentSdAddresses[0] = HomeStandToMin5_Hi; - currentSdAddresses[1] = HomeStandToMin5_Lo; - break; - case State::HomeStandToMin5Activated: - currentSdAddresses[0] = HomeStandToMin5Activated_Hi; - currentSdAddresses[1] = HomeStandToMin5Activated_Lo; - break; - case State::FirstEndStep: - currentSdAddresses[0] = FirstEndStep_Hi; - currentSdAddresses[1] = FirstEndStep_Lo; - break; - case State::FirstEndStepActivated: - currentSdAddresses[0] = FirstEndStepActivated_Hi; - currentSdAddresses[1] = FirstEndStepActivated_Lo; - break; - case State::SecondEndStep: - currentSdAddresses[0] = SecondEndStep_Hi; - currentSdAddresses[1] = SecondEndStep_Lo; - break; - case State::SecondEndStepActivated: - currentSdAddresses[0] = SecondEndStepActivated_Hi; - currentSdAddresses[1] = SecondEndStepActivated_Lo; - break; - case State::HomeForWalk25: - currentSdAddresses[0] = HomeForWalk25_Hi; - currentSdAddresses[1] = HomeForWalk25_Lo; - break; - case State::HomeForWalk25Activated: - currentSdAddresses[0] = HomeForWalk25Activated_Hi; - currentSdAddresses[1] = HomeForWalk25Activated_Lo; - break; - - case State::Stairs: - currentSdAddresses[0] = Stairs_Hi; - currentSdAddresses[1] = Stairs_Lo; - break; - case State::StairsUp: - currentSdAddresses[0] = StairsUp_Hi; - currentSdAddresses[1] = StairsUp_Lo; - break; - case State::StairsUpSelected: - currentSdAddresses[0] = StairsUpSelected_Hi; - currentSdAddresses[1] = StairsUpSelected_Lo; - break; - case State::StairsUpActivated: - currentSdAddresses[0] = StairsUpActivated_Hi; - currentSdAddresses[1] = StairsUpActivated_Lo; - break; - case State::StairsDown: - currentSdAddresses[0] = StairsDown_Hi; - currentSdAddresses[1] = StairsDown_Lo; - break; - case State::StairsDownSelected: - currentSdAddresses[0] = StairsDownSelected_Hi; - currentSdAddresses[1] = StairsDownSelected_Lo; - break; - case State::StairsDownActivated: - currentSdAddresses[0] = StairsDownActivated_Hi; - currentSdAddresses[1] = StairsDownActivated_Lo; - break; - // case State::StairsDownFinal: - // currentSdAddresses[0] = StairsDownFinal_Hi; - // currentSdAddresses[1] = StairsDownFinal_Lo; - // break; - // case State::StairsDownFinalSelected: - // currentSdAddresses[0] = StairsDownFinalSelected_Hi; - // currentSdAddresses[1] = StairsDownFinalSelected_Lo; - // break; - // case State::StairsDownFinalActivated: - // currentSdAddresses[0] = StairsDownFinalActivated_Hi; - // currentSdAddresses[1] = StairsDownFinalActivated_Lo; - // break; - - - -//WIB - case State::WalkObstacle: - currentSdAddresses[0] = WalkObstacle_Hi; - currentSdAddresses[1] = WalkObstacle_Lo; - break; - case State::WalkObstacleSmall: - currentSdAddresses[0] = WalkObstacleSmall_Hi; - currentSdAddresses[1] = WalkObstacleSmall_Lo; - break; - case State::WalkObstacleNormal: - currentSdAddresses[0] = WalkObstacleNormal_Hi; - currentSdAddresses[1] = WalkObstacleNormal_Lo; - break; - case State::WalkObstacleLarge: - currentSdAddresses[0] = WalkObstacleLarge_Hi; - currentSdAddresses[1] = WalkObstacleLarge_Lo; - break; - case State::WalkObstacleNormalSelected: - currentSdAddresses[0] = WalkObstacleNormalSelected_Hi; - currentSdAddresses[1] = WalkObstacleNormalSelected_Lo; - break; - case State::WalkObstacleSmallSelected: - currentSdAddresses[0] = WalkObstacleSmallSelected_Hi; - currentSdAddresses[1] = WalkObstacleSmallSelected_Lo; - break; - case State::WalkObstacleNormalActivated: - currentSdAddresses[0] = WalkObstacleNormalActivated_Hi; - currentSdAddresses[1] = WalkObstacleNormalActivated_Lo; - break; - case State::WalkObstacleSmallActivated: - currentSdAddresses[0] = WalkObstacleSmallActivated_Hi; - currentSdAddresses[1] = WalkObstacleSmallActivated_Lo; - break; - - case State::SingleStepObstacle: - currentSdAddresses[0] = SingleStepObstacle_Hi; - currentSdAddresses[1] = SingleStepObstacle_Lo; - break; - case State::SingleStepObstacleNormal: - currentSdAddresses[0] = SingleStepObstacleNormal_Hi; - currentSdAddresses[1] = SingleStepObstacleNormal_Lo; - break; - case State::SingleStepObstacleSmall: - currentSdAddresses[0] = SingleStepObstacleSmall_Hi; - currentSdAddresses[1] = SingleStepObstacleSmall_Lo; - break; - case State::SingleStepObstacleLarge: - currentSdAddresses[0] = SingleStepObstacleLarge_Hi; - currentSdAddresses[1] = SingleStepObstacleLarge_Lo; - break; - case State::SingleStepObstacleNormalSelected: - currentSdAddresses[0] = SingleStepObstacleNormalSelected_Hi; - currentSdAddresses[1] = SingleStepObstacleNormalSelected_Lo; - break; - case State::SingleStepObstacleSmallSelected: - currentSdAddresses[0] = SingleStepObstacleSmallSelected_Hi; - currentSdAddresses[1] = SingleStepObstacleSmallSelected_Lo; - break; - case State::SingleStepObstacleNormalActivated: - currentSdAddresses[0] = SingleStepObstacleNormalActivated_Hi; - currentSdAddresses[1] = SingleStepObstacleNormalActivated_Lo; - break; - case State::SingleStepObstacleSmallActivated: - currentSdAddresses[0] = SingleStepObstacleSmallActivated_Hi; - currentSdAddresses[1] = SingleStepObstacleSmallActivated_Lo; - break; - - - //Walk Menu - case State::Walk: - currentSdAddresses[0] = Walk_Hi; - currentSdAddresses[1] = Walk_Lo; - break; - case State::WalkSmall: - currentSdAddresses[0] = WalkSmall_Hi; - currentSdAddresses[1] = WalkSmall_Lo; - break; - case State::WalkNormal: - currentSdAddresses[0] = WalkNormal_Hi; - currentSdAddresses[1] = WalkNormal_Lo; - break; - case State::WalkLarge: - currentSdAddresses[0] = WalkLarge_Hi; - currentSdAddresses[1] = WalkLarge_Lo; - break; - case State::WalkNormalSelected: - currentSdAddresses[0] = WalkNormalSelected_Hi; - currentSdAddresses[1] = WalkNormalSelected_Lo; - break; - case State::WalkNormalActivated: - currentSdAddresses[0] = WalkNormalActivated_Hi; - currentSdAddresses[1] = WalkNormalActivated_Lo; - break; - case State::WalkSmallSelected: - currentSdAddresses[0] = WalkSmallSelected_Hi; - currentSdAddresses[1] = WalkSmallSelected_Lo; - break; - case State::WalkSmallActivated: - currentSdAddresses[0] = WalkSmallActivated_Hi; - currentSdAddresses[1] = WalkSmallActivated_Lo; - break; - - case State::SingleStep: - currentSdAddresses[0] = SingleStep_Hi; - currentSdAddresses[1] = SingleStep_Lo; - break; - case State::SingleStepSmall: - currentSdAddresses[0] = SingleStepSmall_Hi; - currentSdAddresses[1] = SingleStepSmall_Lo; - break; - case State::SingleStepNormal: - currentSdAddresses[0] = SingleStepNormal_Hi; - currentSdAddresses[1] = SingleStepNormal_Lo; - break; - case State::SingleStepLarge: - currentSdAddresses[0] = SingleStepLarge_Hi; - currentSdAddresses[1] = SingleStepLarge_Lo; - break; - case State::SingleStepSmallSelected: - currentSdAddresses[0] = SingleStepSmallSelected_Hi; - currentSdAddresses[1] = SingleStepSmallSelected_Lo; - break; - case State::SingleStepNormalSelected: - currentSdAddresses[0] = SingleStepNormalSelected_Hi; - currentSdAddresses[1] = SingleStepNormalSelected_Lo; - break; - case State::SingleStepSmallActivated: - currentSdAddresses[0] = SingleStepSmallActivated_Hi; - currentSdAddresses[1] = SingleStepSmallActivated_Lo; - break; - case State::SingleStepNormalActivated: - currentSdAddresses[0] = SingleStepNormalActivated_Hi; - currentSdAddresses[1] = SingleStepNormalActivated_Lo; - break; - - case State::SideStep: - currentSdAddresses[0] = SideStep_Hi; - currentSdAddresses[1] = SideStep_Lo; - break; - case State::SideStepLeft: - currentSdAddresses[0] = SideStepLeft_Hi; - currentSdAddresses[1] = SideStepLeft_Lo; - break; - case State::SideStepRight: - currentSdAddresses[0] = SideStepRight_Hi; - currentSdAddresses[1] = SideStepRight_Lo; - break; - case State::SideStepLeftSmall: - currentSdAddresses[0] = SideStepLeftSmall_Hi; - currentSdAddresses[1] = SideStepLeftSmall_Lo; - break; - case State::SideStepLeftSmallSelected: - currentSdAddresses[0] = SideStepLeftSmallSelected_Hi; - currentSdAddresses[1] = SideStepLeftSmallSelected_Lo; - break; - case State::SideStepLeftSmallActivated: - currentSdAddresses[0] = SideStepLeftSmallActivated_Hi; - currentSdAddresses[1] = SideStepLeftSmallActivated_Lo; - break; - case State::SideStepLeftNormal: - currentSdAddresses[0] = SideStepLeftNormal_Hi; - currentSdAddresses[1] = SideStepLeftNormal_Lo; - break; - case State::SideStepLeftNormalSelected: - currentSdAddresses[0] = SideStepLeftNormalSelected_Hi; - currentSdAddresses[1] = SideStepLeftNormalSelected_Lo; - break; - case State::SideStepLeftNormalActivated: - currentSdAddresses[0] = SideStepLeftNormalActivated_Hi; - currentSdAddresses[1] = SideStepLeftNormalActivated_Lo; - break; - case State::SideStepRightSmall: - currentSdAddresses[0] = SideStepRightSmall_Hi; - currentSdAddresses[1] = SideStepRightSmall_Lo; - break; - case State::SideStepRightSmallSelected: - currentSdAddresses[0] = SideStepRightSmallSelected_Hi; - currentSdAddresses[1] = SideStepRightSmallSelected_Lo; - break; - case State::SideStepRightSmallActivated: - currentSdAddresses[0] = SideStepRightSmallActivated_Hi; - currentSdAddresses[1] = SideStepRightSmallActivated_Lo; - break; - case State::SideStepRightNormal: - currentSdAddresses[0] = SideStepRightNormal_Hi; - currentSdAddresses[1] = SideStepRightNormal_Lo; - break; - case State::SideStepRightNormalSelected: - currentSdAddresses[0] = SideStepRightNormalSelected_Hi; - currentSdAddresses[1] = SideStepRightNormalSelected_Lo; - break; - case State::SideStepRightNormalActivated: - currentSdAddresses[0] = SideStepRightSmallActivated_Hi; - currentSdAddresses[1] = SideStepRightSmallActivated_Lo; - break; - default: - Serial.println("Can't draw this state"); - currentSdAddresses[0] = 0; - currentSdAddresses[1] = 0; - break; - } - return currentSdAddresses; -} diff --git a/src/main.cpp b/src/main.cpp index b240e92..0c8b775 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include #include @@ -51,7 +51,7 @@ Goldelox_Serial_4DLib screenGoldelox(&screenSerial); // Wrapper instance of the screen Screen screen(&screenGoldelox, &screenSerial, RST, BAUD_SCREEN); // State Machine -StateMachine stateMachine; +StateMachine state_machine; // Haptic Driver Adafruit_DRV2605 driver; @@ -75,8 +75,8 @@ ros::Subscriber gait_instruction_result_subscriber("/march/input &gaitInstructionResponseCallback); march_shared_resources::GaitInstruction gaitInstructionMessage; -ros::Publisher gait_instruction_publisher("/march/input_device/instruction", &gaitInstructionMessage); std_msgs::Time timeMessage; +ros::Publisher gait_instruction_publisher("/march/input_device/instruction", &gaitInstructionMessage); ros::Publisher ping_publisher("/march/input_device/alive", &timeMessage); void sendGaitMessage(std::string name) @@ -171,25 +171,40 @@ void loop() gait_message_send = false; } - // Determine new state - stateMachine.updateState(joystickState, joystickPress, rockerState, triggerPress); - - // Draw appropriate image - int* drawSdAddresses = stateMachine.getScreenImage(); - screen.draw_image(*(drawSdAddresses), *(drawSdAddresses + 1)); - - State newState = stateMachine.getCurrentState(); - std::string name = stateMachine.getGaitNameOfState(newState); - - // If there is a transition to a new screen which belongs to a gait send message with this gait. - if (!name.empty()) - { - sendGaitMessage(name); + bool state_has_changed = false; + if (joystickState == "LEFT") { + state_has_changed = state_machine.left(); + } else if (joystickState == "RIGHT") { + state_has_changed = state_machine.right(); + } else if (joystickState == "UP") { + state_has_changed = state_machine.up(); + } else if (joystickState == "DOWN") { + state_has_changed = state_machine.down(); + } else if (joystickPress == "PUSH") { + state_has_changed = state_machine.select(); + } else if (joystickPress == "DOUBLE") { + state_has_changed = state_machine.back(); + } else if (triggerPress == "PUSH") { + state_has_changed = state_machine.activate(); } - else if (triggerPress == "PUSH") - { - // If the trigger press is not to select a gait, it's interpreted as a stop. - sendStopMessage(); + + if (state_has_changed) { + word address_hi = 0; + word address_lo = 0; + state_machine.getCurrentImage(address_hi, address_lo); + screen.draw_image(address_hi, address_lo); + + const std::string& gait_name = state_machine.getCurrentGaitName(); + + // If there is a transition to a new screen which belongs to a gait send + // message with this gait. + if (!gait_name.empty()) { + sendGaitMessage(gait_name); + } else if (triggerPress == "PUSH") { + // If the trigger press is not to select a gait, it's interpreted as a + // stop. + sendStopMessage(); + } } // Average loop frequency is around 20hz. diff --git a/src/state_machine.cpp b/src/state_machine.cpp new file mode 100644 index 0000000..9a9861d --- /dev/null +++ b/src/state_machine.cpp @@ -0,0 +1,45 @@ +#include "state_machine.h" + +StateMachine::StateMachine() {} + +const std::string& StateMachine::getCurrentGaitName() const { + return this->current_state_->getGaitName(); +} + +void StateMachine::getCurrentImage(word& address_hi, word& address_lo) const { + this->current_state_->getImage(address_hi, address_lo); +} + +bool StateMachine::left() { + return this->setCurrentState(this->current_state_->left()); +} + +bool StateMachine::right() { + return this->setCurrentState(this->current_state_->right()); +} + +bool StateMachine::up() { + return this->setCurrentState(this->current_state_->up()); +} + +bool StateMachine::down() { + return this->setCurrentState(this->current_state_->down()); +} + +bool StateMachine::back() { + return this->setCurrentState(this->current_state_->back()); +} + +bool StateMachine::select() { + return this->setCurrentState(this->current_state_->select()); +} + +bool StateMachine::activate() { + return this->setCurrentState(this->current_state_->activate()); +} + +bool StateMachine::setCurrentState(State* new_state) { + bool has_changed = this->current_state_ != new_state; + this->current_state_ = new_state; + return has_changed; +} From acca8c7a69d3fddd0aa1f5b687ec5d337b09c4e4 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Thu, 12 Dec 2019 20:49:19 +0100 Subject: [PATCH 05/58] Add libraries as pio lib_deps --- .travis.yml | 1 + lib/Adafruit_DRV2605/.library.json | 50 - lib/Adafruit_DRV2605/examples/audio/audio.ino | 23 - lib/Adafruit_DRV2605/examples/basic/basic.ino | 35 - .../examples/complex/complex.ino | 23 - .../examples/realtime/realtime.ino | 39 - lib/Adafruit_DRV2605/library.properties | 9 - lib/Adafruit_DRV2605/src/Adafruit_DRV2605.cpp | 133 -- lib/Adafruit_DRV2605/src/Adafruit_DRV2605.h | 93 -- lib/Goldelox_Serial/Goldelox_Const4D.h | 654 --------- lib/Goldelox_Serial/Goldelox_Const4DSerial.h | 71 - lib/Goldelox_Serial/Goldelox_Serial_4DLib.cpp | 1226 ----------------- lib/Goldelox_Serial/Goldelox_Serial_4DLib.h | 169 --- lib/Goldelox_Serial/Goldelox_Types4D.h | 3 - lib/SoftwareSerial/SoftwareSerial.cpp | 266 ---- lib/SoftwareSerial/SoftwareSerial.h | 87 -- platformio.ini | 5 + src/main.cpp | 2 +- 18 files changed, 7 insertions(+), 2882 deletions(-) delete mode 100644 lib/Adafruit_DRV2605/.library.json delete mode 100644 lib/Adafruit_DRV2605/examples/audio/audio.ino delete mode 100644 lib/Adafruit_DRV2605/examples/basic/basic.ino delete mode 100644 lib/Adafruit_DRV2605/examples/complex/complex.ino delete mode 100644 lib/Adafruit_DRV2605/examples/realtime/realtime.ino delete mode 100644 lib/Adafruit_DRV2605/library.properties delete mode 100644 lib/Adafruit_DRV2605/src/Adafruit_DRV2605.cpp delete mode 100644 lib/Adafruit_DRV2605/src/Adafruit_DRV2605.h delete mode 100644 lib/Goldelox_Serial/Goldelox_Const4D.h delete mode 100644 lib/Goldelox_Serial/Goldelox_Const4DSerial.h delete mode 100644 lib/Goldelox_Serial/Goldelox_Serial_4DLib.cpp delete mode 100644 lib/Goldelox_Serial/Goldelox_Serial_4DLib.h delete mode 100644 lib/Goldelox_Serial/Goldelox_Types4D.h delete mode 100644 lib/SoftwareSerial/SoftwareSerial.cpp delete mode 100644 lib/SoftwareSerial/SoftwareSerial.h diff --git a/.travis.yml b/.travis.yml index ed0bdf4..117807e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ cache: install: - pip install -U platformio - platformio update + - platformio lib install script: - platformio run diff --git a/lib/Adafruit_DRV2605/.library.json b/lib/Adafruit_DRV2605/.library.json deleted file mode 100644 index 745cc79..0000000 --- a/lib/Adafruit_DRV2605/.library.json +++ /dev/null @@ -1,50 +0,0 @@ -{ - "name": "Adafruit DRV2605 Library", - "version": "1.0.1", - "keywords": [ - "device", - "control" - ], - "description": "Arduino library for Adafruit DRV2605L Haptic Controller Breakout", - "frameworks": [ - "arduino" - ], - "platforms": [ - "atmelavr", - "atmelsam", - "espressif32", - "espressif8266", - "intel_arc32", - "microchippic32", - "nordicnrf51", - "nordicnrf52", - "ststm32", - "teensy", - "timsp430" - ], - "authors": [ - { - "email": "info@adafruit.com", - "url": null, - "maintainer": true, - "name": "Adafruit" - } - ], - "repository": { - "type": "git", - "url": "https://github.com/adafruit/Adafruit_DRV2605_Library" - }, - "homepage": null, - "export": { - "include": null, - "exclude": [ - "extras", - "docs", - "tests", - "test", - "*.doxyfile", - "*.pdf" - ] - }, - "id": 632 -} \ No newline at end of file diff --git a/lib/Adafruit_DRV2605/examples/audio/audio.ino b/lib/Adafruit_DRV2605/examples/audio/audio.ino deleted file mode 100644 index 4322b9c..0000000 --- a/lib/Adafruit_DRV2605/examples/audio/audio.ino +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include "Adafruit_DRV2605.h" - -Adafruit_DRV2605 drv; - -void setup() { - Serial.begin(9600); - Serial.println("DRV2605 Audio responsive test"); - drv.begin(); - - - drv.setMode(DRV2605_MODE_AUDIOVIBE); - - // ac coupled input, puts in 0.9V bias - drv.writeRegister8(DRV2605_REG_CONTROL1, 0x20); - - // analog input - drv.writeRegister8(DRV2605_REG_CONTROL3, 0xA3); -} - - -void loop() { -} diff --git a/lib/Adafruit_DRV2605/examples/basic/basic.ino b/lib/Adafruit_DRV2605/examples/basic/basic.ino deleted file mode 100644 index b0b2ab5..0000000 --- a/lib/Adafruit_DRV2605/examples/basic/basic.ino +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include "Adafruit_DRV2605.h" - -Adafruit_DRV2605 drv; - -void setup() { - Serial.begin(9600); - Serial.println("DRV test"); - drv.begin(); - - drv.selectLibrary(1); - - // I2C trigger by sending 'go' command - // default, internal trigger when sending GO command - drv.setMode(DRV2605_MODE_INTTRIG); -} - -uint8_t effect = 1; - -void loop() { - Serial.print("Effect #"); Serial.println(effect); - - // set the effect to play - drv.setWaveform(0, effect); // play effect - drv.setWaveform(1, 0); // end waveform - - // play the effect! - drv.go(); - - // wait a bit - delay(500); - - effect++; - if (effect > 117) effect = 1; -} diff --git a/lib/Adafruit_DRV2605/examples/complex/complex.ino b/lib/Adafruit_DRV2605/examples/complex/complex.ino deleted file mode 100644 index 9b68ef6..0000000 --- a/lib/Adafruit_DRV2605/examples/complex/complex.ino +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include "Adafruit_DRV2605.h" - -Adafruit_DRV2605 drv; - -void setup() { - Serial.begin(9600); - Serial.println("DRV test"); - drv.begin(); - - // I2C trigger by sending 'go' command - drv.setMode(DRV2605_MODE_INTTRIG); // default, internal trigger when sending GO command - - drv.selectLibrary(1); - drv.setWaveform(0, 84); // ramp up medium 1, see datasheet part 11.2 - drv.setWaveform(1, 1); // strong click 100%, see datasheet part 11.2 - drv.setWaveform(2, 0); // end of waveforms -} - -void loop() { - drv.go(); - delay(1000); -} diff --git a/lib/Adafruit_DRV2605/examples/realtime/realtime.ino b/lib/Adafruit_DRV2605/examples/realtime/realtime.ino deleted file mode 100644 index 1eedfce..0000000 --- a/lib/Adafruit_DRV2605/examples/realtime/realtime.ino +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include "Adafruit_DRV2605.h" - -Adafruit_DRV2605 drv; - -void setup() { - Serial.begin(9600); - Serial.println("DRV test"); - drv.begin(); - - // Set Real-Time Playback mode - drv.setMode(DRV2605_MODE_REALTIME); -} - -uint8_t rtp_index = 0; -uint8_t rtp[] = { - 0x30, 100, 0x32, 100, - 0x34, 100, 0x36, 100, - 0x38, 100, 0x3A, 100, - 0x00, 100, - 0x40, 200, 0x00, 100, - 0x40, 200, 0x00, 100, - 0x40, 200, 0x00, 100 -}; - -void loop() { - - if (rtp_index < sizeof(rtp)/sizeof(rtp[0])) { - drv.setRealtimeValue(rtp[rtp_index]); - rtp_index++; - delay(rtp[rtp_index]); - rtp_index++; - } else { - drv.setRealtimeValue(0x00); - delay(1000); - rtp_index = 0; - } - -} diff --git a/lib/Adafruit_DRV2605/library.properties b/lib/Adafruit_DRV2605/library.properties deleted file mode 100644 index 8b1c806..0000000 --- a/lib/Adafruit_DRV2605/library.properties +++ /dev/null @@ -1,9 +0,0 @@ -name=Adafruit DRV2605 Library -version=1.0.1 -author=Adafruit -maintainer=Adafruit -sentence=Arduino library for Adafruit DRV2605L Haptic Controller Breakout -paragraph=Arduino library for Adafruit DRV2605L Haptic Controller Breakout -category=Device Control -url=https://github.com/adafruit/Adafruit_DRV2605_Library -architectures=* diff --git a/lib/Adafruit_DRV2605/src/Adafruit_DRV2605.cpp b/lib/Adafruit_DRV2605/src/Adafruit_DRV2605.cpp deleted file mode 100644 index 0cdbf70..0000000 --- a/lib/Adafruit_DRV2605/src/Adafruit_DRV2605.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/*************************************************** - This is a library for the Adafruit DRV2605L Haptic Driver - - ----> http://www.adafruit.com/products/2306 - - Check out the links above for our tutorials and wiring diagrams - This motor/haptic driver uses I2C to communicate - - Adafruit invests time and resources providing this open source code, - please support Adafruit and open-source hardware by purchasing - products from Adafruit! - - Written by Limor Fried/Ladyada for Adafruit Industries. - MIT license, all text above must be included in any redistribution - ****************************************************/ - - -#if ARDUINO >= 100 - #include "Arduino.h" -#else - #include "WProgram.h" -#endif - -#include - -#include - -/**************************************************************************/ -/*! - @brief Instantiates a new DRV2605 class -*/ -/**************************************************************************/ -// I2C, no address adjustments or pins -Adafruit_DRV2605::Adafruit_DRV2605() { -} - - -/**************************************************************************/ -/*! - @brief Setups the HW -*/ -/**************************************************************************/ -boolean Adafruit_DRV2605::begin() { - Wire.begin(); - uint8_t id = readRegister8(DRV2605_REG_STATUS); - //Serial.print("Status 0x"); Serial.println(id, HEX); - - writeRegister8(DRV2605_REG_MODE, 0x00); // out of standby - - writeRegister8(DRV2605_REG_RTPIN, 0x00); // no real-time-playback - - writeRegister8(DRV2605_REG_WAVESEQ1, 1); // strong click - writeRegister8(DRV2605_REG_WAVESEQ2, 0); - - writeRegister8(DRV2605_REG_OVERDRIVE, 0); // no overdrive - - writeRegister8(DRV2605_REG_SUSTAINPOS, 0); - writeRegister8(DRV2605_REG_SUSTAINNEG, 0); - writeRegister8(DRV2605_REG_BREAK, 0); - writeRegister8(DRV2605_REG_AUDIOMAX, 0x64); - - // ERM open loop - - // turn off N_ERM_LRA - writeRegister8(DRV2605_REG_FEEDBACK, readRegister8(DRV2605_REG_FEEDBACK) & 0x7F); - // turn on ERM_OPEN_LOOP - writeRegister8(DRV2605_REG_CONTROL3, readRegister8(DRV2605_REG_CONTROL3) | 0x20); - - return true; -} - -void Adafruit_DRV2605::setWaveform(uint8_t slot, uint8_t w) { - writeRegister8(DRV2605_REG_WAVESEQ1+slot, w); -} - -void Adafruit_DRV2605::selectLibrary(uint8_t lib) { - writeRegister8(DRV2605_REG_LIBRARY, lib); -} - -void Adafruit_DRV2605::go() { - writeRegister8(DRV2605_REG_GO, 1); -} - -void Adafruit_DRV2605::setMode(uint8_t mode) { - writeRegister8(DRV2605_REG_MODE, mode); -} - -void Adafruit_DRV2605::setRealtimeValue(uint8_t rtp) { - writeRegister8(DRV2605_REG_RTPIN, rtp); -} - -/********************************************************************/ - -uint8_t Adafruit_DRV2605::readRegister8(uint8_t reg) { - uint8_t x ; - // use i2c - Wire.beginTransmission(DRV2605_ADDR); - Wire.write((byte)reg); - Wire.endTransmission(); - Wire.requestFrom((byte)DRV2605_ADDR, (byte)1); - x = Wire.read(); - - // Serial.print("$"); Serial.print(reg, HEX); - // Serial.print(": 0x"); Serial.println(x, HEX); - - return x; -} - -void Adafruit_DRV2605::writeRegister8(uint8_t reg, uint8_t val) { - // use i2c - Wire.beginTransmission(DRV2605_ADDR); - Wire.write((byte)reg); - Wire.write((byte)val); - Wire.endTransmission(); -} - -/****************/ - - -// Allow users to use ERM motor or LRA motors - -void Adafruit_DRV2605::useERM () -{ - writeRegister8(DRV2605_REG_FEEDBACK, readRegister8(DRV2605_REG_FEEDBACK) & 0x7F); -} - -void Adafruit_DRV2605::useLRA () -{ - writeRegister8(DRV2605_REG_FEEDBACK, readRegister8(DRV2605_REG_FEEDBACK) | 0x80); -} - - - diff --git a/lib/Adafruit_DRV2605/src/Adafruit_DRV2605.h b/lib/Adafruit_DRV2605/src/Adafruit_DRV2605.h deleted file mode 100644 index 48563b0..0000000 --- a/lib/Adafruit_DRV2605/src/Adafruit_DRV2605.h +++ /dev/null @@ -1,93 +0,0 @@ -/*************************************************** - This is a library for the Adafruit DRV2605L Haptic Driver - - ----> http://www.adafruit.com/products/2305 - - Check out the links above for our tutorials and wiring diagrams - This motor/haptic driver uses I2C to communicate - - Adafruit invests time and resources providing this open source code, - please support Adafruit and open-source hardware by purchasing - products from Adafruit! - - Written by Limor Fried/Ladyada for Adafruit Industries. - MIT license, all text above must be included in any redistribution - ****************************************************/ - - -#if ARDUINO >= 100 - #include "Arduino.h" -#else - #include "WProgram.h" -#endif - -#include - -#define DRV2605_ADDR 0x5A - -#define DRV2605_REG_STATUS 0x00 -#define DRV2605_REG_MODE 0x01 -#define DRV2605_MODE_INTTRIG 0x00 -#define DRV2605_MODE_EXTTRIGEDGE 0x01 -#define DRV2605_MODE_EXTTRIGLVL 0x02 -#define DRV2605_MODE_PWMANALOG 0x03 -#define DRV2605_MODE_AUDIOVIBE 0x04 -#define DRV2605_MODE_REALTIME 0x05 -#define DRV2605_MODE_DIAGNOS 0x06 -#define DRV2605_MODE_AUTOCAL 0x07 - - -#define DRV2605_REG_RTPIN 0x02 -#define DRV2605_REG_LIBRARY 0x03 -#define DRV2605_REG_WAVESEQ1 0x04 -#define DRV2605_REG_WAVESEQ2 0x05 -#define DRV2605_REG_WAVESEQ3 0x06 -#define DRV2605_REG_WAVESEQ4 0x07 -#define DRV2605_REG_WAVESEQ5 0x08 -#define DRV2605_REG_WAVESEQ6 0x09 -#define DRV2605_REG_WAVESEQ7 0x0A -#define DRV2605_REG_WAVESEQ8 0x0B - -#define DRV2605_REG_GO 0x0C -#define DRV2605_REG_OVERDRIVE 0x0D -#define DRV2605_REG_SUSTAINPOS 0x0E -#define DRV2605_REG_SUSTAINNEG 0x0F -#define DRV2605_REG_BREAK 0x10 -#define DRV2605_REG_AUDIOCTRL 0x11 -#define DRV2605_REG_AUDIOLVL 0x12 -#define DRV2605_REG_AUDIOMAX 0x13 -#define DRV2605_REG_RATEDV 0x16 -#define DRV2605_REG_CLAMPV 0x17 -#define DRV2605_REG_AUTOCALCOMP 0x18 -#define DRV2605_REG_AUTOCALEMP 0x19 -#define DRV2605_REG_FEEDBACK 0x1A -#define DRV2605_REG_CONTROL1 0x1B -#define DRV2605_REG_CONTROL2 0x1C -#define DRV2605_REG_CONTROL3 0x1D -#define DRV2605_REG_CONTROL4 0x1E -#define DRV2605_REG_VBAT 0x21 -#define DRV2605_REG_LRARESON 0x22 - - -class Adafruit_DRV2605 { - public: - - Adafruit_DRV2605(void); - boolean begin(void); - - void writeRegister8(uint8_t reg, uint8_t val); - uint8_t readRegister8(uint8_t reg); - void setWaveform(uint8_t slot, uint8_t w); - void selectLibrary(uint8_t lib); - void go(void); - void setMode(uint8_t mode); - void setRealtimeValue(uint8_t rtp); - // Select ERM (Eccentric Rotating Mass) or LRA (Linear Resonant Actuator) vibration motor - // The default is ERM, which is more common - void useERM(); - void useLRA(); - - private: - -}; - diff --git a/lib/Goldelox_Serial/Goldelox_Const4D.h b/lib/Goldelox_Serial/Goldelox_Const4D.h deleted file mode 100644 index 208ed41..0000000 --- a/lib/Goldelox_Serial/Goldelox_Const4D.h +++ /dev/null @@ -1,654 +0,0 @@ -// undef windows definitions that are also 4DGL definitions -#ifdef TRANSPARENT - #undef TRANSPARENT -#endif -#ifdef OPAQUE - #undef OPAQUE -#endif -#ifdef BAUD_110 - #undef BAUD_110 -#endif -#ifdef BAUD_300 - #undef BAUD_300 -#endif -#ifdef BAUD_600 - #undef BAUD_600 -#endif -#ifdef BAUD_1200 - #undef BAUD_1200 -#endif -#ifdef BAUD_2400 - #undef BAUD_2400 -#endif -#ifdef BAUD_4800 - #undef BAUD_4800 -#endif -#ifdef BAUD_9600 - #undef BAUD_9600 -#endif -#ifdef BAUD_14400 - #undef BAUD_14400 -#endif -#ifdef BAUD_19200 - #undef BAUD_19200 -#endif -#ifdef BAUD_38400 - #undef BAUD_38400 -#endif -#ifdef BAUD_57600 - #undef BAUD_57600 -#endif -#ifdef BAUD_115200 - #undef BAUD_115200 -#endif - -#ifdef TEXT - #undef TEXT -#endif - -/* - //---------------------------------- - // 4DGL - GOLDELOX-GFX2 PLATFORM - //---------------------------------- - - -*/ -/* - System Primitives for 4DGL GOLDELOX GFX2 Platform -*/ - - -//==============================================// -// initialization table additional commands // -//==============================================// -#define INIT_TABLE_END 0xFF // end of initialization table marker -#define INIT_TABLE_DELAY 0xFE // insert delay value -#define INIT_TABLE_16BIT_INDEX_REG_MODE 0xFD // 16 bit display index register -#define INIT_TABLE_8BIT_INDEX_REG_MODE 0xFC // 8 bit display index register -#define INIT_TABLE_16BIT_DUMMY_READ 0xFB // 16 bit display dummy read -#define INIT_TABLE_PORTRAIT 0xFA // initial screen mode requirement -#define INIT_TABLE_LANDSCAPE 0xF9 -#define INIT_TABLE_PORTRAIT_R 0xF8 -#define INIT_TABLE_LANDSCAPE_R 0xF7 - -//==============================================// -// putch, putstr, putnum and print redirection // -// constants // -//==============================================// -#define APPEND 0x0000 -#define COM0 0xFF04 -#define TEXT 0xFF08 -#define MDA 0xFF10 - -//==============================================// -// general number formatting constants // -// for 'print' and 'putnum' // -//==============================================// - // string processing constants -#define STR 0x0080 // display as string -#define CHR 0x0081 // display as single char - - - - // binary, no leading zeroes -#define BIN4d 0x0002 // binary, 16 digits, no leading zeroes -#define BIN1 0x0102 // binary, 1 digit, no leading zeroes -#define BIN2 0x0202 // binary, 2 digits, no leading zeroes -#define BIN3 0x0302 // binary, 3 digits, no leading zeroes -#define BIN4 0x0402 // binary, 4 digits, no leading zeroes -#define BIN5 0x0502 // binary, 5 digits, no leading zeroes -#define BIN6 0x0602 // binary, 6 digits, no leading zeroes -#define BIN7 0x0702 // binary, 7 digits, no leading zeroes -#define BIN8 0x0802 // binary, 8 digits, no leading zeroes -#define BIN9 0x0902 // binary, 9 digits, no leading zeroes -#define BIN10 0x0A02 // binary, 10 digits, no leading zeroes -#define BIN11 0x0B02 // binary, 11 digits, no leading zeroes -#define BIN12 0x0C02 // binary, 12 digits, no leading zeroes -#define BIN13 0x0D02 // binary, 13 digits, no leading zeroes -#define BIN14 0x0E02 // binary, 14 digits, no leading zeroes -#define BIN15 0x0F02 // binary, 15 digits, no leading zeroes -#define BIN16 0x0002 // binary, 16 digits, no leading zeroes - - // binary, with leading zeroes -#define BINZ 0x1002 // binary, 16 digits, leading zeroes -#define BIN1Z 0x1102 // binary, 1 digit, leading zeroes -#define BIN2Z 0x1202 // binary, 2 digits, leading zeroes -#define BIN3Z 0x1302 // binary, 3 digits, leading zeroes -#define BIN4Z 0x1402 // binary, 4 digits, leading zeroes -#define BIN5Z 0x1502 // binary, 5 digits, leading zeroes -#define BIN6Z 0x1602 // binary, 6 digits, leading zeroes -#define BIN7Z 0x1702 // binary, 7 digits, leading zeroes -#define BIN8Z 0x1802 // binary, 8 digits, leading zeroes -#define BIN9Z 0x1902 // binary, 9 digits, leading zeroes -#define BIN10Z 0x1A02 // binary, 10 digits, leading zeroes -#define BIN11Z 0x1B02 // binary, 11 digits, leading zeroes -#define BIN12Z 0x1C02 // binary, 12 digits, leading zeroes -#define BIN13Z 0x1D02 // binary, 13 digits, leading zeroes -#define BIN14Z 0x1E02 // binary, 14 digits, leading zeroes -#define BIN15Z 0x1F02 // binary, 15 digits, leading zeroes -#define BIN16Z 0x1002 // binary, 16 digits, leading zeroes - - // binary, with leading blanked -#define BINZB 0x2002 // binary, 16 digits, leading blanks -#define BIN1ZB 0x2102 // binary, 1 digit, leading blanks -#define BIN2ZB 0x2202 // binary, 2 digits, leading blanks -#define BIN3ZB 0x2302 // binary, 3 digits, leading blanks -#define BIN4ZB 0x2402 // binary, 4 digits, leading blanks -#define BIN5ZB 0x2502 // binary, 5 digits, leading blanks -#define BIN6ZB 0x2602 // binary, 6 digits, leading blanks -#define BIN7ZB 0x2702 // binary, 7 digits, leading blanks -#define BIN8ZB 0x2802 // binary, 8 digits, leading blanks -#define BIN9ZB 0x2902 // binary, 9 digits, leading blanks -#define BIN10ZB 0x2A02 // binary, 10 digits, leading blanks -#define BIN11ZB 0x2B02 // binary, 11 digits, leading blanks -#define BIN12ZB 0x2C02 // binary, 12 digits, leading blanks -#define BIN13ZB 0x2D02 // binary, 13 digits, leading blanks -#define BIN14ZB 0x2E02 // binary, 14 digits, leading blanks -#define BIN15ZB 0x2F02 // binary, 15 digits, leading blanks -#define BIN16ZB 0x2002 // binary, 16 digits, leading blanks - - // signed decimal, no leading zeroes -#define DEC4d 0x050A // signed decimal, 5 digits, no leading zeroes -#define DEC1 0x010A // signed decimal, 1 digit, no leading zeroes -#define DEC2 0x020A // signed decimal, 2 digits, no leading zeroes -#define DEC3 0x030A // signed decimal, 3 digits, no leading zeroes -#define DEC4 0x040A // signed decimal, 4 digits, no leading zeroes -#define DEC5 0x050A // signed decimal, 5 digits, no leading zeroes - - // signed decimal, with leading zeroes -#define DECZ 0x150A // signed decimal, 5 digits, leading zeroes -#define DEC1Z 0x110A // signed decimal, 1 digit, leading zeroes -#define DEC2Z 0x120A // signed decimal, 2 digits, leading zeroes -#define DEC3Z 0x130A // signed decimal, 3 digits, leading zeroes -#define DEC4Z 0x140A // signed decimal, 4 digits, leading zeroes -#define DEC5Z 0x150A // signed decimal, 5 digits, leading zeroes - - // signed decimal, leading zeroes blanked -#define DECZB 0x250A // signed decimal, 5 digits, leading blanks -#define DEC1ZB 0x210A // signed decimal, 1 digit, leading blanks -#define DEC2ZB 0x220A // signed decimal, 2 digits, leading blanks -#define DEC3ZB 0x230A // signed decimal, 3 digits, leading blanks -#define DEC4ZB 0x240A // signed decimal, 4 digits, leading blanks -#define DEC5ZB 0x250A // signed decimal, 5 digits, leading blanks - - // unsigned decimal, no leading zeroes -#define UDEC 0x450A // unsigned decimal, 5 digits, no leading zeroes -#define UDEC1 0x410A // unsigned decimal, 1 digit, no leading zeroes -#define UDEC2 0x420A // unsigned decimal, 2 digits, no leading zeroes -#define UDEC3 0x430A // unsigned decimal, 3 digits, no leading zeroes -#define UDEC4 0x440A // unsigned decimal, 4 digits, no leading zeroes -#define UDEC5 0x450A // unsigned decimal, 5 digits, no leading zeroes - - // unsigned decimal, with leading zero's -#define UDECZ 0x550A // unsigned decimal, 5 digits, leading zeroes -#define UDEC1Z 0x510A // unsigned decimal, 1 digit, leading zeroes -#define UDEC2Z 0x520A // unsigned decimal, 2 digits, leading zeroes -#define UDEC3Z 0x530A // unsigned decimal, 3 digits, leading zeroes -#define UDEC4Z 0x540A // unsigned decimal, 4 digits, leading zeroes -#define UDEC5Z 0x550A // unsigned decimal, 5 digits, leading zeroes - - // unsigned decimal, leading zeroes blanked -#define UDECZB 0x650A // unsigned decimal, 5 digits, leading blanks -#define UDEC1ZB 0x610A // unsigned decimal, 1 digit, leading blanks -#define UDEC2ZB 0x620A // unsigned decimal, 2 digits, leading blanks -#define UDEC3ZB 0x630A // unsigned decimal, 3 digits, leading blanks -#define UDEC4ZB 0x640A // unsigned decimal, 4 digits, leading blanks -#define UDEC5ZB 0x650A // unsigned decimal, 5 digits, leading blanks - - // hex, with leading zero's -#define HEX4d 0x1410 // hex, 4 digits, leading zeroes -#define HEX1 0x1110 // hex, 1 digit, leading zeroes -#define HEX2 0x1210 // hex, 2 digits, leading zeroes -#define HEX3 0x1310 // hex, 3 digits, leading zeroes -#define HEX4 0x1410 // hex, 4 digits, leading zeroes - - // hex, no leading zero's -#define HEXZ 0x0410 // hex, 4 digits, no leading zeroes -#define HEX1Z 0x0110 // hex, 1 digit, no leading zeroes -#define HEX2Z 0x0210 // hex, 2 digits, no leading zeroes -#define HEX3Z 0x0310 // hex, 3 digits, no leading zeroes -#define HEX4Z 0x0410 // hex, 4 digits, no leading zeroes - - // hex, leading zero's blanked -#define HEXZB 0x2410 // hex, 4 digits, leading blanks -#define HEX1ZB 0x2110 // hex, 1 digit, leading blanks -#define HEX2ZB 0x2210 // hex, 2 digits, leading blanks -#define HEX3ZB 0x2310 // hex, 3 digits, leading blanks -#define HEX4ZB 0x2410 // hex, 4 digits, leading blanks - -// baud divisor rates -#define MIDI 95 -#define BAUD_110 27271 -#define BAUD_300 9999 -#define BAUD_600 4999 -#define BAUD_1200 2499 -#define BAUD_2400 1249 -#define BAUD_4800 624 -#define BAUD_9600 312 -#define BAUD_14400 207 -#define BAUD_19200 155 -#define BAUD_31250 95 -#define BAUD_38400 77 -#define BAUD_56000 53 -#define BAUD_57600 51 -#define BAUD_115200 25 -#define BAUD_128000 22 -#define BAUD_256000 11 -#define BAUD_300000 10 -#define BAUD_375000 8 -#define BAUD_500000 6 -#define BAUD_600000 4 - - -//==============================================// -// generic constants // -//==============================================// -#define ENABLE 1 -#define DISABLE 0 -#define ON 1 -#define OFF 0 -#define TRUE 1 -#define FALSE 0 - -//==============================================// -// joystick() function return constants // -//==============================================// -#define RELEASED 0 -#define UP 1 -#define LEFT 2 -#define DOWN 3 -#define RIGHT 4 -#define FIRE 5 - -//==============================================// -// spi_Init(...) mode arguments // -//==============================================// -#define SPI_SLOW 2 // 750khz -#define SPI_MED 1 // 3mhz -#define SPI_FAST 0 // 12mhz -#define RXMODE_0 0 // receive sample pos -#define RXMODE_1 1 // receive sample pos -#define CKMODE_0 0 // transmit sample pos -#define CKMODE_1 1 // transmit sample pos -#define CKMODE_2 2 // transmit sample pos -#define CKMODE_3 3 // transmit sample pos - -//==============================================// -//Pin related constants // -//==============================================// -#define IO1 0 -#define IO2 1 -#define LO 0 -#define HI 1 -#define OUTPUT4d 0 -#define INPUT4d 1 -#define ANALOGUE_8 2 -#define ANALOGUE_10 3 -#define ONEWIRE 4 -#define SOUND 5 - -//==============================================// -//gfx_Set() related constants // -//==============================================// -#define PEN_SIZE 0 // not necessary to use (legacy mode) -#define BACKGROUND_COLOUR 1 // screen background colour -#define OBJECT_COLOUR 2 // line / circle / rectangle generic colour -#define CLIPPING 3 // clipping ON / OFF -#define TRANSPARENT_COLOUR 4 // (only on displays with specific hware feature) -#define TRANSPARENCY 5 // 0 = OFF, 1 = ON (only on displays with specific hware feature) -#define FRAME_DELAY 6 // legacy mode, see pokeB(IMAGE_DELAY, n); -#define SCREEN_MODE 7 // LANDSCAPE, LANDSCAPE_R, PORTRAIT, PORTRAIT_R -#define OUTLINE_COLOUR 8 // if not BLACK (0) , used for outline around circles and rectanglse -#define CONTRAST 9 // set contrast ratuio in uOLED modules -#define LINE_PATTERN 10 // used for patterned lines, 16bit value (0 = no pattern) -#define COLOUR_MODE 11 // select 8 or 16 bit colour mode - - -#define SOLID 0 // PEN_SIZE argument (gfx_Set legacy mode) -#define OUTLINE 1 // PEN_SIZE argument (gfx_Set legacy mode) - -#define LANDSCAPE 0 // SCREEN_MODE (north) -#define LANDSCAPE_R 1 // SCREEN_MODE (south) -#define PORTRAIT 2 // SCREEN_MODE (west) -#define PORTRAIT_R 3 // SCREEN_MODE (east) - -#define COLOUR8 1 // COLOUR_MODE 8 bit colour mode -#define COLOUR16 0 // COLOUR_MODE 16 bit colour mode - -//==============================================// -//txt_Set() related constants // -//==============================================// -#define TEXT_COLOUR 0 // text foreground colr -#define TEXT_HIGHLIGHT 1 // text background colr -#define FONT_ID 2 // default 0, else points to data statement font -#define TEXT_WIDTH 3 // text width multiplier -#define TEXT_HEIGHT 4 // text height multiplier -#define TEXT_XGAP 5 // horizontal text gap (default 1) -#define TEXT_YGAP 6 // vertical text gap (default 1) -#define TEXT_PRINTDELAY 7 // for 'teletype' like effect when pronting -#define TEXT_OPACITY 8 // text mode flag, TRANSPARENT or OPAQUE -#define TEXT_BOLD 9 // embolden text (auto reset) - legacy -#define TEXT_ITALIC 10 // italicize text (auto reset) -#define TEXT_INVERSE 11 // invert text (auto reset) -#define TEXT_UNDERLINED 12 // underline text (auto reset) -#define TEXT_ATTRIBUTES 13 // controls BOLD/ITALIC/INVERSE/UNDERLINE simultaneously - -//==============================================// -//txt_Set() related arguments // -//==============================================// -#define SYSTEM 0 // internal system font -#define MEDIA 7 // font is at uSD_add - - -#define TRANSPARENT 0 // TEXT_OPACITY transparent text -#define OPAQUE 1 // TEXT_OPACITY opaque text - -#define BOLD 16 // TEXT_ATTRIBUTES bold text (auto reset) -#define ITALIC 32 // TEXT_ATTRIBUTES italic text (auto reset) -#define INVERSE 64 // TEXT_ATTRIBUTES inverse text (auto reset) -#define UNDERLINED 128 // TEXT_ATTRIBUTES underlined text (auto reset) - - -//==============================================// -// Memory MAP // -// system BYTE variables accesible with // -// peekB and pokeB // -//==============================================// -#define VX1 128 // display hardware x1 pos -#define VY1 129 // display hardware y1 pos -#define VX2 130 // display hardware x2 pos -#define VY2 131 // display hardware y2 pos -#define SYS_X_MAX 132 // display hardware X res-1 -#define SYS_Y_MAX 133 // display hardware Y res-1 -#define WRITE_GRAM_REG 134 // device register address for write operation -#define READ_GRAM_REG 135 // device register address for write operation -#define IMAGE_WIDTH 136 // width of currently loaded image -#define IMAGE_HEIGHT 137 // height of currently loaded image -#define IMAGE_DELAY 138 // 0 if image, else inter frame delay for movie -#define IMAGE_MODE 139 // bit 4 determines colr mode, other bits reserved -#define CLIP_LEFT_POS 140 // left clipping point (set with gfx_ClipWindow(...) -#define CLIP_TOP_POS 141 // top clipping point (set with gfx_ClipWindow(...) -#define CLIP_RIGHT_POS 142 // right clipping point (set with gfx_ClipWindow(...) -#define CLIP_BOTTOM_POS 143 // bottom clipping point (set with gfx_ClipWindow(...) -#define CLIP_LEFT 144 // current clip value (reads as full size if clipping turned off) -#define CLIP_TOP 145 // current clip value (reads as full size if clipping turned off) -#define CLIP_RIGHT 146 // current clip value (reads as full size if clipping turned off) -#define CLIP_BOTTOM 147 // current clip value (reads full size if clipping turned off) -#define FONT_TYPE 148 // font type, 0 = system font, else pointer to user or media font -#define FONT_MAX 149 // number of chars in current font -#define FONT_OFFSET 150 // starting offset (normally 0x20) -#define FONT_WIDTH 151 // current font width -#define FONT_HEIGHT 152 // current font height -#define TEXT_XMAG 153 // text width magnification -#define TEXT_YMAG 154 // text height magnification -#define TEXT_MARGIN 155 // left column for carriage return -#define TEXT_DELAY 156 // print delay -#define TEXT_X_GAP 157 // text horizontal gap size -#define TEXT_Y_GAP 158 // text vertical gap size -#define GFX_XMAX 159 // current display width-1 determined by portrait / landscape swapping -#define GFX_YMAX 160 // current display width-1 determined by portrait / landscape swapping -#define GFX_SCREENMODE 161 // holds current screen mode - // - - -//==============================================// -// system WORD variables accesible with peekW // -// and pokeW or pointer access // -//==============================================// -#define VM_OVERFLOW 83 // 16bit overflow of 32bit results (see OVF() funtion) -#define VM_COLOUR 84 // general working var for colour -#define VM_RETVAL 85 // last value returned from any function -#define GFX_BACK_COLOUR 86 // screen background colour -#define GFX_OBJECT_COLOUR 87 // graphics object colour -#define GFX_TEXT_COLOUR 88 // text forground colour -#define GFX_TEXT_BGCOLOUR 89 // text background colour -#define GFX_OUTLINE_COLOUR 90 // screen background colour -#define GFX_LINE_PATTERN 91 // line draw 16bit linear pattern -#define IMG_PIXEL_COUNT 92 // pixel count of current object (may be altered by clipping) -#define IMG_FRAME_COUNT 93 // count of frames in currently loaded video -#define MEDIA_HEAD 94 // media sector head position -#define SYS_OSTREAM 95 // system output redirection -#define GFX_LEFT 96 // virtual left point for current image -#define GFX_TOP 97 // virtual top point for current image -#define GFX_RIGHT 98 // virtual right point for current image -#define GFX_BOTTOM 99 // virtual bottom point for current image -#define GFX_X1 100 // clipped left point for current image -#define GFX_Y1 101 // clipped top point for current image -#define GFX_X2 102 // clipped right point for current image -#define GFX_Y2 103 // clipped bottom point for current image -#define GFX_X_ORG 104 // current Y origin -#define GFX_Y_ORG 105 // current Y origin -#define RANDOM_LO 106 // random number generator LO word -#define RANDOM_HI 107 // random number generator LO word -#define MEDIA_ADDR_LO 108 // uSD/FLASH absolute byte address LO -#define MEDIA_ADDR_HI 109 // uSD/FLASH absolute byte address HI -#define SECTOR_ADDR_LO 110 // uSD/FLASH sector address LO -#define SECTOR_ADDR_HI 111 // uSD/FLASH sector address HI -#define SYSTEM_TIMER_LO 112 // 1msec 32 bit free running timer LO word -#define SYSTEM_TIMER_HI 113 // 1msec 32 bit free running timer HI word -#define TIMER04d 114 // user timer0 -#define TIMER14d 115 // user timer1 -#define TIMER24d 116 // user timer2 -#define TIMER34d 117 // user timer3 (10msec resolution) -#define INCVAL 118 // incrementer size -#define TEMP_MEDIA_ADDRLO 119 // temp stroage while printing font from media storage -#define TEMP_MEDIA_ADDRHI 120 // temp stroage while printing font from media storage -#define GFX_TRANSPARENTCOLOUR 121 // image transparency colour -#define GFX_STRINGMETRIX 122 // low byte = string width, hi byte = string height -#define GFX_TEMPSTORE1 123 // low byte = last char printed, hi byte = frame timer over-ride - // reserved 124 // internal use - // reserved 125 // internal use -#define SYS_FLAGS1 126 // system control flags word 1 -#define SYS_FLAGS2 127 // system control flags word 2 - -//==============================================// -// bit constants for SYS_FLAGS1 // -//==============================================// -#define _STREAMLOCK 0x0001 // Used internally -#define _PENSIZE 0x0002 // object, 0=solid,1=outline -#define _OPACITY 0x0004 // text, 0=transparent,1=opaque -#define _OUTLINED 0x0008 // box/circle outline 0=off,1=on -#define _BOLD 0x0010 // text, 0=normal,1=bold (auto reset) -#define _ITALIC 0x0020 // Text, 0=normal,1=italic (auto reset) -#define _INVERSE 0x0040 // Text, 0=normal,1=inverse (auto reset) -#define _UNDERLINED 0x0080 // Text, 0=normal,1=underlined (auto reset) -#define _CLIPPING 0x0100 // Used internally, 0-clipping off, 1-clipping on -#define _STRMODE 0x0200 // Used internally -#define _SERMODE 0x0400 // Used internally -#define _TXTMODE 0x0800 // Used internally -#define _MEDIAMODE 0x1000 // Used internally -#define _PATTERNED 0x2000 // Used internally -#define _COLOUR8 0x4000 // Display mode, 0=16bit, 1=8bit -#define _MEDIAFONT 0x8000 // 0=internal font, 1=media font - -//==============================================// -// bit constants for SYS_FLAGS2 // -//==============================================// -#define _MEDIA_INSTALLED 0x0001 // SD of FLASH device is installed -#define _MEDIA_TYPE 0x0002 // 0=SD, 1=FLASH media device detected -#define _MEDIA_READ 0x0004 // 1=MEDIA read in progress -#define _MEDIA_WRITE 0x0008 // 1=MEDIA write in progress -#define _OW_PIN 0x0010 // 0=IO1, 1=IO2 (Dallas OW Pin) -#define _PTR_TYPE 0x0020 // Used internally -#define _TEMP1 0x0040 // Used internally -#define _TEMP2 0x0080 // Used internally -#define _RUNMODE 0x0100 // 1=running pcode from media -#define _SIGNED 0x0200 // 0=number printed '-' prepend -#define _RUNFLAG 0x0400 // 1=EVE processor is running SYSTEM -#define _SINGLESTEP 0x0800 // 1=set breakpoint for debugger -#define _COMMINT 0x1000 // 1=buffered comms active -#define _DUMMY16 0x2000 // 1=display needs 16bit dummy -#define _DISP16 0x4000 // 1=display is 16bit interface -#define _PROPFONT 0x8000 // 1=current font is proportional - - -//==============================================// -// EVE User Resources // -//==============================================// -#define USR_SP 128 // EVE user defined stack pointer -#define USRVARS 129 // EVE user variables VARS[255] -#define USRSTACK 384 // EVE machine stack STACK[128] - -//------------------------------------------------------------------------------ -//------------------------------------------------------------------------------ -//------------------------------------------------------------------------------ -//------------------------------------------------------------------------------ -//------------------------------------------------------------------------------ - -/* - 16 bit RGB (565) Colour Chart - Original work by 4D Forum Member: skadoo -*/ - - - -#define ALICEBLUE 0xF7DF -#define ANTIQUEWHITE 0xFF5A -#define AQUA 0x07FF -#define AQUAMARINE 0x7FFA -#define AZURE 0xF7FF -#define BEIGE 0xF7BB -#define BISQUE 0xFF38 -#define BLACK 0x0000 -#define BLANCHEDALMOND 0xFF59 -#define BLUE 0x001F -#define BLUEVIOLET 0x895C -#define BROWN 0xA145 -#define BURLYWOOD 0xDDD0 -#define CADETBLUE 0x5CF4 -#define CHARTREUSE 0x7FE0 -#define CHOCOLATE 0xD343 -#define CORAL 0xFBEA -#define CORNFLOWERBLUE 0x64BD -#define CORNSILK 0xFFDB -#define CRIMSON 0xD8A7 -#define CYAN 0x07FF -#define DARKBLUE 0x0011 -#define DARKCYAN 0x0451 -#define DARKGOLDENROD 0xBC21 -#define DARKGRAY 0xAD55 -#define DARKGREEN 0x0320 -#define DARKKHAKI 0xBDAD -#define DARKMAGENTA 0x8811 -#define DARKOLIVEGREEN 0x5345 -#define DARKORANGE 0xFC60 -#define DARKORCHID 0x9999 -#define DARKRED 0x8800 -#define DARKSALMON 0xECAF -#define DARKSEAGREEN 0x8DF1 -#define DARKSLATEBLUE 0x49F1 -#define DARKSLATEGRAY 0x2A69 -#define DARKTURQUOISE 0x067A -#define DARKVIOLET 0x901A -#define DEEPPINK 0xF8B2 -#define DEEPSKYBLUE 0x05FF -#define DIMGRAY 0x6B4D -#define DODGERBLUE 0x1C9F -#define FIREBRICK 0xB104 -#define FLORALWHITE 0xFFDE -#define FORESTGREEN 0x2444 -#define FUCHSIA 0xF81F -#define GAINSBORO 0xDEFB -#define GHOSTWHITE 0xFFDF -#define GOLD 0xFEA0 -#define GOLDENROD 0xDD24 -#define GRAY 0x8410 -#define GREEN 0x0400 -#define GREENYELLOW 0xAFE5 -#define HONEYDEW 0xF7FE -#define HOTPINK 0xFB56 -#define INDIANRED 0xCAEB -#define INDIGO 0x4810 -#define IVORY 0xFFFE -#define KHAKI 0xF731 -#define LAVENDER 0xE73F -#define LAVENDERBLUSH 0xFF9E -#define LAWNGREEN 0x7FE0 -#define LEMONCHIFFON 0xFFD9 -#define LIGHTBLUE 0xAEDC -#define LIGHTCORAL 0xF410 -#define LIGHTCYAN 0xE7FF -#define LIGHTGOLD 0xFFDA -#define LIGHTGREEN 0x9772 -#define LIGHTGREY 0xD69A -#define LIGHTPINK 0xFDB8 -#define LIGHTSALMON 0xFD0F -#define LIGHTSEAGREEN 0x2595 -#define LIGHTSKYBLUE 0x867F -#define LIGHTSLATEGRAY 0x7453 -#define LIGHTSTEELBLUE 0xB63B -#define LIGHTYELLOW 0xFFFC -#define LIME 0x07E0 -#define LIMEGREEN 0x3666 -#define LINEN 0xFF9C -#define MAGENTA 0xF81F -#define MAROON 0x8000 -#define MEDIUMAQUAMARINE 0x6675 -#define MEDIUMBLUE 0x0019 -#define MEDIUMORCHID 0xBABA -#define MEDIUMPURPLE 0x939B -#define MEDIUMSEAGREEN 0x3D8E -#define MEDIUMSLATEBLUE 0x7B5D -#define MEDIUMSPRINGGREEN 0x07D3 -#define MEDIUMTURQUOISE 0x4E99 -#define MEDIUMVIOLETRED 0xC0B0 -#define MIDNIGHTBLUE 0x18CE -#define MINTCREAM 0xF7FF -#define MISTYROSE 0xFF3C -#define MOCCASIN 0xFF36 -#define NAVAJOWHITE 0xFEF5 -#define NAVY 0x0010 -#define OLDLACE 0xFFBC -#define OLIVE 0x8400 -#define OLIVEDRAB 0x6C64 -#define ORANGE 0xFD20 -#define ORANGERED 0xFA20 -#define ORCHID 0xDB9A -#define PALEGOLDENROD 0xEF55 -#define PALEGREEN 0x9FD3 -#define PALETURQUOISE 0xAF7D -#define PALEVIOLETRED 0xDB92 -#define PAPAYAWHIP 0xFF7A -#define PEACHPUFF 0xFED7 -#define PERU 0xCC27 -#define PINK 0xFE19 -#define PLUM 0xDD1B -#define POWDERBLUE 0xB71C -#define PURPLE 0x8010 -#define RED 0xF800 -#define ROSYBROWN 0xBC71 -#define ROYALBLUE 0x435C -#define SADDLEBROWN 0x8A22 -#define SALMON 0xFC0E -#define SANDYBROWN 0xF52C -#define SEAGREEN 0x2C4A -#define SEASHELL 0xFFBD -#define SIENNA 0xA285 -#define SILVER 0xC618 -#define SKYBLUE 0x867D -#define SLATEBLUE 0x6AD9 -#define SLATEGRAY 0x7412 -#define SNOW 0xFFDF -#define SPRINGGREEN 0x07EF -#define STEELBLUE 0x4416 -#define TAN 0xD5B1 -#define TEAL 0x0410 -#define THISTLE 0xDDFB -#define TOMATO 0xFB08 -#define TURQUOISE 0x471A -#define VIOLET 0xEC1D -#define WHEAT 0xF6F6 -#define WHITE 0xFFFF -#define WHITESMOKE 0xF7BE -#define YELLOW 0xFFE0 -#define YELLOWGREEN 0x9E66 - - - - - - - - - - diff --git a/lib/Goldelox_Serial/Goldelox_Const4DSerial.h b/lib/Goldelox_Serial/Goldelox_Const4DSerial.h deleted file mode 100644 index 428c157..0000000 --- a/lib/Goldelox_Serial/Goldelox_Const4DSerial.h +++ /dev/null @@ -1,71 +0,0 @@ -#define F_charheight 1 -#define F_charwidth 2 -#define F_gfx_BGcolour -146 -#define F_gfx_ChangeColour -66 -#define F_gfx_Circle -51 -#define F_gfx_CircleFilled -52 -#define F_gfx_Clipping -148 -#define F_gfx_ClipWindow -65 -#define F_gfx_Cls -41 -#define F_gfx_Contrast -154 -#define F_gfx_FrameDelay -151 -#define F_gfx_GetPixel -54 -#define F_gfx_Line -46 -#define F_gfx_LinePattern -155 -#define F_gfx_LineTo -44 -#define F_gfx_MoveTo -42 -#define F_gfx_Orbit 3 -#define F_gfx_OutlineColour -153 -#define F_gfx_Polygon 4 -#define F_gfx_Polyline 5 -#define F_gfx_PutPixel -53 -#define F_gfx_Rectangle -49 -#define F_gfx_RectangleFilled -50 -#define F_gfx_ScreenMode -152 -#define F_gfx_Set -40 -#define F_gfx_SetClipRegion -68 -#define F_gfx_Transparency -150 -#define F_gfx_TransparentColour -149 -#define F_gfx_Triangle -55 -#define F_media_Flush -78 -#define F_media_Image -77 -#define F_media_Init -79 -#define F_media_ReadByte -73 -#define F_media_ReadWord -74 -#define F_media_SetAdd -71 -#define F_media_SetSector -72 -#define F_media_Video -69 -#define F_media_VideoFrame -70 -#define F_media_WriteByte -75 -#define F_media_WriteWord -76 -#define F_putCH -2 -#define F_putstr 6 -#define F_txt_Attributes -142 -#define F_txt_BGcolour -130 -#define F_txt_Bold -138 -#define F_txt_FGcolour -129 -#define F_txt_FontID -131 -#define F_txt_Height -133 -#define F_txt_Inverse -140 -#define F_txt_Italic -139 -#define F_txt_MoveCursor -28 -#define F_txt_Opacity -137 -#define F_txt_Set -29 -#define F_txt_Underline -141 -#define F_txt_Width -132 -#define F_txt_Xgap -134 -#define F_txt_Ygap -135 -#define F_BeeP -38 -#define F_sys_GetModel 7 -#define F_sys_GetVersion 8 -#define F_sys_GetPmmC 9 -#define F_blitComtoDisplay 10 -#define F_setbaudWait 11 -#define F_peekW -11 -#define F_pokeW -13 -#define F_peekB -10 -#define F_pokeB -12 -#define F_joystick -39 -#define F_SSTimeout 12 -#define F_SSSpeed 13 -#define F_SSMode 14 diff --git a/lib/Goldelox_Serial/Goldelox_Serial_4DLib.cpp b/lib/Goldelox_Serial/Goldelox_Serial_4DLib.cpp deleted file mode 100644 index f8a0b8f..0000000 --- a/lib/Goldelox_Serial/Goldelox_Serial_4DLib.cpp +++ /dev/null @@ -1,1226 +0,0 @@ -/* - Goldelox_Serial_4DLib.cpp - Library for 4D Systems Serial Environment. - */ - -#include "Goldelox_Serial_4DLib.h" - -#if (ARDUINO >= 100) - #include "Arduino.h" // for Arduino 1.0 -#else - #include "WProgram.h" // for Arduino 23 -#endif - -Goldelox_Serial_4DLib::Goldelox_Serial_4DLib(Stream * virtualPort) { - _virtualPort = virtualPort; -#ifndef _SAM3XA_ - // Only done on non Arduino Due Boards - _virtualPort->flush(); -#endif -} - -//*********************************************************************************************// -//**********************************Intrinsic 4D Routines**************************************// -//*********************************************************************************************// - -void Goldelox_Serial_4DLib::WriteChars(char * charsout) -{ - unsigned char wk ; - do - { - wk = *charsout++ ; - _virtualPort->write(wk) ; - } while (wk) ; -} - -void Goldelox_Serial_4DLib::WriteBytes(char * Source, int Size) -{ - unsigned char wk ; - int i ; - for (i = 0; i < Size; i++) - { - wk = *Source++ ; - _virtualPort->write(wk) ; - } -} - -void Goldelox_Serial_4DLib::WriteWords(word * Source, int Size) -{ - word wk ; - int i ; - for (i = 0; i < Size; i++) - { - wk = *Source++ ; - _virtualPort->write(wk >> 8) ; - _virtualPort->write(wk) ; - } -} - -void Goldelox_Serial_4DLib::getbytes(char * data, int size) -{ - int read ; - unsigned long sttime ; - int readc ; - readc = 0 ; - sttime = millis() ; - while ((readc != size) && (millis() - sttime < TimeLimit4D)) - { - if(_virtualPort->available()) - { - data[readc++] = _virtualPort->read() ; - } - } - if (readc != size) - { - Error4D = Err4D_Timeout ; - if (Callback4D != NULL) - Callback4D(Error4D, Error4D_Inv) ; - } -} - -void Goldelox_Serial_4DLib::GetAck(void) -{ - int read ; - unsigned char readx ; - unsigned long sttime ; - Error4D = Err4D_OK ; - sttime = millis(); - read = 0 ; - while ((read != 1) && (millis() - sttime < TimeLimit4D)) - { - if(_virtualPort->available() != 0) - { - readx = _virtualPort->read() ; - read = 1 ; - } - } - if (read == 0) - { - Error4D = Err4D_Timeout ; - if (Callback4D != NULL) - Callback4D(Error4D, Error4D_Inv) ; - } - else if (readx != 6) - { - Error4D = Err4D_NAK ; - Error4D_Inv = readx ; - if (Callback4D != NULL) - Callback4D(Error4D, Error4D_Inv) ; - } -} - -word Goldelox_Serial_4DLib::GetWord(void) -{ - unsigned char readx[2] ; - int readc ; - unsigned long sttime ; - - if (Error4D != Err4D_OK) - return 0 ; - sttime = millis(); - readc = 0 ; - while ((readc != 2) && (millis() - sttime < TimeLimit4D)) - { - if(_virtualPort->available()) - { - readx[readc++] = _virtualPort->read() ; - } - } - - if (readc != 2) - { - Error4D = Err4D_Timeout ; - if (Callback4D != NULL) - Callback4D(Error4D, Error4D_Inv) ; - return 0 ; - } - else - return readx[0] << 8 | readx[1] ; -} - -void Goldelox_Serial_4DLib::getString(char * outStr, int strLen) -{ - unsigned char readx[2] ; - int readc ; - unsigned long sttime ; - - if (Error4D != Err4D_OK) - { - outStr[0] = 0 ; - return ; - } - sttime = millis(); - readc = 0 ; - while ((readc != strLen) && (millis() - sttime < TimeLimit4D)) - { - if(_virtualPort->available()) - { - outStr[readc++] = _virtualPort->read() ; - } - } - - if (readc != strLen) - { - Error4D = Err4D_Timeout ; - if (Callback4D != NULL) - Callback4D(Error4D, Error4D_Inv) ; - } - outStr[readc] = 0 ; -} - -word Goldelox_Serial_4DLib::GetAckResp(void) -{ - GetAck() ; - return GetWord() ; -} - -word Goldelox_Serial_4DLib::GetAckRes2Words(word * word1, word * word2) -{ - int Result ; - GetAck() ; - Result = GetWord() ; - *word1 = GetWord() ; - *word2 = GetWord() ; - return Result ; -} - -void Goldelox_Serial_4DLib::GetAck2Words(word * word1, word * word2) -{ - GetAck() ; - *word1 = GetWord() ; - *word2 = GetWord() ; -} - -word Goldelox_Serial_4DLib::GetAckResStr(char * OutStr) -{ - int Result ; - GetAck() ; - Result = GetWord() ; - getString(OutStr, Result) ; - return Result ; -} -/* -word Goldelox_Serial_4DLib::GetAckResData(t4DByteArray OutData, word size) -{ - int Result ; - GetAck() ; - Result = GetWord() ; - getbytes(OutData, size) ; - return Result ; -} -*/ -void Goldelox_Serial_4DLib::SetThisBaudrate(int Newrate) -{ - int br ; - _virtualPort->flush() ; -// _virtualPort->end() ; - switch(Newrate) - { - /* case BAUD_110 : br = 110 ; - break ; - case BAUD_300 : br = 300 ; - break ; - case BAUD_600 : br = 600 ; - break ; - case BAUD_1200 : br = 1200 ; - break ; - case BAUD_2400 : br = 2400 ; - break ; - case BAUD_4800 : br = 4800 ; - break ;*/ - case BAUD_9600 : br = 9600 ; - break ; -// case BAUD_14400 : br = 14400 ; -// break ; - case BAUD_19200 : br = 19200 ; - break ; - /* case BAUD_31250 : br = 31250 ; - break ; - case BAUD_38400 : br = 38400 ; - break ; - case BAUD_56000 : br = 56000 ; - break ; - case BAUD_57600 : br = 57600 ; - break ; - case BAUD_115200 : br = 115200 ; - break ; - case BAUD_128000 : br = 133928 ; // actual rate is not 128000 ; - break ; - case BAUD_256000 : br = 281250 ; // actual rate is not 256000 ; - break ; - case BAUD_300000 : br = 312500 ; // actual rate is not 300000 ; - break ; - case BAUD_375000 : br = 401785 ; // actual rate is not 375000 ; - break ; - case BAUD_500000 : br = 562500 ; // actual rate is not 500000 ; - break ; - case BAUD_600000 : br = 703125 ; // actual rate is not 600000 ; - break ;*/ - } -// _virtualPort->begin(br) ; - delay(50) ; // Display sleeps for 100 - _virtualPort->flush() ; -} - -//*********************************************************************************************// -//**********************************Compound 4D Routines***************************************// -//*********************************************************************************************// - -word Goldelox_Serial_4DLib::charheight(char TestChar) -{ - _virtualPort->print((char)(F_charheight >> 8)) ; - _virtualPort->print((char)(F_charheight)) ; - _virtualPort->print((char)(TestChar)) ; - return GetAckResp() ; -} - -word Goldelox_Serial_4DLib::charwidth(char TestChar) -{ - _virtualPort->print((char)(F_charwidth >> 8)) ; - _virtualPort->print((char)(F_charwidth)) ; - _virtualPort->print((char)(TestChar)) ; - return GetAckResp() ; -} - -void Goldelox_Serial_4DLib::gfx_BGcolour(word Color) -{ - _virtualPort->print((char)(F_gfx_BGcolour >> 8)) ; - _virtualPort->print((char)(F_gfx_BGcolour)) ; - _virtualPort->print((char)(Color >> 8)) ; - _virtualPort->print((char)(Color)) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::gfx_ChangeColour(word OldColor, word NewColor) -{ - _virtualPort->print((char)(F_gfx_ChangeColour >> 8)) ; - _virtualPort->print((char)(F_gfx_ChangeColour)) ; - _virtualPort->print((char)(OldColor >> 8)) ; - _virtualPort->print((char)(OldColor)) ; - _virtualPort->print((char)(NewColor >> 8)) ; - _virtualPort->print((char)(NewColor)) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::gfx_Circle(word X, word Y, word Radius, word Color) -{ - _virtualPort->print((char)(F_gfx_Circle >> 8)) ; - _virtualPort->print((char)(F_gfx_Circle)) ; - _virtualPort->print((char)(X >> 8)) ; - _virtualPort->print((char)(X)) ; - _virtualPort->print((char)(Y >> 8)) ; - _virtualPort->print((char)(Y)) ; - _virtualPort->print((char)(Radius >> 8)) ; - _virtualPort->print((char)(Radius)) ; - _virtualPort->print((char)(Color >> 8)) ; - _virtualPort->print((char)(Color)) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::gfx_CircleFilled(word X, word Y, word Radius, word Color) -{ - _virtualPort->print((char)(F_gfx_CircleFilled >> 8)) ; - _virtualPort->print((char)(F_gfx_CircleFilled)) ; - _virtualPort->print((char)(X >> 8)) ; - _virtualPort->print((char)(X)) ; - _virtualPort->print((char)(Y >> 8)) ; - _virtualPort->print((char)(Y)) ; - _virtualPort->print((char)(Radius >> 8)) ; - _virtualPort->print((char)(Radius)) ; - _virtualPort->print((char)(Color >> 8)) ; - _virtualPort->print((char)(Color)) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::gfx_Clipping(word OnOff) -{ - _virtualPort->print((char)(F_gfx_Clipping >> 8)) ; - _virtualPort->print((char)(F_gfx_Clipping)) ; - _virtualPort->print((char)(OnOff >> 8)) ; - _virtualPort->print((char)(OnOff)) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::gfx_ClipWindow(word X1, word Y1, word X2, word Y2) -{ - _virtualPort->print((char)(F_gfx_ClipWindow >> 8)) ; - _virtualPort->print((char)(F_gfx_ClipWindow)) ; - _virtualPort->print((char)(X1 >> 8)) ; - _virtualPort->print((char)(X1)) ; - _virtualPort->print((char)(Y1 >> 8)) ; - _virtualPort->print((char)(Y1)) ; - _virtualPort->print((char)(X2 >> 8)) ; - _virtualPort->print((char)(X2)) ; - _virtualPort->print((char)(Y2 >> 8)) ; - _virtualPort->print((char)(Y2)) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::gfx_Cls() -{ - _virtualPort->print((char)(F_gfx_Cls >> 8)) ; - _virtualPort->print((char)(F_gfx_Cls)) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::gfx_Contrast(word Contrast) -{ - _virtualPort->print((char)(F_gfx_Contrast >> 8)) ; - _virtualPort->print((char)(F_gfx_Contrast)) ; - _virtualPort->print((char)(Contrast >> 8)) ; - _virtualPort->print((char)(Contrast)) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::gfx_FrameDelay(word Msec) -{ - _virtualPort->print((char)(F_gfx_FrameDelay >> 8)) ; - _virtualPort->print((char)(F_gfx_FrameDelay)) ; - _virtualPort->print((char)(Msec >> 8)) ; - _virtualPort->print((char)(Msec)) ; - GetAck() ; -} - -word Goldelox_Serial_4DLib::gfx_GetPixel(word X, word Y) -{ - _virtualPort->print((char)(F_gfx_GetPixel >> 8 )) ; - _virtualPort->print((char)(F_gfx_GetPixel )) ; - _virtualPort->print((char)(X >> 8 )) ; - _virtualPort->print((char)(X )) ; - _virtualPort->print((char)(Y >> 8 )) ; - _virtualPort->print((char)(Y )) ; - return GetAckResp() ; -} - -void Goldelox_Serial_4DLib::gfx_Line(word X1, word Y1, word X2, word Y2, word Color) -{ - _virtualPort->print((char)(F_gfx_Line >> 8 )) ; - _virtualPort->print((char)(F_gfx_Line )) ; - _virtualPort->print((char)(X1 >> 8 )) ; - _virtualPort->print((char)(X1 )) ; - _virtualPort->print((char)(Y1 >> 8 )) ; - _virtualPort->print((char)(Y1 )) ; - _virtualPort->print((char)(X2 >> 8 )) ; - _virtualPort->print((char)(X2 )) ; - _virtualPort->print((char)(Y2 >> 8 )) ; - _virtualPort->print((char)(Y2 )) ; - _virtualPort->print((char)(Color >> 8 )) ; - _virtualPort->print((char)(Color )) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::gfx_LinePattern(word Pattern) -{ - _virtualPort->print((char)(F_gfx_LinePattern >> 8 )) ; - _virtualPort->print((char)(F_gfx_LinePattern )) ; - _virtualPort->print((char)(Pattern >> 8 )) ; - _virtualPort->print((char)(Pattern )) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::gfx_LineTo(word X, word Y) -{ - _virtualPort->print((char)(F_gfx_LineTo >> 8 )) ; - _virtualPort->print((char)(F_gfx_LineTo )) ; - _virtualPort->print((char)(X >> 8 )) ; - _virtualPort->print((char)(X )) ; - _virtualPort->print((char)(Y >> 8 )) ; - _virtualPort->print((char)(Y )) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::gfx_MoveTo(word X, word Y) -{ - _virtualPort->print((char)(F_gfx_MoveTo >> 8 )) ; - _virtualPort->print((char)(F_gfx_MoveTo )) ; - _virtualPort->print((char)(X >> 8 )) ; - _virtualPort->print((char)(X )) ; - _virtualPort->print((char)(Y >> 8 )) ; - _virtualPort->print((char)(Y )) ; - GetAck() ; -} - -word Goldelox_Serial_4DLib::gfx_Orbit(word Angle, word Distance, word * Xdest, word * Ydest) -{ - _virtualPort->print((char)(F_gfx_Orbit >> 8 )) ; - _virtualPort->print((char)(F_gfx_Orbit )) ; - _virtualPort->print((char)(Angle >> 8 )) ; - _virtualPort->print((char)(Angle )) ; - _virtualPort->print((char)(Distance >> 8 )) ; - _virtualPort->print((char)(Distance )) ; - GetAck2Words(Xdest,Ydest) ; - return 0 ; -} - -void Goldelox_Serial_4DLib::gfx_OutlineColour(word Color) -{ - _virtualPort->print((char)(F_gfx_OutlineColour >> 8 )) ; - _virtualPort->print((char)(F_gfx_OutlineColour )) ; - _virtualPort->print((char)(Color >> 8 )) ; - _virtualPort->print((char)(Color )) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::gfx_Polygon(word n, t4DWordArray Xvalues, t4DWordArray Yvalues, word Color) -{ - _virtualPort->print((char)(F_gfx_Polygon >> 8 )) ; - _virtualPort->print((char)(F_gfx_Polygon )) ; - _virtualPort->print((char)(n >> 8 )) ; - _virtualPort->print((char)(n )) ; - WriteWords(Xvalues, n) ; - WriteWords(Yvalues, n) ; - _virtualPort->print((char)(Color >> 8 )) ; - _virtualPort->print((char)(Color )) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::gfx_Polyline(word n, t4DWordArray Xvalues, t4DWordArray Yvalues, word Color) -{ - _virtualPort->print((char)(F_gfx_Polyline >> 8 )) ; - _virtualPort->print((char)(F_gfx_Polyline )) ; - _virtualPort->print((char)(n >> 8 )) ; - _virtualPort->print((char)(n )) ; - WriteWords(Xvalues, n) ; - WriteWords(Yvalues, n) ; - _virtualPort->print((char)(Color >> 8 )) ; - _virtualPort->print((char)(Color )) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::gfx_PutPixel(word X, word Y, word Color) -{ - _virtualPort->print((char)(F_gfx_PutPixel >> 8 )) ; - _virtualPort->print((char)(F_gfx_PutPixel )) ; - _virtualPort->print((char)(X >> 8 )) ; - _virtualPort->print((char)(X )) ; - _virtualPort->print((char)(Y >> 8 )) ; - _virtualPort->print((char)(Y )) ; - _virtualPort->print((char)(Color >> 8 )) ; - _virtualPort->print((char)(Color )) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::gfx_Rectangle(word X1, word Y1, word X2, word Y2, word Color) -{ - _virtualPort->print((char)(F_gfx_Rectangle >> 8 )) ; - _virtualPort->print((char)(F_gfx_Rectangle )) ; - _virtualPort->print((char)(X1 >> 8 )) ; - _virtualPort->print((char)(X1 )) ; - _virtualPort->print((char)(Y1 >> 8 )) ; - _virtualPort->print((char)(Y1 )) ; - _virtualPort->print((char)(X2 >> 8 )) ; - _virtualPort->print((char)(X2 )) ; - _virtualPort->print((char)(Y2 >> 8 )) ; - _virtualPort->print((char)(Y2 )) ; - _virtualPort->print((char)(Color >> 8 )) ; - _virtualPort->print((char)(Color )) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::gfx_RectangleFilled(word X1, word Y1, word X2, word Y2, word Color) -{ - _virtualPort->print((char)(F_gfx_RectangleFilled >> 8 )) ; - _virtualPort->print((char)(F_gfx_RectangleFilled )) ; - _virtualPort->print((char)(X1 >> 8 )) ; - _virtualPort->print((char)(X1 )) ; - _virtualPort->print((char)(Y1 >> 8 )) ; - _virtualPort->print((char)(Y1 )) ; - _virtualPort->print((char)(X2 >> 8 )) ; - _virtualPort->print((char)(X2 )) ; - _virtualPort->print((char)(Y2 >> 8 )) ; - _virtualPort->print((char)(Y2 )) ; - _virtualPort->print((char)(Color >> 8 )) ; - _virtualPort->print((char)(Color )) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::gfx_ScreenMode(word ScreenMode) -{ - _virtualPort->print((char)(F_gfx_ScreenMode >> 8 )) ; - _virtualPort->print((char)(F_gfx_ScreenMode )) ; - _virtualPort->print((char)(ScreenMode >> 8 )) ; - _virtualPort->print((char)(ScreenMode )) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::gfx_Set(word Func, word Value) -{ - _virtualPort->print((char)(F_gfx_Set >> 8 )) ; - _virtualPort->print((char)(F_gfx_Set )) ; - _virtualPort->print((char)(Func >> 8 )) ; - _virtualPort->print((char)(Func )) ; - _virtualPort->print((char)(Value >> 8 )) ; - _virtualPort->print((char)(Value )) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::gfx_SetClipRegion() -{ - _virtualPort->print((char)(F_gfx_SetClipRegion >> 8)) ; - _virtualPort->print((char)(F_gfx_SetClipRegion)) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::gfx_Transparency(word OnOff) -{ - _virtualPort->print((char)(F_gfx_Transparency >> 8)) ; - _virtualPort->print((char)(F_gfx_Transparency)) ; - _virtualPort->print((char)(OnOff >> 8)) ; - _virtualPort->print((char)(OnOff)) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::gfx_TransparentColour(word Color) -{ - _virtualPort->print((char)(F_gfx_TransparentColour >> 8)) ; - _virtualPort->print((char)(F_gfx_TransparentColour)) ; - _virtualPort->print((char)(Color >> 8)) ; - _virtualPort->print((char)(Color)) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::gfx_Triangle(word X1, word Y1, word X2, word Y2, word X3, word Y3, word Color) -{ - _virtualPort->print((char)(F_gfx_Triangle >> 8)) ; - _virtualPort->print((char)(F_gfx_Triangle)) ; - _virtualPort->print((char)(X1 >> 8)) ; - _virtualPort->print((char)(X1)) ; - _virtualPort->print((char)(Y1 >> 8)) ; - _virtualPort->print((char)(Y1)) ; - _virtualPort->print((char)(X2 >> 8)) ; - _virtualPort->print((char)(X2)) ; - _virtualPort->print((char)(Y2 >> 8)) ; - _virtualPort->print((char)(Y2)) ; - _virtualPort->print((char)(X3 >> 8)) ; - _virtualPort->print((char)(X3)) ; - _virtualPort->print((char)(Y3 >> 8)) ; - _virtualPort->print((char)(Y3)) ; - _virtualPort->print((char)(Color >> 8)) ; - _virtualPort->print((char)(Color)) ; - GetAck() ; -} - -word Goldelox_Serial_4DLib::media_Flush() -{ - _virtualPort->print((char)(F_media_Flush >> 8)) ; - _virtualPort->print((char)(F_media_Flush)) ; - return GetAckResp() ; -} - -void Goldelox_Serial_4DLib::media_Image(word X, word Y) -{ - _virtualPort->print((char)(F_media_Image >> 8)) ; - _virtualPort->print((char)(F_media_Image)) ; - _virtualPort->print((char)(X >> 8)) ; - _virtualPort->print((char)(X)) ; - _virtualPort->print((char)(Y >> 8)) ; - _virtualPort->print((char)(Y)) ; - GetAck() ; -} - -word Goldelox_Serial_4DLib::media_Init() -{ - _virtualPort->print((char)(F_media_Init >> 8)) ; - _virtualPort->print((char)(F_media_Init)) ; - return GetAckResp() ; -} - -word Goldelox_Serial_4DLib::media_ReadByte() -{ - _virtualPort->print((char)(F_media_ReadByte >> 8)) ; - _virtualPort->print((char)(F_media_ReadByte)) ; - return GetAckResp() ; -} - -word Goldelox_Serial_4DLib::media_ReadWord() -{ - _virtualPort->print((char)(F_media_ReadWord >> 8)) ; - _virtualPort->print((char)(F_media_ReadWord)) ; - return GetAckResp() ; -} - -void Goldelox_Serial_4DLib::media_SetAdd(word HiWord, word LoWord) -{ - _virtualPort->print((char)(F_media_SetAdd >> 8)) ; - _virtualPort->print((char)(F_media_SetAdd)) ; - _virtualPort->print((char)(HiWord >> 8)) ; - _virtualPort->print((char)(HiWord)) ; - _virtualPort->print((char)(LoWord >> 8)) ; - _virtualPort->print((char)(LoWord)) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::media_SetSector(word HiWord, word LoWord) -{ - _virtualPort->print((char)(F_media_SetSector >> 8)) ; - _virtualPort->print((char)(F_media_SetSector)) ; - _virtualPort->print((char)(HiWord >> 8)) ; - _virtualPort->print((char)(HiWord)) ; - _virtualPort->print((char)(LoWord >> 8)) ; - _virtualPort->print((char)(LoWord)) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::media_Video(word X, word Y) -{ - _virtualPort->print((char)(F_media_Video >> 8)) ; - _virtualPort->print((char)(F_media_Video)) ; - _virtualPort->print((char)(X >> 8)) ; - _virtualPort->print((char)(X)) ; - _virtualPort->print((char)(Y >> 8)) ; - _virtualPort->print((char)(Y)) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::media_VideoFrame(word X, word Y, word Framenumber) -{ - _virtualPort->print((char)(F_media_VideoFrame >> 8)) ; - _virtualPort->print((char)(F_media_VideoFrame)) ; - _virtualPort->print((char)(X >> 8)) ; - _virtualPort->print((char)(X)) ; - _virtualPort->print((char)(Y >> 8)) ; - _virtualPort->print((char)(Y)) ; - _virtualPort->print((char)(Framenumber >> 8)) ; - _virtualPort->print((char)(Framenumber)) ; - GetAck() ; -} - -word Goldelox_Serial_4DLib::media_WriteByte(word Byte) -{ - _virtualPort->print((char)(F_media_WriteByte >> 8)) ; - _virtualPort->print((char)(F_media_WriteByte)) ; - _virtualPort->print((char)(Byte >> 8)) ; - _virtualPort->print((char)(Byte)) ; - return GetAckResp() ; -} - -word Goldelox_Serial_4DLib::media_WriteWord(word Word) -{ - _virtualPort->print((char)(F_media_WriteWord >> 8)) ; - _virtualPort->print((char)(F_media_WriteWord)) ; - _virtualPort->print((char)(Word >> 8)) ; - _virtualPort->print((char)(Word)) ; - return GetAckResp() ; -} - -void Goldelox_Serial_4DLib::putCH(word WordChar) -{ - _virtualPort->print((char)(F_putCH >> 8)) ; - _virtualPort->print((char)(F_putCH)) ; - _virtualPort->print((char)(WordChar >> 8)) ; - _virtualPort->print((char)(WordChar)) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::putstr(char * InString) -{ - _virtualPort->print((char)(F_putstr >> 8)) ; - _virtualPort->print((char)(F_putstr)) ; - WriteChars(InString) ; - GetAck() ; -} -////////////////////////////////////////////////////// -//-----------------print---------------------------------- - -#ifdef AVR -void Goldelox_Serial_4DLib::print(const __FlashStringHelper *ifsh) -{ - PGM_P p = reinterpret_cast(ifsh); - size_t n = 0; - while (1) { - unsigned char c = pgm_read_byte(p++); - if (c == 0) break; - putCH(c); - } -} -#endif - -void Goldelox_Serial_4DLib::print(const String &s) -{ - int len = s.length(); - char arr[len + 1]; - s.toCharArray(arr,len + 1); - //putstr(arr); - for(int x=0; x=0; x--) - { - putCH(buf[x]); - } -} - -void Goldelox_Serial_4DLib::printFloat(double number, uint8_t digits) -{ - size_t n = 0; - if (isnan(number)) print("nan"); - else if (isinf(number)) print("inf"); - else if (number > 4294967040.0) print ("ovf"); // constant determined empirically - else if (number <-4294967040.0) print ("ovf"); // constant determined empirically - else{ - // Handle negative numbers - if (number < 0.0) - { - putCH('-'); - number = -number; - } - - // Round correctly so that print(1.999, 2) prints as "2.00" - double rounding = 0.5; - for (uint8_t i=0; i 0) { - putCH('.'); - } - - // Extract digits from the remainder one at a time - while (digits-- > 0) - { - remainder *= 10.0; - int toPrint = int(remainder); - printNumber((unsigned long)toPrint, 10); - remainder -= toPrint; - } - } -} - - -//-------------------------------------------------------- - - - - -////////////////////////////////////////////////////// - -void Goldelox_Serial_4DLib::txt_Attributes(word Attribs) -{ - _virtualPort->print((char)(F_txt_Attributes >> 8)) ; - _virtualPort->print((char)(F_txt_Attributes)) ; - _virtualPort->print((char)(Attribs >> 8)) ; - _virtualPort->print((char)(Attribs)) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::txt_BGcolour(word Color) -{ - _virtualPort->print((char)(F_txt_BGcolour >> 8)) ; - _virtualPort->print((char)(F_txt_BGcolour)) ; - _virtualPort->print((char)(Color >> 8)) ; - _virtualPort->print((char)(Color)) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::txt_Bold(word Bold) -{ - _virtualPort->print((char)(F_txt_Bold >> 8)) ; - _virtualPort->print((char)(F_txt_Bold)) ; - _virtualPort->print((char)(Bold >> 8)) ; - _virtualPort->print((char)(Bold)) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::txt_FGcolour(word Color) -{ - _virtualPort->print((char)(F_txt_FGcolour >> 8)) ; - _virtualPort->print((char)(F_txt_FGcolour)) ; - _virtualPort->print((char)(Color >> 8)) ; - _virtualPort->print((char)(Color)) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::txt_FontID(word FontNumber) -{ - _virtualPort->print((char)(F_txt_FontID >> 8)) ; - _virtualPort->print((char)(F_txt_FontID)) ; - _virtualPort->print((char)(FontNumber >> 8)) ; - _virtualPort->print((char)(FontNumber)) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::txt_Height(word Multiplier) -{ - _virtualPort->print((char)(F_txt_Height >> 8)) ; - _virtualPort->print((char)(F_txt_Height)) ; - _virtualPort->print((char)(Multiplier >> 8)) ; - _virtualPort->print((char)(Multiplier)) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::txt_Inverse(word Inverse) -{ - _virtualPort->print((char)(F_txt_Inverse >> 8)) ; - _virtualPort->print((char)(F_txt_Inverse)) ; - _virtualPort->print((char)(Inverse >> 8)) ; - _virtualPort->print((char)(Inverse)) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::txt_Italic(word Italic) -{ - _virtualPort->print((char)(F_txt_Italic >> 8)) ; - _virtualPort->print((char)(F_txt_Italic)) ; - _virtualPort->print((char)(Italic >> 8)) ; - _virtualPort->print((char)(Italic)) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::txt_MoveCursor(word Line, word Column) -{ - _virtualPort->print((char)(F_txt_MoveCursor >> 8)) ; - _virtualPort->print((char)(F_txt_MoveCursor)) ; - _virtualPort->print((char)(Line >> 8)) ; - _virtualPort->print((char)(Line)) ; - _virtualPort->print((char)(Column >> 8)) ; - _virtualPort->print((char)(Column)) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::txt_Opacity(word TransparentOpaque) -{ - _virtualPort->print((char)(F_txt_Opacity >> 8)) ; - _virtualPort->print((char)(F_txt_Opacity)) ; - _virtualPort->print((char)(TransparentOpaque >> 8)) ; - _virtualPort->print((char)(TransparentOpaque)) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::txt_Set(word Func, word Value) -{ - _virtualPort->print((char)(F_txt_Set >> 8)) ; - _virtualPort->print((char)(F_txt_Set)) ; - _virtualPort->print((char)(Func >> 8)) ; - _virtualPort->print((char)(Func)) ; - _virtualPort->print((char)(Value >> 8)) ; - _virtualPort->print((char)(Value)) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::txt_Underline(word Underline) -{ - _virtualPort->print((char)(F_txt_Underline >> 8)) ; - _virtualPort->print((char)(F_txt_Underline)) ; - _virtualPort->print((char)(Underline >> 8)) ; - _virtualPort->print((char)(Underline)) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::txt_Width(word Multiplier) -{ - _virtualPort->print((char)(F_txt_Width >> 8)) ; - _virtualPort->print((char)(F_txt_Width)) ; - _virtualPort->print((char)(Multiplier >> 8)) ; - _virtualPort->print((char)(Multiplier)) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::txt_Xgap(word Pixels) -{ - _virtualPort->print((char)(F_txt_Xgap >> 8)) ; - _virtualPort->print((char)(F_txt_Xgap)) ; - _virtualPort->print((char)(Pixels >> 8)) ; - _virtualPort->print((char)(Pixels)) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::txt_Ygap(word Pixels) -{ - _virtualPort->print((char)(F_txt_Ygap >> 8)) ; - _virtualPort->print((char)(F_txt_Ygap)) ; - _virtualPort->print((char)(Pixels >> 8)) ; - _virtualPort->print((char)(Pixels)) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::BeeP(word Note, word Duration) -{ - _virtualPort->print((char)(F_BeeP >> 8)) ; - _virtualPort->print((char)(F_BeeP)) ; - _virtualPort->print((char)(Note >> 8)) ; - _virtualPort->print((char)(Note)) ; - _virtualPort->print((char)(Duration >> 8)) ; - _virtualPort->print((char)(Duration)) ; - GetAck() ; -} - -word Goldelox_Serial_4DLib::sys_GetModel(char * ModelStr) -{ - _virtualPort->print((char)(F_sys_GetModel >> 8)) ; - _virtualPort->print((char)(F_sys_GetModel)) ; - return GetAckResStr(ModelStr) ; -} - -word Goldelox_Serial_4DLib::sys_GetVersion() -{ - _virtualPort->print((char)(F_sys_GetVersion >> 8)) ; - _virtualPort->print((char)(F_sys_GetVersion)) ; - return GetAckResp() ; -} - -word Goldelox_Serial_4DLib::sys_GetPmmC() -{ - _virtualPort->print((char)(F_sys_GetPmmC >> 8)) ; - _virtualPort->print((char)(F_sys_GetPmmC)) ; - return GetAckResp() ; -} - -void Goldelox_Serial_4DLib::blitComtoDisplay(word X, word Y, word Width, word Height, t4DByteArray Pixels) -{ - _virtualPort->print((char)(F_blitComtoDisplay >> 8)) ; - _virtualPort->print((char)(F_blitComtoDisplay)) ; - _virtualPort->print((char)(X >> 8)) ; - _virtualPort->print((char)(X)) ; - _virtualPort->print((char)(Y >> 8)) ; - _virtualPort->print((char)(Y)) ; - _virtualPort->print((char)(Width >> 8)) ; - _virtualPort->print((char)(Width)) ; - _virtualPort->print((char)(Height >> 8)) ; - _virtualPort->print((char)(Height)) ; - WriteBytes(Pixels, Width*Height*2) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::setbaudWait(word Newrate) -{ - _virtualPort->print((char)(F_setbaudWait >> 8)) ; - _virtualPort->print((char)(F_setbaudWait)) ; - _virtualPort->print((char)(Newrate >> 8)) ; - _virtualPort->print((char)(Newrate)) ; - SetThisBaudrate(Newrate) ; // change this systems baud rate to match new display rate, ACK is 100ms away - GetAck() ; -} - -word Goldelox_Serial_4DLib::peekW(word Address) -{ - _virtualPort->print((char)(F_peekW >> 8)) ; - _virtualPort->print((char)(F_peekW)) ; - _virtualPort->print((char)(Address >> 8)) ; - _virtualPort->print((char)(Address)) ; - return GetAckResp() ; -} - -void Goldelox_Serial_4DLib::pokeW(word Address, word WordValue) -{ - _virtualPort->print((char)(F_pokeW >> 8)) ; - _virtualPort->print((char)(F_pokeW)) ; - _virtualPort->print((char)(Address >> 8)) ; - _virtualPort->print((char)(Address)) ; - _virtualPort->print((char)(WordValue >> 8)) ; - _virtualPort->print((char)(WordValue)) ; - GetAck() ; -} - -word Goldelox_Serial_4DLib::peekB(word Address) -{ - _virtualPort->print((char)(F_peekB >> 8)) ; - _virtualPort->print((char)(F_peekB)) ; - _virtualPort->print((char)(Address >> 8)) ; - _virtualPort->print((char)(Address)) ; - return GetAckResp() ; -} - -void Goldelox_Serial_4DLib::pokeB(word Address, word ByteValue) -{ - _virtualPort->print((char)(F_pokeB >> 8)) ; - _virtualPort->print((char)(F_pokeB)) ; - _virtualPort->print((char)(Address >> 8)) ; - _virtualPort->print((char)(Address)) ; - _virtualPort->print((char)(ByteValue >> 8)) ; - _virtualPort->print((char)(ByteValue)) ; - GetAck() ; -} - -word Goldelox_Serial_4DLib::joystick() -{ - _virtualPort->print((char)(F_joystick >> 8)) ; - _virtualPort->print((char)(F_joystick)) ; - return GetAckResp() ; -} - -void Goldelox_Serial_4DLib::SSTimeout(word Seconds) -{ - _virtualPort->print((char)(F_SSTimeout >> 8)) ; - _virtualPort->print((char)(F_SSTimeout)) ; - _virtualPort->print((char)(Seconds >> 8)) ; - _virtualPort->print((char)(Seconds)) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::SSSpeed(word Speed) -{ - _virtualPort->print((char)(F_SSSpeed >> 8)) ; - _virtualPort->print((char)(F_SSSpeed)) ; - _virtualPort->print((char)(Speed >> 8)) ; - _virtualPort->print((char)(Speed)) ; - GetAck() ; -} - -void Goldelox_Serial_4DLib::SSMode(word Parm) -{ - _virtualPort->print((char)(F_SSMode >> 8)) ; - _virtualPort->print((char)(F_SSMode)) ; - _virtualPort->print((char)(Parm >> 8)) ; - _virtualPort->print((char)(Parm)) ; - GetAck() ; -} diff --git a/lib/Goldelox_Serial/Goldelox_Serial_4DLib.h b/lib/Goldelox_Serial/Goldelox_Serial_4DLib.h deleted file mode 100644 index d52136d..0000000 --- a/lib/Goldelox_Serial/Goldelox_Serial_4DLib.h +++ /dev/null @@ -1,169 +0,0 @@ -/* - 4DSerial - Library for 4D Systems Serial Environment. - Released into the public domain. -*/ - -#ifndef Goldelox_Serial_4DLib_h -#define Goldelox_Serial_4DLib_h - -#if (ARDUINO >= 100) - #include "Arduino.h" // for Arduino 1.0 -#else - #include "WProgram.h" // for Arduino 23 -#endif - -#define Err4D_OK 0 -#define Err4D_Timeout 1 -#define Err4D_NAK 2 // other than ACK received - -#include "Goldelox_Types4D.h" // Defines for 4dgl constants, generated by conversion of 4DGL constants to target language -#include "Goldelox_Const4DSerial.h" // Defines for 4dgl constants, generated by conversion of 4DGL constants to target language -#include "Goldelox_Const4D.h" // Defines for 4dgl constants, generated by conversion of 4DGL constants to target language - -#include - -#define DEC 10 -#define HEX 16 -#define OCT 8 -#define BIN 2 - -typedef void (*Tcallback4D)(int, unsigned char); - -class Goldelox_Serial_4DLib -{ - public: - Goldelox_Serial_4DLib(Stream * virtualPort); - Tcallback4D Callback4D ; - - //Compound 4D Routines - void blitComtoDisplay(word X, word Y, word Width, word Height, t4DByteArray Pixels) ; - void gfx_BGcolour(word Color) ; - void gfx_ChangeColour(word OldColor, word NewColor) ; - void gfx_Circle(word X, word Y, word Radius, word Color) ; - void gfx_CircleFilled(word X, word Y, word Radius, word Color) ; - void gfx_Clipping(word OnOff) ; - void gfx_ClipWindow(word X1, word Y1, word X2, word Y2) ; - void gfx_Cls(void) ; - void gfx_Contrast(word Contrast) ; - void gfx_FrameDelay(word Msec) ; - void gfx_Line(word X1, word Y1, word X2, word Y2, word Color) ; - void gfx_LinePattern(word Pattern) ; - void gfx_LineTo(word X, word Y) ; - void gfx_MoveTo(word X, word Y) ; - void gfx_OutlineColour(word Color) ; - void gfx_Polygon(word n, t4DWordArray Xvalues, t4DWordArray Yvalues, word Color) ; - void gfx_Polyline(word n, t4DWordArray Xvalues, t4DWordArray Yvalues, word Color) ; - void gfx_PutPixel(word X, word Y, word Color) ; - void gfx_Rectangle(word X1, word Y1, word X2, word Y2, word Color) ; - void gfx_RectangleFilled(word X1, word Y1, word X2, word Y2, word Color) ; - void gfx_ScreenMode(word ScreenMode) ; - void gfx_Set(word Func, word Value) ; - void gfx_Transparency(word OnOff) ; - void gfx_TransparentColour(word Color) ; - void gfx_Triangle(word X1, word Y1, word X2, word Y2, word X3, word Y3, word Color) ; - void media_Image(word X, word Y) ; - void media_SetAdd(word Hiword, word Loword) ; - void media_SetSector(word Hiword, word Loword) ; - void media_Video(word X, word Y) ; - void media_VideoFrame(word X, word Y, word Framenumber) ; - void pokeB(word Address, word ByteValue) ; - void pokeW(word Address, word wordValue) ; - void putCH(word wordChar) ; - //---------------------print----------------------/ - - void print(const __FlashStringHelper *); - void print(const String &); - void print(const char[]); - void print(char); - void print(unsigned char, int = DEC); - void print(int, int = DEC); - void print(unsigned int, int = DEC); - void print(long, int = DEC); - void print(unsigned long n, int = DEC); - void print(double, int = 2); - - void println(const __FlashStringHelper *); - void println(const String &); - void println(const char[]); - void println(char); - void println(unsigned char, int = DEC); - void println(int, int = DEC); - void println(unsigned int, int = DEC); - void println(long, int = DEC); - void println(unsigned long, int = DEC); - void println(double, int = 2); - - //------------------------------------------------/ - - void setbaudWait(word Newrate) ; - void SSMode(word Parm) ; - void SSSpeed(word Speed) ; - void SSTimeout(word Seconds) ; - void txt_Attributes(word Attribs) ; - void txt_BGcolour(word Color) ; - void txt_Bold(word Bold) ; - void txt_FGcolour(word Color) ; - void txt_FontID(word FontNumber) ; - void txt_Height(word Multiplier) ; - void txt_Inverse(word Inverse) ; - void txt_Italic(word Italic) ; - void txt_MoveCursor(word Line, word Column) ; - void txt_Opacity(word TransparentOpaque) ; - void txt_Set(word Func, word Value) ; - void txt_Underline(word Underline) ; - void txt_Width(word Multiplier) ; - void txt_Xgap(word Pixels) ; - void txt_Ygap(word Pixels) ; - void BeeP(word Note, word Duration) ; - word charheight(char TestChar) ; - word charwidth(char TestChar) ; - word gfx_GetPixel(word X, word Y) ; - word gfx_Orbit(word Angle, word Distance, word * Xdest, word * Ydest) ; - void gfx_SetClipRegion(void) ; - word joystick(void) ; - word media_Flush(void) ; - word media_Init(void) ; - word media_ReadByte(void) ; - word media_ReadWord(void) ; - word media_WriteByte(word Byte) ; - word media_WriteWord(word word) ; - word peekB(word Address) ; - word peekW(word Address) ; - void putstr(char * InString) ; - word sys_GetModel(char * ModelStr) ; - word sys_GetPmmC(void) ; - word sys_GetVersion(void) ; - - void GetAck(void); - - //4D Global Variables Used - int Error4D; // Error indicator, used and set by Intrinsic routines - unsigned char Error4D_Inv; // Error byte returned from com port, onl set if error = Err_Invalid - // int Error_Abort4D; // if true routines will abort when detecting an error - unsigned long TimeLimit4D; // time limit in ms for total serial command duration, 2000 (2 seconds) should be adequate for most commands - // assuming a reasonable baud rate AND low latency AND 0 for the Serial Delay Parameter - // temporary increase might be required for very long (bitmap write, large image file opens) - // or indeterminate (eg file_exec, file_run, file_callFunction) commands - - private: - Stream * _virtualPort; - - //Intrinsic 4D Routines - void WriteChars(char * charsout); - void WriteBytes(char * Source, int Size); - void WriteWords(word * Source, int Size); - void getbytes(char * data, int size); - word GetWord(void); - void getString(char * outStr, int strLen); - word GetAckResp(void); - word GetAckRes2Words(word * word1, word * word2); - void GetAck2Words(word * word1, word * word2); - word GetAckResStr(char * OutStr); - // word GetAckResData(t4DByteArray OutData, word size); - void SetThisBaudrate(int Newrate); - - void printNumber(unsigned long, uint8_t); - void printFloat(double number, uint8_t digits); -}; - -#endif diff --git a/lib/Goldelox_Serial/Goldelox_Types4D.h b/lib/Goldelox_Serial/Goldelox_Types4D.h deleted file mode 100644 index 4e105dc..0000000 --- a/lib/Goldelox_Serial/Goldelox_Types4D.h +++ /dev/null @@ -1,3 +0,0 @@ -#define t4DWordArray word * -#define t4DByteArray char * -//#define t4DSector unsigned char * diff --git a/lib/SoftwareSerial/SoftwareSerial.cpp b/lib/SoftwareSerial/SoftwareSerial.cpp deleted file mode 100644 index 67756af..0000000 --- a/lib/SoftwareSerial/SoftwareSerial.cpp +++ /dev/null @@ -1,266 +0,0 @@ -/* - -SoftwareSerial.cpp - Implementation of the Arduino software serial for ESP8266. -Copyright (c) 2015-2016 Peter Lerup. All rights reserved. - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License as published by the Free Software Foundation; either -version 2.1 of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with this library; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - -#include - -// The Arduino standard GPIO routines are not enough, -// must use some from the Espressif SDK as well -extern "C" { - #include "esp32-hal-gpio.h" -} - -#include - -#define MAX_PIN 35 -#define DEFAULT_BUAD_RATE 9600 - -// As the Arduino attachInterrupt has no parameter, lists of objects -// and callbacks corresponding to each possible GPIO pins have to be defined -SoftwareSerial *ObjList[MAX_PIN+1]; - -void IRAM_ATTR sws_isr_0() { ObjList[0]->rxRead(); }; -void IRAM_ATTR sws_isr_1() { ObjList[1]->rxRead(); }; -void IRAM_ATTR sws_isr_2() { ObjList[2]->rxRead(); }; -void IRAM_ATTR sws_isr_3() { ObjList[3]->rxRead(); }; -void IRAM_ATTR sws_isr_4() { ObjList[4]->rxRead(); }; -void IRAM_ATTR sws_isr_5() { ObjList[5]->rxRead(); }; -// Pin 6 to 11 can not be used -void IRAM_ATTR sws_isr_12() { ObjList[12]->rxRead(); }; -void IRAM_ATTR sws_isr_13() { ObjList[13]->rxRead(); }; -void IRAM_ATTR sws_isr_14() { ObjList[14]->rxRead(); }; -void IRAM_ATTR sws_isr_15() { ObjList[15]->rxRead(); }; -void IRAM_ATTR sws_isr_16() { ObjList[16]->rxRead(); }; -void IRAM_ATTR sws_isr_17() { ObjList[17]->rxRead(); }; -void IRAM_ATTR sws_isr_18() { ObjList[18]->rxRead(); }; -void IRAM_ATTR sws_isr_19() { ObjList[19]->rxRead(); }; -void IRAM_ATTR sws_isr_20() { ObjList[20]->rxRead(); }; -void IRAM_ATTR sws_isr_21() { ObjList[21]->rxRead(); }; -void IRAM_ATTR sws_isr_22() { ObjList[22]->rxRead(); }; -void IRAM_ATTR sws_isr_23() { ObjList[23]->rxRead(); }; -void IRAM_ATTR sws_isr_24() { ObjList[24]->rxRead(); }; -void IRAM_ATTR sws_isr_25() { ObjList[25]->rxRead(); }; -void IRAM_ATTR sws_isr_26() { ObjList[26]->rxRead(); }; -void IRAM_ATTR sws_isr_27() { ObjList[27]->rxRead(); }; -void IRAM_ATTR sws_isr_28() { ObjList[28]->rxRead(); }; -void IRAM_ATTR sws_isr_29() { ObjList[29]->rxRead(); }; -void IRAM_ATTR sws_isr_30() { ObjList[30]->rxRead(); }; -void IRAM_ATTR sws_isr_31() { ObjList[31]->rxRead(); }; -void IRAM_ATTR sws_isr_32() { ObjList[32]->rxRead(); }; -void IRAM_ATTR sws_isr_33() { ObjList[33]->rxRead(); }; -void IRAM_ATTR sws_isr_34() { ObjList[34]->rxRead(); }; -void IRAM_ATTR sws_isr_35() { ObjList[35]->rxRead(); }; - -static void (*ISRList[MAX_PIN+1])() = { - sws_isr_0, - sws_isr_1, - sws_isr_2, - sws_isr_3, - sws_isr_4, - sws_isr_5, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - sws_isr_12, - sws_isr_13, - sws_isr_14, - sws_isr_15, - sws_isr_16, - sws_isr_17, - sws_isr_18, - sws_isr_19, - sws_isr_20, - sws_isr_21, - sws_isr_22, - sws_isr_23, - sws_isr_24, - sws_isr_25, - sws_isr_26, - sws_isr_27, - sws_isr_28, - sws_isr_29, - sws_isr_30, - sws_isr_31, - sws_isr_32, - sws_isr_33, - sws_isr_34, - sws_isr_35 -}; - -SoftwareSerial::SoftwareSerial(int receivePin, int transmitPin, bool inverse_logic, unsigned int buffSize) { - m_rxValid = m_txValid = m_txEnableValid = false; - m_buffer = NULL; - m_invert = inverse_logic; - m_overflow = false; - m_rxEnabled = false; - if (isValidGPIOpin(receivePin)) { - m_rxPin = receivePin; - m_buffSize = buffSize; - m_buffer = (uint8_t*)malloc(m_buffSize); - if (m_buffer != NULL) { - m_rxValid = true; - m_inPos = m_outPos = 0; - pinMode(m_rxPin, INPUT); - ObjList[m_rxPin] = this; - enableRx(true); - } - } - if (isValidGPIOpin(transmitPin)) { - m_txValid = true; - m_txPin = transmitPin; - pinMode(m_txPin, OUTPUT); - digitalWrite(m_txPin, !m_invert); - } - // Default speed - //begin(DEFAULT_BUAD_RATE); -} - -SoftwareSerial::~SoftwareSerial() { - enableRx(false); - if (m_rxValid) - ObjList[m_rxPin] = NULL; - if (m_buffer) - free(m_buffer); -} - -bool SoftwareSerial::isValidGPIOpin(int pin) { - return (pin >= 0 && pin <= 5) || (pin >= 12 && pin <= MAX_PIN); -} - -void SoftwareSerial::begin(long speed) { - // Use getCycleCount() loop to get as exact timing as possible - m_bitTime = ESP.getCpuFreqMHz()*1000000/speed; - - if (!m_rxEnabled) - enableRx(true); -} - -long SoftwareSerial::baudRate() { - return ESP.getCpuFreqMHz()*1000000/m_bitTime; -} - -void SoftwareSerial::setTransmitEnablePin(int transmitEnablePin) { - if (isValidGPIOpin(transmitEnablePin)) { - m_txEnableValid = true; - m_txEnablePin = transmitEnablePin; - pinMode(m_txEnablePin, OUTPUT); - digitalWrite(m_txEnablePin, LOW); - } else { - m_txEnableValid = false; - } -} - -void SoftwareSerial::enableRx(bool on) { - if (m_rxValid) { - if (on) - attachInterrupt(m_rxPin, ISRList[m_rxPin], m_invert ? RISING : FALLING); - else - detachInterrupt(m_rxPin); - m_rxEnabled = on; - } -} - -int SoftwareSerial::read() { - if (!m_rxValid || (m_inPos == m_outPos)) return -1; - uint8_t ch = m_buffer[m_outPos]; - m_outPos = (m_outPos+1) % m_buffSize; - return ch; -} - -int SoftwareSerial::available() { - if (!m_rxValid) return 0; - int avail = m_inPos - m_outPos; - if (avail < 0) avail += m_buffSize; - return avail; -} - -#define WAIT { while (ESP.getCycleCount()-start < wait); wait += m_bitTime; } - -size_t SoftwareSerial::write(uint8_t b) { - if (!m_txValid) return 0; - - if (m_invert) b = ~b; - // Disable interrupts in order to get a clean transmit - cli(); - if (m_txEnableValid) digitalWrite(m_txEnablePin, HIGH); - unsigned long wait = m_bitTime; - digitalWrite(m_txPin, HIGH); - unsigned long start = ESP.getCycleCount(); - // Start bit; - digitalWrite(m_txPin, LOW); - WAIT; - for (int i = 0; i < 8; i++) { - digitalWrite(m_txPin, (b & 1) ? HIGH : LOW); - WAIT; - b >>= 1; - } - // Stop bit - digitalWrite(m_txPin, HIGH); - WAIT; - if (m_txEnableValid) digitalWrite(m_txEnablePin, LOW); - sei(); - return 1; -} - -void SoftwareSerial::flush() { - m_inPos = m_outPos = 0; -} - -bool SoftwareSerial::overflow() { - bool res = m_overflow; - m_overflow = false; - return res; -} - -int SoftwareSerial::peek() { - if (!m_rxValid || (m_inPos == m_outPos)) return -1; - return m_buffer[m_outPos]; -} - -void IRAM_ATTR SoftwareSerial::rxRead() { - // Advance the starting point for the samples but compensate for the - // initial delay which occurs before the interrupt is delivered - unsigned long wait = m_bitTime + m_bitTime/3 - 500; - unsigned long start = ESP.getCycleCount(); - uint8_t rec = 0; - for (int i = 0; i < 8; i++) { - WAIT; - rec >>= 1; - if (digitalRead(m_rxPin)) - rec |= 0x80; - } - if (m_invert) rec = ~rec; - // Stop bit - WAIT; - // Store the received value in the buffer unless we have an overflow - int next = (m_inPos+1) % m_buffSize; - if (next != m_outPos) { - m_buffer[m_inPos] = rec; - m_inPos = next; - } else { - m_overflow = true; - } - // Must clear this bit in the interrupt register, - // it gets set even when interrupts are disabled - GPIO_REG_WRITE(GPIO.status_w1tc, 1 << m_rxPin); -} diff --git a/lib/SoftwareSerial/SoftwareSerial.h b/lib/SoftwareSerial/SoftwareSerial.h deleted file mode 100644 index 3b1a001..0000000 --- a/lib/SoftwareSerial/SoftwareSerial.h +++ /dev/null @@ -1,87 +0,0 @@ -/* -SoftwareSerial.h - -SoftwareSerial.cpp - Implementation of the Arduino software serial for ESP8266. -Copyright (c) 2015-2016 Peter Lerup. All rights reserved. - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License as published by the Free Software Foundation; either -version 2.1 of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with this library; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - -#ifndef SoftwareSerial_h -#define SoftwareSerial_h - -#include -#include - - -// This class is compatible with the corresponding AVR one, -// the constructor however has an optional rx buffer size. -// Speed up to 115200 can be used. - - -class SoftwareSerial : public Stream -{ -public: - SoftwareSerial(int receivePin, int transmitPin, bool inverse_logic = false, unsigned int buffSize = 64); - ~SoftwareSerial(); - - void begin(long speed); - long baudRate(); - void setTransmitEnablePin(int transmitEnablePin); - - bool overflow(); - int peek(); - - virtual size_t write(uint8_t byte); - virtual int read(); - virtual int available(); - virtual void flush(); - operator bool() {return m_rxValid || m_txValid;} - - // Disable or enable interrupts on the rx pin - void enableRx(bool on); - - void rxRead(); - - // AVR compatibility methods - bool listen() { enableRx(true); return true; } - void end() { stopListening(); } - bool isListening() { return m_rxEnabled; } - bool stopListening() { enableRx(false); return true; } - - using Print::write; - -private: - bool isValidGPIOpin(int pin); - - // Member variables - int m_rxPin, m_txPin, m_txEnablePin; - bool m_rxValid, m_rxEnabled; - bool m_txValid, m_txEnableValid; - bool m_invert; - bool m_overflow; - unsigned long m_bitTime; - unsigned int m_inPos, m_outPos; - int m_buffSize; - uint8_t *m_buffer; - -}; - -// If only one tx or rx wanted then use this as parameter for the unused pin -#define SW_SERIAL_UNUSED_PIN -1 - - -#endif diff --git a/platformio.ini b/platformio.ini index 5ae559e..72fcd73 100644 --- a/platformio.ini +++ b/platformio.ini @@ -26,6 +26,11 @@ check_patterns = include/*.h src/*.cpp +lib_deps = + Adafruit DRV2605 Library + EspSoftwareSerial + Goldelox-Serial-Arduino-Library + ; Demo build environment that enables demo purposes for the input device. [env:demo] build_type = debug diff --git a/src/main.cpp b/src/main.cpp index 0c8b775..22fb573 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,7 +8,7 @@ #include #include #include -#include "Adafruit_DRV2605.h" +#include #include #include #include From b57b94acc63a9f79aa77c4e9f1e74e44faaf0150 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Thu, 12 Dec 2019 21:03:06 +0100 Subject: [PATCH 06/58] Add more build flags for debug and release --- platformio.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platformio.ini b/platformio.ini index 72fcd73..af6605c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -38,8 +38,8 @@ build_flags = -D DEBUG -D DEMO_INPUT_DEVICE [env:debug] build_type = debug -build_flags = -D DEBUG +build_flags = -g -D DEBUG [env:release] build_type = release -build_flags = -D RELEASE +build_flags = -O3 -D RELEASE From b37c490d740b4a05debe06641ebb877241bdcb3a Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Thu, 12 Dec 2019 21:09:31 +0100 Subject: [PATCH 07/58] Update encrypted slack --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 117807e..e729b4f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ language: python notifications: slack: - secure: DX4zerMP4tLgR8rMBnY36YhrdtULunl+aROFq7dWy0vXvxiegWfvGY0eWU7K36kcVToPV1LJ9ilFGxfOi5VELkFQHsxYCRaBddSgQ4pAxppygVPhlmOUdpkZsGxrJU27ajcy6OY/pwEFBsABIXitoEC2U0yDzx3J9bWjzz+QH14MLfH07zeYuuAfhloZ8IZk6TbSVeg8X/jhc1QUZhn7QgN+hvXo1MMSaq99TXXK7jO7soq5oRbTSOkohSiVm7XgbjL9haoWXQSBJlb82qu94wFlBBZlZ05oEVGzith36d4gVPJ5wbmoRQy5X/shGBBNGiyv8JRQ6Z18zgdsra1sWPNI7Yv5o91sMySx/g+OOqyJqQKq5y5ohb1Y4hI24zy9Xj8Bjac9wt9O4wvgn5+dlz2qgIkXbJeSodEB4OE0lBEeiQACkYpHz9UbxZrcaBtrq9tEHSrl7lwj/AgRckaIIr+6BURvQ21RIqXhajKiaSO05KqL0spyM8pVvNHn+0W1oznVuEMZOywy7bZ83JiodKVZPwJQWPetOAet8r4PnkulUSseJ8ckVpoz5Kfs/IrSAKMSlOeD19AgLm7Q/ejpoimfTJUJsDRgP7asRVuqgzl7ruBuQOwbaWg3FRgaW7WJ66LPmdNwI5bokThaMaE3oB17l2Y+Kt93CAxUDAKSStI= + secure: agpTHpiGJVNU8EtJV+nbiM8LYp7RkXPMpvrpa7yjlNKep4i0jQscFpOyylh+7Toekfh1F7ZMGhyBQfWsgzSKK4OtKgUY36jV3NJ04d1Jjf4CaypUsXe9eQ7KNIHLI+zPgwan+yf1iL6daF8uvRNT8SHCxTdRfVcwWaViQuh6/JbusxpSSojaT/BinCF/lItHC2+ixO1cQ7iFbBsaRyrEI76IUeaoMAUogqoNx+KdAYORMTcFI1i+6bw5TzsWY8Md8Kxn1YhvyeJv87LJjRhLyXLqzhp4XFjPUY0Vb9/iSihX7UfFoAPTPqmrlaATW6TEu0uo5fVJY6MWifAlcsuNGqL//saVqPHTiOqyEg1LcEUtdmR5+ljyMaSirV+pJA/vBNo61bjQeFzBf4d/kXiej0UQfLG1DFjUlYij++t6kr+EklYkwNYbfOQ75cLXrneG+nxjwg8KID2AVkjshLdjOfHFlGuzDTliId4lYU5FMdBl/dVS2u5qvVo8kaaTvvoAWjzp9KfdWHB1BmpAX06PblLWHnXuhJujBEyeT/9+D9eGmCmvYAsfLpky2hxWOHTkTbKGS9K60c2pHIhhzMRiOMZAVmbG7A2+7XdoaeBJ9cEHET09Ep2WY76jX5hTDbbA3xLZJB8e8O6TdCxXxp9xQvoPpmRK3rjsiun3thlFDBI= email: false cache: @@ -18,4 +18,3 @@ install: script: - platformio run - platformio check --environment debug -# - platformio test From 60303054a228cef779cc5d1c82c960e2854acd22 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Thu, 12 Dec 2019 21:53:50 +0100 Subject: [PATCH 08/58] Cleanup code --- include/state.h | 11 ----------- include/state_machine.h | 3 +-- src/state_machine.cpp | 2 -- 3 files changed, 1 insertion(+), 15 deletions(-) diff --git a/include/state.h b/include/state.h index 492b413..14db62e 100644 --- a/include/state.h +++ b/include/state.h @@ -4,17 +4,6 @@ #include -class AbstractState { -public: - virtual AbstractState* left() = 0; - virtual AbstractState* right() = 0; - virtual AbstractState* up() = 0; - virtual AbstractState* down() = 0; - - virtual AbstractState* back() = 0; - virtual AbstractState* select() = 0; - virtual AbstractState* activate() = 0; -}; class State { public: diff --git a/include/state_machine.h b/include/state_machine.h index eb4f2fb..0515505 100644 --- a/include/state_machine.h +++ b/include/state_machine.h @@ -5,13 +5,12 @@ #include -#include #include #include class StateMachine { public: - StateMachine(); + StateMachine() = default; const std::string& getCurrentGaitName() const; diff --git a/src/state_machine.cpp b/src/state_machine.cpp index 9a9861d..a018d3f 100644 --- a/src/state_machine.cpp +++ b/src/state_machine.cpp @@ -1,7 +1,5 @@ #include "state_machine.h" -StateMachine::StateMachine() {} - const std::string& StateMachine::getCurrentGaitName() const { return this->current_state_->getGaitName(); } From f1cd1f3be51e2111a57fbbd3f2758995f0b9a1b3 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Thu, 12 Dec 2019 22:41:19 +0100 Subject: [PATCH 09/58] Refactor joystick, button, screen and rockerswitch --- include/Button.h | 19 --- include/Joystick.h | 35 ----- include/RockerSwitch.h | 20 --- include/SD_sector_addresses.h | 6 +- include/Screen.h | 57 ------- include/button.h | 24 +++ include/button_state.h | 11 ++ include/joystick.h | 50 ++++++ include/rocker_switch.h | 33 ++++ include/screen.h | 61 ++++++++ include/state.h | 6 +- include/state_machine.h | 6 +- ...lessConnection.h => wireless_connection.h} | 2 +- src/Button.cpp | 32 ---- src/Joystick.cpp | 116 -------------- src/RockerSwitch.cpp | 46 ------ src/Screen.cpp | 52 ------- src/button.cpp | 25 +++ src/joystick.cpp | 110 +++++++++++++ src/main.cpp | 146 +++++++++--------- src/rocker_switch.cpp | 41 +++++ src/screen.cpp | 41 +++++ 22 files changed, 479 insertions(+), 460 deletions(-) delete mode 100644 include/Button.h delete mode 100644 include/Joystick.h delete mode 100644 include/RockerSwitch.h delete mode 100644 include/Screen.h create mode 100644 include/button.h create mode 100644 include/button_state.h create mode 100644 include/joystick.h create mode 100644 include/rocker_switch.h create mode 100644 include/screen.h rename include/{WirelessConnection.h => wireless_connection.h} (98%) delete mode 100644 src/Button.cpp delete mode 100644 src/Joystick.cpp delete mode 100644 src/RockerSwitch.cpp delete mode 100644 src/Screen.cpp create mode 100644 src/button.cpp create mode 100644 src/joystick.cpp create mode 100644 src/rocker_switch.cpp create mode 100644 src/screen.cpp diff --git a/include/Button.h b/include/Button.h deleted file mode 100644 index 8a17242..0000000 --- a/include/Button.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef Button_h -#define Button_h - -#include - -class Button { - public: - Button(int pin); - String read_state(); - - private: - int input_pin; - String lastPosition; - unsigned long lastPrintTime; - const unsigned int bounceTime = 20000; //us. May introduce unwanted behaviour if changed - const unsigned int holdTime = 1000; //ms. Determines how often 'push' is returned if the button is held -}; - -#endif \ No newline at end of file diff --git a/include/Joystick.h b/include/Joystick.h deleted file mode 100644 index 4bcf711..0000000 --- a/include/Joystick.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef Joystick_h -#define Joystick_h - -#include - -class Joystick { -public: - Joystick(int pin_left, int pin_right, int pin_up, int pin_down, int pin_press); - String get_position(); - String get_press(); - -private: - int left_pin; - int right_pin; - int up_pin; - int down_pin; - int press_pin; - - String lastPosition; - String lastPushPosition; - unsigned long lastPrintTime; - unsigned long lastPushPrintTime; - bool recentInitialClick; - bool recentDoubleClick; - bool lastPush; - unsigned long lastPushReleaseTime; - unsigned long lastDoubleClickTime; - - const int bounceTime = 5000; //us. May introduce unwanted behaviour if changed - const unsigned long holdTime = 1000; //ms. Determines how often up or down are returned if the joystick is held. - const unsigned long doubleClickTime = 300; //ms. - const unsigned long doubleClickTimeoutTime = 500; //ms -}; - -#endif \ No newline at end of file diff --git a/include/RockerSwitch.h b/include/RockerSwitch.h deleted file mode 100644 index 8543397..0000000 --- a/include/RockerSwitch.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef RockerSwitch_h -#define RockerSwitch_h - -#include - -class RockerSwitch { -public: - RockerSwitch(int upPin, int downPin); - String get_position(); - -private: - int pinUp; - int pinDown; - String lastPosition; - unsigned long lastPrintTime; - const unsigned int bounceTime = 20000; //us. May introduce unwanted behaviour if changed - const unsigned long holdTime = 1000; //ms. Determines how often up or down are returned if the rocker switch is held up or down. -}; - -#endif \ No newline at end of file diff --git a/include/SD_sector_addresses.h b/include/SD_sector_addresses.h index 8aedbab..71c0689 100644 --- a/include/SD_sector_addresses.h +++ b/include/SD_sector_addresses.h @@ -1,5 +1,5 @@ -#ifndef SD_ADDRESSES_H -#define SD_ADDRESSES_H +#ifndef SD_SECTOR_ADDRESSES_H +#define SD_SECTOR_ADDRESSES_H // This file defines the sector addresses of the images to be loaded on the screen // The sector addresses can be found via the 4D Systems Workshop 4D IDE @@ -564,4 +564,4 @@ #define HomeForWalk25Activated_Lo 0x2AB7 -#endif //SD_ADDRESSES_H \ No newline at end of file +#endif // SD_SECTOR_ADDRESSES_H diff --git a/include/Screen.h b/include/Screen.h deleted file mode 100644 index d7c772f..0000000 --- a/include/Screen.h +++ /dev/null @@ -1,57 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ - * Library implementing the software interface for a 4D Systems uOLED-160G2 microOLED * - * GOLDELOX Display. * - * Hardware consists of a screen with a set of ten pins on the back. * - * Pins "+5V" and "GND" should be connected to their respective voltages. * - * Pin "RES" should be connected to a digital output pin. * - * Pins "RX" and "TX" should be connected to the pins of a UART peripheral * - * interface. Note that the "RX" pin of the screen should be connected to the * - * "TX" pin of the UART interface, and vice versa. * - * The other pins should be unconnected. * - * ┌────────────────────┐ * - * │ 3.3V ──O O─┼── RES * - * │ GND ──O O─┼── GND * - * │ IO1 ──O O─┼── RX * - * │ IO2 ──O O─┼── TX * - * │ 5V OUT ──O O─┼── +5V * - * │ │ * - * │ │ * - * │ │ * - * └────────────────────┘ * - * * - * Created by P. Verton and M. van der Marel for Project MARCH * - * Date: 27-MAR-2018 * -\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -#ifndef SCREEN_ -#define SCREEN_ -#include -#include "SoftwareSerial.h" -#include "Goldelox_Serial_4DLib.h" - -class Screen -{ -public: -//Constructors - Screen(Goldelox_Serial_4DLib * screen, SoftwareSerial * screenSerial, int rst, int baud); - -//Public member functions - void initialize(); - void clear(); - void reset(); - void draw_image(word addr_hi, word addr_lo); - -private: - SoftwareSerial * m_serial; - Goldelox_Serial_4DLib * m_screen; - int m_mediaInitialized; - int m_baud; - int m_rst; - int m_tx; - int m_rx; - unsigned long m_lastDrawTime; - const int m_waitTimeUs = 500000; // Needed for functioning, can still be optimized - -}; - -#endif //SCREEN_ \ No newline at end of file diff --git a/include/button.h b/include/button.h new file mode 100644 index 0000000..c13e016 --- /dev/null +++ b/include/button.h @@ -0,0 +1,24 @@ +#ifndef BUTTON_H +#define BUTTON_H +#include "button_state.h" + +#include + +class Button { +public: + explicit Button(uint8_t pin); + + ButtonState getState(); + +private: + const uint8_t input_pin_; + ButtonState last_position_ = ButtonState::NEUTRAL; + unsigned long last_print_time_ = 0; + + const useconds_t bounce_time_ = + 20000; // us. May introduce unwanted behaviour if changed + const unsigned long hold_time_ = + 1000; // ms. Determines how often 'push' is returned if the button is held +}; + +#endif // BUTTON_H diff --git a/include/button_state.h b/include/button_state.h new file mode 100644 index 0000000..94bd71a --- /dev/null +++ b/include/button_state.h @@ -0,0 +1,11 @@ +#ifndef BUTTON_STATE_H +#define BUTTON_STATE_H + +enum class ButtonState { + NEUTRAL, + HOLDING, + PUSH, + DOUBLE, +}; + +#endif // BUTTON_STATE_H diff --git a/include/joystick.h b/include/joystick.h new file mode 100644 index 0000000..3bd0d57 --- /dev/null +++ b/include/joystick.h @@ -0,0 +1,50 @@ +#ifndef JOYSTICK_H +#define JOYSTICK_H +#include "button_state.h" + +#include + +enum class JoystickPosition { + LEFT, + RIGHT, + UP, + DOWN, + NEUTRAL, + HOLDING, +}; + +class Joystick { +public: + explicit Joystick(uint8_t left_pin, uint8_t right_pin, uint8_t up_pin, + uint8_t down_pin, uint8_t press_pin); + + JoystickPosition getPosition(); + ButtonState getState(); + +private: + const uint8_t left_pin_; + const uint8_t right_pin_; + const uint8_t up_pin_; + const uint8_t down_pin_; + const uint8_t press_pin_; + + JoystickPosition last_position_ = JoystickPosition::NEUTRAL; + ButtonState last_push_position_ = ButtonState::NEUTRAL; + unsigned long last_print_time_ = 0; + unsigned long last_push_print_time_ = 0; + bool recent_initial_click_ = false; + bool recent_double_click_ = false; + bool last_push_ = false; + unsigned long last_push_release_time_ = 0; + unsigned long last_double_click_time_ = 0; + + const useconds_t bounce_time_ = + 5000; // us. May introduce unwanted behaviour if changed + const unsigned long hold_time_ = + 1000; // ms. Determines how often up or down + // are returned if the joystick is held. + const unsigned long double_click_time_ = 300; // ms. + const unsigned long double_click_timeout_time_ = 500; // ms +}; + +#endif // JOYSTICK_H diff --git a/include/rocker_switch.h b/include/rocker_switch.h new file mode 100644 index 0000000..df89412 --- /dev/null +++ b/include/rocker_switch.h @@ -0,0 +1,33 @@ +#ifndef ROCKER_SWITCH_H +#define ROCKER_SWITCH_H +#include + +enum class RockerSwitchState { + UP, + HOLDING_UP, + DOWN, + HOLDING_DOWN, + NEUTRAL, +}; + +class RockerSwitch { +public: + explicit RockerSwitch(uint8_t up_pin, uint8_t down_pin); + + RockerSwitchState getState(); + +private: + const uint8_t up_pin_; + const uint8_t down_pin_; + RockerSwitchState last_position_ = RockerSwitchState::NEUTRAL; + unsigned long last_print_time_ = 0; + + // us. May introduce unwanted behaviour if changed + const useconds_t bounce_time_ = 20000; + + // ms. Determines how often up or down are returned if the rocker + // switch is held up or down. + const unsigned long hold_time_ = 1000; +}; + +#endif // ROCKER_SWITCH_H diff --git a/include/screen.h b/include/screen.h new file mode 100644 index 0000000..78ce79a --- /dev/null +++ b/include/screen.h @@ -0,0 +1,61 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* * * * *\ + * Library implementing the software interface for a 4D Systems uOLED-160G2 +microOLED * + * GOLDELOX Display. * + * Hardware consists of a screen with a set of ten pins on the back. * + * Pins "+5V" and "GND" should be connected to their respective voltages. * + * Pin "RES" should be connected to a digital output pin. * + * Pins "RX" and "TX" should be connected to the pins of a UART peripheral +* + * interface. Note that the "RX" pin of the screen should be connected +to the * + * "TX" pin of the UART interface, and vice versa. * + * The other pins should be unconnected. * + * ┌────────────────────┐ * + * │ 3.3V ──O O─┼── RES * + * │ GND ──O O─┼── GND * + * │ IO1 ──O O─┼── RX * + * │ IO2 ──O O─┼── TX * + * │ 5V OUT ──O O─┼── +5V * + * │ │ * + * │ │ * + * │ │ * + * └────────────────────┘ * + * * + * Created by P. Verton and M. van der Marel for Project MARCH * + * Date: 27-MAR-2018 * +\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* * * * */ +#ifndef SCREEN_H +#define SCREEN_H +#include +#include +#include + +class Screen { +public: + // Constructors + Screen(Goldelox_Serial_4DLib* screen, SoftwareSerial* screen_serial, + uint8_t rst, uint32_t baud); + + // Public member functions + void initialize(); + void clear(); + void reset(); + void draw_image(word addr_hi, word addr_lo); + +private: + Goldelox_Serial_4DLib* screen_; + SoftwareSerial* serial_; + word media_initialized_ = 0; + unsigned long last_draw_time_ = 0; + + const uint8_t rst_; + const uint32_t baud_; + + const useconds_t wait_time_ms_ = + 500000; // Needed for functioning, can still be optimized +}; + +#endif // SCREEN_H \ No newline at end of file diff --git a/include/state.h b/include/state.h index 14db62e..ea8dc66 100644 --- a/include/state.h +++ b/include/state.h @@ -1,5 +1,5 @@ -#ifndef INPUT_DEVICE_STATE_H -#define INPUT_DEVICE_STATE_H +#ifndef STATE_H +#define STATE_H #include #include @@ -44,4 +44,4 @@ class State { State* activate_ = nullptr; }; -#endif // INPUT_DEVICE_STATE_H +#endif // STATE_H diff --git a/include/state_machine.h b/include/state_machine.h index 0515505..353ca81 100644 --- a/include/state_machine.h +++ b/include/state_machine.h @@ -1,5 +1,5 @@ -#ifndef INPUT_DEVICE_STATE_MACHINE_H -#define INPUT_DEVICE_STATE_MACHINE_H +#ifndef STATE_MACHINE_H +#define STATE_MACHINE_H #include "SD_sector_addresses.h" #include "state.h" @@ -32,4 +32,4 @@ class StateMachine { State* current_state_ = nullptr; }; -#endif // INPUT_DEVICE_STATE_MACHINE_H +#endif // STATE_MACHINE_H diff --git a/include/WirelessConnection.h b/include/wireless_connection.h similarity index 98% rename from include/WirelessConnection.h rename to include/wireless_connection.h index 58fb733..9101c98 100644 --- a/include/WirelessConnection.h +++ b/include/wireless_connection.h @@ -1,7 +1,7 @@ // Copyright 2018 Project March. - #ifndef WIRELESS_CONNECTION_H #define WIRELESS_CONNECTION_H +#include ////////////////////// // WiFi Definitions // ////////////////////// diff --git a/src/Button.cpp b/src/Button.cpp deleted file mode 100644 index 1b214a6..0000000 --- a/src/Button.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include - -Button::Button(int pin) { - pinMode(pin, INPUT_PULLUP); - - this->input_pin = pin; - this->lastPrintTime = millis(); - this->lastPosition = "NEUTRAL"; -} - -// Returns either "NEUTRAL", "PUSH" or "HOLDING" -// It is advised to treat "HOLDING" the same as "NEUTRAL" outside this function -String Button::read_state() { - String returnString; - if(!digitalRead(this->input_pin)){ - if(this->lastPosition != "PUSH" || (millis() - this->lastPrintTime) > this->holdTime){ - this->lastPrintTime = millis(); - this->lastPosition = "PUSH"; - returnString = "PUSH"; - } - else{ - returnString = "HOLDING"; - } - } - else{ - this->lastPosition = "NEUTRAL"; - returnString = "NEUTRAL"; - } - // To prevent multiple 'up's and 'down's per press due to bouncing - usleep(this->bounceTime); - return returnString; -} \ No newline at end of file diff --git a/src/Joystick.cpp b/src/Joystick.cpp deleted file mode 100644 index 6c7622f..0000000 --- a/src/Joystick.cpp +++ /dev/null @@ -1,116 +0,0 @@ -#include - -Joystick::Joystick(int pin_left, int pin_right, int pin_up, int pin_down, int pin_press) { - pinMode(pin_left, INPUT_PULLUP); - pinMode(pin_right, INPUT_PULLUP); - pinMode(pin_up, INPUT_PULLUP); - pinMode(pin_down, INPUT_PULLUP); - pinMode(pin_press, INPUT_PULLUP); - - this->left_pin = pin_left; - this->right_pin = pin_right; - this->up_pin = pin_up; - this->down_pin = pin_down; - this->press_pin = pin_press; - - this->lastPrintTime = millis(); - this->lastPushPrintTime = millis(); - this->lastPosition = "NEUTRAL"; - this->lastPushPosition = "NEUTRAL"; -} - -// Returns either "NEUTRAL", "[DIRECTION]" or "HOLDING" -// It is advised to treat "HOLDING" the same as "NEUTRAL" outside this function -String Joystick::get_position() { - String returnString; - if(!digitalRead(this->left_pin)){ - if(this->lastPosition != "LEFT" || (millis()-this->lastPrintTime) > this->holdTime){ - returnString = "LEFT"; - this->lastPrintTime = millis(); - this->lastPosition = "LEFT"; - } - else{ - returnString = "HOLDING"; - } - }else if(!digitalRead(this->right_pin)){ - if(this->lastPosition != "RIGHT" || (millis()-this->lastPrintTime) > this->holdTime){ - returnString = "RIGHT"; - this->lastPrintTime = millis(); - this->lastPosition = "RIGHT"; - } - else{ - returnString = "HOLDING"; - } - }else if(!digitalRead(this->up_pin)){ - if(this->lastPosition != "UP" || (millis()-this->lastPrintTime) > this->holdTime){ - returnString = "UP"; - this->lastPrintTime = millis(); - this->lastPosition = "UP"; - } - else{ - returnString = "HOLDING"; - } - }else if(!digitalRead(this->down_pin)){ - if(this->lastPosition != "DOWN" || (millis()-this->lastPrintTime) > this->holdTime){ - returnString = "DOWN"; - this->lastPrintTime = millis(); - this->lastPosition = "DOWN"; - } - else{ - returnString = "HOLDING"; - } - }else{ - returnString = "NEUTRAL"; - this->lastPosition = "NEUTRAL"; - } - // To prevent multiple prints per action due to bouncing - usleep(this->bounceTime); - return returnString; -} - -// Returns either "NEUTRAL", "PUSH" or "DOUBLE" -String Joystick::get_press(){ - String returnString; - if(this->recentDoubleClick){ - if(millis() - this->lastDoubleClickTime > this->doubleClickTimeoutTime){ - this->recentDoubleClick = false; // Go back to an mode where we can publish stuff - } - } - if(this->recentInitialClick && !this->recentDoubleClick){ - if(millis() - this->lastPushReleaseTime > this->doubleClickTime && digitalRead(this->press_pin)){ // Enough time has elapsed since last push release time and not pressed - this->lastPush = false; - returnString = "PUSH"; // No second click, so publish the single click - this->recentInitialClick = false; - } - else if(!digitalRead(this->press_pin)){ // Joystick is pressed - this->lastPush = true; - returnString = "DOUBLE"; // A second click, so publish the double click - this->recentInitialClick = false; - this->recentDoubleClick = true; - this->lastDoubleClickTime = millis(); - } - else{ // Joystick not pressed, not just released and recent enough initial click - this->lastPush = false; - returnString = "NEUTRAL"; - } - } - else{ // No recent initial click or a recent double click - if(!digitalRead(this->press_pin)){ // Pressed - this->lastPush = true; - } - else{ // Not pressed - if(this->lastPush){ // Just released - this->recentInitialClick = true; - this->lastPushReleaseTime = millis(); - } - else{ - this->recentInitialClick = false; - } - this->lastPush = false; - } - returnString = "NEUTRAL"; - } - // To prevent multiple prints per action due to bouncing - usleep(this->bounceTime); - return returnString; -} \ No newline at end of file diff --git a/src/RockerSwitch.cpp b/src/RockerSwitch.cpp deleted file mode 100644 index 16532aa..0000000 --- a/src/RockerSwitch.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include - -RockerSwitch::RockerSwitch(int upPin, int downPin){ - pinMode(upPin, INPUT_PULLUP); - pinMode(downPin, INPUT_PULLUP); - - this->pinUp = upPin; - this->pinDown = downPin; - this->lastPosition = "NEUTRAL"; - this->lastPrintTime = millis(); -} - -// Returns either "NEUTRAL", "UP", "HOLDING UP", "DOWN" or "HOLDING DOWN" -// It is advised to treat "HOLDING X" the same as "NEUTRAL" outside this function -String RockerSwitch::get_position(){ - String returnString; - if (!digitalRead(this->pinUp)){ - if(this->lastPosition != "UP" || (millis() - this->lastPrintTime) > this->holdTime){ - // reset lastPrintTime - this->lastPrintTime = millis(); - this->lastPosition = "UP"; - returnString = "UP"; - } - else{ - returnString = "HOLDING UP"; - } - } - else if (!digitalRead(this->pinDown)){ - if(this->lastPosition != "DOWN" || (millis() - this->lastPrintTime) > this->holdTime){ - // reset lastPrintTime - this->lastPrintTime = millis(); - this->lastPosition = "DOWN"; - returnString = "DOWN"; - } - else{ - returnString = "HOLDING DOWN"; - } - } - else{ - this->lastPosition = "NEUTRAL"; - returnString = "NEUTRAL"; - } - // To prevent multiple 'up's and 'down's per press due to bouncing - usleep(this->bounceTime); - return returnString; -} \ No newline at end of file diff --git a/src/Screen.cpp b/src/Screen.cpp deleted file mode 100644 index a217397..0000000 --- a/src/Screen.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "Screen.h" - -Screen::Screen(Goldelox_Serial_4DLib * screen, SoftwareSerial * screenSerial, int rst, int baud) -{ - this->m_serial = screenSerial; - this->m_screen = screen; - this->m_mediaInitialized = 0; - this->m_baud = baud; - this->m_rst = rst; -} - -void Screen::initialize(){ - - digitalWrite(m_rst, 1); - - m_serial->begin(m_baud); - - this->reset(); - - m_mediaInitialized = m_screen->media_Init(); - usleep(m_waitTimeUs); - - char str[100]; - sprintf(str, "SD Init status = 0x%02X\n", m_mediaInitialized); - m_screen->print(str); - usleep(m_waitTimeUs); - - this->clear(); - - this->m_lastDrawTime = millis(); -}; - -void Screen::clear(){ - m_screen->gfx_Cls(); - usleep(m_waitTimeUs); -} - -void Screen::reset(){ - digitalWrite(m_rst, 0); - usleep(m_waitTimeUs); - - digitalWrite(m_rst, 1); - sleep(3); -}; - -void Screen::draw_image(word addr_hi, word addr_lo){ - if((millis() - m_lastDrawTime)*1000 > m_waitTimeUs){ - m_screen->media_SetSector(addr_hi, addr_lo); - m_screen->media_Image(0,0); - this->m_lastDrawTime = millis(); - } -} diff --git a/src/button.cpp b/src/button.cpp new file mode 100644 index 0000000..783ed44 --- /dev/null +++ b/src/button.cpp @@ -0,0 +1,25 @@ +#include "button.h" + +Button::Button(uint8_t pin) : input_pin_(pin) { pinMode(pin, INPUT_PULLUP); } + +// Returns either "NEUTRAL", "PUSH" or "HOLDING" +// It is advised to treat "HOLDING" the same as "NEUTRAL" outside this function +ButtonState Button::getState() { + ButtonState state; + if (digitalRead(this->input_pin_) == LOW) { + if (this->last_position_ != ButtonState::PUSH || + (millis() - this->last_print_time_) > this->hold_time_) { + this->last_print_time_ = millis(); + this->last_position_ = ButtonState::PUSH; + state = ButtonState::PUSH; + } else { + state = ButtonState::HOLDING; + } + } else { + this->last_position_ = ButtonState::NEUTRAL; + state = ButtonState::NEUTRAL; + } + // To prevent multiple 'up's and 'down's per press due to bouncing + usleep(this->bounce_time_); + return state; +} diff --git a/src/joystick.cpp b/src/joystick.cpp new file mode 100644 index 0000000..d58b7e0 --- /dev/null +++ b/src/joystick.cpp @@ -0,0 +1,110 @@ +#include "joystick.h" + +Joystick::Joystick(uint8_t left_pin, uint8_t right_pin, uint8_t up_pin, + uint8_t down_pin, uint8_t press_pin) + : left_pin_(left_pin), right_pin_(right_pin), up_pin_(up_pin), + down_pin_(down_pin), press_pin_(press_pin) { + pinMode(left_pin, INPUT_PULLUP); + pinMode(right_pin, INPUT_PULLUP); + pinMode(up_pin, INPUT_PULLUP); + pinMode(down_pin, INPUT_PULLUP); + pinMode(press_pin, INPUT_PULLUP); +} + +// Returns either "NEUTRAL", "[DIRECTION]" or "HOLDING" +// It is advised to treat "HOLDING" the same as "NEUTRAL" outside this function +JoystickPosition Joystick::getPosition() { + JoystickPosition position; + if (digitalRead(this->left_pin_) == LOW) { + if (this->last_position_ != JoystickPosition::LEFT || + (millis() - this->last_print_time_) > this->hold_time_) { + position = JoystickPosition::LEFT; + this->last_print_time_ = millis(); + this->last_position_ = JoystickPosition::LEFT; + } else { + position = JoystickPosition::HOLDING; + } + } else if (digitalRead(this->right_pin_) == LOW) { + if (this->last_position_ != JoystickPosition::RIGHT || + (millis() - this->last_print_time_) > this->hold_time_) { + position = JoystickPosition::RIGHT; + this->last_print_time_ = millis(); + this->last_position_ = JoystickPosition::RIGHT; + } else { + position = JoystickPosition::HOLDING; + } + } else if (digitalRead(this->up_pin_) == LOW) { + if (this->last_position_ != JoystickPosition::UP || + (millis() - this->last_print_time_) > this->hold_time_) { + position = JoystickPosition::UP; + this->last_print_time_ = millis(); + this->last_position_ = JoystickPosition::UP; + } else { + position = JoystickPosition::HOLDING; + } + } else if (digitalRead(this->down_pin_) == LOW) { + if (this->last_position_ != JoystickPosition::DOWN || + (millis() - this->last_print_time_) > this->hold_time_) { + position = JoystickPosition::DOWN; + this->last_print_time_ = millis(); + this->last_position_ = JoystickPosition::DOWN; + } else { + position = JoystickPosition::HOLDING; + } + } else { + position = JoystickPosition::NEUTRAL; + this->last_position_ = JoystickPosition::NEUTRAL; + } + // To prevent multiple prints per action due to bouncing + usleep(this->bounce_time_); + return position; +} + +// Returns either "NEUTRAL", "PUSH" or "DOUBLE" +ButtonState Joystick::getState() { + ButtonState state; + if (this->recent_double_click_) { + if (millis() - this->last_double_click_time_ > + this->double_click_timeout_time_) { + this->recent_double_click_ = + false; // Go back to an mode where we can publish stuff + } + } + if (this->recent_initial_click_ && !this->recent_double_click_) { + if (millis() - this->last_push_release_time_ > this->double_click_time_ && + digitalRead(this->press_pin_) == + HIGH) { // Enough time has elapsed since last + // push release time and not pressed + this->last_push_ = false; + state = ButtonState::PUSH; // No second click, so publish the single click + this->recent_initial_click_ = false; + } else if (digitalRead(this->press_pin_) == LOW) { // Joystick is pressed + this->last_push_ = true; + state = + ButtonState::DOUBLE; // A second click, so publish the double click + this->recent_initial_click_ = false; + this->recent_double_click_ = true; + this->last_double_click_time_ = millis(); + } else { // Joystick not pressed, not just released and recent enough + // initial click + this->last_push_ = false; + state = ButtonState::NEUTRAL; + } + } else { // No recent initial click or a recent double click + if (digitalRead(this->press_pin_) == LOW) { // Pressed + this->last_push_ = true; + } else { // Not pressed + if (this->last_push_) { // Just released + this->recent_initial_click_ = true; + this->last_push_release_time_ = millis(); + } else { + this->recent_initial_click_ = false; + } + this->last_push_ = false; + } + state = ButtonState::NEUTRAL; + } + // To prevent multiple prints per action due to bouncing + usleep(this->bounce_time_); + return state; +} diff --git a/src/main.cpp b/src/main.cpp index 22fb573..d393ed1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,22 +1,22 @@ +#include "button.h" +#include "joystick.h" +#include "rocker_switch.h" +#include "screen.h" +#include "state_machine.h" +#include "wireless_connection.h" + +#include #include -#include -#include -#include -#include -#include -#include -#include #include -#include -#include +#include +#include +#include #include -#include +#include +#include #include +#include #include -#include -#include -#include -#include // Pin definitions // Trigger @@ -31,11 +31,16 @@ #define JOYSTICK_DOWN 19 #define JOYSTICK_PUSH 18 // Screen -#define UART_TX 32 // Software serial -#define UART_RX 34 // Software serial -#define RST 13 // Reset +#define UART_TX 32 // Software serial +#define UART_RX 34 // Software serial +#define RST 13 // Reset #define BAUD_SCREEN 9600 +#undef LEFT +#undef RIGHT +#undef UP +#undef DOWN + //#define USE_WIRELESS // comment this to use wired connection. // Trigger @@ -43,19 +48,21 @@ Button trigger(TRIGGER); // Rocker switch RockerSwitch rocker(ROCKER_UP, ROCKER_DOWN); // Joystick -Joystick joystick(JOYSTICK_LEFT, JOYSTICK_RIGHT, JOYSTICK_UP, JOYSTICK_DOWN, JOYSTICK_PUSH); +Joystick joystick(JOYSTICK_LEFT, JOYSTICK_RIGHT, JOYSTICK_UP, JOYSTICK_DOWN, + JOYSTICK_PUSH); // Serial communication between Lolin and Screen -SoftwareSerial screenSerial(UART_RX, UART_TX); +SoftwareSerial screen_serial(UART_RX, UART_TX); // Instance of the screen as in Goldelox_Serial library -Goldelox_Serial_4DLib screenGoldelox(&screenSerial); +Goldelox_Serial_4DLib screen_goldelox(&screen_serial); // Wrapper instance of the screen -Screen screen(&screenGoldelox, &screenSerial, RST, BAUD_SCREEN); +Screen screen(&screen_goldelox, &screen_serial, RST, BAUD_SCREEN); // State Machine StateMachine state_machine; // Haptic Driver Adafruit_DRV2605 driver; -uint8_t effect = 14; // Select the desired effect, for now test effect "Buzz 100%" +uint8_t effect = + 14; // Select the desired effect, for now test effect "Buzz 100%" // Create ros nodehandle with publishers #ifdef USE_WIRELESS @@ -66,26 +73,25 @@ ros::NodeHandle nh; bool received_gait_instruction_response; bool gait_message_send; -void gaitInstructionResponseCallback(const std_msgs::Bool& msg) -{ +void gaitInstructionResponseCallback(const std_msgs::Bool& msg) { received_gait_instruction_response = true; } -ros::Subscriber gait_instruction_result_subscriber("/march/input_device/instruction_response", - &gaitInstructionResponseCallback); - -march_shared_resources::GaitInstruction gaitInstructionMessage; -std_msgs::Time timeMessage; -ros::Publisher gait_instruction_publisher("/march/input_device/instruction", &gaitInstructionMessage); -ros::Publisher ping_publisher("/march/input_device/alive", &timeMessage); - -void sendGaitMessage(std::string name) -{ - if (!name.empty() && !gait_message_send) - { - gaitInstructionMessage.type = march_shared_resources::GaitInstruction::GAIT; - gaitInstructionMessage.gait_name = name.c_str(); - gait_instruction_publisher.publish(&gaitInstructionMessage); +ros::Subscriber gait_instruction_result_subscriber( + "/march/input_device/instruction_response", + &gaitInstructionResponseCallback); + +march_shared_resources::GaitInstruction gait_instruction_msg; +std_msgs::Time time_msg; +ros::Publisher gait_instruction_publisher("/march/input_device/instruction", + &gait_instruction_msg); +ros::Publisher ping_publisher("/march/input_device/alive", &time_msg); + +void sendGaitMessage(const std::string& name) { + if (!name.empty() && !gait_message_send) { + gait_instruction_msg.type = march_shared_resources::GaitInstruction::GAIT; + gait_instruction_msg.gait_name = name.c_str(); + gait_instruction_publisher.publish(&gait_instruction_msg); gait_message_send = true; #ifdef DEMO_INPUT_DEVICE received_gait_instruction_response = true; @@ -93,21 +99,18 @@ void sendGaitMessage(std::string name) } } -void sendStopMessage() -{ - gaitInstructionMessage.type = march_shared_resources::GaitInstruction::STOP; - gaitInstructionMessage.gait_name = ""; - gait_instruction_publisher.publish(&gaitInstructionMessage); +void sendStopMessage() { + gait_instruction_msg.type = march_shared_resources::GaitInstruction::STOP; + gait_instruction_msg.gait_name = ""; + gait_instruction_publisher.publish(&gait_instruction_msg); } -void sendAliveMessage() -{ - timeMessage.data = nh.now(); - ping_publisher.publish(&timeMessage); +void sendAliveMessage() { + time_msg.data = nh.now(); + ping_publisher.publish(&time_msg); } -void setup() -{ +void setup() { Serial.begin(57600); Serial.println("Start Input Device"); @@ -135,7 +138,8 @@ void setup() nh.subscribe(gait_instruction_result_subscriber); Serial.println("ros node initialized"); - // Reset the joystick right pin, this needed after the ROS node init pin 14 is apparently used by ROS. + // Reset the joystick right pin, this needed after the ROS node init pin 14 is + // apparently used by ROS. pinMode(JOYSTICK_RIGHT, INPUT_PULLUP); // initialize screen by resetting, initing uSD card, clearing screen @@ -143,48 +147,44 @@ void setup() sleep(1); } -void loop() -{ - +void loop() { // Get button states - String rockerState = rocker.get_position(); - String joystickState = joystick.get_position(); - String joystickPress = joystick.get_press(); - String triggerPress = trigger.read_state(); + RockerSwitchState rocker_switch_state = rocker.getState(); + JoystickPosition joystick_position = joystick.getPosition(); + ButtonState joystick_state = joystick.getState(); + ButtonState trigger_state = trigger.getState(); // Set the effect to be played hoi // Waveforms can be combined, to create new wavefroms, see driver datasheet - driver.setWaveform(0, effect); // Setup the waveform(s) - driver.setWaveform(1, 0); // end of waveform waveform + driver.setWaveform(0, effect); // Setup the waveform(s) + driver.setWaveform(1, 0); // end of waveform waveform // When button is pressed, vibrate - if (triggerPress == "PUSH") - { + if (trigger_state == ButtonState::PUSH) { driver.go(); } - if (received_gait_instruction_response) - { + if (received_gait_instruction_response) { // This means gait instruction handled - triggerPress = "EXIT_GAIT"; + // trigger_state = "EXIT_GAIT"; received_gait_instruction_response = false; gait_message_send = false; } bool state_has_changed = false; - if (joystickState == "LEFT") { + if (joystick_position == JoystickPosition::LEFT) { state_has_changed = state_machine.left(); - } else if (joystickState == "RIGHT") { + } else if (joystick_position == JoystickPosition::RIGHT) { state_has_changed = state_machine.right(); - } else if (joystickState == "UP") { + } else if (joystick_position == JoystickPosition::UP) { state_has_changed = state_machine.up(); - } else if (joystickState == "DOWN") { + } else if (joystick_position == JoystickPosition::DOWN) { state_has_changed = state_machine.down(); - } else if (joystickPress == "PUSH") { + } else if (joystick_state == ButtonState::PUSH) { state_has_changed = state_machine.select(); - } else if (joystickPress == "DOUBLE") { + } else if (joystick_state == ButtonState::DOUBLE) { state_has_changed = state_machine.back(); - } else if (triggerPress == "PUSH") { + } else if (trigger_state == ButtonState::PUSH) { state_has_changed = state_machine.activate(); } @@ -200,7 +200,7 @@ void loop() // message with this gait. if (!gait_name.empty()) { sendGaitMessage(gait_name); - } else if (triggerPress == "PUSH") { + } else if (trigger_state == ButtonState::PUSH) { // If the trigger press is not to select a gait, it's interpreted as a // stop. sendStopMessage(); diff --git a/src/rocker_switch.cpp b/src/rocker_switch.cpp new file mode 100644 index 0000000..b4f030d --- /dev/null +++ b/src/rocker_switch.cpp @@ -0,0 +1,41 @@ +#include "rocker_switch.h" + +RockerSwitch::RockerSwitch(uint8_t up_pin, uint8_t down_pin) + : up_pin_(up_pin), down_pin_(down_pin) { + pinMode(up_pin, INPUT_PULLUP); + pinMode(down_pin, INPUT_PULLUP); +} + +// Returns either "NEUTRAL", "UP", "HOLDING UP", "DOWN" or "HOLDING DOWN" +// It is advised to treat "HOLDING X" the same as "NEUTRAL" outside this +// function +RockerSwitchState RockerSwitch::getState() { + RockerSwitchState state; + if (digitalRead(this->up_pin_) == LOW) { + if (this->last_position_ != RockerSwitchState::UP || + (millis() - this->last_print_time_) > this->hold_time_) { + // reset lastPrintTime + this->last_print_time_ = millis(); + this->last_position_ = RockerSwitchState::UP; + state = RockerSwitchState::UP; + } else { + state = RockerSwitchState::HOLDING_UP; + } + } else if (digitalRead(this->down_pin_) == LOW) { + if (this->last_position_ != RockerSwitchState::DOWN || + (millis() - this->last_print_time_) > this->hold_time_) { + // reset lastPrintTime + this->last_print_time_ = millis(); + this->last_position_ = RockerSwitchState::DOWN; + state = RockerSwitchState::DOWN; + } else { + state = RockerSwitchState::HOLDING_DOWN; + } + } else { + this->last_position_ = RockerSwitchState::NEUTRAL; + state = RockerSwitchState::NEUTRAL; + } + // To prevent multiple 'up's and 'down's per press due to bouncing + usleep(this->bounce_time_); + return state; +} diff --git a/src/screen.cpp b/src/screen.cpp new file mode 100644 index 0000000..e9b6b9e --- /dev/null +++ b/src/screen.cpp @@ -0,0 +1,41 @@ +#include "screen.h" + +Screen::Screen(Goldelox_Serial_4DLib* screen, SoftwareSerial* screen_serial, + uint8_t rst, uint32_t baud) + : screen_(screen), serial_(screen_serial), rst_(rst), baud_(baud) {} + +void Screen::initialize() { + digitalWrite(this->rst_, 1); + + serial_->begin(this->baud_); + + this->reset(); + + this->media_initialized_ = this->screen_->media_Init(); + usleep(this->wait_time_ms_); + + this->clear(); + + this->last_draw_time_ = millis(); +} + +void Screen::clear() { + this->screen_->gfx_Cls(); + usleep(this->wait_time_ms_); +} + +void Screen::reset() { + digitalWrite(this->rst_, 0); + usleep(this->wait_time_ms_); + + digitalWrite(this->rst_, 1); + sleep(3); +} + +void Screen::draw_image(word addr_hi, word addr_lo) { + if ((millis() - this->last_draw_time_) * 1000 > this->wait_time_ms_) { + screen_->media_SetSector(addr_hi, addr_lo); + screen_->media_Image(0, 0); + this->last_draw_time_ = millis(); + } +} From 61b77cb1bbaaf02038264fdb98c43ac01e8ab0ae Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Fri, 13 Dec 2019 10:42:28 +0100 Subject: [PATCH 10/58] Add monitor flags --- .travis.yml | 2 +- platformio.ini | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e729b4f..41d8158 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,4 +17,4 @@ install: script: - platformio run - - platformio check --environment debug + - platformio check diff --git a/platformio.ini b/platformio.ini index af6605c..037e77e 100644 --- a/platformio.ini +++ b/platformio.ini @@ -20,6 +20,12 @@ framework = arduino upload_port = /dev/ttyUSB0 upload_speed = 230400 +monitor_port = /dev/ttyUSB0 +monitor_speed = 57600 +monitor_flags = + --encoding + UTF-8 + check_tool = cppcheck, clangtidy check_severity = low, medium, high check_patterns = From 8442ba121db08f4ab1154e7f6311d50a3a74ab76 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Fri, 13 Dec 2019 10:48:26 +0100 Subject: [PATCH 11/58] Add check for nullptr --- include/state_machine.h | 1 + src/state_machine.cpp | 24 +++++++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/include/state_machine.h b/include/state_machine.h index 353ca81..104ea01 100644 --- a/include/state_machine.h +++ b/include/state_machine.h @@ -26,6 +26,7 @@ class StateMachine { bool activate(); private: + bool hasState() const; bool setCurrentState(State* new_state); std::vector states_; diff --git a/src/state_machine.cpp b/src/state_machine.cpp index a018d3f..b1d4c35 100644 --- a/src/state_machine.cpp +++ b/src/state_machine.cpp @@ -9,31 +9,41 @@ void StateMachine::getCurrentImage(word& address_hi, word& address_lo) const { } bool StateMachine::left() { - return this->setCurrentState(this->current_state_->left()); + return this->hasState() && + this->setCurrentState(this->current_state_->left()); } bool StateMachine::right() { - return this->setCurrentState(this->current_state_->right()); + return this->hasState() && + this->setCurrentState(this->current_state_->right()); } bool StateMachine::up() { - return this->setCurrentState(this->current_state_->up()); + return this->hasState() && this->setCurrentState(this->current_state_->up()); } bool StateMachine::down() { - return this->setCurrentState(this->current_state_->down()); + return this->hasState() && + this->setCurrentState(this->current_state_->down()); } bool StateMachine::back() { - return this->setCurrentState(this->current_state_->back()); + return this->hasState() && + this->setCurrentState(this->current_state_->back()); } bool StateMachine::select() { - return this->setCurrentState(this->current_state_->select()); + return this->hasState() && + this->setCurrentState(this->current_state_->select()); } bool StateMachine::activate() { - return this->setCurrentState(this->current_state_->activate()); + return this->hasState() && + this->setCurrentState(this->current_state_->activate()); +} + +bool StateMachine::hasState() const { + return this->current_state_ != nullptr; } bool StateMachine::setCurrentState(State* new_state) { From d29b3875add8378b90848ed5da55242815729b04 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Fri, 13 Dec 2019 10:54:02 +0100 Subject: [PATCH 12/58] Allow inline functions to be on one line --- .clang-format | 2 ++ include/state.h | 1 - src/main.cpp | 12 +++++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.clang-format b/.clang-format index 4a88ce1..b5f4fd5 100644 --- a/.clang-format +++ b/.clang-format @@ -4,4 +4,6 @@ BasedOnStyle: LLVM Language: Cpp DerivePointerAlignment: false PointerAlignment: Left +AllowShortFunctionsOnASingleLine: Inline +AllowShortBlocksOnASingleLine: false --- diff --git a/include/state.h b/include/state.h index ea8dc66..ad262f7 100644 --- a/include/state.h +++ b/include/state.h @@ -4,7 +4,6 @@ #include - class State { public: State(const word address_hi = 0, const word address_lo = 0, diff --git a/src/main.cpp b/src/main.cpp index d393ed1..a8c477b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -112,6 +112,7 @@ void sendAliveMessage() { void setup() { Serial.begin(57600); + Serial.println(); Serial.println("Start Input Device"); #ifdef USE_WIRELESS @@ -136,7 +137,7 @@ void setup() { nh.advertise(gait_instruction_publisher); nh.advertise(ping_publisher); nh.subscribe(gait_instruction_result_subscriber); - Serial.println("ros node initialized"); + Serial.println("ROS node initialized"); // Reset the joystick right pin, this needed after the ROS node init pin 14 is // apparently used by ROS. @@ -144,7 +145,9 @@ void setup() { // initialize screen by resetting, initing uSD card, clearing screen screen.initialize(); + Serial.println("Screen initialized"); sleep(1); + Serial.println("Ready for use"); } void loop() { @@ -174,18 +177,25 @@ void loop() { bool state_has_changed = false; if (joystick_position == JoystickPosition::LEFT) { state_has_changed = state_machine.left(); + Serial.println("Joystick left"); } else if (joystick_position == JoystickPosition::RIGHT) { state_has_changed = state_machine.right(); + Serial.println("Joystick right"); } else if (joystick_position == JoystickPosition::UP) { state_has_changed = state_machine.up(); + Serial.println("Joystick up"); } else if (joystick_position == JoystickPosition::DOWN) { state_has_changed = state_machine.down(); + Serial.println("Joystick down"); } else if (joystick_state == ButtonState::PUSH) { state_has_changed = state_machine.select(); + Serial.println("Joystick pushed"); } else if (joystick_state == ButtonState::DOUBLE) { state_has_changed = state_machine.back(); + Serial.println("Joystick double"); } else if (trigger_state == ButtonState::PUSH) { state_has_changed = state_machine.activate(); + Serial.println("Trigger pushed"); } if (state_has_changed) { From 09a9967293de87c30d37284f86e5c1370ae46657 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Fri, 13 Dec 2019 11:03:05 +0100 Subject: [PATCH 13/58] Add monitor target to README --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fa4d922..a9bb9ec 100644 --- a/README.md +++ b/README.md @@ -27,10 +27,19 @@ build the release environment run: pio run -e release This only builds the project. To actually upload the project, connect the -input device and use the `--target (-t)` option. +input device and use the `--target (-t)` option. This will by default upload +the `debug` environment. pio run -t upload +When you run the input device you can read the messages sent over the +USB serial by adding the `monitor` target. + + pio run -t upload -t monitor + +This will build, upload and then print messages sent over the serial +by the input device using `Serial.println()`. + ## 🚀 Launch process The input device can be launched with a ROS serial connection. For this a workspace with the [march repository](https://github.com/project-march/march) From 934cc8baaab50475bfafc9dc7c0f254e8872264d Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Sat, 14 Dec 2019 17:18:10 +0100 Subject: [PATCH 14/58] Add check for valid state --- src/state_machine.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/state_machine.cpp b/src/state_machine.cpp index b1d4c35..c792244 100644 --- a/src/state_machine.cpp +++ b/src/state_machine.cpp @@ -1,11 +1,16 @@ #include "state_machine.h" const std::string& StateMachine::getCurrentGaitName() const { - return this->current_state_->getGaitName(); + if (this->hasState()) { + return this->current_state_->getGaitName(); + } + return ""; } void StateMachine::getCurrentImage(word& address_hi, word& address_lo) const { - this->current_state_->getImage(address_hi, address_lo); + if (this->hasState()) { + this->current_state_->getImage(address_hi, address_lo); + } } bool StateMachine::left() { From eef8460b3eb9f827fba753073e2a84fd60dd3465 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Sat, 14 Dec 2019 17:18:48 +0100 Subject: [PATCH 15/58] Add method for drawing --- src/main.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index a8c477b..881369e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -110,6 +110,13 @@ void sendAliveMessage() { ping_publisher.publish(&time_msg); } +void drawCurrentImage() { + word address_hi = 0; + word address_lo = 0; + state_machine.getCurrentImage(address_hi, address_lo); + screen.draw_image(address_hi, address_lo); +} + void setup() { Serial.begin(57600); Serial.println(); @@ -147,6 +154,8 @@ void setup() { screen.initialize(); Serial.println("Screen initialized"); sleep(1); + + drawCurrentImage(); Serial.println("Ready for use"); } @@ -199,10 +208,7 @@ void loop() { } if (state_has_changed) { - word address_hi = 0; - word address_lo = 0; - state_machine.getCurrentImage(address_hi, address_lo); - screen.draw_image(address_hi, address_lo); + drawCurrentImage(); const std::string& gait_name = state_machine.getCurrentGaitName(); From c28e300c81f76dec53d8f8201b8a5e1c18d82d73 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Mon, 16 Dec 2019 09:52:40 +0100 Subject: [PATCH 16/58] Clean up sector addresses --- include/SD_sector_addresses.h | 567 ---------------------------------- include/sd_sector_addresses.h | 366 ++++++++++++++++++++++ 2 files changed, 366 insertions(+), 567 deletions(-) delete mode 100644 include/SD_sector_addresses.h create mode 100644 include/sd_sector_addresses.h diff --git a/include/SD_sector_addresses.h b/include/SD_sector_addresses.h deleted file mode 100644 index 71c0689..0000000 --- a/include/SD_sector_addresses.h +++ /dev/null @@ -1,567 +0,0 @@ -#ifndef SD_SECTOR_ADDRESSES_H -#define SD_SECTOR_ADDRESSES_H - -// This file defines the sector addresses of the images to be loaded on the screen -// The sector addresses can be found via the 4D Systems Workshop 4D IDE -// The Graphics Composer of this software should be used: -// - To load the desired images on the uSD card -// - To find the sector addresses of said images (via generated .Gc file) - -// HomeSitStart -#define HomeSitStart_Hi 0x0000 -#define HomeSitStart_Lo 0x0000 - -// HomeSitStartSelected -#define HomeSitStartSelected_Hi 0x0000 -#define HomeSitStartSelected_Lo 0x00A2 - -// HomeSitStartActivated -#define HomeSitStartActivated_Hi 0x0000 -#define HomeSitStartActivated_Lo 0x0051 - -// StandUp -#define StandUp_Hi 0x0000 -#define StandUp_Lo 0x1209 - -// StandUpSelected -#define StandUpSelected_Hi 0x0000 -#define StandUpSelected_Lo 0x12AB - -// StandUpActivated -#define StandUpActivated_Hi 0x0000 -#define StandUpActivated_Lo 0x125A - - -// TurnOffStart -#define TurnOffStart_Hi 0x0000 -#define TurnOffStart_Lo 0x14E2 - -// TurnOffStartSelected -#define TurnOffStartSelected_Hi 0x0000 -#define TurnOffStartSelected_Lo 0x1584 - -// TurnOffStartActivated -#define TurnOffStartActivated_Hi 0x0000 -#define TurnOffStartActivated_Lo 0x1533 - - - -// HomeStandStart -#define HomeStandStart_Hi 0x0000 -#define HomeStandStart_Lo 0x01E6 - -// HomeStandStartSelected unknown -#define HomeStandStartSelected_Hi 0x0000 -#define HomeStandStartSelected_Lo 0x0288 - -// HomeStandStartActivated unknown -#define HomeStandStartActivated_Hi 0x0000 -#define HomeStandStartActivated_Lo 0x0237 - - -// Sit -#define Sit_Hi 0x0000 -#define Sit_Lo 0x222C - -// SitSelected -#define SitSelected_Hi 0x0000 -#define SitSelected_Lo 0x0B13 - -// SitActivated -#define SitActivated_Hi 0x0000 -#define SitActivated_Lo 0x0AC2 - -// HomeSit -#define HomeSit_Hi 0x0000 -#define HomeSit_Lo 0x218A - -// HomeSitSelected -#define HomeSitSelected_Hi 0x0000 -#define HomeSitSelected_Lo 0x00A2 - -// HomeSitActivated -#define HomeSitActivated_Hi 0x0000 -#define HomeSitActivated_Lo 0x0051 - -// HomeStand -#define HomeStand_Hi 0x0000 -#define HomeStand_Lo 0x21DB - -// HomeStandSelected unknown -#define HomeStandSelected_Hi 0x0000 -#define HomeStandSelected_Lo 0x0288 - -// HomeStandActivated unknown -#define HomeStandActivated_Hi 0x0000 -#define HomeStandActivated_Lo 0x0237 - - - -// TurnOff -#define TurnOff_Hi 0x0000 -#define TurnOff_Lo 0x227D - -// TurnOffSelected -#define TurnOffSelected_Hi 0x0000 -#define TurnOffSelected_Lo 0x1491 - -// TurnOffActivated -#define TurnOffActivated_Hi 0x0000 -#define TurnOffActivated_Lo 0x1440 - - -// Sofa -#define Sofa_Hi 0x0000 -#define Sofa_Lo 0x2505 - -// SofaSit -#define SofaSit_Hi 0x0000 -#define SofaSit_Lo 0x25F8 - -// SofaSitSelected -#define SofaSitSelected_Hi 0x0000 -#define SofaSitSelected_Lo 0x0E8E - -// SofaSitActivated -#define SofaSitActivated_Hi 0x0000 -#define SofaSitActivated_Lo 0x0E3D - -// SofaStandUp -#define SofaStandUp_Hi 0x0000 -#define SofaStandUp_Lo 0x2649 - -// SofaStandUpSelected -#define SofaStandUpSelected_Hi 0x0000 -#define SofaStandUpSelected_Lo 0x0F81 - -// SofaStandUpActivated -#define SofaStandUpActivated_Hi 0x0000 -#define SofaStandUpActivated_Lo 0x0F30 - - -// // Slope -// #define Slope_Hi 0x0000 -// #define Slope_Lo 0x0B64 - -// // SlopeUp -// #define SlopeUp_Hi 0x0000 -// #define SlopeUp_Lo 0x0CA8 - -// // SlopeUpSelected -// #define SlopeUpSelected_Hi 0x0000 -// #define SlopeUpSelected_Lo 0x0D4A - -// // SlopeUpActivated -// #define SlopeUpActivated_Hi 0x0000 -// #define SlopeUpActivated_Lo 0x0CF9 - -// // SlopeDown -// #define SlopeDown_Hi 0x0000 -// #define SlopeDown_Lo 0x0BB5 - -// // SlopeDownSelected -// #define SlopeDownSelected_Hi 0x0000 -// #define SlopeDownSelected_Lo 0x0C57 - -// // SlopeDownActivated -// #define SlopeDownActivated_Hi 0x0000 -// #define SlopeDownActivated_Lo 0x0C06 - -// // SlopeDownFinal -// #define SlopeDownFinal_Hi 0x0000 -// #define SlopeDownFinal_Lo 0x0BB5 - -// // SlopeDownFinalSelected -// #define SlopeDownFinalSelected_Hi 0x0000 -// #define SlopeDownFinalSelected_Lo 0x0C57 - -// // SlopeDownFinalActivated -// #define SlopeDownFinalActivated_Hi 0x0000 -// #define SlopeDownFinalActivated_Lo 0x0C06 - - -// // RoughTerrain -// #define RoughTerrain_Hi 0x0000 -// #define RoughTerrain_Lo 0x02D9 - -// // RoughTerrainSelected unknown -// #define RoughTerrainSelected_Hi 0x0000 -// #define RoughTerrainSelected_Lo 0x037B - -// // RoughTerrainActivated unknown -// #define RoughTerrainActivated_Hi 0x0000 -// #define RoughTerrainActivated_Lo 0x032A - - -// TiltedPath -#define TiltedPath_Hi 0x0000 -#define TiltedPath_Lo 0x25A7 - -// TiltedPathSelected unknown yet! -#define TiltedPathSelected_Hi 0x0000 -#define TiltedPathSelected_Lo 0x139E - -// TiltedPathActivated unknown yet! -#define TiltedPathActivated_Hi 0x0000 -#define TiltedPathActivated_Lo 0x134D - - -// Stairs -#define Stairs_Hi 0x0000 -#define Stairs_Lo 0x2556 - -// StairsUp -#define StairsUp_Hi 0x0000 -#define StairsUp_Lo 0x26EB - -// StairsUpSelected -#define StairsUpSelected_Hi 0x0000 -#define StairsUpSelected_Lo 0x11B8 - -// StairsUpActivated -#define StairsUpActivated_Hi 0x0000 -#define StairsUpActivated_Lo 0x1167 - -// StairsDown -#define StairsDown_Hi 0x0000 -#define StairsDown_Lo 0x269A - -// StairsDownSelected, -#define StairsDownSelected_Hi 0x0000 -#define StairsDownSelected_Lo 0x10C5 - -// StairsDownActivated -#define StairsDownActivated_Hi 0x0000 -#define StairsDownActivated_Lo 0x1074 - -// StairsDownFinal -// #define StairsDownFinal_Hi 0x0000 -// #define StairsDownFinal_Lo 0x24B4 - -// StairsDownFinalSelected, -// #define StairsDownFinalSelected_Hi 0x0000 -// #define StairsDownFinalSelected_Lo 0x10C5 - -// StairsDownFinalActivated -// #define StairsDownFinalActivated_Hi 0x0000 -// #define StairsDownFinalActivated_Lo 0x1074 - - - -// WalkObstacle -#define WalkObstacle_Hi 0x0000 -#define WalkObstacle_Lo 0x180C - -// WalkObstacleSmall -#define WalkObstacleSmall_Hi 0x0000 -#define WalkObstacleSmall_Lo 0x18FF - -// WalkObstacleNormal -#define WalkObstacleNormal_Hi 0x0000 -#define WalkObstacleNormal_Lo 0x18AE - -// WalkObstacleLarge -#define WalkObstacleLarge_Hi 0x0000 -#define WalkObstacleLarge_Lo 0x185D - -// WalkObstacleSmallSelected -#define WalkObstacleSmallSelected_Hi 0x0000 -#define WalkObstacleSmallSelected_Lo 0x19F2 - -// WalkObstacleNormalSelected -#define WalkObstacleNormalSelected_Hi 0x0000 -#define WalkObstacleNormalSelected_Lo 0x17BB - -// // WalkObstacleLargeSelected -// #define WalkObstacleLargeSelected_Hi 0x0000 -// #define WalkObstacleLargeSelected_Lo 0x16C8 - -// WalkObstacleSmallActivated -#define WalkObstacleSmallActivated_Hi 0x0000 -#define WalkObstacleSmallActivated_Lo 0x19A1 - -// WalkObstacleNormalActivated -#define WalkObstacleNormalActivated_Hi 0x0000 -#define WalkObstacleNormalActivated_Lo 0x176A - -// // WalkObstacleLargeActivated -// #define WalkObstacleLargeActivated_Hi 0x0000 -// #define WalkObstacleLargeActivated_Lo 0x1677 - -// SingleStepObstacle -#define SingleStepObstacle_Hi 0x0000 -#define SingleStepObstacle_Lo 0x083A - -// SingleStepObstacleSmall -#define SingleStepObstacleSmall_Hi 0x0000 -#define SingleStepObstacleSmall_Lo 0x092D - -// SingleStepObstacleNormal -#define SingleStepObstacleNormal_Hi 0x0000 -#define SingleStepObstacleNormal_Lo 0x08DC - -// SingleStepObstacleLarge -#define SingleStepObstacleLarge_Hi 0x0000 -#define SingleStepObstacleLarge_Lo 0x088B - -// // SingleStepObstacleLargeSelected -// #define SingleStepObstacleLargeSelected_Hi 0x0000 -// #define SingleStepObstacleLargeSelected_Lo 0x06F6 - -// SingleStepObstacleSmallSelected -#define SingleStepObstacleSmallSelected_Hi 0x0000 -#define SingleStepObstacleSmallSelected_Lo 0x0A20 - -// SingleStepObstacleNormalSelected -#define SingleStepObstacleNormalSelected_Hi 0x0000 -#define SingleStepObstacleNormalSelected_Lo 0x07E9 - -// SingleStepObstacleSmallActivated -#define SingleStepObstacleSmallActivated_Hi 0x0000 -#define SingleStepObstacleSmallActivated_Lo 0x09CF - -// SingleStepObstacleNormalActivated -#define SingleStepObstacleNormalActivated_Hi 0x0000 -#define SingleStepObstacleNormalActivated_Lo 0x0798 - -// // SingleStepObstacleLargeActivated -// #define SingleStepObstacleLargeActivated_Hi 0x0000 -// #define SingleStepObstacleLargeActivated_Lo 0x06A5 - - - -// Walk -#define Walk_Hi 0x0000 -#define Walk_Lo 0x15D5 - -// WalkSmall -#define WalkSmall_Hi 0x0000 -#define WalkSmall_Lo 0x1950 - -// WalkNormal -#define WalkNormal_Hi 0x0000 -#define WalkNormal_Lo 0x1719 - -// WalkLarge -#define WalkLarge_Hi 0x0000 -#define WalkLarge_Lo 0x1626 - -// WalkNormalSelected -#define WalkNormalSelected_Hi 0x0000 -#define WalkNormalSelected_Lo 0x17BB - -// WalkNormalActivated -#define WalkNormalActivated_Hi 0x0000 -#define WalkNormalActivated_Lo 0x176A - - -// WalkSmallSelected -#define WalkSmallSelected_Hi 0x0000 -#define WalkSmallSelected_Lo 0x19F2 - -// // WalkLargeSelected -// #define WalkLargeSelected_Hi 0x0000 -// #define WalkLargeSelected_Lo 0x16C8 - -// WalkSmallActivated -#define WalkSmallActivated_Hi 0x0000 -#define WalkSmallActivated_Lo 0x19A1 - -// // WalkLargeActivated -// #define WalkLargeActivated_Hi 0x0000 -// #define WalkLargeActivated_Lo 0x1677 - -// SingleStep -#define SingleStep_Hi 0x0000 -#define SingleStep_Lo 0x0603 - -// SingleStepSmall -#define SingleStepSmall_Hi 0x0000 -#define SingleStepSmall_Lo 0x097E - -// SingleStepNormal -#define SingleStepNormal_Hi 0x0000 -#define SingleStepNormal_Lo 0x0747 - -// SingleStepLarge -#define SingleStepLarge_Hi 0x0000 -#define SingleStepLarge_Lo 0x0654 - -// SingleStepSmallSelected -#define SingleStepSmallSelected_Hi 0x0000 -#define SingleStepSmallSelected_Lo 0x0A20 - -// SingleStepNormalSelected -#define SingleStepNormalSelected_Hi 0x0000 -#define SingleStepNormalSelected_Lo 0x07E9 - -// // SingleStepLargeSelected -// #define SingleStepLargeSelected_Hi 0x0000 -// #define SingleStepLargeSelected_Lo 0x06F6 - -// SingleStepSmallActivated -#define SingleStepSmallActivated_Hi 0x0000 -#define SingleStepSmallActivated_Lo 0x09CF - -// SingleStepNormalActivated -#define SingleStepNormalActivated_Hi 0x0000 -#define SingleStepNormalActivated_Lo 0x0798 - -// // SingleStepLargeActivated -// #define SingleStepLargeActivated_Hi 0x0000 -// #define SingleStepLargeActivated_Lo 0x06A5 - -// SideStep -#define SideStep_Hi 0x0000 -#define SideStep_Lo 0x03CC - -// SideStepLeft -#define SideStepLeft_Hi 0x0000 -#define SideStepLeft_Lo 0x041D - -// SideStepRight -#define SideStepRight_Hi 0x0000 -#define SideStepRight_Lo 0x0510 - -// SideStepLeftSelected -#define SideStepLeftSelected_Hi 0x0000 -#define SideStepLeftSelected_Lo 0x04BF - -// SideStepRightSelected -#define SideStepRightSelected_Hi 0x0000 -#define SideStepRightSelected_Lo 0x05B2 - -// SideStepLeftActivated -#define SideStepLeftActivated_Hi 0x0000 -#define SideStepLeftActivated_Lo 0x046E - -// SideStepRightActivated -#define SideStepRightActivated_Hi 0x0000 -#define SideStepRightActivated_Lo 0x0561 - -//SiderStepLeftSmall -#define SideStepLeftSmall_Hi 0x0000 -#define SideStepLeftSmall_Lo 0x2F76 - -//SideStepLeftSmallSelected -#define SideStepLeftSmallSelected_Hi 0x0000 -#define SideStepLeftSmallSelected_Lo 0x3018 - -//SideStepLeftSmallActivated -#define SideStepLeftSmallActivated_Hi 0x0000 -#define SideStepLeftSmallActivated_Lo 0x2FC7 - -//SideStepLeftNormal -#define SideStepLeftNormal_Hi 0x0000 -#define SideStepLeftNormal_Lo 0x2C9D - -//SideStepLeftNormalSelected -#define SideStepLeftNormalSelected_Hi 0x0000 -#define SideStepLeftNormalSelected_Lo 0x2D3F - -//SideStepLeftNormalActivated -#define SideStepLeftNormalActivated_Hi 0x0000 -#define SideStepLeftNormalActivated_Lo 0x2CEE - -//SiderStepRightSmall -#define SideStepRightSmall_Hi 0x0000 -#define SideStepRightSmall_Lo 0x3069 - -//SideStepRightRightSelected -#define SideStepRightSmallSelected_Hi 0x0000 -#define SideStepRightSmallSelected_Lo 0x310B - -//SideStepRightSmallActivated -#define SideStepRightSmallActivated_Hi 0x0000 -#define SideStepRightSmallActivated_Lo 0x30BA - -//SideStepRightNormal -#define SideStepRightNormal_Hi 0x0000 -#define SideStepRightNormal_Lo 0x2D90 - -//SideStepRightNormalSelected -#define SideStepRightNormalSelected_Hi 0x0000 -#define SideStepRightNormalSelected_Lo 0x2E32 - -//SideStepRightNormalActivated -#define SideStepRightNormalActivated_Hi 0x0000 -#define SideStepRightNormalActivated_Lo - -//TiltedPathStartHomeToMin5 -#define TiltedPathStartHomeToMin5_Hi 0x0000 -#define TiltedPathStartHomeToMin5_Lo 0x2B59 - -//TiltedPathStartHomeToMin5Selected -#define TiltedPathStartHomeToMin5Selected_Hi 0x0000 -#define TiltedPathStartHomeToMin5Selected_Lo 0x2BFB - -//TiltedPathStartHomeToMin5Activated -#define TiltedPathStartHomeToMin5Activated_Hi 0x0000 -#define TiltedPathStartHomeToMin5Activated_Lo 0x2BAA - -//FirstStartStep -#define FirstStartStep_Hi 0x0000 -#define FirstStartStep_Lo 0x2A66 - -//FirstStartStepActivated -#define FirstStartStepActivated_Hi 0x0000 -#define FirstStartStepActivated_Lo 0x2A66 - -//SecondStartStep -#define SecondStartStep_Hi 0x0000 -#define SecondStartStep_Lo 0x2F25 - -//SecondStartStepActivated -#define SecondStartStepActivated_Hi 0x0000 -#define SecondStartStepActivated_Lo 0x2F25 - -//HomeStandToMin10 -#define HomeStandToMin10_Hi 0x0000 -#define HomeStandToMin10_Lo 0x2C4C - -//HomeStandToMin10Activated -#define HomeStandToMin10Activated_Hi 0x0000 -#define HomeStandToMin10Activated_Lo 0x2C4C - -//TiltedPathMiddleStep -#define TiltedPathMiddleStep_Hi 0x0000 -#define TiltedPathMiddleStep_Lo 0x2E83 - -//TiltedPathMiddleStepActivated -#define TiltedPathMiddleStepActivated_Hi 0x0000 -#define TiltedPathMiddleStepActivated_Lo 0x2E83 - -//HomeStandToMin5 -#define HomeStandToMin5_Hi 0x0000 -#define HomeStandToMin5_Lo 0x2B08 - -//HomeStandToMin5Activated -#define HomeStandToMin5Activated_Hi 0x0000 -#define HomeStandToMin5Activated_Lo 0x2B08 - -//FirstEndStep -#define FirstEndStep_Hi 0x0000 -#define FirstEndStep_Lo 0x2A15 - -//FirstEndStepActivated -#define FirstEndStepActivated_Hi 0x0000 -#define FirstEndStepActivated_Lo 0x2A15 - -//SecondEndStep -#define SecondEndStep_Hi 0x0000 -#define SecondEndStep_Lo 0x2ED4 - -//SecondEndStepActivated -#define SecondEndStepActivated_Hi 0x0000 -#define SecondEndStepActivated_Lo 0x2ED4 - -//HomeForWalk25 -#define HomeForWalk25_Hi 0x0000 -#define HomeForWalk25_Lo 0x2AB7 - -//HomeForWalk25Activated -#define HomeForWalk25Activated_Hi 0x0000 -#define HomeForWalk25Activated_Lo 0x2AB7 - - -#endif // SD_SECTOR_ADDRESSES_H diff --git a/include/sd_sector_addresses.h b/include/sd_sector_addresses.h new file mode 100644 index 0000000..e192675 --- /dev/null +++ b/include/sd_sector_addresses.h @@ -0,0 +1,366 @@ +#ifndef SD_SECTOR_ADDRESSES_H +#define SD_SECTOR_ADDRESSES_H + +// This file defines the sector addresses of the images to be loaded on the +// screen The sector addresses can be found via the 4D Systems Workshop 4D IDE +// The Graphics Composer of this software should be used: +// - To load the desired images on the uSD card +// - To find the sector addresses of said images (via generated .Gc file) + +// HomeSitStart +#define HomeSitStart_Hi 0x0000 +#define HomeSitStart_Lo 0x0000 + +// HomeSitStartSelected +#define HomeSitStartSelected_Hi 0x0000 +#define HomeSitStartSelected_Lo 0x00A2 + +// HomeSitStartActivated +#define HomeSitStartActivated_Hi 0x0000 +#define HomeSitStartActivated_Lo 0x0051 + +// StandUp +#define StandUp_Hi 0x0000 +#define StandUp_Lo 0x1209 + +// StandUpSelected +#define StandUpSelected_Hi 0x0000 +#define StandUpSelected_Lo 0x12AB + +// StandUpActivated +#define StandUpActivated_Hi 0x0000 +#define StandUpActivated_Lo 0x125A + +// TurnOffStart +#define TurnOffStart_Hi 0x0000 +#define TurnOffStart_Lo 0x14E2 + +// TurnOffStartSelected +#define TurnOffStartSelected_Hi 0x0000 +#define TurnOffStartSelected_Lo 0x1584 + +// TurnOffStartActivated +#define TurnOffStartActivated_Hi 0x0000 +#define TurnOffStartActivated_Lo 0x1533 + +// HomeStandStart +#define HomeStandStart_Hi 0x0000 +#define HomeStandStart_Lo 0x01E6 + +// HomeStandStartSelected unknown +#define HomeStandStartSelected_Hi 0x0000 +#define HomeStandStartSelected_Lo 0x0288 + +// HomeStandStartActivated unknown +#define HomeStandStartActivated_Hi 0x0000 +#define HomeStandStartActivated_Lo 0x0237 + +// Sit +#define Sit_Hi 0x0000 +#define Sit_Lo 0x222C + +// SitSelected +#define SitSelected_Hi 0x0000 +#define SitSelected_Lo 0x0B13 + +// SitActivated +#define SitActivated_Hi 0x0000 +#define SitActivated_Lo 0x0AC2 + +// HomeSit +#define HomeSit_Hi 0x0000 +#define HomeSit_Lo 0x218A + +// HomeSitSelected +#define HomeSitSelected_Hi 0x0000 +#define HomeSitSelected_Lo 0x00A2 + +// HomeSitActivated +#define HomeSitActivated_Hi 0x0000 +#define HomeSitActivated_Lo 0x0051 + +// HomeStand +#define HomeStand_Hi 0x0000 +#define HomeStand_Lo 0x21DB + +// HomeStandSelected unknown +#define HomeStandSelected_Hi 0x0000 +#define HomeStandSelected_Lo 0x0288 + +// HomeStandActivated unknown +#define HomeStandActivated_Hi 0x0000 +#define HomeStandActivated_Lo 0x0237 + +// TurnOff +#define TurnOff_Hi 0x0000 +#define TurnOff_Lo 0x227D + +// TurnOffSelected +#define TurnOffSelected_Hi 0x0000 +#define TurnOffSelected_Lo 0x1491 + +// TurnOffActivated +#define TurnOffActivated_Hi 0x0000 +#define TurnOffActivated_Lo 0x1440 + +// Sofa +#define Sofa_Hi 0x0000 +#define Sofa_Lo 0x2505 + +// SofaSit +#define SofaSit_Hi 0x0000 +#define SofaSit_Lo 0x25F8 + +// SofaSitSelected +#define SofaSitSelected_Hi 0x0000 +#define SofaSitSelected_Lo 0x0E8E + +// SofaSitActivated +#define SofaSitActivated_Hi 0x0000 +#define SofaSitActivated_Lo 0x0E3D + +// SofaStandUp +#define SofaStandUp_Hi 0x0000 +#define SofaStandUp_Lo 0x2649 + +// SofaStandUpSelected +#define SofaStandUpSelected_Hi 0x0000 +#define SofaStandUpSelected_Lo 0x0F81 + +// SofaStandUpActivated +#define SofaStandUpActivated_Hi 0x0000 +#define SofaStandUpActivated_Lo 0x0F30 + +// Stairs +#define Stairs_Hi 0x0000 +#define Stairs_Lo 0x2556 + +// StairsUp +#define StairsUp_Hi 0x0000 +#define StairsUp_Lo 0x26EB + +// StairsUpSelected +#define StairsUpSelected_Hi 0x0000 +#define StairsUpSelected_Lo 0x11B8 + +// StairsUpActivated +#define StairsUpActivated_Hi 0x0000 +#define StairsUpActivated_Lo 0x1167 + +// StairsDown +#define StairsDown_Hi 0x0000 +#define StairsDown_Lo 0x269A + +// StairsDownSelected, +#define StairsDownSelected_Hi 0x0000 +#define StairsDownSelected_Lo 0x10C5 + +// StairsDownActivated +#define StairsDownActivated_Hi 0x0000 +#define StairsDownActivated_Lo 0x1074 + +// WalkObstacle +#define WalkObstacle_Hi 0x0000 +#define WalkObstacle_Lo 0x180C + +// WalkObstacleSmall +#define WalkObstacleSmall_Hi 0x0000 +#define WalkObstacleSmall_Lo 0x18FF + +// WalkObstacleNormal +#define WalkObstacleNormal_Hi 0x0000 +#define WalkObstacleNormal_Lo 0x18AE + +// WalkObstacleLarge +#define WalkObstacleLarge_Hi 0x0000 +#define WalkObstacleLarge_Lo 0x185D + +// WalkObstacleSmallSelected +#define WalkObstacleSmallSelected_Hi 0x0000 +#define WalkObstacleSmallSelected_Lo 0x19F2 + +// WalkObstacleNormalSelected +#define WalkObstacleNormalSelected_Hi 0x0000 +#define WalkObstacleNormalSelected_Lo 0x17BB + +// WalkObstacleSmallActivated +#define WalkObstacleSmallActivated_Hi 0x0000 +#define WalkObstacleSmallActivated_Lo 0x19A1 + +// WalkObstacleNormalActivated +#define WalkObstacleNormalActivated_Hi 0x0000 +#define WalkObstacleNormalActivated_Lo 0x176A + +// SingleStepObstacle +#define SingleStepObstacle_Hi 0x0000 +#define SingleStepObstacle_Lo 0x083A + +// SingleStepObstacleSmall +#define SingleStepObstacleSmall_Hi 0x0000 +#define SingleStepObstacleSmall_Lo 0x092D + +// SingleStepObstacleNormal +#define SingleStepObstacleNormal_Hi 0x0000 +#define SingleStepObstacleNormal_Lo 0x08DC + +// SingleStepObstacleLarge +#define SingleStepObstacleLarge_Hi 0x0000 +#define SingleStepObstacleLarge_Lo 0x088B + +// SingleStepObstacleSmallSelected +#define SingleStepObstacleSmallSelected_Hi 0x0000 +#define SingleStepObstacleSmallSelected_Lo 0x0A20 + +// SingleStepObstacleNormalSelected +#define SingleStepObstacleNormalSelected_Hi 0x0000 +#define SingleStepObstacleNormalSelected_Lo 0x07E9 + +// SingleStepObstacleSmallActivated +#define SingleStepObstacleSmallActivated_Hi 0x0000 +#define SingleStepObstacleSmallActivated_Lo 0x09CF + +// SingleStepObstacleNormalActivated +#define SingleStepObstacleNormalActivated_Hi 0x0000 +#define SingleStepObstacleNormalActivated_Lo 0x0798 + +// Walk +#define Walk_Hi 0x0000 +#define Walk_Lo 0x15D5 + +// WalkSmall +#define WalkSmall_Hi 0x0000 +#define WalkSmall_Lo 0x1950 + +// WalkNormal +#define WalkNormal_Hi 0x0000 +#define WalkNormal_Lo 0x1719 + +// WalkLarge +#define WalkLarge_Hi 0x0000 +#define WalkLarge_Lo 0x1626 + +// WalkNormalSelected +#define WalkNormalSelected_Hi 0x0000 +#define WalkNormalSelected_Lo 0x17BB + +// WalkNormalActivated +#define WalkNormalActivated_Hi 0x0000 +#define WalkNormalActivated_Lo 0x176A + +// WalkSmallSelected +#define WalkSmallSelected_Hi 0x0000 +#define WalkSmallSelected_Lo 0x19F2 + +// WalkSmallActivated +#define WalkSmallActivated_Hi 0x0000 +#define WalkSmallActivated_Lo 0x19A1 + +// SingleStep +#define SingleStep_Hi 0x0000 +#define SingleStep_Lo 0x0603 + +// SingleStepSmall +#define SingleStepSmall_Hi 0x0000 +#define SingleStepSmall_Lo 0x097E + +// SingleStepNormal +#define SingleStepNormal_Hi 0x0000 +#define SingleStepNormal_Lo 0x0747 + +// SingleStepLarge +#define SingleStepLarge_Hi 0x0000 +#define SingleStepLarge_Lo 0x0654 + +// SingleStepSmallSelected +#define SingleStepSmallSelected_Hi 0x0000 +#define SingleStepSmallSelected_Lo 0x0A20 + +// SingleStepNormalSelected +#define SingleStepNormalSelected_Hi 0x0000 +#define SingleStepNormalSelected_Lo 0x07E9 + +// SingleStepSmallActivated +#define SingleStepSmallActivated_Hi 0x0000 +#define SingleStepSmallActivated_Lo 0x09CF + +// SingleStepNormalActivated +#define SingleStepNormalActivated_Hi 0x0000 +#define SingleStepNormalActivated_Lo 0x0798 + +// SideStep +#define SideStep_Hi 0x0000 +#define SideStep_Lo 0x03CC + +// SideStepLeft +#define SideStepLeft_Hi 0x0000 +#define SideStepLeft_Lo 0x041D + +// SideStepRight +#define SideStepRight_Hi 0x0000 +#define SideStepRight_Lo 0x0510 + +// SideStepLeftSelected +#define SideStepLeftSelected_Hi 0x0000 +#define SideStepLeftSelected_Lo 0x04BF + +// SideStepRightSelected +#define SideStepRightSelected_Hi 0x0000 +#define SideStepRightSelected_Lo 0x05B2 + +// SideStepLeftActivated +#define SideStepLeftActivated_Hi 0x0000 +#define SideStepLeftActivated_Lo 0x046E + +// SideStepRightActivated +#define SideStepRightActivated_Hi 0x0000 +#define SideStepRightActivated_Lo 0x0561 + +// SiderStepLeftSmall +#define SideStepLeftSmall_Hi 0x0000 +#define SideStepLeftSmall_Lo 0x2F76 + +// SideStepLeftSmallSelected +#define SideStepLeftSmallSelected_Hi 0x0000 +#define SideStepLeftSmallSelected_Lo 0x3018 + +// SideStepLeftSmallActivated +#define SideStepLeftSmallActivated_Hi 0x0000 +#define SideStepLeftSmallActivated_Lo 0x2FC7 + +// SideStepLeftNormal +#define SideStepLeftNormal_Hi 0x0000 +#define SideStepLeftNormal_Lo 0x2C9D + +// SideStepLeftNormalSelected +#define SideStepLeftNormalSelected_Hi 0x0000 +#define SideStepLeftNormalSelected_Lo 0x2D3F + +// SideStepLeftNormalActivated +#define SideStepLeftNormalActivated_Hi 0x0000 +#define SideStepLeftNormalActivated_Lo 0x2CEE + +// SiderStepRightSmall +#define SideStepRightSmall_Hi 0x0000 +#define SideStepRightSmall_Lo 0x3069 + +// SideStepRightRightSelected +#define SideStepRightSmallSelected_Hi 0x0000 +#define SideStepRightSmallSelected_Lo 0x310B + +// SideStepRightSmallActivated +#define SideStepRightSmallActivated_Hi 0x0000 +#define SideStepRightSmallActivated_Lo 0x30BA + +// SideStepRightNormal +#define SideStepRightNormal_Hi 0x0000 +#define SideStepRightNormal_Lo 0x2D90 + +// SideStepRightNormalSelected +#define SideStepRightNormalSelected_Hi 0x0000 +#define SideStepRightNormalSelected_Lo 0x2E32 + +// SideStepRightNormalActivated +#define SideStepRightNormalActivated_Hi 0x0000 +#define SideStepRightNormalActivated_Lo + +#endif // SD_SECTOR_ADDRESSES_H From 13853db19971b414f388bd19f0856c7b8fdbb256 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Mon, 16 Dec 2019 10:10:30 +0100 Subject: [PATCH 17/58] Add clang format to travis --- .travis.yml | 6 ++++++ include/wireless_connection.h | 30 +++++++++++------------------- src/button.cpp | 4 +++- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/.travis.yml b/.travis.yml index 41d8158..0d7e2c2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,11 @@ os: linux language: python +addons: + apt: + packages: + - clang-format + notifications: slack: secure: agpTHpiGJVNU8EtJV+nbiM8LYp7RkXPMpvrpa7yjlNKep4i0jQscFpOyylh+7Toekfh1F7ZMGhyBQfWsgzSKK4OtKgUY36jV3NJ04d1Jjf4CaypUsXe9eQ7KNIHLI+zPgwan+yf1iL6daF8uvRNT8SHCxTdRfVcwWaViQuh6/JbusxpSSojaT/BinCF/lItHC2+ixO1cQ7iFbBsaRyrEI76IUeaoMAUogqoNx+KdAYORMTcFI1i+6bw5TzsWY8Md8Kxn1YhvyeJv87LJjRhLyXLqzhp4XFjPUY0Vb9/iSihX7UfFoAPTPqmrlaATW6TEu0uo5fVJY6MWifAlcsuNGqL//saVqPHTiOqyEg1LcEUtdmR5+ljyMaSirV+pJA/vBNo61bjQeFzBf4d/kXiej0UQfLG1DFjUlYij++t6kr+EklYkwNYbfOQ75cLXrneG+nxjwg8KID2AVkjshLdjOfHFlGuzDTliId4lYU5FMdBl/dVS2u5qvVo8kaaTvvoAWjzp9KfdWHB1BmpAX06PblLWHnXuhJujBEyeT/9+D9eGmCmvYAsfLpky2hxWOHTkTbKGS9K60c2pHIhhzMRiOMZAVmbG7A2+7XdoaeBJ9cEHET09Ep2WY76jX5hTDbbA3xLZJB8e8O6TdCxXxp9xQvoPpmRK3rjsiun3thlFDBI= @@ -16,5 +21,6 @@ install: - platformio lib install script: + - wget -qO- https://raw.githubusercontent.com/Sarcasm/run-clang-format/master/run-clang-format.py | python - -r src include - platformio run - platformio check diff --git a/include/wireless_connection.h b/include/wireless_connection.h index 9101c98..8699cd2 100644 --- a/include/wireless_connection.h +++ b/include/wireless_connection.h @@ -11,19 +11,17 @@ const char* ssid = "OnePlus5"; const char* password = "timisdik"; -IPAddress server(192, 168, 43, 83); // ip of your ROS server +IPAddress server(192, 168, 43, 83); // ip of your ROS server IPAddress ip_address; // int status = WL_IDLE_STATUS; WiFiClient client; -void setupWiFi() -{ +void setupWiFi() { WiFi.begin(ssid, password); Serial.print("\nConnecting to "); Serial.println(ssid); - while (WiFi.status() != WL_CONNECTED) - { + while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("Could not connect to "); Serial.println(ssid); @@ -34,37 +32,31 @@ void setupWiFi() Serial.println(" to access client"); } -class WiFiHardware -{ +class WiFiHardware { public: WiFiHardware(){}; - void init() - { + void init() { // Initialization of TCP server/client setup client.connect(server, 11411); } // read a byte from the serial port. -1 = failure - int read() - { - // Read byte from the TCP connection and returns it. returns -1 when not working + int read() { + // Read byte from the TCP connection and returns it. returns -1 when not + // working return client.read(); } // write data to the connection to ROS - void write(uint8_t* data, int length) - { + void write(uint8_t* data, int length) { // write arguments to TCP connection for (int i = 0; i < length; i++) client.write(data[i]); } // returns milliseconds since start of program - unsigned long time() - { - return millis(); - } + unsigned long time() { return millis(); } }; -#endif // WIRELESS_CONNECTION_H +#endif // WIRELESS_CONNECTION_H diff --git a/src/button.cpp b/src/button.cpp index 783ed44..aa6dd9f 100644 --- a/src/button.cpp +++ b/src/button.cpp @@ -1,6 +1,8 @@ #include "button.h" -Button::Button(uint8_t pin) : input_pin_(pin) { pinMode(pin, INPUT_PULLUP); } +Button::Button(uint8_t pin) : input_pin_(pin) { + pinMode(pin, INPUT_PULLUP); +} // Returns either "NEUTRAL", "PUSH" or "HOLDING" // It is advised to treat "HOLDING" the same as "NEUTRAL" outside this function From 5a76a76f411f481db8df77f266dbc14e22cd1801 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Mon, 16 Dec 2019 10:10:55 +0100 Subject: [PATCH 18/58] Add construct method --- include/state_machine.h | 3 ++- src/main.cpp | 4 ++++ src/state_machine.cpp | 7 +++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/state_machine.h b/include/state_machine.h index 104ea01..b98b987 100644 --- a/include/state_machine.h +++ b/include/state_machine.h @@ -1,6 +1,5 @@ #ifndef STATE_MACHINE_H #define STATE_MACHINE_H -#include "SD_sector_addresses.h" #include "state.h" #include @@ -12,6 +11,8 @@ class StateMachine { public: StateMachine() = default; + void construct(); + const std::string& getCurrentGaitName() const; void getCurrentImage(word& address_hi, word& address_lo) const; diff --git a/src/main.cpp b/src/main.cpp index 881369e..a9a9f11 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -122,6 +122,10 @@ void setup() { Serial.println(); Serial.println("Start Input Device"); + Serial.println("Constructing state machine"); + state_machine.construct(); + Serial.println("Constructed state machine"); + #ifdef USE_WIRELESS setupWiFi(); #endif diff --git a/src/state_machine.cpp b/src/state_machine.cpp index c792244..d650f99 100644 --- a/src/state_machine.cpp +++ b/src/state_machine.cpp @@ -1,4 +1,11 @@ #include "state_machine.h" +#include "sd_sector_addresses.h" + +void StateMachine::construct() { + this->states_.emplace_back(HomeSitStart_Hi, HomeSitStart_Lo); + + this->current_state_ = &this->states_[0]; +} const std::string& StateMachine::getCurrentGaitName() const { if (this->hasState()) { From a776f5dbccce974f7f33b64f286fbb2ef6c304cd Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Mon, 16 Dec 2019 11:01:28 +0100 Subject: [PATCH 19/58] Fix string reference return --- include/state.h | 6 ++++-- include/state_machine.h | 2 +- src/main.cpp | 7 ++++--- src/state_machine.cpp | 4 ++-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/include/state.h b/include/state.h index ad262f7..5f8d84c 100644 --- a/include/state.h +++ b/include/state.h @@ -6,12 +6,14 @@ class State { public: - State(const word address_hi = 0, const word address_lo = 0, - const std::string& gait = "") + State(const word address_hi, const word address_lo, const std::string& gait) : gait_(gait), image_address_hi_(address_hi), image_address_lo_(address_lo), left_(this), right_(this), up_(this), down_(this) {} + State(const word address_hi, const word address_lo) + : State(address_hi, address_lo, "") {} + const std::string& getGaitName() const { return this->gait_; } void getImage(word& image_address_hi, word& image_address_lo) const { diff --git a/include/state_machine.h b/include/state_machine.h index b98b987..a7d791b 100644 --- a/include/state_machine.h +++ b/include/state_machine.h @@ -13,7 +13,7 @@ class StateMachine { void construct(); - const std::string& getCurrentGaitName() const; + std::string getCurrentGaitName() const; void getCurrentImage(word& address_hi, word& address_lo) const; diff --git a/src/main.cpp b/src/main.cpp index a9a9f11..174d8e8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -211,10 +211,11 @@ void loop() { Serial.println("Trigger pushed"); } - if (state_has_changed) { - drawCurrentImage(); + drawCurrentImage(); - const std::string& gait_name = state_machine.getCurrentGaitName(); + if (state_has_changed) { + std::string gait_name = state_machine.getCurrentGaitName(); + Serial.println(gait_name.c_str()); // If there is a transition to a new screen which belongs to a gait send // message with this gait. diff --git a/src/state_machine.cpp b/src/state_machine.cpp index d650f99..6678524 100644 --- a/src/state_machine.cpp +++ b/src/state_machine.cpp @@ -7,11 +7,11 @@ void StateMachine::construct() { this->current_state_ = &this->states_[0]; } -const std::string& StateMachine::getCurrentGaitName() const { +std::string StateMachine::getCurrentGaitName() const { if (this->hasState()) { return this->current_state_->getGaitName(); } - return ""; + return std::string(); } void StateMachine::getCurrentImage(word& address_hi, word& address_lo) const { From 5ea63e482594886728e10d58920127cc1c22a6f2 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Mon, 16 Dec 2019 11:14:59 +0100 Subject: [PATCH 20/58] Fix state pointers to pointers to const state --- include/state.h | 30 +++++++++++++++--------------- include/state_machine.h | 4 ++-- src/state_machine.cpp | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/include/state.h b/include/state.h index 5f8d84c..874a5bd 100644 --- a/include/state.h +++ b/include/state.h @@ -21,28 +21,28 @@ class State { image_address_lo = this->image_address_lo_; }; - State* left() const { return this->left_; } - State* right() const { return this->right_; } - State* up() const { return this->up_; } - State* down() const { return this->down_; } + const State* left() const { return this->left_; } + const State* right() const { return this->right_; } + const State* up() const { return this->up_; } + const State* down() const { return this->down_; } - State* back() const { return this->back_; } - State* select() const { return this->select_; } - State* activate() const { return this->activate_; } + const State* back() const { return this->back_; } + const State* select() const { return this->select_; } + const State* activate() const { return this->activate_; } private: - std::string gait_; + const std::string gait_; const word image_address_hi_; const word image_address_lo_; - State* left_ = nullptr; - State* right_ = nullptr; - State* up_ = nullptr; - State* down_ = nullptr; + const State* left_ = nullptr; + const State* right_ = nullptr; + const State* up_ = nullptr; + const State* down_ = nullptr; - State* back_ = nullptr; - State* select_ = nullptr; - State* activate_ = nullptr; + const State* back_ = nullptr; + const State* select_ = nullptr; + const State* activate_ = nullptr; }; #endif // STATE_H diff --git a/include/state_machine.h b/include/state_machine.h index a7d791b..f03e44a 100644 --- a/include/state_machine.h +++ b/include/state_machine.h @@ -28,10 +28,10 @@ class StateMachine { private: bool hasState() const; - bool setCurrentState(State* new_state); + bool setCurrentState(const State* new_state); std::vector states_; - State* current_state_ = nullptr; + const State* current_state_ = nullptr; }; #endif // STATE_MACHINE_H diff --git a/src/state_machine.cpp b/src/state_machine.cpp index 6678524..348a379 100644 --- a/src/state_machine.cpp +++ b/src/state_machine.cpp @@ -58,7 +58,7 @@ bool StateMachine::hasState() const { return this->current_state_ != nullptr; } -bool StateMachine::setCurrentState(State* new_state) { +bool StateMachine::setCurrentState(const State* new_state) { bool has_changed = this->current_state_ != new_state; this->current_state_ = new_state; return has_changed; From 9cae8d85c8734fad109fd59be3006438706c975a Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Mon, 16 Dec 2019 14:04:59 +0100 Subject: [PATCH 21/58] Add state unit tests --- .travis.yml | 3 ++- include/state.h | 29 ++++++++++------------ include/state_machine.h | 4 +--- platformio.ini | 22 +++++++++++++---- src/state_machine.cpp | 2 +- test/test_state/test_state.cpp | 44 ++++++++++++++++++++++++++++++++++ 6 files changed, 79 insertions(+), 25 deletions(-) create mode 100644 test/test_state/test_state.cpp diff --git a/.travis.yml b/.travis.yml index 0d7e2c2..d5821e7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,6 +21,7 @@ install: - platformio lib install script: - - wget -qO- https://raw.githubusercontent.com/Sarcasm/run-clang-format/master/run-clang-format.py | python - -r src include - platformio run + - platformio test --environment native - platformio check + - wget -qO- https://raw.githubusercontent.com/Sarcasm/run-clang-format/master/run-clang-format.py | python - -r src include test diff --git a/include/state.h b/include/state.h index 874a5bd..938ed39 100644 --- a/include/state.h +++ b/include/state.h @@ -1,22 +1,19 @@ #ifndef STATE_H #define STATE_H -#include - #include class State { public: - State(const word address_hi, const word address_lo, const std::string& gait) + State(const unsigned int address_hi, const unsigned int address_lo, const std::string& gait) : gait_(gait), image_address_hi_(address_hi), - image_address_lo_(address_lo), left_(this), right_(this), up_(this), - down_(this) {} + image_address_lo_(address_lo) {} - State(const word address_hi, const word address_lo) + State(const unsigned int address_hi, const unsigned int address_lo) : State(address_hi, address_lo, "") {} const std::string& getGaitName() const { return this->gait_; } - void getImage(word& image_address_hi, word& image_address_lo) const { + void getImage(unsigned int& image_address_hi, unsigned int& image_address_lo) const { image_address_hi = this->image_address_hi_; image_address_lo = this->image_address_lo_; }; @@ -32,17 +29,17 @@ class State { private: const std::string gait_; - const word image_address_hi_; - const word image_address_lo_; + const unsigned int image_address_hi_; + const unsigned int image_address_lo_; - const State* left_ = nullptr; - const State* right_ = nullptr; - const State* up_ = nullptr; - const State* down_ = nullptr; + const State* left_ = this; + const State* right_ = this; + const State* up_ = this; + const State* down_ = this; - const State* back_ = nullptr; - const State* select_ = nullptr; - const State* activate_ = nullptr; + const State* back_ = this; + const State* select_ = this; + const State* activate_ = this; }; #endif // STATE_H diff --git a/include/state_machine.h b/include/state_machine.h index f03e44a..555441b 100644 --- a/include/state_machine.h +++ b/include/state_machine.h @@ -2,8 +2,6 @@ #define STATE_MACHINE_H #include "state.h" -#include - #include #include @@ -15,7 +13,7 @@ class StateMachine { std::string getCurrentGaitName() const; - void getCurrentImage(word& address_hi, word& address_lo) const; + void getCurrentImage(unsigned int& address_hi, unsigned int& address_lo) const; bool left(); bool right(); diff --git a/platformio.ini b/platformio.ini index 037e77e..8adb8bf 100644 --- a/platformio.ini +++ b/platformio.ini @@ -12,10 +12,6 @@ description = Embedded software for the input device embedded in the crutch default_envs = debug [env] -platform = espressif32 -board = lolin_d32_pro -framework = arduino - ; If Platformio gives a upload error, please specify this for your respective COM port upload_port = /dev/ttyUSB0 upload_speed = 230400 @@ -39,13 +35,31 @@ lib_deps = ; Demo build environment that enables demo purposes for the input device. [env:demo] +platform = espressif32 +board = lolin_d32_pro +framework = arduino + build_type = debug build_flags = -D DEBUG -D DEMO_INPUT_DEVICE [env:debug] +platform = espressif32 +board = lolin_d32_pro +framework = arduino + build_type = debug build_flags = -g -D DEBUG [env:release] +platform = espressif32 +board = lolin_d32_pro +framework = arduino + build_type = release build_flags = -O3 -D RELEASE + +[env:native] +platform = native +test_build_project_src = true +test_filter = test_state +src_filter = + diff --git a/src/state_machine.cpp b/src/state_machine.cpp index 348a379..10a2a67 100644 --- a/src/state_machine.cpp +++ b/src/state_machine.cpp @@ -14,7 +14,7 @@ std::string StateMachine::getCurrentGaitName() const { return std::string(); } -void StateMachine::getCurrentImage(word& address_hi, word& address_lo) const { +void StateMachine::getCurrentImage(unsigned int& address_hi, unsigned int& address_lo) const { if (this->hasState()) { this->current_state_->getImage(address_hi, address_lo); } diff --git a/test/test_state/test_state.cpp b/test/test_state/test_state.cpp new file mode 100644 index 0000000..23435c9 --- /dev/null +++ b/test/test_state/test_state.cpp @@ -0,0 +1,44 @@ +#include "state.h" + +#include + +#include + +void test_state_get_gait_name() { + std::string gait("test"); + State state(0, 0, gait); + TEST_ASSERT_EQUAL_STRING(gait.c_str(), state.getGaitName().c_str()); +} + +void test_state_get_address() { + unsigned int expected_hi = 7; + unsigned int expected_lo = 8; + State state(expected_hi, expected_lo); + + unsigned int hi = 0; + unsigned int lo = 0; + state.getImage(hi, lo); + TEST_ASSERT_EQUAL(expected_hi, hi); + TEST_ASSERT_EQUAL(expected_lo, lo); +} + +void test_state_default_transitions() { + State state(0, 0); + TEST_ASSERT_EQUAL(&state, state.left()); + TEST_ASSERT_EQUAL(&state, state.right()); + TEST_ASSERT_EQUAL(&state, state.up()); + TEST_ASSERT_EQUAL(&state, state.down()); + TEST_ASSERT_EQUAL(&state, state.back()); + TEST_ASSERT_EQUAL(&state, state.select()); + TEST_ASSERT_EQUAL(&state, state.activate()); +} + +int main(int argc, char** argv) { + UNITY_BEGIN(); + RUN_TEST(test_state_get_gait_name); + RUN_TEST(test_state_get_address); + RUN_TEST(test_state_default_transitions); + UNITY_END(); + + return 0; +} From 2f575375d4e01f92e3c2c26cf48cff77f20bbf6c Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Mon, 16 Dec 2019 14:08:03 +0100 Subject: [PATCH 22/58] Add state machine unit tests --- .../test_state_machine/test_state_machine.cpp | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 test/test_state_machine/test_state_machine.cpp diff --git a/test/test_state_machine/test_state_machine.cpp b/test/test_state_machine/test_state_machine.cpp new file mode 100644 index 0000000..e025583 --- /dev/null +++ b/test/test_state_machine/test_state_machine.cpp @@ -0,0 +1,43 @@ +#include "state_machine.h" + +#include + +#include + +void test_get_gait_name() { + StateMachine state_machine; + std::string gait_name = state_machine.getCurrentGaitName(); + TEST_ASSERT_EQUAL_STRING("", gait_name.c_str()); +} + +void test_get_image() { + StateMachine state_machine; + unsigned int expected_hi = 2; + unsigned int expected_lo = 3; + unsigned int hi = expected_hi; + unsigned int lo = expected_lo; + state_machine.getCurrentImage(hi, lo); + TEST_ASSERT_EQUAL(expected_hi, hi); + TEST_ASSERT_EQUAL(expected_lo, lo); +} + +void test_state_machine_default_no_transitions() { + StateMachine state_machine; + TEST_ASSERT_FALSE(state_machine.left()); + TEST_ASSERT_FALSE(state_machine.right()); + TEST_ASSERT_FALSE(state_machine.up()); + TEST_ASSERT_FALSE(state_machine.down()); + TEST_ASSERT_FALSE(state_machine.back()); + TEST_ASSERT_FALSE(state_machine.select()); + TEST_ASSERT_FALSE(state_machine.activate()); +} + +int main(int argc, char** argv) { + UNITY_BEGIN(); + RUN_TEST(test_get_gait_name); + RUN_TEST(test_get_image); + RUN_TEST(test_state_machine_default_no_transitions); + UNITY_END(); + + return 0; +} From 2306492cf33f17d3ef046281b6f8777f705ed64a Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Mon, 16 Dec 2019 14:09:32 +0100 Subject: [PATCH 23/58] Fix clang format --- include/state.h | 6 ++++-- include/state_machine.h | 3 ++- src/state_machine.cpp | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/state.h b/include/state.h index 938ed39..30b3a52 100644 --- a/include/state.h +++ b/include/state.h @@ -4,7 +4,8 @@ class State { public: - State(const unsigned int address_hi, const unsigned int address_lo, const std::string& gait) + State(const unsigned int address_hi, const unsigned int address_lo, + const std::string& gait) : gait_(gait), image_address_hi_(address_hi), image_address_lo_(address_lo) {} @@ -13,7 +14,8 @@ class State { const std::string& getGaitName() const { return this->gait_; } - void getImage(unsigned int& image_address_hi, unsigned int& image_address_lo) const { + void getImage(unsigned int& image_address_hi, + unsigned int& image_address_lo) const { image_address_hi = this->image_address_hi_; image_address_lo = this->image_address_lo_; }; diff --git a/include/state_machine.h b/include/state_machine.h index 555441b..7a01de7 100644 --- a/include/state_machine.h +++ b/include/state_machine.h @@ -13,7 +13,8 @@ class StateMachine { std::string getCurrentGaitName() const; - void getCurrentImage(unsigned int& address_hi, unsigned int& address_lo) const; + void getCurrentImage(unsigned int& address_hi, + unsigned int& address_lo) const; bool left(); bool right(); diff --git a/src/state_machine.cpp b/src/state_machine.cpp index 10a2a67..58241a9 100644 --- a/src/state_machine.cpp +++ b/src/state_machine.cpp @@ -14,7 +14,8 @@ std::string StateMachine::getCurrentGaitName() const { return std::string(); } -void StateMachine::getCurrentImage(unsigned int& address_hi, unsigned int& address_lo) const { +void StateMachine::getCurrentImage(unsigned int& address_hi, + unsigned int& address_lo) const { if (this->hasState()) { this->current_state_->getImage(address_hi, address_lo); } From d77da1835ff53b065d0c87af4f7d7cef98fbf068 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Mon, 16 Dec 2019 14:16:35 +0100 Subject: [PATCH 24/58] Add c++11 build flag --- platformio.ini | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/platformio.ini b/platformio.ini index 8adb8bf..ce8d778 100644 --- a/platformio.ini +++ b/platformio.ini @@ -40,7 +40,7 @@ board = lolin_d32_pro framework = arduino build_type = debug -build_flags = -D DEBUG -D DEMO_INPUT_DEVICE +build_flags = -std=c++11 -D DEBUG -D DEMO_INPUT_DEVICE [env:debug] platform = espressif32 @@ -48,7 +48,7 @@ board = lolin_d32_pro framework = arduino build_type = debug -build_flags = -g -D DEBUG +build_flags = -std=c++11 -g -D DEBUG [env:release] platform = espressif32 @@ -56,7 +56,7 @@ board = lolin_d32_pro framework = arduino build_type = release -build_flags = -O3 -D RELEASE +build_flags = -std=c++11 -O3 -D RELEASE [env:native] platform = native From dfab91d86085353d072ba725ca1922121744b04f Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Mon, 16 Dec 2019 16:12:05 +0100 Subject: [PATCH 25/58] Remove serial prints, since ROS requires exclusive use --- include/wireless_connection.h | 8 -------- src/main.cpp | 19 ++----------------- 2 files changed, 2 insertions(+), 25 deletions(-) diff --git a/include/wireless_connection.h b/include/wireless_connection.h index 8699cd2..706597e 100644 --- a/include/wireless_connection.h +++ b/include/wireless_connection.h @@ -19,17 +19,9 @@ WiFiClient client; void setupWiFi() { WiFi.begin(ssid, password); - Serial.print("\nConnecting to "); - Serial.println(ssid); while (WiFi.status() != WL_CONNECTED) { delay(500); - Serial.print("Could not connect to "); - Serial.println(ssid); } - - Serial.print("Ready! Use "); - Serial.print(WiFi.localIP()); - Serial.println(" to access client"); } class WiFiHardware { diff --git a/src/main.cpp b/src/main.cpp index 174d8e8..c36b2bc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -119,12 +119,6 @@ void drawCurrentImage() { void setup() { Serial.begin(57600); - Serial.println(); - Serial.println("Start Input Device"); - - Serial.println("Constructing state machine"); - state_machine.construct(); - Serial.println("Constructed state machine"); #ifdef USE_WIRELESS setupWiFi(); @@ -148,7 +142,6 @@ void setup() { nh.advertise(gait_instruction_publisher); nh.advertise(ping_publisher); nh.subscribe(gait_instruction_result_subscriber); - Serial.println("ROS node initialized"); // Reset the joystick right pin, this needed after the ROS node init pin 14 is // apparently used by ROS. @@ -156,11 +149,11 @@ void setup() { // initialize screen by resetting, initing uSD card, clearing screen screen.initialize(); - Serial.println("Screen initialized"); sleep(1); + state_machine.construct(); + drawCurrentImage(); - Serial.println("Ready for use"); } void loop() { @@ -190,32 +183,24 @@ void loop() { bool state_has_changed = false; if (joystick_position == JoystickPosition::LEFT) { state_has_changed = state_machine.left(); - Serial.println("Joystick left"); } else if (joystick_position == JoystickPosition::RIGHT) { state_has_changed = state_machine.right(); - Serial.println("Joystick right"); } else if (joystick_position == JoystickPosition::UP) { state_has_changed = state_machine.up(); - Serial.println("Joystick up"); } else if (joystick_position == JoystickPosition::DOWN) { state_has_changed = state_machine.down(); - Serial.println("Joystick down"); } else if (joystick_state == ButtonState::PUSH) { state_has_changed = state_machine.select(); - Serial.println("Joystick pushed"); } else if (joystick_state == ButtonState::DOUBLE) { state_has_changed = state_machine.back(); - Serial.println("Joystick double"); } else if (trigger_state == ButtonState::PUSH) { state_has_changed = state_machine.activate(); - Serial.println("Trigger pushed"); } drawCurrentImage(); if (state_has_changed) { std::string gait_name = state_machine.getCurrentGaitName(); - Serial.println(gait_name.c_str()); // If there is a transition to a new screen which belongs to a gait send // message with this gait. From edc8e22de2c18b69d9833ba53fbf726f7fda46f2 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Mon, 16 Dec 2019 18:03:28 +0100 Subject: [PATCH 26/58] Add constructing first startup menu --- include/state.h | 41 +++++++++++++++++++++++++++++++++++++++++ include/state_machine.h | 10 ++++++++-- src/state_machine.cpp | 31 +++++++++++++++++++++++++++++-- 3 files changed, 78 insertions(+), 4 deletions(-) diff --git a/include/state.h b/include/state.h index 30b3a52..64d2356 100644 --- a/include/state.h +++ b/include/state.h @@ -29,6 +29,47 @@ class State { const State* select() const { return this->select_; } const State* activate() const { return this->activate_; } + State& withLeft(State* left) { + this->left_ = left; + left->right_ = this; + return *this; + } + + State& withRight(State* right) { + this->right_ = right; + right->left_ = this; + return *this; + } + + State& withUp(State* up) { + this->up_ = up; + up->down_ = this; + return *this; + } + + State& withDown(State* down) { + this->down_ = down; + down->up_ = this; + return *this; + } + + State& withBack(State* back) { + this->back_ = back; + back->select_ = this; + return *this; + } + + State& withSelect(State* select) { + this->select_ = select; + select->back_ = this; + return *this; + } + + State& withActivate(State* activate) { + this->activate_ = activate; + return *this; + } + private: const std::string gait_; const unsigned int image_address_hi_; diff --git a/include/state_machine.h b/include/state_machine.h index 7a01de7..dacff0b 100644 --- a/include/state_machine.h +++ b/include/state_machine.h @@ -2,8 +2,8 @@ #define STATE_MACHINE_H #include "state.h" +#include #include -#include class StateMachine { public: @@ -16,6 +16,8 @@ class StateMachine { void getCurrentImage(unsigned int& address_hi, unsigned int& address_lo) const; + size_t size() const; + bool left(); bool right(); bool up(); @@ -29,7 +31,11 @@ class StateMachine { bool hasState() const; bool setCurrentState(const State* new_state); - std::vector states_; + State& createState(const unsigned int address_hi, + const unsigned int address_lo, + const std::string& gait_name = ""); + + std::list states_; const State* current_state_ = nullptr; }; diff --git a/src/state_machine.cpp b/src/state_machine.cpp index 58241a9..29df1c8 100644 --- a/src/state_machine.cpp +++ b/src/state_machine.cpp @@ -2,9 +2,25 @@ #include "sd_sector_addresses.h" void StateMachine::construct() { - this->states_.emplace_back(HomeSitStart_Hi, HomeSitStart_Lo); + State& home_sit_start = this->createState(HomeSitStart_Hi, HomeSitStart_Lo); + State& home_sit_start_activated = this->createState(HomeSitStartActivated_Hi, HomeSitStartActivated_Lo, "home_sit"); + State& home_sit_start_selected = this->createState(HomeSitStartSelected_Hi, HomeSitStartSelected_Lo).withBack(&home_sit_start).withActivate(&home_sit_start_activated); - this->current_state_ = &this->states_[0]; + State& stand_up = + this->createState(StandUp_Hi, StandUp_Lo).withLeft(&home_sit_start); + State& stand_up_activated = this->createState(StandUpActivated_Hi, StandUpActivated_Lo, "gait_sit"); + State& stand_up_selected = this->createState(StandUpSelected_Hi, StandUpSelected_Lo).withBack(&stand_up).withActivate(&stand_up_activated); + + State& home_stand_start = + this->createState(HomeStandStart_Hi, HomeStandStart_Lo) + .withLeft(&stand_up); + State& home_stand_activated = this->createState(HomeStandActivated_Hi, HomeStandActivated_Lo, "home_stand"); + State& home_stand_selected = this->createState(HomeStandSelected_Hi, HomeStandSelected_Lo).withBack(&home_stand_start).withActivate(&home_stand_activated); + State& power_off = this->createState(TurnOff_Hi, TurnOff_Lo) + .withLeft(&home_stand_start) + .withRight(&home_sit_start); + + this->current_state_ = &this->states_.front(); } std::string StateMachine::getCurrentGaitName() const { @@ -21,6 +37,10 @@ void StateMachine::getCurrentImage(unsigned int& address_hi, } } +size_t StateMachine::size() const { + return this->states_.size(); +} + bool StateMachine::left() { return this->hasState() && this->setCurrentState(this->current_state_->left()); @@ -64,3 +84,10 @@ bool StateMachine::setCurrentState(const State* new_state) { this->current_state_ = new_state; return has_changed; } + +State& StateMachine::createState(const unsigned int address_hi, + const unsigned int address_lo, + const std::string& gait_name) { + this->states_.emplace_back(address_hi, address_lo, gait_name); + return this->states_.back(); +} \ No newline at end of file From 26d2fbc845efcfeb6e490071227f56ac89606ce3 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Mon, 16 Dec 2019 22:24:07 +0100 Subject: [PATCH 27/58] WIP: refactor screen --- include/screen.h | 15 ++++++------ include/version.h | 8 +++++++ src/main.cpp | 12 ++++------ src/screen.cpp | 60 ++++++++++++++++++++++++++++++++++++++++------- 4 files changed, 71 insertions(+), 24 deletions(-) create mode 100644 include/version.h diff --git a/include/screen.h b/include/screen.h index 78ce79a..ed732b4 100644 --- a/include/screen.h +++ b/include/screen.h @@ -35,27 +35,28 @@ to the * class Screen { public: - // Constructors Screen(Goldelox_Serial_4DLib* screen, SoftwareSerial* screen_serial, uint8_t rst, uint32_t baud); - // Public member functions - void initialize(); + void init(); void clear(); - void reset(); void draw_image(word addr_hi, word addr_lo); private: + void reset(); + + void printVersion(); + void mountImages(); + Goldelox_Serial_4DLib* screen_; SoftwareSerial* serial_; - word media_initialized_ = 0; unsigned long last_draw_time_ = 0; const uint8_t rst_; const uint32_t baud_; - const useconds_t wait_time_ms_ = - 500000; // Needed for functioning, can still be optimized + // In microseconds. Needed for functioning, can still be optimized + const useconds_t wait_time_ms_ = 500000; }; #endif // SCREEN_H \ No newline at end of file diff --git a/include/version.h b/include/version.h new file mode 100644 index 0000000..3e1188b --- /dev/null +++ b/include/version.h @@ -0,0 +1,8 @@ +#ifndef VERSION_H +#define VERSION_H + +#define ORGANIZATION "Project March" +#define PROJECT_NAME "input-device" +#define VERSION "v2.0.0-beta.1" + +#endif // VERSION_H diff --git a/src/main.cpp b/src/main.cpp index c36b2bc..0b9660e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,8 +14,6 @@ #include #include #include -#include -#include #include // Pin definitions @@ -125,10 +123,12 @@ void setup() { #endif // Set screen pins as either input or output - pinMode(RST, OUTPUT); pinMode(UART_TX, OUTPUT); pinMode(UART_RX, INPUT); + // initialize screen by resetting, initing uSD card, clearing screen + screen.init(); + // Setup I2C protocol driver.begin(); // Select the effect library @@ -147,10 +147,6 @@ void setup() { // apparently used by ROS. pinMode(JOYSTICK_RIGHT, INPUT_PULLUP); - // initialize screen by resetting, initing uSD card, clearing screen - screen.initialize(); - sleep(1); - state_machine.construct(); drawCurrentImage(); @@ -158,7 +154,7 @@ void setup() { void loop() { // Get button states - RockerSwitchState rocker_switch_state = rocker.getState(); + // RockerSwitchState rocker_switch_state = rocker.getState(); JoystickPosition joystick_position = joystick.getPosition(); ButtonState joystick_state = joystick.getState(); ButtonState trigger_state = trigger.getState(); diff --git a/src/screen.cpp b/src/screen.cpp index e9b6b9e..44d0e98 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -1,19 +1,29 @@ #include "screen.h" +#include "version.h" + +// 16-bit color March blue converted from 24bit 0x126287 +#define MARCH_COLOR 0x218B Screen::Screen(Goldelox_Serial_4DLib* screen, SoftwareSerial* screen_serial, uint8_t rst, uint32_t baud) - : screen_(screen), serial_(screen_serial), rst_(rst), baud_(baud) {} + : screen_(screen), serial_(screen_serial), rst_(rst), baud_(baud) { + pinMode(rst, OUTPUT); +} -void Screen::initialize() { +void Screen::init() { digitalWrite(this->rst_, 1); - serial_->begin(this->baud_); + this->serial_->begin(this->baud_); this->reset(); + this->clear(); - this->media_initialized_ = this->screen_->media_Init(); - usleep(this->wait_time_ms_); + this->screen_->gfx_ScreenMode(PORTRAIT); + this->printVersion(); + this->mountImages(); + this->screen_->gfx_ScreenMode(LANDSCAPE); + sleep(5); this->clear(); this->last_draw_time_ = millis(); @@ -21,21 +31,53 @@ void Screen::initialize() { void Screen::clear() { this->screen_->gfx_Cls(); - usleep(this->wait_time_ms_); } void Screen::reset() { digitalWrite(this->rst_, 0); usleep(this->wait_time_ms_); - digitalWrite(this->rst_, 1); + + // Let the display start up sleep(3); } void Screen::draw_image(word addr_hi, word addr_lo) { if ((millis() - this->last_draw_time_) * 1000 > this->wait_time_ms_) { - screen_->media_SetSector(addr_hi, addr_lo); - screen_->media_Image(0, 0); + this->screen_->media_SetSector(addr_hi, addr_lo); + this->screen_->media_Image(0, 0); this->last_draw_time_ = millis(); } } + +void Screen::printVersion() { + this->screen_->txt_Bold(ON); + this->screen_->txt_Width(2); + this->screen_->txt_Height(2); + this->screen_->txt_FGcolour(MARCH_COLOR); + this->screen_->println(ORGANIZATION); + this->screen_->println(""); + + this->screen_->txt_Bold(OFF); + this->screen_->txt_Width(1); + this->screen_->txt_Height(1); + this->screen_->txt_FGcolour(WHITE); + this->screen_->println(PROJECT_NAME); + this->screen_->println(VERSION); + this->screen_->println(""); +} + +void Screen::mountImages() { + word initialized = this->screen_->media_Init(); + if (initialized == 0) { + this->screen_->txt_FGcolour(RED); + this->screen_->print("Pls insert SD"); + while (initialized == 0) { + sleep(1); + this->screen_->print('.'); + initialized = this->screen_->media_Init(); + } + this->screen_->println("Done"); + this->screen_->txt_FGcolour(WHITE); + } +} From 095c3bd76b07f7d95955af512bdeb0123dad5be6 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Mon, 16 Dec 2019 22:45:14 +0100 Subject: [PATCH 28/58] Update ros_lib --- lib/ros_lib/actionlib/TestAction.h | 56 ----- lib/ros_lib/actionlib/TestActionFeedback.h | 56 ----- lib/ros_lib/actionlib/TestActionGoal.h | 56 ----- lib/ros_lib/actionlib/TestActionResult.h | 56 ----- lib/ros_lib/actionlib/TestFeedback.h | 62 ----- lib/ros_lib/actionlib/TestGoal.h | 62 ----- lib/ros_lib/actionlib/TestRequestAction.h | 56 ----- .../actionlib/TestRequestActionFeedback.h | 56 ----- lib/ros_lib/actionlib/TestRequestActionGoal.h | 56 ----- .../actionlib/TestRequestActionResult.h | 56 ----- lib/ros_lib/actionlib/TestRequestFeedback.h | 38 ---- lib/ros_lib/actionlib/TestRequestGoal.h | 215 ------------------ lib/ros_lib/actionlib/TestRequestResult.h | 80 ------- lib/ros_lib/actionlib/TestResult.h | 62 ----- lib/ros_lib/actionlib/TwoIntsAction.h | 56 ----- lib/ros_lib/actionlib/TwoIntsActionFeedback.h | 56 ----- lib/ros_lib/actionlib/TwoIntsActionGoal.h | 56 ----- lib/ros_lib/actionlib/TwoIntsActionResult.h | 56 ----- lib/ros_lib/actionlib/TwoIntsFeedback.h | 38 ---- lib/ros_lib/actionlib/TwoIntsGoal.h | 102 --------- lib/ros_lib/actionlib/TwoIntsResult.h | 70 ------ lib/ros_lib/actionlib_msgs/GoalID.h | 79 ------- lib/ros_lib/actionlib_msgs/GoalStatus.h | 78 ------- lib/ros_lib/actionlib_msgs/GoalStatusArray.h | 70 ------ lib/ros_lib/march_shared_resources/Gait.h | 87 ------- .../march_shared_resources/GaitAction.h | 2 +- .../march_shared_resources/GaitActionGoal.h | 2 +- lib/ros_lib/march_shared_resources/GaitGoal.h | 2 +- .../march_shared_resources/GaitInput.h | 154 ------------- .../march_shared_resources/GaitInstruction.h | 17 +- .../GaitInstructionResponse.h | 59 +++++ .../march_shared_resources/GaitRequest.h | 122 ---------- .../march_shared_resources/GaitStatus.h | 87 ------- .../march_shared_resources/MoveToGaitAction.h | 56 ----- .../MoveToGaitActionFeedback.h | 56 ----- .../MoveToGaitActionGoal.h | 56 ----- .../MoveToGaitActionResult.h | 56 ----- .../MoveToGaitFeedback.h | 38 ---- .../march_shared_resources/MoveToGaitGoal.h | 89 -------- .../march_shared_resources/MoveToGaitResult.h | 38 ---- .../march_shared_resources/PerformGait.h | 119 ---------- .../march_shared_resources/PlayInput.h | 137 ----------- .../march_shared_resources/PlayInputMaster.h | 70 ------ lib/ros_lib/march_shared_resources/StepSize.h | 70 ------ lib/ros_lib/march_shared_resources/Subgait.h | 19 +- lib/ros_lib/roscpp/Empty.h | 70 ------ lib/ros_lib/roscpp/GetLoggers.h | 96 -------- lib/ros_lib/roscpp/Logger.h | 72 ------ lib/ros_lib/roscpp/SetLoggerLevel.h | 104 --------- lib/ros_lib/rosserial_arduino/Adc.h | 92 -------- lib/ros_lib/rosserial_arduino/Test.h | 104 --------- lib/ros_lib/rosserial_mbed/Adc.h | 92 -------- lib/ros_lib/rosserial_mbed/Test.h | 104 --------- lib/ros_lib/std_srvs/Empty.h | 70 ------ lib/ros_lib/std_srvs/SetBool.h | 123 ---------- lib/ros_lib/std_srvs/Trigger.h | 105 --------- 56 files changed, 87 insertions(+), 3909 deletions(-) delete mode 100644 lib/ros_lib/actionlib/TestAction.h delete mode 100644 lib/ros_lib/actionlib/TestActionFeedback.h delete mode 100644 lib/ros_lib/actionlib/TestActionGoal.h delete mode 100644 lib/ros_lib/actionlib/TestActionResult.h delete mode 100644 lib/ros_lib/actionlib/TestFeedback.h delete mode 100644 lib/ros_lib/actionlib/TestGoal.h delete mode 100644 lib/ros_lib/actionlib/TestRequestAction.h delete mode 100644 lib/ros_lib/actionlib/TestRequestActionFeedback.h delete mode 100644 lib/ros_lib/actionlib/TestRequestActionGoal.h delete mode 100644 lib/ros_lib/actionlib/TestRequestActionResult.h delete mode 100644 lib/ros_lib/actionlib/TestRequestFeedback.h delete mode 100644 lib/ros_lib/actionlib/TestRequestGoal.h delete mode 100644 lib/ros_lib/actionlib/TestRequestResult.h delete mode 100644 lib/ros_lib/actionlib/TestResult.h delete mode 100644 lib/ros_lib/actionlib/TwoIntsAction.h delete mode 100644 lib/ros_lib/actionlib/TwoIntsActionFeedback.h delete mode 100644 lib/ros_lib/actionlib/TwoIntsActionGoal.h delete mode 100644 lib/ros_lib/actionlib/TwoIntsActionResult.h delete mode 100644 lib/ros_lib/actionlib/TwoIntsFeedback.h delete mode 100644 lib/ros_lib/actionlib/TwoIntsGoal.h delete mode 100644 lib/ros_lib/actionlib/TwoIntsResult.h delete mode 100644 lib/ros_lib/actionlib_msgs/GoalID.h delete mode 100644 lib/ros_lib/actionlib_msgs/GoalStatus.h delete mode 100644 lib/ros_lib/actionlib_msgs/GoalStatusArray.h delete mode 100644 lib/ros_lib/march_shared_resources/Gait.h delete mode 100644 lib/ros_lib/march_shared_resources/GaitInput.h create mode 100644 lib/ros_lib/march_shared_resources/GaitInstructionResponse.h delete mode 100644 lib/ros_lib/march_shared_resources/GaitRequest.h delete mode 100644 lib/ros_lib/march_shared_resources/GaitStatus.h delete mode 100644 lib/ros_lib/march_shared_resources/MoveToGaitAction.h delete mode 100644 lib/ros_lib/march_shared_resources/MoveToGaitActionFeedback.h delete mode 100644 lib/ros_lib/march_shared_resources/MoveToGaitActionGoal.h delete mode 100644 lib/ros_lib/march_shared_resources/MoveToGaitActionResult.h delete mode 100644 lib/ros_lib/march_shared_resources/MoveToGaitFeedback.h delete mode 100644 lib/ros_lib/march_shared_resources/MoveToGaitGoal.h delete mode 100644 lib/ros_lib/march_shared_resources/MoveToGaitResult.h delete mode 100644 lib/ros_lib/march_shared_resources/PerformGait.h delete mode 100644 lib/ros_lib/march_shared_resources/PlayInput.h delete mode 100644 lib/ros_lib/march_shared_resources/PlayInputMaster.h delete mode 100644 lib/ros_lib/march_shared_resources/StepSize.h delete mode 100644 lib/ros_lib/roscpp/Empty.h delete mode 100644 lib/ros_lib/roscpp/GetLoggers.h delete mode 100644 lib/ros_lib/roscpp/Logger.h delete mode 100644 lib/ros_lib/roscpp/SetLoggerLevel.h delete mode 100644 lib/ros_lib/rosserial_arduino/Adc.h delete mode 100644 lib/ros_lib/rosserial_arduino/Test.h delete mode 100644 lib/ros_lib/rosserial_mbed/Adc.h delete mode 100644 lib/ros_lib/rosserial_mbed/Test.h delete mode 100644 lib/ros_lib/std_srvs/Empty.h delete mode 100644 lib/ros_lib/std_srvs/SetBool.h delete mode 100644 lib/ros_lib/std_srvs/Trigger.h diff --git a/lib/ros_lib/actionlib/TestAction.h b/lib/ros_lib/actionlib/TestAction.h deleted file mode 100644 index ef50b96..0000000 --- a/lib/ros_lib/actionlib/TestAction.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef _ROS_actionlib_TestAction_h -#define _ROS_actionlib_TestAction_h - -#include -#include -#include -#include "ros/msg.h" -#include "actionlib/TestActionGoal.h" -#include "actionlib/TestActionResult.h" -#include "actionlib/TestActionFeedback.h" - -namespace actionlib -{ - - class TestAction : public ros::Msg - { - public: - typedef actionlib::TestActionGoal _action_goal_type; - _action_goal_type action_goal; - typedef actionlib::TestActionResult _action_result_type; - _action_result_type action_result; - typedef actionlib::TestActionFeedback _action_feedback_type; - _action_feedback_type action_feedback; - - TestAction(): - action_goal(), - action_result(), - action_feedback() - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - offset += this->action_goal.serialize(outbuffer + offset); - offset += this->action_result.serialize(outbuffer + offset); - offset += this->action_feedback.serialize(outbuffer + offset); - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - offset += this->action_goal.deserialize(inbuffer + offset); - offset += this->action_result.deserialize(inbuffer + offset); - offset += this->action_feedback.deserialize(inbuffer + offset); - return offset; - } - - const char * getType(){ return "actionlib/TestAction"; }; - const char * getMD5(){ return "991e87a72802262dfbe5d1b3cf6efc9a"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/actionlib/TestActionFeedback.h b/lib/ros_lib/actionlib/TestActionFeedback.h deleted file mode 100644 index 3fd85bf..0000000 --- a/lib/ros_lib/actionlib/TestActionFeedback.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef _ROS_actionlib_TestActionFeedback_h -#define _ROS_actionlib_TestActionFeedback_h - -#include -#include -#include -#include "ros/msg.h" -#include "std_msgs/Header.h" -#include "actionlib_msgs/GoalStatus.h" -#include "actionlib/TestFeedback.h" - -namespace actionlib -{ - - class TestActionFeedback : public ros::Msg - { - public: - typedef std_msgs::Header _header_type; - _header_type header; - typedef actionlib_msgs::GoalStatus _status_type; - _status_type status; - typedef actionlib::TestFeedback _feedback_type; - _feedback_type feedback; - - TestActionFeedback(): - header(), - status(), - feedback() - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - offset += this->header.serialize(outbuffer + offset); - offset += this->status.serialize(outbuffer + offset); - offset += this->feedback.serialize(outbuffer + offset); - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - offset += this->header.deserialize(inbuffer + offset); - offset += this->status.deserialize(inbuffer + offset); - offset += this->feedback.deserialize(inbuffer + offset); - return offset; - } - - const char * getType(){ return "actionlib/TestActionFeedback"; }; - const char * getMD5(){ return "6d3d0bf7fb3dda24779c010a9f3eb7cb"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/actionlib/TestActionGoal.h b/lib/ros_lib/actionlib/TestActionGoal.h deleted file mode 100644 index 5c2cb95..0000000 --- a/lib/ros_lib/actionlib/TestActionGoal.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef _ROS_actionlib_TestActionGoal_h -#define _ROS_actionlib_TestActionGoal_h - -#include -#include -#include -#include "ros/msg.h" -#include "std_msgs/Header.h" -#include "actionlib_msgs/GoalID.h" -#include "actionlib/TestGoal.h" - -namespace actionlib -{ - - class TestActionGoal : public ros::Msg - { - public: - typedef std_msgs::Header _header_type; - _header_type header; - typedef actionlib_msgs::GoalID _goal_id_type; - _goal_id_type goal_id; - typedef actionlib::TestGoal _goal_type; - _goal_type goal; - - TestActionGoal(): - header(), - goal_id(), - goal() - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - offset += this->header.serialize(outbuffer + offset); - offset += this->goal_id.serialize(outbuffer + offset); - offset += this->goal.serialize(outbuffer + offset); - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - offset += this->header.deserialize(inbuffer + offset); - offset += this->goal_id.deserialize(inbuffer + offset); - offset += this->goal.deserialize(inbuffer + offset); - return offset; - } - - const char * getType(){ return "actionlib/TestActionGoal"; }; - const char * getMD5(){ return "348369c5b403676156094e8c159720bf"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/actionlib/TestActionResult.h b/lib/ros_lib/actionlib/TestActionResult.h deleted file mode 100644 index e6f92ec..0000000 --- a/lib/ros_lib/actionlib/TestActionResult.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef _ROS_actionlib_TestActionResult_h -#define _ROS_actionlib_TestActionResult_h - -#include -#include -#include -#include "ros/msg.h" -#include "std_msgs/Header.h" -#include "actionlib_msgs/GoalStatus.h" -#include "actionlib/TestResult.h" - -namespace actionlib -{ - - class TestActionResult : public ros::Msg - { - public: - typedef std_msgs::Header _header_type; - _header_type header; - typedef actionlib_msgs::GoalStatus _status_type; - _status_type status; - typedef actionlib::TestResult _result_type; - _result_type result; - - TestActionResult(): - header(), - status(), - result() - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - offset += this->header.serialize(outbuffer + offset); - offset += this->status.serialize(outbuffer + offset); - offset += this->result.serialize(outbuffer + offset); - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - offset += this->header.deserialize(inbuffer + offset); - offset += this->status.deserialize(inbuffer + offset); - offset += this->result.deserialize(inbuffer + offset); - return offset; - } - - const char * getType(){ return "actionlib/TestActionResult"; }; - const char * getMD5(){ return "3d669e3a63aa986c667ea7b0f46ce85e"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/actionlib/TestFeedback.h b/lib/ros_lib/actionlib/TestFeedback.h deleted file mode 100644 index a059f79..0000000 --- a/lib/ros_lib/actionlib/TestFeedback.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef _ROS_actionlib_TestFeedback_h -#define _ROS_actionlib_TestFeedback_h - -#include -#include -#include -#include "ros/msg.h" - -namespace actionlib -{ - - class TestFeedback : public ros::Msg - { - public: - typedef int32_t _feedback_type; - _feedback_type feedback; - - TestFeedback(): - feedback(0) - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - union { - int32_t real; - uint32_t base; - } u_feedback; - u_feedback.real = this->feedback; - *(outbuffer + offset + 0) = (u_feedback.base >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (u_feedback.base >> (8 * 1)) & 0xFF; - *(outbuffer + offset + 2) = (u_feedback.base >> (8 * 2)) & 0xFF; - *(outbuffer + offset + 3) = (u_feedback.base >> (8 * 3)) & 0xFF; - offset += sizeof(this->feedback); - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - union { - int32_t real; - uint32_t base; - } u_feedback; - u_feedback.base = 0; - u_feedback.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); - u_feedback.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); - u_feedback.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); - u_feedback.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); - this->feedback = u_feedback.real; - offset += sizeof(this->feedback); - return offset; - } - - const char * getType(){ return "actionlib/TestFeedback"; }; - const char * getMD5(){ return "49ceb5b32ea3af22073ede4a0328249e"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/actionlib/TestGoal.h b/lib/ros_lib/actionlib/TestGoal.h deleted file mode 100644 index 018b66f..0000000 --- a/lib/ros_lib/actionlib/TestGoal.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef _ROS_actionlib_TestGoal_h -#define _ROS_actionlib_TestGoal_h - -#include -#include -#include -#include "ros/msg.h" - -namespace actionlib -{ - - class TestGoal : public ros::Msg - { - public: - typedef int32_t _goal_type; - _goal_type goal; - - TestGoal(): - goal(0) - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - union { - int32_t real; - uint32_t base; - } u_goal; - u_goal.real = this->goal; - *(outbuffer + offset + 0) = (u_goal.base >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (u_goal.base >> (8 * 1)) & 0xFF; - *(outbuffer + offset + 2) = (u_goal.base >> (8 * 2)) & 0xFF; - *(outbuffer + offset + 3) = (u_goal.base >> (8 * 3)) & 0xFF; - offset += sizeof(this->goal); - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - union { - int32_t real; - uint32_t base; - } u_goal; - u_goal.base = 0; - u_goal.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); - u_goal.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); - u_goal.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); - u_goal.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); - this->goal = u_goal.real; - offset += sizeof(this->goal); - return offset; - } - - const char * getType(){ return "actionlib/TestGoal"; }; - const char * getMD5(){ return "18df0149936b7aa95588e3862476ebde"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/actionlib/TestRequestAction.h b/lib/ros_lib/actionlib/TestRequestAction.h deleted file mode 100644 index 8bf3ea2..0000000 --- a/lib/ros_lib/actionlib/TestRequestAction.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef _ROS_actionlib_TestRequestAction_h -#define _ROS_actionlib_TestRequestAction_h - -#include -#include -#include -#include "ros/msg.h" -#include "actionlib/TestRequestActionGoal.h" -#include "actionlib/TestRequestActionResult.h" -#include "actionlib/TestRequestActionFeedback.h" - -namespace actionlib -{ - - class TestRequestAction : public ros::Msg - { - public: - typedef actionlib::TestRequestActionGoal _action_goal_type; - _action_goal_type action_goal; - typedef actionlib::TestRequestActionResult _action_result_type; - _action_result_type action_result; - typedef actionlib::TestRequestActionFeedback _action_feedback_type; - _action_feedback_type action_feedback; - - TestRequestAction(): - action_goal(), - action_result(), - action_feedback() - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - offset += this->action_goal.serialize(outbuffer + offset); - offset += this->action_result.serialize(outbuffer + offset); - offset += this->action_feedback.serialize(outbuffer + offset); - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - offset += this->action_goal.deserialize(inbuffer + offset); - offset += this->action_result.deserialize(inbuffer + offset); - offset += this->action_feedback.deserialize(inbuffer + offset); - return offset; - } - - const char * getType(){ return "actionlib/TestRequestAction"; }; - const char * getMD5(){ return "dc44b1f4045dbf0d1db54423b3b86b30"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/actionlib/TestRequestActionFeedback.h b/lib/ros_lib/actionlib/TestRequestActionFeedback.h deleted file mode 100644 index 95e3dd3..0000000 --- a/lib/ros_lib/actionlib/TestRequestActionFeedback.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef _ROS_actionlib_TestRequestActionFeedback_h -#define _ROS_actionlib_TestRequestActionFeedback_h - -#include -#include -#include -#include "ros/msg.h" -#include "std_msgs/Header.h" -#include "actionlib_msgs/GoalStatus.h" -#include "actionlib/TestRequestFeedback.h" - -namespace actionlib -{ - - class TestRequestActionFeedback : public ros::Msg - { - public: - typedef std_msgs::Header _header_type; - _header_type header; - typedef actionlib_msgs::GoalStatus _status_type; - _status_type status; - typedef actionlib::TestRequestFeedback _feedback_type; - _feedback_type feedback; - - TestRequestActionFeedback(): - header(), - status(), - feedback() - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - offset += this->header.serialize(outbuffer + offset); - offset += this->status.serialize(outbuffer + offset); - offset += this->feedback.serialize(outbuffer + offset); - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - offset += this->header.deserialize(inbuffer + offset); - offset += this->status.deserialize(inbuffer + offset); - offset += this->feedback.deserialize(inbuffer + offset); - return offset; - } - - const char * getType(){ return "actionlib/TestRequestActionFeedback"; }; - const char * getMD5(){ return "aae20e09065c3809e8a8e87c4c8953fd"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/actionlib/TestRequestActionGoal.h b/lib/ros_lib/actionlib/TestRequestActionGoal.h deleted file mode 100644 index 8ccf742..0000000 --- a/lib/ros_lib/actionlib/TestRequestActionGoal.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef _ROS_actionlib_TestRequestActionGoal_h -#define _ROS_actionlib_TestRequestActionGoal_h - -#include -#include -#include -#include "ros/msg.h" -#include "std_msgs/Header.h" -#include "actionlib_msgs/GoalID.h" -#include "actionlib/TestRequestGoal.h" - -namespace actionlib -{ - - class TestRequestActionGoal : public ros::Msg - { - public: - typedef std_msgs::Header _header_type; - _header_type header; - typedef actionlib_msgs::GoalID _goal_id_type; - _goal_id_type goal_id; - typedef actionlib::TestRequestGoal _goal_type; - _goal_type goal; - - TestRequestActionGoal(): - header(), - goal_id(), - goal() - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - offset += this->header.serialize(outbuffer + offset); - offset += this->goal_id.serialize(outbuffer + offset); - offset += this->goal.serialize(outbuffer + offset); - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - offset += this->header.deserialize(inbuffer + offset); - offset += this->goal_id.deserialize(inbuffer + offset); - offset += this->goal.deserialize(inbuffer + offset); - return offset; - } - - const char * getType(){ return "actionlib/TestRequestActionGoal"; }; - const char * getMD5(){ return "1889556d3fef88f821c7cb004e4251f3"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/actionlib/TestRequestActionResult.h b/lib/ros_lib/actionlib/TestRequestActionResult.h deleted file mode 100644 index 63038f6..0000000 --- a/lib/ros_lib/actionlib/TestRequestActionResult.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef _ROS_actionlib_TestRequestActionResult_h -#define _ROS_actionlib_TestRequestActionResult_h - -#include -#include -#include -#include "ros/msg.h" -#include "std_msgs/Header.h" -#include "actionlib_msgs/GoalStatus.h" -#include "actionlib/TestRequestResult.h" - -namespace actionlib -{ - - class TestRequestActionResult : public ros::Msg - { - public: - typedef std_msgs::Header _header_type; - _header_type header; - typedef actionlib_msgs::GoalStatus _status_type; - _status_type status; - typedef actionlib::TestRequestResult _result_type; - _result_type result; - - TestRequestActionResult(): - header(), - status(), - result() - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - offset += this->header.serialize(outbuffer + offset); - offset += this->status.serialize(outbuffer + offset); - offset += this->result.serialize(outbuffer + offset); - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - offset += this->header.deserialize(inbuffer + offset); - offset += this->status.deserialize(inbuffer + offset); - offset += this->result.deserialize(inbuffer + offset); - return offset; - } - - const char * getType(){ return "actionlib/TestRequestActionResult"; }; - const char * getMD5(){ return "0476d1fdf437a3a6e7d6d0e9f5561298"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/actionlib/TestRequestFeedback.h b/lib/ros_lib/actionlib/TestRequestFeedback.h deleted file mode 100644 index 4a104be..0000000 --- a/lib/ros_lib/actionlib/TestRequestFeedback.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef _ROS_actionlib_TestRequestFeedback_h -#define _ROS_actionlib_TestRequestFeedback_h - -#include -#include -#include -#include "ros/msg.h" - -namespace actionlib -{ - - class TestRequestFeedback : public ros::Msg - { - public: - - TestRequestFeedback() - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - return offset; - } - - const char * getType(){ return "actionlib/TestRequestFeedback"; }; - const char * getMD5(){ return "d41d8cd98f00b204e9800998ecf8427e"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/actionlib/TestRequestGoal.h b/lib/ros_lib/actionlib/TestRequestGoal.h deleted file mode 100644 index ea49774..0000000 --- a/lib/ros_lib/actionlib/TestRequestGoal.h +++ /dev/null @@ -1,215 +0,0 @@ -#ifndef _ROS_actionlib_TestRequestGoal_h -#define _ROS_actionlib_TestRequestGoal_h - -#include -#include -#include -#include "ros/msg.h" -#include "ros/duration.h" - -namespace actionlib -{ - - class TestRequestGoal : public ros::Msg - { - public: - typedef int32_t _terminate_status_type; - _terminate_status_type terminate_status; - typedef bool _ignore_cancel_type; - _ignore_cancel_type ignore_cancel; - typedef const char* _result_text_type; - _result_text_type result_text; - typedef int32_t _the_result_type; - _the_result_type the_result; - typedef bool _is_simple_client_type; - _is_simple_client_type is_simple_client; - typedef ros::Duration _delay_accept_type; - _delay_accept_type delay_accept; - typedef ros::Duration _delay_terminate_type; - _delay_terminate_type delay_terminate; - typedef ros::Duration _pause_status_type; - _pause_status_type pause_status; - enum { TERMINATE_SUCCESS = 0 }; - enum { TERMINATE_ABORTED = 1 }; - enum { TERMINATE_REJECTED = 2 }; - enum { TERMINATE_LOSE = 3 }; - enum { TERMINATE_DROP = 4 }; - enum { TERMINATE_EXCEPTION = 5 }; - - TestRequestGoal(): - terminate_status(0), - ignore_cancel(0), - result_text(""), - the_result(0), - is_simple_client(0), - delay_accept(), - delay_terminate(), - pause_status() - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - union { - int32_t real; - uint32_t base; - } u_terminate_status; - u_terminate_status.real = this->terminate_status; - *(outbuffer + offset + 0) = (u_terminate_status.base >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (u_terminate_status.base >> (8 * 1)) & 0xFF; - *(outbuffer + offset + 2) = (u_terminate_status.base >> (8 * 2)) & 0xFF; - *(outbuffer + offset + 3) = (u_terminate_status.base >> (8 * 3)) & 0xFF; - offset += sizeof(this->terminate_status); - union { - bool real; - uint8_t base; - } u_ignore_cancel; - u_ignore_cancel.real = this->ignore_cancel; - *(outbuffer + offset + 0) = (u_ignore_cancel.base >> (8 * 0)) & 0xFF; - offset += sizeof(this->ignore_cancel); - uint32_t length_result_text = strlen(this->result_text); - varToArr(outbuffer + offset, length_result_text); - offset += 4; - memcpy(outbuffer + offset, this->result_text, length_result_text); - offset += length_result_text; - union { - int32_t real; - uint32_t base; - } u_the_result; - u_the_result.real = this->the_result; - *(outbuffer + offset + 0) = (u_the_result.base >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (u_the_result.base >> (8 * 1)) & 0xFF; - *(outbuffer + offset + 2) = (u_the_result.base >> (8 * 2)) & 0xFF; - *(outbuffer + offset + 3) = (u_the_result.base >> (8 * 3)) & 0xFF; - offset += sizeof(this->the_result); - union { - bool real; - uint8_t base; - } u_is_simple_client; - u_is_simple_client.real = this->is_simple_client; - *(outbuffer + offset + 0) = (u_is_simple_client.base >> (8 * 0)) & 0xFF; - offset += sizeof(this->is_simple_client); - *(outbuffer + offset + 0) = (this->delay_accept.sec >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (this->delay_accept.sec >> (8 * 1)) & 0xFF; - *(outbuffer + offset + 2) = (this->delay_accept.sec >> (8 * 2)) & 0xFF; - *(outbuffer + offset + 3) = (this->delay_accept.sec >> (8 * 3)) & 0xFF; - offset += sizeof(this->delay_accept.sec); - *(outbuffer + offset + 0) = (this->delay_accept.nsec >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (this->delay_accept.nsec >> (8 * 1)) & 0xFF; - *(outbuffer + offset + 2) = (this->delay_accept.nsec >> (8 * 2)) & 0xFF; - *(outbuffer + offset + 3) = (this->delay_accept.nsec >> (8 * 3)) & 0xFF; - offset += sizeof(this->delay_accept.nsec); - *(outbuffer + offset + 0) = (this->delay_terminate.sec >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (this->delay_terminate.sec >> (8 * 1)) & 0xFF; - *(outbuffer + offset + 2) = (this->delay_terminate.sec >> (8 * 2)) & 0xFF; - *(outbuffer + offset + 3) = (this->delay_terminate.sec >> (8 * 3)) & 0xFF; - offset += sizeof(this->delay_terminate.sec); - *(outbuffer + offset + 0) = (this->delay_terminate.nsec >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (this->delay_terminate.nsec >> (8 * 1)) & 0xFF; - *(outbuffer + offset + 2) = (this->delay_terminate.nsec >> (8 * 2)) & 0xFF; - *(outbuffer + offset + 3) = (this->delay_terminate.nsec >> (8 * 3)) & 0xFF; - offset += sizeof(this->delay_terminate.nsec); - *(outbuffer + offset + 0) = (this->pause_status.sec >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (this->pause_status.sec >> (8 * 1)) & 0xFF; - *(outbuffer + offset + 2) = (this->pause_status.sec >> (8 * 2)) & 0xFF; - *(outbuffer + offset + 3) = (this->pause_status.sec >> (8 * 3)) & 0xFF; - offset += sizeof(this->pause_status.sec); - *(outbuffer + offset + 0) = (this->pause_status.nsec >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (this->pause_status.nsec >> (8 * 1)) & 0xFF; - *(outbuffer + offset + 2) = (this->pause_status.nsec >> (8 * 2)) & 0xFF; - *(outbuffer + offset + 3) = (this->pause_status.nsec >> (8 * 3)) & 0xFF; - offset += sizeof(this->pause_status.nsec); - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - union { - int32_t real; - uint32_t base; - } u_terminate_status; - u_terminate_status.base = 0; - u_terminate_status.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); - u_terminate_status.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); - u_terminate_status.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); - u_terminate_status.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); - this->terminate_status = u_terminate_status.real; - offset += sizeof(this->terminate_status); - union { - bool real; - uint8_t base; - } u_ignore_cancel; - u_ignore_cancel.base = 0; - u_ignore_cancel.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0); - this->ignore_cancel = u_ignore_cancel.real; - offset += sizeof(this->ignore_cancel); - uint32_t length_result_text; - arrToVar(length_result_text, (inbuffer + offset)); - offset += 4; - for(unsigned int k= offset; k< offset+length_result_text; ++k){ - inbuffer[k-1]=inbuffer[k]; - } - inbuffer[offset+length_result_text-1]=0; - this->result_text = (char *)(inbuffer + offset-1); - offset += length_result_text; - union { - int32_t real; - uint32_t base; - } u_the_result; - u_the_result.base = 0; - u_the_result.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); - u_the_result.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); - u_the_result.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); - u_the_result.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); - this->the_result = u_the_result.real; - offset += sizeof(this->the_result); - union { - bool real; - uint8_t base; - } u_is_simple_client; - u_is_simple_client.base = 0; - u_is_simple_client.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0); - this->is_simple_client = u_is_simple_client.real; - offset += sizeof(this->is_simple_client); - this->delay_accept.sec = ((uint32_t) (*(inbuffer + offset))); - this->delay_accept.sec |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); - this->delay_accept.sec |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); - this->delay_accept.sec |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); - offset += sizeof(this->delay_accept.sec); - this->delay_accept.nsec = ((uint32_t) (*(inbuffer + offset))); - this->delay_accept.nsec |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); - this->delay_accept.nsec |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); - this->delay_accept.nsec |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); - offset += sizeof(this->delay_accept.nsec); - this->delay_terminate.sec = ((uint32_t) (*(inbuffer + offset))); - this->delay_terminate.sec |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); - this->delay_terminate.sec |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); - this->delay_terminate.sec |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); - offset += sizeof(this->delay_terminate.sec); - this->delay_terminate.nsec = ((uint32_t) (*(inbuffer + offset))); - this->delay_terminate.nsec |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); - this->delay_terminate.nsec |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); - this->delay_terminate.nsec |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); - offset += sizeof(this->delay_terminate.nsec); - this->pause_status.sec = ((uint32_t) (*(inbuffer + offset))); - this->pause_status.sec |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); - this->pause_status.sec |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); - this->pause_status.sec |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); - offset += sizeof(this->pause_status.sec); - this->pause_status.nsec = ((uint32_t) (*(inbuffer + offset))); - this->pause_status.nsec |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); - this->pause_status.nsec |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); - this->pause_status.nsec |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); - offset += sizeof(this->pause_status.nsec); - return offset; - } - - const char * getType(){ return "actionlib/TestRequestGoal"; }; - const char * getMD5(){ return "db5d00ba98302d6c6dd3737e9a03ceea"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/actionlib/TestRequestResult.h b/lib/ros_lib/actionlib/TestRequestResult.h deleted file mode 100644 index b2814ec..0000000 --- a/lib/ros_lib/actionlib/TestRequestResult.h +++ /dev/null @@ -1,80 +0,0 @@ -#ifndef _ROS_actionlib_TestRequestResult_h -#define _ROS_actionlib_TestRequestResult_h - -#include -#include -#include -#include "ros/msg.h" - -namespace actionlib -{ - - class TestRequestResult : public ros::Msg - { - public: - typedef int32_t _the_result_type; - _the_result_type the_result; - typedef bool _is_simple_server_type; - _is_simple_server_type is_simple_server; - - TestRequestResult(): - the_result(0), - is_simple_server(0) - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - union { - int32_t real; - uint32_t base; - } u_the_result; - u_the_result.real = this->the_result; - *(outbuffer + offset + 0) = (u_the_result.base >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (u_the_result.base >> (8 * 1)) & 0xFF; - *(outbuffer + offset + 2) = (u_the_result.base >> (8 * 2)) & 0xFF; - *(outbuffer + offset + 3) = (u_the_result.base >> (8 * 3)) & 0xFF; - offset += sizeof(this->the_result); - union { - bool real; - uint8_t base; - } u_is_simple_server; - u_is_simple_server.real = this->is_simple_server; - *(outbuffer + offset + 0) = (u_is_simple_server.base >> (8 * 0)) & 0xFF; - offset += sizeof(this->is_simple_server); - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - union { - int32_t real; - uint32_t base; - } u_the_result; - u_the_result.base = 0; - u_the_result.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); - u_the_result.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); - u_the_result.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); - u_the_result.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); - this->the_result = u_the_result.real; - offset += sizeof(this->the_result); - union { - bool real; - uint8_t base; - } u_is_simple_server; - u_is_simple_server.base = 0; - u_is_simple_server.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0); - this->is_simple_server = u_is_simple_server.real; - offset += sizeof(this->is_simple_server); - return offset; - } - - const char * getType(){ return "actionlib/TestRequestResult"; }; - const char * getMD5(){ return "61c2364524499c7c5017e2f3fce7ba06"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/actionlib/TestResult.h b/lib/ros_lib/actionlib/TestResult.h deleted file mode 100644 index 10e6bc5..0000000 --- a/lib/ros_lib/actionlib/TestResult.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef _ROS_actionlib_TestResult_h -#define _ROS_actionlib_TestResult_h - -#include -#include -#include -#include "ros/msg.h" - -namespace actionlib -{ - - class TestResult : public ros::Msg - { - public: - typedef int32_t _result_type; - _result_type result; - - TestResult(): - result(0) - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - union { - int32_t real; - uint32_t base; - } u_result; - u_result.real = this->result; - *(outbuffer + offset + 0) = (u_result.base >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (u_result.base >> (8 * 1)) & 0xFF; - *(outbuffer + offset + 2) = (u_result.base >> (8 * 2)) & 0xFF; - *(outbuffer + offset + 3) = (u_result.base >> (8 * 3)) & 0xFF; - offset += sizeof(this->result); - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - union { - int32_t real; - uint32_t base; - } u_result; - u_result.base = 0; - u_result.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); - u_result.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); - u_result.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); - u_result.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); - this->result = u_result.real; - offset += sizeof(this->result); - return offset; - } - - const char * getType(){ return "actionlib/TestResult"; }; - const char * getMD5(){ return "034a8e20d6a306665e3a5b340fab3f09"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/actionlib/TwoIntsAction.h b/lib/ros_lib/actionlib/TwoIntsAction.h deleted file mode 100644 index 573ffcd..0000000 --- a/lib/ros_lib/actionlib/TwoIntsAction.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef _ROS_actionlib_TwoIntsAction_h -#define _ROS_actionlib_TwoIntsAction_h - -#include -#include -#include -#include "ros/msg.h" -#include "actionlib/TwoIntsActionGoal.h" -#include "actionlib/TwoIntsActionResult.h" -#include "actionlib/TwoIntsActionFeedback.h" - -namespace actionlib -{ - - class TwoIntsAction : public ros::Msg - { - public: - typedef actionlib::TwoIntsActionGoal _action_goal_type; - _action_goal_type action_goal; - typedef actionlib::TwoIntsActionResult _action_result_type; - _action_result_type action_result; - typedef actionlib::TwoIntsActionFeedback _action_feedback_type; - _action_feedback_type action_feedback; - - TwoIntsAction(): - action_goal(), - action_result(), - action_feedback() - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - offset += this->action_goal.serialize(outbuffer + offset); - offset += this->action_result.serialize(outbuffer + offset); - offset += this->action_feedback.serialize(outbuffer + offset); - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - offset += this->action_goal.deserialize(inbuffer + offset); - offset += this->action_result.deserialize(inbuffer + offset); - offset += this->action_feedback.deserialize(inbuffer + offset); - return offset; - } - - const char * getType(){ return "actionlib/TwoIntsAction"; }; - const char * getMD5(){ return "6d1aa538c4bd6183a2dfb7fcac41ee50"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/actionlib/TwoIntsActionFeedback.h b/lib/ros_lib/actionlib/TwoIntsActionFeedback.h deleted file mode 100644 index cad817d..0000000 --- a/lib/ros_lib/actionlib/TwoIntsActionFeedback.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef _ROS_actionlib_TwoIntsActionFeedback_h -#define _ROS_actionlib_TwoIntsActionFeedback_h - -#include -#include -#include -#include "ros/msg.h" -#include "std_msgs/Header.h" -#include "actionlib_msgs/GoalStatus.h" -#include "actionlib/TwoIntsFeedback.h" - -namespace actionlib -{ - - class TwoIntsActionFeedback : public ros::Msg - { - public: - typedef std_msgs::Header _header_type; - _header_type header; - typedef actionlib_msgs::GoalStatus _status_type; - _status_type status; - typedef actionlib::TwoIntsFeedback _feedback_type; - _feedback_type feedback; - - TwoIntsActionFeedback(): - header(), - status(), - feedback() - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - offset += this->header.serialize(outbuffer + offset); - offset += this->status.serialize(outbuffer + offset); - offset += this->feedback.serialize(outbuffer + offset); - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - offset += this->header.deserialize(inbuffer + offset); - offset += this->status.deserialize(inbuffer + offset); - offset += this->feedback.deserialize(inbuffer + offset); - return offset; - } - - const char * getType(){ return "actionlib/TwoIntsActionFeedback"; }; - const char * getMD5(){ return "aae20e09065c3809e8a8e87c4c8953fd"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/actionlib/TwoIntsActionGoal.h b/lib/ros_lib/actionlib/TwoIntsActionGoal.h deleted file mode 100644 index 6b99941..0000000 --- a/lib/ros_lib/actionlib/TwoIntsActionGoal.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef _ROS_actionlib_TwoIntsActionGoal_h -#define _ROS_actionlib_TwoIntsActionGoal_h - -#include -#include -#include -#include "ros/msg.h" -#include "std_msgs/Header.h" -#include "actionlib_msgs/GoalID.h" -#include "actionlib/TwoIntsGoal.h" - -namespace actionlib -{ - - class TwoIntsActionGoal : public ros::Msg - { - public: - typedef std_msgs::Header _header_type; - _header_type header; - typedef actionlib_msgs::GoalID _goal_id_type; - _goal_id_type goal_id; - typedef actionlib::TwoIntsGoal _goal_type; - _goal_type goal; - - TwoIntsActionGoal(): - header(), - goal_id(), - goal() - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - offset += this->header.serialize(outbuffer + offset); - offset += this->goal_id.serialize(outbuffer + offset); - offset += this->goal.serialize(outbuffer + offset); - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - offset += this->header.deserialize(inbuffer + offset); - offset += this->goal_id.deserialize(inbuffer + offset); - offset += this->goal.deserialize(inbuffer + offset); - return offset; - } - - const char * getType(){ return "actionlib/TwoIntsActionGoal"; }; - const char * getMD5(){ return "684a2db55d6ffb8046fb9d6764ce0860"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/actionlib/TwoIntsActionResult.h b/lib/ros_lib/actionlib/TwoIntsActionResult.h deleted file mode 100644 index e3943fd..0000000 --- a/lib/ros_lib/actionlib/TwoIntsActionResult.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef _ROS_actionlib_TwoIntsActionResult_h -#define _ROS_actionlib_TwoIntsActionResult_h - -#include -#include -#include -#include "ros/msg.h" -#include "std_msgs/Header.h" -#include "actionlib_msgs/GoalStatus.h" -#include "actionlib/TwoIntsResult.h" - -namespace actionlib -{ - - class TwoIntsActionResult : public ros::Msg - { - public: - typedef std_msgs::Header _header_type; - _header_type header; - typedef actionlib_msgs::GoalStatus _status_type; - _status_type status; - typedef actionlib::TwoIntsResult _result_type; - _result_type result; - - TwoIntsActionResult(): - header(), - status(), - result() - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - offset += this->header.serialize(outbuffer + offset); - offset += this->status.serialize(outbuffer + offset); - offset += this->result.serialize(outbuffer + offset); - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - offset += this->header.deserialize(inbuffer + offset); - offset += this->status.deserialize(inbuffer + offset); - offset += this->result.deserialize(inbuffer + offset); - return offset; - } - - const char * getType(){ return "actionlib/TwoIntsActionResult"; }; - const char * getMD5(){ return "3ba7dea8b8cddcae4528ade4ef74b6e7"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/actionlib/TwoIntsFeedback.h b/lib/ros_lib/actionlib/TwoIntsFeedback.h deleted file mode 100644 index 2cd4f60..0000000 --- a/lib/ros_lib/actionlib/TwoIntsFeedback.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef _ROS_actionlib_TwoIntsFeedback_h -#define _ROS_actionlib_TwoIntsFeedback_h - -#include -#include -#include -#include "ros/msg.h" - -namespace actionlib -{ - - class TwoIntsFeedback : public ros::Msg - { - public: - - TwoIntsFeedback() - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - return offset; - } - - const char * getType(){ return "actionlib/TwoIntsFeedback"; }; - const char * getMD5(){ return "d41d8cd98f00b204e9800998ecf8427e"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/actionlib/TwoIntsGoal.h b/lib/ros_lib/actionlib/TwoIntsGoal.h deleted file mode 100644 index 2e3fb5c..0000000 --- a/lib/ros_lib/actionlib/TwoIntsGoal.h +++ /dev/null @@ -1,102 +0,0 @@ -#ifndef _ROS_actionlib_TwoIntsGoal_h -#define _ROS_actionlib_TwoIntsGoal_h - -#include -#include -#include -#include "ros/msg.h" - -namespace actionlib -{ - - class TwoIntsGoal : public ros::Msg - { - public: - typedef int64_t _a_type; - _a_type a; - typedef int64_t _b_type; - _b_type b; - - TwoIntsGoal(): - a(0), - b(0) - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - union { - int64_t real; - uint64_t base; - } u_a; - u_a.real = this->a; - *(outbuffer + offset + 0) = (u_a.base >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (u_a.base >> (8 * 1)) & 0xFF; - *(outbuffer + offset + 2) = (u_a.base >> (8 * 2)) & 0xFF; - *(outbuffer + offset + 3) = (u_a.base >> (8 * 3)) & 0xFF; - *(outbuffer + offset + 4) = (u_a.base >> (8 * 4)) & 0xFF; - *(outbuffer + offset + 5) = (u_a.base >> (8 * 5)) & 0xFF; - *(outbuffer + offset + 6) = (u_a.base >> (8 * 6)) & 0xFF; - *(outbuffer + offset + 7) = (u_a.base >> (8 * 7)) & 0xFF; - offset += sizeof(this->a); - union { - int64_t real; - uint64_t base; - } u_b; - u_b.real = this->b; - *(outbuffer + offset + 0) = (u_b.base >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (u_b.base >> (8 * 1)) & 0xFF; - *(outbuffer + offset + 2) = (u_b.base >> (8 * 2)) & 0xFF; - *(outbuffer + offset + 3) = (u_b.base >> (8 * 3)) & 0xFF; - *(outbuffer + offset + 4) = (u_b.base >> (8 * 4)) & 0xFF; - *(outbuffer + offset + 5) = (u_b.base >> (8 * 5)) & 0xFF; - *(outbuffer + offset + 6) = (u_b.base >> (8 * 6)) & 0xFF; - *(outbuffer + offset + 7) = (u_b.base >> (8 * 7)) & 0xFF; - offset += sizeof(this->b); - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - union { - int64_t real; - uint64_t base; - } u_a; - u_a.base = 0; - u_a.base |= ((uint64_t) (*(inbuffer + offset + 0))) << (8 * 0); - u_a.base |= ((uint64_t) (*(inbuffer + offset + 1))) << (8 * 1); - u_a.base |= ((uint64_t) (*(inbuffer + offset + 2))) << (8 * 2); - u_a.base |= ((uint64_t) (*(inbuffer + offset + 3))) << (8 * 3); - u_a.base |= ((uint64_t) (*(inbuffer + offset + 4))) << (8 * 4); - u_a.base |= ((uint64_t) (*(inbuffer + offset + 5))) << (8 * 5); - u_a.base |= ((uint64_t) (*(inbuffer + offset + 6))) << (8 * 6); - u_a.base |= ((uint64_t) (*(inbuffer + offset + 7))) << (8 * 7); - this->a = u_a.real; - offset += sizeof(this->a); - union { - int64_t real; - uint64_t base; - } u_b; - u_b.base = 0; - u_b.base |= ((uint64_t) (*(inbuffer + offset + 0))) << (8 * 0); - u_b.base |= ((uint64_t) (*(inbuffer + offset + 1))) << (8 * 1); - u_b.base |= ((uint64_t) (*(inbuffer + offset + 2))) << (8 * 2); - u_b.base |= ((uint64_t) (*(inbuffer + offset + 3))) << (8 * 3); - u_b.base |= ((uint64_t) (*(inbuffer + offset + 4))) << (8 * 4); - u_b.base |= ((uint64_t) (*(inbuffer + offset + 5))) << (8 * 5); - u_b.base |= ((uint64_t) (*(inbuffer + offset + 6))) << (8 * 6); - u_b.base |= ((uint64_t) (*(inbuffer + offset + 7))) << (8 * 7); - this->b = u_b.real; - offset += sizeof(this->b); - return offset; - } - - const char * getType(){ return "actionlib/TwoIntsGoal"; }; - const char * getMD5(){ return "36d09b846be0b371c5f190354dd3153e"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/actionlib/TwoIntsResult.h b/lib/ros_lib/actionlib/TwoIntsResult.h deleted file mode 100644 index afae9b0..0000000 --- a/lib/ros_lib/actionlib/TwoIntsResult.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef _ROS_actionlib_TwoIntsResult_h -#define _ROS_actionlib_TwoIntsResult_h - -#include -#include -#include -#include "ros/msg.h" - -namespace actionlib -{ - - class TwoIntsResult : public ros::Msg - { - public: - typedef int64_t _sum_type; - _sum_type sum; - - TwoIntsResult(): - sum(0) - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - union { - int64_t real; - uint64_t base; - } u_sum; - u_sum.real = this->sum; - *(outbuffer + offset + 0) = (u_sum.base >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (u_sum.base >> (8 * 1)) & 0xFF; - *(outbuffer + offset + 2) = (u_sum.base >> (8 * 2)) & 0xFF; - *(outbuffer + offset + 3) = (u_sum.base >> (8 * 3)) & 0xFF; - *(outbuffer + offset + 4) = (u_sum.base >> (8 * 4)) & 0xFF; - *(outbuffer + offset + 5) = (u_sum.base >> (8 * 5)) & 0xFF; - *(outbuffer + offset + 6) = (u_sum.base >> (8 * 6)) & 0xFF; - *(outbuffer + offset + 7) = (u_sum.base >> (8 * 7)) & 0xFF; - offset += sizeof(this->sum); - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - union { - int64_t real; - uint64_t base; - } u_sum; - u_sum.base = 0; - u_sum.base |= ((uint64_t) (*(inbuffer + offset + 0))) << (8 * 0); - u_sum.base |= ((uint64_t) (*(inbuffer + offset + 1))) << (8 * 1); - u_sum.base |= ((uint64_t) (*(inbuffer + offset + 2))) << (8 * 2); - u_sum.base |= ((uint64_t) (*(inbuffer + offset + 3))) << (8 * 3); - u_sum.base |= ((uint64_t) (*(inbuffer + offset + 4))) << (8 * 4); - u_sum.base |= ((uint64_t) (*(inbuffer + offset + 5))) << (8 * 5); - u_sum.base |= ((uint64_t) (*(inbuffer + offset + 6))) << (8 * 6); - u_sum.base |= ((uint64_t) (*(inbuffer + offset + 7))) << (8 * 7); - this->sum = u_sum.real; - offset += sizeof(this->sum); - return offset; - } - - const char * getType(){ return "actionlib/TwoIntsResult"; }; - const char * getMD5(){ return "b88405221c77b1878a3cbbfff53428d7"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/actionlib_msgs/GoalID.h b/lib/ros_lib/actionlib_msgs/GoalID.h deleted file mode 100644 index 160ca8a..0000000 --- a/lib/ros_lib/actionlib_msgs/GoalID.h +++ /dev/null @@ -1,79 +0,0 @@ -#ifndef _ROS_actionlib_msgs_GoalID_h -#define _ROS_actionlib_msgs_GoalID_h - -#include -#include -#include -#include "ros/msg.h" -#include "ros/time.h" - -namespace actionlib_msgs -{ - - class GoalID : public ros::Msg - { - public: - typedef ros::Time _stamp_type; - _stamp_type stamp; - typedef const char* _id_type; - _id_type id; - - GoalID(): - stamp(), - id("") - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - *(outbuffer + offset + 0) = (this->stamp.sec >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (this->stamp.sec >> (8 * 1)) & 0xFF; - *(outbuffer + offset + 2) = (this->stamp.sec >> (8 * 2)) & 0xFF; - *(outbuffer + offset + 3) = (this->stamp.sec >> (8 * 3)) & 0xFF; - offset += sizeof(this->stamp.sec); - *(outbuffer + offset + 0) = (this->stamp.nsec >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (this->stamp.nsec >> (8 * 1)) & 0xFF; - *(outbuffer + offset + 2) = (this->stamp.nsec >> (8 * 2)) & 0xFF; - *(outbuffer + offset + 3) = (this->stamp.nsec >> (8 * 3)) & 0xFF; - offset += sizeof(this->stamp.nsec); - uint32_t length_id = strlen(this->id); - varToArr(outbuffer + offset, length_id); - offset += 4; - memcpy(outbuffer + offset, this->id, length_id); - offset += length_id; - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - this->stamp.sec = ((uint32_t) (*(inbuffer + offset))); - this->stamp.sec |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); - this->stamp.sec |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); - this->stamp.sec |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); - offset += sizeof(this->stamp.sec); - this->stamp.nsec = ((uint32_t) (*(inbuffer + offset))); - this->stamp.nsec |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); - this->stamp.nsec |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); - this->stamp.nsec |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); - offset += sizeof(this->stamp.nsec); - uint32_t length_id; - arrToVar(length_id, (inbuffer + offset)); - offset += 4; - for(unsigned int k= offset; k< offset+length_id; ++k){ - inbuffer[k-1]=inbuffer[k]; - } - inbuffer[offset+length_id-1]=0; - this->id = (char *)(inbuffer + offset-1); - offset += length_id; - return offset; - } - - const char * getType(){ return "actionlib_msgs/GoalID"; }; - const char * getMD5(){ return "302881f31927c1df708a2dbab0e80ee8"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/actionlib_msgs/GoalStatus.h b/lib/ros_lib/actionlib_msgs/GoalStatus.h deleted file mode 100644 index 52e58af..0000000 --- a/lib/ros_lib/actionlib_msgs/GoalStatus.h +++ /dev/null @@ -1,78 +0,0 @@ -#ifndef _ROS_actionlib_msgs_GoalStatus_h -#define _ROS_actionlib_msgs_GoalStatus_h - -#include -#include -#include -#include "ros/msg.h" -#include "actionlib_msgs/GoalID.h" - -namespace actionlib_msgs -{ - - class GoalStatus : public ros::Msg - { - public: - typedef actionlib_msgs::GoalID _goal_id_type; - _goal_id_type goal_id; - typedef uint8_t _status_type; - _status_type status; - typedef const char* _text_type; - _text_type text; - enum { PENDING = 0 }; - enum { ACTIVE = 1 }; - enum { PREEMPTED = 2 }; - enum { SUCCEEDED = 3 }; - enum { ABORTED = 4 }; - enum { REJECTED = 5 }; - enum { PREEMPTING = 6 }; - enum { RECALLING = 7 }; - enum { RECALLED = 8 }; - enum { LOST = 9 }; - - GoalStatus(): - goal_id(), - status(0), - text("") - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - offset += this->goal_id.serialize(outbuffer + offset); - *(outbuffer + offset + 0) = (this->status >> (8 * 0)) & 0xFF; - offset += sizeof(this->status); - uint32_t length_text = strlen(this->text); - varToArr(outbuffer + offset, length_text); - offset += 4; - memcpy(outbuffer + offset, this->text, length_text); - offset += length_text; - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - offset += this->goal_id.deserialize(inbuffer + offset); - this->status = ((uint8_t) (*(inbuffer + offset))); - offset += sizeof(this->status); - uint32_t length_text; - arrToVar(length_text, (inbuffer + offset)); - offset += 4; - for(unsigned int k= offset; k< offset+length_text; ++k){ - inbuffer[k-1]=inbuffer[k]; - } - inbuffer[offset+length_text-1]=0; - this->text = (char *)(inbuffer + offset-1); - offset += length_text; - return offset; - } - - const char * getType(){ return "actionlib_msgs/GoalStatus"; }; - const char * getMD5(){ return "d388f9b87b3c471f784434d671988d4a"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/actionlib_msgs/GoalStatusArray.h b/lib/ros_lib/actionlib_msgs/GoalStatusArray.h deleted file mode 100644 index e658c50..0000000 --- a/lib/ros_lib/actionlib_msgs/GoalStatusArray.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef _ROS_actionlib_msgs_GoalStatusArray_h -#define _ROS_actionlib_msgs_GoalStatusArray_h - -#include -#include -#include -#include "ros/msg.h" -#include "std_msgs/Header.h" -#include "actionlib_msgs/GoalStatus.h" - -namespace actionlib_msgs -{ - - class GoalStatusArray : public ros::Msg - { - public: - typedef std_msgs::Header _header_type; - _header_type header; - uint32_t status_list_length; - typedef actionlib_msgs::GoalStatus _status_list_type; - _status_list_type st_status_list; - _status_list_type * status_list; - - GoalStatusArray(): - header(), - status_list_length(0), status_list(NULL) - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - offset += this->header.serialize(outbuffer + offset); - *(outbuffer + offset + 0) = (this->status_list_length >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (this->status_list_length >> (8 * 1)) & 0xFF; - *(outbuffer + offset + 2) = (this->status_list_length >> (8 * 2)) & 0xFF; - *(outbuffer + offset + 3) = (this->status_list_length >> (8 * 3)) & 0xFF; - offset += sizeof(this->status_list_length); - for( uint32_t i = 0; i < status_list_length; i++){ - offset += this->status_list[i].serialize(outbuffer + offset); - } - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - offset += this->header.deserialize(inbuffer + offset); - uint32_t status_list_lengthT = ((uint32_t) (*(inbuffer + offset))); - status_list_lengthT |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); - status_list_lengthT |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); - status_list_lengthT |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); - offset += sizeof(this->status_list_length); - if(status_list_lengthT > status_list_length) - this->status_list = (actionlib_msgs::GoalStatus*)realloc(this->status_list, status_list_lengthT * sizeof(actionlib_msgs::GoalStatus)); - status_list_length = status_list_lengthT; - for( uint32_t i = 0; i < status_list_length; i++){ - offset += this->st_status_list.deserialize(inbuffer + offset); - memcpy( &(this->status_list[i]), &(this->st_status_list), sizeof(actionlib_msgs::GoalStatus)); - } - return offset; - } - - const char * getType(){ return "actionlib_msgs/GoalStatusArray"; }; - const char * getMD5(){ return "8b2b82f13216d0a8ea88bd3af735e619"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/march_shared_resources/Gait.h b/lib/ros_lib/march_shared_resources/Gait.h deleted file mode 100644 index 151d146..0000000 --- a/lib/ros_lib/march_shared_resources/Gait.h +++ /dev/null @@ -1,87 +0,0 @@ -#ifndef _ROS_march_shared_resources_Gait_h -#define _ROS_march_shared_resources_Gait_h - -#include -#include -#include -#include "ros/msg.h" - -namespace march_shared_resources -{ - - class Gait : public ros::Msg - { - public: - typedef const char* _gait_name_type; - _gait_name_type gait_name; - typedef double _step_size_type; - _step_size_type step_size; - - Gait(): - gait_name(""), - step_size(0) - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - uint32_t length_gait_name = strlen(this->gait_name); - varToArr(outbuffer + offset, length_gait_name); - offset += 4; - memcpy(outbuffer + offset, this->gait_name, length_gait_name); - offset += length_gait_name; - union { - double real; - uint64_t base; - } u_step_size; - u_step_size.real = this->step_size; - *(outbuffer + offset + 0) = (u_step_size.base >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (u_step_size.base >> (8 * 1)) & 0xFF; - *(outbuffer + offset + 2) = (u_step_size.base >> (8 * 2)) & 0xFF; - *(outbuffer + offset + 3) = (u_step_size.base >> (8 * 3)) & 0xFF; - *(outbuffer + offset + 4) = (u_step_size.base >> (8 * 4)) & 0xFF; - *(outbuffer + offset + 5) = (u_step_size.base >> (8 * 5)) & 0xFF; - *(outbuffer + offset + 6) = (u_step_size.base >> (8 * 6)) & 0xFF; - *(outbuffer + offset + 7) = (u_step_size.base >> (8 * 7)) & 0xFF; - offset += sizeof(this->step_size); - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - uint32_t length_gait_name; - arrToVar(length_gait_name, (inbuffer + offset)); - offset += 4; - for(unsigned int k= offset; k< offset+length_gait_name; ++k){ - inbuffer[k-1]=inbuffer[k]; - } - inbuffer[offset+length_gait_name-1]=0; - this->gait_name = (char *)(inbuffer + offset-1); - offset += length_gait_name; - union { - double real; - uint64_t base; - } u_step_size; - u_step_size.base = 0; - u_step_size.base |= ((uint64_t) (*(inbuffer + offset + 0))) << (8 * 0); - u_step_size.base |= ((uint64_t) (*(inbuffer + offset + 1))) << (8 * 1); - u_step_size.base |= ((uint64_t) (*(inbuffer + offset + 2))) << (8 * 2); - u_step_size.base |= ((uint64_t) (*(inbuffer + offset + 3))) << (8 * 3); - u_step_size.base |= ((uint64_t) (*(inbuffer + offset + 4))) << (8 * 4); - u_step_size.base |= ((uint64_t) (*(inbuffer + offset + 5))) << (8 * 5); - u_step_size.base |= ((uint64_t) (*(inbuffer + offset + 6))) << (8 * 6); - u_step_size.base |= ((uint64_t) (*(inbuffer + offset + 7))) << (8 * 7); - this->step_size = u_step_size.real; - offset += sizeof(this->step_size); - return offset; - } - - const char * getType(){ return "march_shared_resources/Gait"; }; - const char * getMD5(){ return "ff98d402c494c993ddd86edf09731c1a"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/march_shared_resources/GaitAction.h b/lib/ros_lib/march_shared_resources/GaitAction.h index 64d32e8..ff65b78 100644 --- a/lib/ros_lib/march_shared_resources/GaitAction.h +++ b/lib/ros_lib/march_shared_resources/GaitAction.h @@ -48,7 +48,7 @@ namespace march_shared_resources } const char * getType(){ return "march_shared_resources/GaitAction"; }; - const char * getMD5(){ return "c85799c93718e9625224b00f52bb84cf"; }; + const char * getMD5(){ return "cefddf7f6db8e5953001d960f0a2e7ac"; }; }; diff --git a/lib/ros_lib/march_shared_resources/GaitActionGoal.h b/lib/ros_lib/march_shared_resources/GaitActionGoal.h index 776481a..90a7cc9 100644 --- a/lib/ros_lib/march_shared_resources/GaitActionGoal.h +++ b/lib/ros_lib/march_shared_resources/GaitActionGoal.h @@ -48,7 +48,7 @@ namespace march_shared_resources } const char * getType(){ return "march_shared_resources/GaitActionGoal"; }; - const char * getMD5(){ return "8e4739ca52f8b8c0d762799c41212a05"; }; + const char * getMD5(){ return "8b330ab474fa41e3badfee238768ff05"; }; }; diff --git a/lib/ros_lib/march_shared_resources/GaitGoal.h b/lib/ros_lib/march_shared_resources/GaitGoal.h index 98ecdbe..96dc887 100644 --- a/lib/ros_lib/march_shared_resources/GaitGoal.h +++ b/lib/ros_lib/march_shared_resources/GaitGoal.h @@ -59,7 +59,7 @@ namespace march_shared_resources } const char * getType(){ return "march_shared_resources/GaitGoal"; }; - const char * getMD5(){ return "1bbe0ea9e2df05297b8428716718f7d2"; }; + const char * getMD5(){ return "de1744cba95645d4a7c6f1406b2d6f43"; }; }; diff --git a/lib/ros_lib/march_shared_resources/GaitInput.h b/lib/ros_lib/march_shared_resources/GaitInput.h deleted file mode 100644 index 8f5506c..0000000 --- a/lib/ros_lib/march_shared_resources/GaitInput.h +++ /dev/null @@ -1,154 +0,0 @@ -#ifndef _ROS_SERVICE_GaitInput_h -#define _ROS_SERVICE_GaitInput_h -#include -#include -#include -#include "ros/msg.h" - -namespace march_shared_resources -{ - -static const char GAITINPUT[] = "march_shared_resources/GaitInput"; - - class GaitInputRequest : public ros::Msg - { - public: - typedef const char* _gait_name_type; - _gait_name_type gait_name; - typedef double _time_type; - _time_type time; - - GaitInputRequest(): - gait_name(""), - time(0) - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - uint32_t length_gait_name = strlen(this->gait_name); - varToArr(outbuffer + offset, length_gait_name); - offset += 4; - memcpy(outbuffer + offset, this->gait_name, length_gait_name); - offset += length_gait_name; - union { - double real; - uint64_t base; - } u_time; - u_time.real = this->time; - *(outbuffer + offset + 0) = (u_time.base >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (u_time.base >> (8 * 1)) & 0xFF; - *(outbuffer + offset + 2) = (u_time.base >> (8 * 2)) & 0xFF; - *(outbuffer + offset + 3) = (u_time.base >> (8 * 3)) & 0xFF; - *(outbuffer + offset + 4) = (u_time.base >> (8 * 4)) & 0xFF; - *(outbuffer + offset + 5) = (u_time.base >> (8 * 5)) & 0xFF; - *(outbuffer + offset + 6) = (u_time.base >> (8 * 6)) & 0xFF; - *(outbuffer + offset + 7) = (u_time.base >> (8 * 7)) & 0xFF; - offset += sizeof(this->time); - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - uint32_t length_gait_name; - arrToVar(length_gait_name, (inbuffer + offset)); - offset += 4; - for(unsigned int k= offset; k< offset+length_gait_name; ++k){ - inbuffer[k-1]=inbuffer[k]; - } - inbuffer[offset+length_gait_name-1]=0; - this->gait_name = (char *)(inbuffer + offset-1); - offset += length_gait_name; - union { - double real; - uint64_t base; - } u_time; - u_time.base = 0; - u_time.base |= ((uint64_t) (*(inbuffer + offset + 0))) << (8 * 0); - u_time.base |= ((uint64_t) (*(inbuffer + offset + 1))) << (8 * 1); - u_time.base |= ((uint64_t) (*(inbuffer + offset + 2))) << (8 * 2); - u_time.base |= ((uint64_t) (*(inbuffer + offset + 3))) << (8 * 3); - u_time.base |= ((uint64_t) (*(inbuffer + offset + 4))) << (8 * 4); - u_time.base |= ((uint64_t) (*(inbuffer + offset + 5))) << (8 * 5); - u_time.base |= ((uint64_t) (*(inbuffer + offset + 6))) << (8 * 6); - u_time.base |= ((uint64_t) (*(inbuffer + offset + 7))) << (8 * 7); - this->time = u_time.real; - offset += sizeof(this->time); - return offset; - } - - const char * getType(){ return GAITINPUT; }; - const char * getMD5(){ return "2d623642030e07b94e6482959561c22f"; }; - - }; - - class GaitInputResponse : public ros::Msg - { - public: - typedef bool _is_successful_type; - _is_successful_type is_successful; - typedef const char* _message_type; - _message_type message; - - GaitInputResponse(): - is_successful(0), - message("") - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - union { - bool real; - uint8_t base; - } u_is_successful; - u_is_successful.real = this->is_successful; - *(outbuffer + offset + 0) = (u_is_successful.base >> (8 * 0)) & 0xFF; - offset += sizeof(this->is_successful); - uint32_t length_message = strlen(this->message); - varToArr(outbuffer + offset, length_message); - offset += 4; - memcpy(outbuffer + offset, this->message, length_message); - offset += length_message; - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - union { - bool real; - uint8_t base; - } u_is_successful; - u_is_successful.base = 0; - u_is_successful.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0); - this->is_successful = u_is_successful.real; - offset += sizeof(this->is_successful); - uint32_t length_message; - arrToVar(length_message, (inbuffer + offset)); - offset += 4; - for(unsigned int k= offset; k< offset+length_message; ++k){ - inbuffer[k-1]=inbuffer[k]; - } - inbuffer[offset+length_message-1]=0; - this->message = (char *)(inbuffer + offset-1); - offset += length_message; - return offset; - } - - const char * getType(){ return GAITINPUT; }; - const char * getMD5(){ return "92814ca95de64c716f615f50abf3a8c8"; }; - - }; - - class GaitInput { - public: - typedef GaitInputRequest Request; - typedef GaitInputResponse Response; - }; - -} -#endif diff --git a/lib/ros_lib/march_shared_resources/GaitInstruction.h b/lib/ros_lib/march_shared_resources/GaitInstruction.h index b1e24c6..f759a17 100644 --- a/lib/ros_lib/march_shared_resources/GaitInstruction.h +++ b/lib/ros_lib/march_shared_resources/GaitInstruction.h @@ -15,11 +15,10 @@ namespace march_shared_resources public: typedef std_msgs::Header _header_type; _header_type header; - typedef int16_t _type_type; + typedef int8_t _type_type; _type_type type; typedef const char* _gait_name_type; _gait_name_type gait_name; - enum { INPUT_DEVICE_LOST = -1 }; enum { STOP = 0 }; enum { GAIT = 1 }; enum { PAUSE = 2 }; @@ -37,12 +36,11 @@ namespace march_shared_resources int offset = 0; offset += this->header.serialize(outbuffer + offset); union { - int16_t real; - uint16_t base; + int8_t real; + uint8_t base; } u_type; u_type.real = this->type; *(outbuffer + offset + 0) = (u_type.base >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (u_type.base >> (8 * 1)) & 0xFF; offset += sizeof(this->type); uint32_t length_gait_name = strlen(this->gait_name); varToArr(outbuffer + offset, length_gait_name); @@ -57,12 +55,11 @@ namespace march_shared_resources int offset = 0; offset += this->header.deserialize(inbuffer + offset); union { - int16_t real; - uint16_t base; + int8_t real; + uint8_t base; } u_type; u_type.base = 0; - u_type.base |= ((uint16_t) (*(inbuffer + offset + 0))) << (8 * 0); - u_type.base |= ((uint16_t) (*(inbuffer + offset + 1))) << (8 * 1); + u_type.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0); this->type = u_type.real; offset += sizeof(this->type); uint32_t length_gait_name; @@ -78,7 +75,7 @@ namespace march_shared_resources } const char * getType(){ return "march_shared_resources/GaitInstruction"; }; - const char * getMD5(){ return "33baee28fc7d9ee7dee1e42d340e1783"; }; + const char * getMD5(){ return "33391f0a380b417c7e824a1f2d772540"; }; }; diff --git a/lib/ros_lib/march_shared_resources/GaitInstructionResponse.h b/lib/ros_lib/march_shared_resources/GaitInstructionResponse.h new file mode 100644 index 0000000..e88be6b --- /dev/null +++ b/lib/ros_lib/march_shared_resources/GaitInstructionResponse.h @@ -0,0 +1,59 @@ +#ifndef _ROS_march_shared_resources_GaitInstructionResponse_h +#define _ROS_march_shared_resources_GaitInstructionResponse_h + +#include +#include +#include +#include "ros/msg.h" + +namespace march_shared_resources +{ + + class GaitInstructionResponse : public ros::Msg + { + public: + typedef int8_t _result_type; + _result_type result; + enum { GAIT_REJECTED = -1 }; + enum { GAIT_ACCEPTED = 0 }; + enum { GAIT_FINISHED = 1 }; + + GaitInstructionResponse(): + result(0) + { + } + + virtual int serialize(unsigned char *outbuffer) const + { + int offset = 0; + union { + int8_t real; + uint8_t base; + } u_result; + u_result.real = this->result; + *(outbuffer + offset + 0) = (u_result.base >> (8 * 0)) & 0xFF; + offset += sizeof(this->result); + return offset; + } + + virtual int deserialize(unsigned char *inbuffer) + { + int offset = 0; + union { + int8_t real; + uint8_t base; + } u_result; + u_result.base = 0; + u_result.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0); + this->result = u_result.real; + offset += sizeof(this->result); + return offset; + } + + const char * getType(){ return "march_shared_resources/GaitInstructionResponse"; }; + const char * getMD5(){ return "0a9a7173d5945f6df13f205af2597eb4"; }; + + }; + +} +#endif diff --git a/lib/ros_lib/march_shared_resources/GaitRequest.h b/lib/ros_lib/march_shared_resources/GaitRequest.h deleted file mode 100644 index e79c007..0000000 --- a/lib/ros_lib/march_shared_resources/GaitRequest.h +++ /dev/null @@ -1,122 +0,0 @@ -#ifndef _ROS_SERVICE_GaitRequest_h -#define _ROS_SERVICE_GaitRequest_h -#include -#include -#include -#include "ros/msg.h" - -namespace march_shared_resources -{ - -static const char GAITREQUEST[] = "march_shared_resources/GaitRequest"; - - class GaitRequestRequest : public ros::Msg - { - public: - typedef const char* _gait_file_type; - _gait_file_type gait_file; - - GaitRequestRequest(): - gait_file("") - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - uint32_t length_gait_file = strlen(this->gait_file); - varToArr(outbuffer + offset, length_gait_file); - offset += 4; - memcpy(outbuffer + offset, this->gait_file, length_gait_file); - offset += length_gait_file; - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - uint32_t length_gait_file; - arrToVar(length_gait_file, (inbuffer + offset)); - offset += 4; - for(unsigned int k= offset; k< offset+length_gait_file; ++k){ - inbuffer[k-1]=inbuffer[k]; - } - inbuffer[offset+length_gait_file-1]=0; - this->gait_file = (char *)(inbuffer + offset-1); - offset += length_gait_file; - return offset; - } - - const char * getType(){ return GAITREQUEST; }; - const char * getMD5(){ return "f891f6238cf59a5f9f2daa63e7a355a4"; }; - - }; - - class GaitRequestResponse : public ros::Msg - { - public: - typedef bool _success_type; - _success_type success; - typedef const char* _message_type; - _message_type message; - - GaitRequestResponse(): - success(0), - message("") - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - union { - bool real; - uint8_t base; - } u_success; - u_success.real = this->success; - *(outbuffer + offset + 0) = (u_success.base >> (8 * 0)) & 0xFF; - offset += sizeof(this->success); - uint32_t length_message = strlen(this->message); - varToArr(outbuffer + offset, length_message); - offset += 4; - memcpy(outbuffer + offset, this->message, length_message); - offset += length_message; - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - union { - bool real; - uint8_t base; - } u_success; - u_success.base = 0; - u_success.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0); - this->success = u_success.real; - offset += sizeof(this->success); - uint32_t length_message; - arrToVar(length_message, (inbuffer + offset)); - offset += 4; - for(unsigned int k= offset; k< offset+length_message; ++k){ - inbuffer[k-1]=inbuffer[k]; - } - inbuffer[offset+length_message-1]=0; - this->message = (char *)(inbuffer + offset-1); - offset += length_message; - return offset; - } - - const char * getType(){ return GAITREQUEST; }; - const char * getMD5(){ return "937c9679a518e3a18d831e57125ea522"; }; - - }; - - class GaitRequest { - public: - typedef GaitRequestRequest Request; - typedef GaitRequestResponse Response; - }; - -} -#endif diff --git a/lib/ros_lib/march_shared_resources/GaitStatus.h b/lib/ros_lib/march_shared_resources/GaitStatus.h deleted file mode 100644 index ace7597..0000000 --- a/lib/ros_lib/march_shared_resources/GaitStatus.h +++ /dev/null @@ -1,87 +0,0 @@ -#ifndef _ROS_march_shared_resources_GaitStatus_h -#define _ROS_march_shared_resources_GaitStatus_h - -#include -#include -#include -#include "ros/msg.h" - -namespace march_shared_resources -{ - - class GaitStatus : public ros::Msg - { - public: - typedef int64_t _type_type; - _type_type type; - typedef const char* _gait_name_type; - _gait_name_type gait_name; - - GaitStatus(): - type(0), - gait_name("") - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - union { - int64_t real; - uint64_t base; - } u_type; - u_type.real = this->type; - *(outbuffer + offset + 0) = (u_type.base >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (u_type.base >> (8 * 1)) & 0xFF; - *(outbuffer + offset + 2) = (u_type.base >> (8 * 2)) & 0xFF; - *(outbuffer + offset + 3) = (u_type.base >> (8 * 3)) & 0xFF; - *(outbuffer + offset + 4) = (u_type.base >> (8 * 4)) & 0xFF; - *(outbuffer + offset + 5) = (u_type.base >> (8 * 5)) & 0xFF; - *(outbuffer + offset + 6) = (u_type.base >> (8 * 6)) & 0xFF; - *(outbuffer + offset + 7) = (u_type.base >> (8 * 7)) & 0xFF; - offset += sizeof(this->type); - uint32_t length_gait_name = strlen(this->gait_name); - varToArr(outbuffer + offset, length_gait_name); - offset += 4; - memcpy(outbuffer + offset, this->gait_name, length_gait_name); - offset += length_gait_name; - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - union { - int64_t real; - uint64_t base; - } u_type; - u_type.base = 0; - u_type.base |= ((uint64_t) (*(inbuffer + offset + 0))) << (8 * 0); - u_type.base |= ((uint64_t) (*(inbuffer + offset + 1))) << (8 * 1); - u_type.base |= ((uint64_t) (*(inbuffer + offset + 2))) << (8 * 2); - u_type.base |= ((uint64_t) (*(inbuffer + offset + 3))) << (8 * 3); - u_type.base |= ((uint64_t) (*(inbuffer + offset + 4))) << (8 * 4); - u_type.base |= ((uint64_t) (*(inbuffer + offset + 5))) << (8 * 5); - u_type.base |= ((uint64_t) (*(inbuffer + offset + 6))) << (8 * 6); - u_type.base |= ((uint64_t) (*(inbuffer + offset + 7))) << (8 * 7); - this->type = u_type.real; - offset += sizeof(this->type); - uint32_t length_gait_name; - arrToVar(length_gait_name, (inbuffer + offset)); - offset += 4; - for(unsigned int k= offset; k< offset+length_gait_name; ++k){ - inbuffer[k-1]=inbuffer[k]; - } - inbuffer[offset+length_gait_name-1]=0; - this->gait_name = (char *)(inbuffer + offset-1); - offset += length_gait_name; - return offset; - } - - const char * getType(){ return "march_shared_resources/GaitStatus"; }; - const char * getMD5(){ return "ac2e94188f865942da982b5b64401ab2"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/march_shared_resources/MoveToGaitAction.h b/lib/ros_lib/march_shared_resources/MoveToGaitAction.h deleted file mode 100644 index 9c6f69a..0000000 --- a/lib/ros_lib/march_shared_resources/MoveToGaitAction.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef _ROS_march_shared_resources_MoveToGaitAction_h -#define _ROS_march_shared_resources_MoveToGaitAction_h - -#include -#include -#include -#include "ros/msg.h" -#include "march_shared_resources/MoveToGaitActionGoal.h" -#include "march_shared_resources/MoveToGaitActionResult.h" -#include "march_shared_resources/MoveToGaitActionFeedback.h" - -namespace march_shared_resources -{ - - class MoveToGaitAction : public ros::Msg - { - public: - typedef march_shared_resources::MoveToGaitActionGoal _action_goal_type; - _action_goal_type action_goal; - typedef march_shared_resources::MoveToGaitActionResult _action_result_type; - _action_result_type action_result; - typedef march_shared_resources::MoveToGaitActionFeedback _action_feedback_type; - _action_feedback_type action_feedback; - - MoveToGaitAction(): - action_goal(), - action_result(), - action_feedback() - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - offset += this->action_goal.serialize(outbuffer + offset); - offset += this->action_result.serialize(outbuffer + offset); - offset += this->action_feedback.serialize(outbuffer + offset); - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - offset += this->action_goal.deserialize(inbuffer + offset); - offset += this->action_result.deserialize(inbuffer + offset); - offset += this->action_feedback.deserialize(inbuffer + offset); - return offset; - } - - const char * getType(){ return "march_shared_resources/MoveToGaitAction"; }; - const char * getMD5(){ return "7f6f08d79e3be16de203dd0c4d237a26"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/march_shared_resources/MoveToGaitActionFeedback.h b/lib/ros_lib/march_shared_resources/MoveToGaitActionFeedback.h deleted file mode 100644 index eb45b31..0000000 --- a/lib/ros_lib/march_shared_resources/MoveToGaitActionFeedback.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef _ROS_march_shared_resources_MoveToGaitActionFeedback_h -#define _ROS_march_shared_resources_MoveToGaitActionFeedback_h - -#include -#include -#include -#include "ros/msg.h" -#include "std_msgs/Header.h" -#include "actionlib_msgs/GoalStatus.h" -#include "march_shared_resources/MoveToGaitFeedback.h" - -namespace march_shared_resources -{ - - class MoveToGaitActionFeedback : public ros::Msg - { - public: - typedef std_msgs::Header _header_type; - _header_type header; - typedef actionlib_msgs::GoalStatus _status_type; - _status_type status; - typedef march_shared_resources::MoveToGaitFeedback _feedback_type; - _feedback_type feedback; - - MoveToGaitActionFeedback(): - header(), - status(), - feedback() - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - offset += this->header.serialize(outbuffer + offset); - offset += this->status.serialize(outbuffer + offset); - offset += this->feedback.serialize(outbuffer + offset); - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - offset += this->header.deserialize(inbuffer + offset); - offset += this->status.deserialize(inbuffer + offset); - offset += this->feedback.deserialize(inbuffer + offset); - return offset; - } - - const char * getType(){ return "march_shared_resources/MoveToGaitActionFeedback"; }; - const char * getMD5(){ return "aae20e09065c3809e8a8e87c4c8953fd"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/march_shared_resources/MoveToGaitActionGoal.h b/lib/ros_lib/march_shared_resources/MoveToGaitActionGoal.h deleted file mode 100644 index 0ee544f..0000000 --- a/lib/ros_lib/march_shared_resources/MoveToGaitActionGoal.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef _ROS_march_shared_resources_MoveToGaitActionGoal_h -#define _ROS_march_shared_resources_MoveToGaitActionGoal_h - -#include -#include -#include -#include "ros/msg.h" -#include "std_msgs/Header.h" -#include "actionlib_msgs/GoalID.h" -#include "march_shared_resources/MoveToGaitGoal.h" - -namespace march_shared_resources -{ - - class MoveToGaitActionGoal : public ros::Msg - { - public: - typedef std_msgs::Header _header_type; - _header_type header; - typedef actionlib_msgs::GoalID _goal_id_type; - _goal_id_type goal_id; - typedef march_shared_resources::MoveToGaitGoal _goal_type; - _goal_type goal; - - MoveToGaitActionGoal(): - header(), - goal_id(), - goal() - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - offset += this->header.serialize(outbuffer + offset); - offset += this->goal_id.serialize(outbuffer + offset); - offset += this->goal.serialize(outbuffer + offset); - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - offset += this->header.deserialize(inbuffer + offset); - offset += this->goal_id.deserialize(inbuffer + offset); - offset += this->goal.deserialize(inbuffer + offset); - return offset; - } - - const char * getType(){ return "march_shared_resources/MoveToGaitActionGoal"; }; - const char * getMD5(){ return "035864cd1ebe4d6ec52034ce69b023da"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/march_shared_resources/MoveToGaitActionResult.h b/lib/ros_lib/march_shared_resources/MoveToGaitActionResult.h deleted file mode 100644 index 895df1f..0000000 --- a/lib/ros_lib/march_shared_resources/MoveToGaitActionResult.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef _ROS_march_shared_resources_MoveToGaitActionResult_h -#define _ROS_march_shared_resources_MoveToGaitActionResult_h - -#include -#include -#include -#include "ros/msg.h" -#include "std_msgs/Header.h" -#include "actionlib_msgs/GoalStatus.h" -#include "march_shared_resources/MoveToGaitResult.h" - -namespace march_shared_resources -{ - - class MoveToGaitActionResult : public ros::Msg - { - public: - typedef std_msgs::Header _header_type; - _header_type header; - typedef actionlib_msgs::GoalStatus _status_type; - _status_type status; - typedef march_shared_resources::MoveToGaitResult _result_type; - _result_type result; - - MoveToGaitActionResult(): - header(), - status(), - result() - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - offset += this->header.serialize(outbuffer + offset); - offset += this->status.serialize(outbuffer + offset); - offset += this->result.serialize(outbuffer + offset); - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - offset += this->header.deserialize(inbuffer + offset); - offset += this->status.deserialize(inbuffer + offset); - offset += this->result.deserialize(inbuffer + offset); - return offset; - } - - const char * getType(){ return "march_shared_resources/MoveToGaitActionResult"; }; - const char * getMD5(){ return "1eb06eeff08fa7ea874431638cb52332"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/march_shared_resources/MoveToGaitFeedback.h b/lib/ros_lib/march_shared_resources/MoveToGaitFeedback.h deleted file mode 100644 index 2d9312e..0000000 --- a/lib/ros_lib/march_shared_resources/MoveToGaitFeedback.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef _ROS_march_shared_resources_MoveToGaitFeedback_h -#define _ROS_march_shared_resources_MoveToGaitFeedback_h - -#include -#include -#include -#include "ros/msg.h" - -namespace march_shared_resources -{ - - class MoveToGaitFeedback : public ros::Msg - { - public: - - MoveToGaitFeedback() - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - return offset; - } - - const char * getType(){ return "march_shared_resources/MoveToGaitFeedback"; }; - const char * getMD5(){ return "d41d8cd98f00b204e9800998ecf8427e"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/march_shared_resources/MoveToGaitGoal.h b/lib/ros_lib/march_shared_resources/MoveToGaitGoal.h deleted file mode 100644 index d2b2a1c..0000000 --- a/lib/ros_lib/march_shared_resources/MoveToGaitGoal.h +++ /dev/null @@ -1,89 +0,0 @@ -#ifndef _ROS_march_shared_resources_MoveToGaitGoal_h -#define _ROS_march_shared_resources_MoveToGaitGoal_h - -#include -#include -#include -#include "ros/msg.h" - -namespace march_shared_resources -{ - - class MoveToGaitGoal : public ros::Msg - { - public: - typedef const char* _name_type; - _name_type name; - typedef const char* _subgait_name_type; - _subgait_name_type subgait_name; - typedef const char* _gait_name_type; - _gait_name_type gait_name; - - MoveToGaitGoal(): - name(""), - subgait_name(""), - gait_name("") - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - uint32_t length_name = strlen(this->name); - varToArr(outbuffer + offset, length_name); - offset += 4; - memcpy(outbuffer + offset, this->name, length_name); - offset += length_name; - uint32_t length_subgait_name = strlen(this->subgait_name); - varToArr(outbuffer + offset, length_subgait_name); - offset += 4; - memcpy(outbuffer + offset, this->subgait_name, length_subgait_name); - offset += length_subgait_name; - uint32_t length_gait_name = strlen(this->gait_name); - varToArr(outbuffer + offset, length_gait_name); - offset += 4; - memcpy(outbuffer + offset, this->gait_name, length_gait_name); - offset += length_gait_name; - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - uint32_t length_name; - arrToVar(length_name, (inbuffer + offset)); - offset += 4; - for(unsigned int k= offset; k< offset+length_name; ++k){ - inbuffer[k-1]=inbuffer[k]; - } - inbuffer[offset+length_name-1]=0; - this->name = (char *)(inbuffer + offset-1); - offset += length_name; - uint32_t length_subgait_name; - arrToVar(length_subgait_name, (inbuffer + offset)); - offset += 4; - for(unsigned int k= offset; k< offset+length_subgait_name; ++k){ - inbuffer[k-1]=inbuffer[k]; - } - inbuffer[offset+length_subgait_name-1]=0; - this->subgait_name = (char *)(inbuffer + offset-1); - offset += length_subgait_name; - uint32_t length_gait_name; - arrToVar(length_gait_name, (inbuffer + offset)); - offset += 4; - for(unsigned int k= offset; k< offset+length_gait_name; ++k){ - inbuffer[k-1]=inbuffer[k]; - } - inbuffer[offset+length_gait_name-1]=0; - this->gait_name = (char *)(inbuffer + offset-1); - offset += length_gait_name; - return offset; - } - - const char * getType(){ return "march_shared_resources/MoveToGaitGoal"; }; - const char * getMD5(){ return "0dc8656b4dc6724d9fd4f6a17ec2f6a9"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/march_shared_resources/MoveToGaitResult.h b/lib/ros_lib/march_shared_resources/MoveToGaitResult.h deleted file mode 100644 index c88eb86..0000000 --- a/lib/ros_lib/march_shared_resources/MoveToGaitResult.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef _ROS_march_shared_resources_MoveToGaitResult_h -#define _ROS_march_shared_resources_MoveToGaitResult_h - -#include -#include -#include -#include "ros/msg.h" - -namespace march_shared_resources -{ - - class MoveToGaitResult : public ros::Msg - { - public: - - MoveToGaitResult() - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - return offset; - } - - const char * getType(){ return "march_shared_resources/MoveToGaitResult"; }; - const char * getMD5(){ return "d41d8cd98f00b204e9800998ecf8427e"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/march_shared_resources/PerformGait.h b/lib/ros_lib/march_shared_resources/PerformGait.h deleted file mode 100644 index 3dc5203..0000000 --- a/lib/ros_lib/march_shared_resources/PerformGait.h +++ /dev/null @@ -1,119 +0,0 @@ -#ifndef _ROS_march_shared_resources_PerformGait_h -#define _ROS_march_shared_resources_PerformGait_h - -#include -#include -#include -#include "ros/msg.h" - -namespace march_shared_resources -{ - - class PerformGait : public ros::Msg - { - public: - typedef const char* _gait_name_type; - _gait_name_type gait_name; - typedef double _time_type; - _time_type time; - typedef int64_t _repeat_type; - _repeat_type repeat; - - PerformGait(): - gait_name(""), - time(0), - repeat(0) - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - uint32_t length_gait_name = strlen(this->gait_name); - varToArr(outbuffer + offset, length_gait_name); - offset += 4; - memcpy(outbuffer + offset, this->gait_name, length_gait_name); - offset += length_gait_name; - union { - double real; - uint64_t base; - } u_time; - u_time.real = this->time; - *(outbuffer + offset + 0) = (u_time.base >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (u_time.base >> (8 * 1)) & 0xFF; - *(outbuffer + offset + 2) = (u_time.base >> (8 * 2)) & 0xFF; - *(outbuffer + offset + 3) = (u_time.base >> (8 * 3)) & 0xFF; - *(outbuffer + offset + 4) = (u_time.base >> (8 * 4)) & 0xFF; - *(outbuffer + offset + 5) = (u_time.base >> (8 * 5)) & 0xFF; - *(outbuffer + offset + 6) = (u_time.base >> (8 * 6)) & 0xFF; - *(outbuffer + offset + 7) = (u_time.base >> (8 * 7)) & 0xFF; - offset += sizeof(this->time); - union { - int64_t real; - uint64_t base; - } u_repeat; - u_repeat.real = this->repeat; - *(outbuffer + offset + 0) = (u_repeat.base >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (u_repeat.base >> (8 * 1)) & 0xFF; - *(outbuffer + offset + 2) = (u_repeat.base >> (8 * 2)) & 0xFF; - *(outbuffer + offset + 3) = (u_repeat.base >> (8 * 3)) & 0xFF; - *(outbuffer + offset + 4) = (u_repeat.base >> (8 * 4)) & 0xFF; - *(outbuffer + offset + 5) = (u_repeat.base >> (8 * 5)) & 0xFF; - *(outbuffer + offset + 6) = (u_repeat.base >> (8 * 6)) & 0xFF; - *(outbuffer + offset + 7) = (u_repeat.base >> (8 * 7)) & 0xFF; - offset += sizeof(this->repeat); - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - uint32_t length_gait_name; - arrToVar(length_gait_name, (inbuffer + offset)); - offset += 4; - for(unsigned int k= offset; k< offset+length_gait_name; ++k){ - inbuffer[k-1]=inbuffer[k]; - } - inbuffer[offset+length_gait_name-1]=0; - this->gait_name = (char *)(inbuffer + offset-1); - offset += length_gait_name; - union { - double real; - uint64_t base; - } u_time; - u_time.base = 0; - u_time.base |= ((uint64_t) (*(inbuffer + offset + 0))) << (8 * 0); - u_time.base |= ((uint64_t) (*(inbuffer + offset + 1))) << (8 * 1); - u_time.base |= ((uint64_t) (*(inbuffer + offset + 2))) << (8 * 2); - u_time.base |= ((uint64_t) (*(inbuffer + offset + 3))) << (8 * 3); - u_time.base |= ((uint64_t) (*(inbuffer + offset + 4))) << (8 * 4); - u_time.base |= ((uint64_t) (*(inbuffer + offset + 5))) << (8 * 5); - u_time.base |= ((uint64_t) (*(inbuffer + offset + 6))) << (8 * 6); - u_time.base |= ((uint64_t) (*(inbuffer + offset + 7))) << (8 * 7); - this->time = u_time.real; - offset += sizeof(this->time); - union { - int64_t real; - uint64_t base; - } u_repeat; - u_repeat.base = 0; - u_repeat.base |= ((uint64_t) (*(inbuffer + offset + 0))) << (8 * 0); - u_repeat.base |= ((uint64_t) (*(inbuffer + offset + 1))) << (8 * 1); - u_repeat.base |= ((uint64_t) (*(inbuffer + offset + 2))) << (8 * 2); - u_repeat.base |= ((uint64_t) (*(inbuffer + offset + 3))) << (8 * 3); - u_repeat.base |= ((uint64_t) (*(inbuffer + offset + 4))) << (8 * 4); - u_repeat.base |= ((uint64_t) (*(inbuffer + offset + 5))) << (8 * 5); - u_repeat.base |= ((uint64_t) (*(inbuffer + offset + 6))) << (8 * 6); - u_repeat.base |= ((uint64_t) (*(inbuffer + offset + 7))) << (8 * 7); - this->repeat = u_repeat.real; - offset += sizeof(this->repeat); - return offset; - } - - const char * getType(){ return "march_shared_resources/PerformGait"; }; - const char * getMD5(){ return "c2856c4d066eecb97166932dc6907aa4"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/march_shared_resources/PlayInput.h b/lib/ros_lib/march_shared_resources/PlayInput.h deleted file mode 100644 index 1f7c0e4..0000000 --- a/lib/ros_lib/march_shared_resources/PlayInput.h +++ /dev/null @@ -1,137 +0,0 @@ -#ifndef _ROS_SERVICE_PlayInput_h -#define _ROS_SERVICE_PlayInput_h -#include -#include -#include -#include "ros/msg.h" - -namespace march_shared_resources -{ - -static const char PLAYINPUT[] = "march_shared_resources/PlayInput"; - - class PlayInputRequest : public ros::Msg - { - public: - typedef int64_t _play_input_type; - _play_input_type play_input; - - PlayInputRequest(): - play_input(0) - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - union { - int64_t real; - uint64_t base; - } u_play_input; - u_play_input.real = this->play_input; - *(outbuffer + offset + 0) = (u_play_input.base >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (u_play_input.base >> (8 * 1)) & 0xFF; - *(outbuffer + offset + 2) = (u_play_input.base >> (8 * 2)) & 0xFF; - *(outbuffer + offset + 3) = (u_play_input.base >> (8 * 3)) & 0xFF; - *(outbuffer + offset + 4) = (u_play_input.base >> (8 * 4)) & 0xFF; - *(outbuffer + offset + 5) = (u_play_input.base >> (8 * 5)) & 0xFF; - *(outbuffer + offset + 6) = (u_play_input.base >> (8 * 6)) & 0xFF; - *(outbuffer + offset + 7) = (u_play_input.base >> (8 * 7)) & 0xFF; - offset += sizeof(this->play_input); - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - union { - int64_t real; - uint64_t base; - } u_play_input; - u_play_input.base = 0; - u_play_input.base |= ((uint64_t) (*(inbuffer + offset + 0))) << (8 * 0); - u_play_input.base |= ((uint64_t) (*(inbuffer + offset + 1))) << (8 * 1); - u_play_input.base |= ((uint64_t) (*(inbuffer + offset + 2))) << (8 * 2); - u_play_input.base |= ((uint64_t) (*(inbuffer + offset + 3))) << (8 * 3); - u_play_input.base |= ((uint64_t) (*(inbuffer + offset + 4))) << (8 * 4); - u_play_input.base |= ((uint64_t) (*(inbuffer + offset + 5))) << (8 * 5); - u_play_input.base |= ((uint64_t) (*(inbuffer + offset + 6))) << (8 * 6); - u_play_input.base |= ((uint64_t) (*(inbuffer + offset + 7))) << (8 * 7); - this->play_input = u_play_input.real; - offset += sizeof(this->play_input); - return offset; - } - - const char * getType(){ return PLAYINPUT; }; - const char * getMD5(){ return "fc968e449017caef1e2788eccc41a159"; }; - - }; - - class PlayInputResponse : public ros::Msg - { - public: - typedef bool _is_successful_type; - _is_successful_type is_successful; - typedef const char* _message_type; - _message_type message; - - PlayInputResponse(): - is_successful(0), - message("") - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - union { - bool real; - uint8_t base; - } u_is_successful; - u_is_successful.real = this->is_successful; - *(outbuffer + offset + 0) = (u_is_successful.base >> (8 * 0)) & 0xFF; - offset += sizeof(this->is_successful); - uint32_t length_message = strlen(this->message); - varToArr(outbuffer + offset, length_message); - offset += 4; - memcpy(outbuffer + offset, this->message, length_message); - offset += length_message; - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - union { - bool real; - uint8_t base; - } u_is_successful; - u_is_successful.base = 0; - u_is_successful.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0); - this->is_successful = u_is_successful.real; - offset += sizeof(this->is_successful); - uint32_t length_message; - arrToVar(length_message, (inbuffer + offset)); - offset += 4; - for(unsigned int k= offset; k< offset+length_message; ++k){ - inbuffer[k-1]=inbuffer[k]; - } - inbuffer[offset+length_message-1]=0; - this->message = (char *)(inbuffer + offset-1); - offset += length_message; - return offset; - } - - const char * getType(){ return PLAYINPUT; }; - const char * getMD5(){ return "92814ca95de64c716f615f50abf3a8c8"; }; - - }; - - class PlayInput { - public: - typedef PlayInputRequest Request; - typedef PlayInputResponse Response; - }; - -} -#endif diff --git a/lib/ros_lib/march_shared_resources/PlayInputMaster.h b/lib/ros_lib/march_shared_resources/PlayInputMaster.h deleted file mode 100644 index 25a47ca..0000000 --- a/lib/ros_lib/march_shared_resources/PlayInputMaster.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef _ROS_march_shared_resources_PlayInputMaster_h -#define _ROS_march_shared_resources_PlayInputMaster_h - -#include -#include -#include -#include "ros/msg.h" - -namespace march_shared_resources -{ - - class PlayInputMaster : public ros::Msg - { - public: - typedef int64_t _play_input_type; - _play_input_type play_input; - - PlayInputMaster(): - play_input(0) - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - union { - int64_t real; - uint64_t base; - } u_play_input; - u_play_input.real = this->play_input; - *(outbuffer + offset + 0) = (u_play_input.base >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (u_play_input.base >> (8 * 1)) & 0xFF; - *(outbuffer + offset + 2) = (u_play_input.base >> (8 * 2)) & 0xFF; - *(outbuffer + offset + 3) = (u_play_input.base >> (8 * 3)) & 0xFF; - *(outbuffer + offset + 4) = (u_play_input.base >> (8 * 4)) & 0xFF; - *(outbuffer + offset + 5) = (u_play_input.base >> (8 * 5)) & 0xFF; - *(outbuffer + offset + 6) = (u_play_input.base >> (8 * 6)) & 0xFF; - *(outbuffer + offset + 7) = (u_play_input.base >> (8 * 7)) & 0xFF; - offset += sizeof(this->play_input); - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - union { - int64_t real; - uint64_t base; - } u_play_input; - u_play_input.base = 0; - u_play_input.base |= ((uint64_t) (*(inbuffer + offset + 0))) << (8 * 0); - u_play_input.base |= ((uint64_t) (*(inbuffer + offset + 1))) << (8 * 1); - u_play_input.base |= ((uint64_t) (*(inbuffer + offset + 2))) << (8 * 2); - u_play_input.base |= ((uint64_t) (*(inbuffer + offset + 3))) << (8 * 3); - u_play_input.base |= ((uint64_t) (*(inbuffer + offset + 4))) << (8 * 4); - u_play_input.base |= ((uint64_t) (*(inbuffer + offset + 5))) << (8 * 5); - u_play_input.base |= ((uint64_t) (*(inbuffer + offset + 6))) << (8 * 6); - u_play_input.base |= ((uint64_t) (*(inbuffer + offset + 7))) << (8 * 7); - this->play_input = u_play_input.real; - offset += sizeof(this->play_input); - return offset; - } - - const char * getType(){ return "march_shared_resources/PlayInputMaster"; }; - const char * getMD5(){ return "fc968e449017caef1e2788eccc41a159"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/march_shared_resources/StepSize.h b/lib/ros_lib/march_shared_resources/StepSize.h deleted file mode 100644 index 7c619f9..0000000 --- a/lib/ros_lib/march_shared_resources/StepSize.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef _ROS_march_shared_resources_StepSize_h -#define _ROS_march_shared_resources_StepSize_h - -#include -#include -#include -#include "ros/msg.h" - -namespace march_shared_resources -{ - - class StepSize : public ros::Msg - { - public: - typedef double _step_size_type; - _step_size_type step_size; - - StepSize(): - step_size(0) - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - union { - double real; - uint64_t base; - } u_step_size; - u_step_size.real = this->step_size; - *(outbuffer + offset + 0) = (u_step_size.base >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (u_step_size.base >> (8 * 1)) & 0xFF; - *(outbuffer + offset + 2) = (u_step_size.base >> (8 * 2)) & 0xFF; - *(outbuffer + offset + 3) = (u_step_size.base >> (8 * 3)) & 0xFF; - *(outbuffer + offset + 4) = (u_step_size.base >> (8 * 4)) & 0xFF; - *(outbuffer + offset + 5) = (u_step_size.base >> (8 * 5)) & 0xFF; - *(outbuffer + offset + 6) = (u_step_size.base >> (8 * 6)) & 0xFF; - *(outbuffer + offset + 7) = (u_step_size.base >> (8 * 7)) & 0xFF; - offset += sizeof(this->step_size); - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - union { - double real; - uint64_t base; - } u_step_size; - u_step_size.base = 0; - u_step_size.base |= ((uint64_t) (*(inbuffer + offset + 0))) << (8 * 0); - u_step_size.base |= ((uint64_t) (*(inbuffer + offset + 1))) << (8 * 1); - u_step_size.base |= ((uint64_t) (*(inbuffer + offset + 2))) << (8 * 2); - u_step_size.base |= ((uint64_t) (*(inbuffer + offset + 3))) << (8 * 3); - u_step_size.base |= ((uint64_t) (*(inbuffer + offset + 4))) << (8 * 4); - u_step_size.base |= ((uint64_t) (*(inbuffer + offset + 5))) << (8 * 5); - u_step_size.base |= ((uint64_t) (*(inbuffer + offset + 6))) << (8 * 6); - u_step_size.base |= ((uint64_t) (*(inbuffer + offset + 7))) << (8 * 7); - this->step_size = u_step_size.real; - offset += sizeof(this->step_size); - return offset; - } - - const char * getType(){ return "march_shared_resources/StepSize"; }; - const char * getMD5(){ return "76290af81b223bb4ba79cf43558301b6"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/march_shared_resources/Subgait.h b/lib/ros_lib/march_shared_resources/Subgait.h index c65e222..41301e2 100644 --- a/lib/ros_lib/march_shared_resources/Subgait.h +++ b/lib/ros_lib/march_shared_resources/Subgait.h @@ -22,6 +22,8 @@ namespace march_shared_resources _version_type version; typedef const char* _description_type; _description_type description; + typedef const char* _gait_type_type; + _gait_type_type gait_type; uint32_t setpoints_length; typedef march_shared_resources::Setpoint _setpoints_type; _setpoints_type st_setpoints; @@ -39,6 +41,7 @@ namespace march_shared_resources name(""), version(""), description(""), + gait_type(""), setpoints_length(0), setpoints(NULL), trajectory(), duration(), @@ -64,6 +67,11 @@ namespace march_shared_resources offset += 4; memcpy(outbuffer + offset, this->description, length_description); offset += length_description; + uint32_t length_gait_type = strlen(this->gait_type); + varToArr(outbuffer + offset, length_gait_type); + offset += 4; + memcpy(outbuffer + offset, this->gait_type, length_gait_type); + offset += length_gait_type; *(outbuffer + offset + 0) = (this->setpoints_length >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (this->setpoints_length >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (this->setpoints_length >> (8 * 2)) & 0xFF; @@ -124,6 +132,15 @@ namespace march_shared_resources inbuffer[offset+length_description-1]=0; this->description = (char *)(inbuffer + offset-1); offset += length_description; + uint32_t length_gait_type; + arrToVar(length_gait_type, (inbuffer + offset)); + offset += 4; + for(unsigned int k= offset; k< offset+length_gait_type; ++k){ + inbuffer[k-1]=inbuffer[k]; + } + inbuffer[offset+length_gait_type-1]=0; + this->gait_type = (char *)(inbuffer + offset-1); + offset += length_gait_type; uint32_t setpoints_lengthT = ((uint32_t) (*(inbuffer + offset))); setpoints_lengthT |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); setpoints_lengthT |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); @@ -163,7 +180,7 @@ namespace march_shared_resources } const char * getType(){ return "march_shared_resources/Subgait"; }; - const char * getMD5(){ return "56dd95f06d51574a3fc7a0eac6b1b780"; }; + const char * getMD5(){ return "7ce6c0af68699674ac863f06f39674ac"; }; }; diff --git a/lib/ros_lib/roscpp/Empty.h b/lib/ros_lib/roscpp/Empty.h deleted file mode 100644 index df021b7..0000000 --- a/lib/ros_lib/roscpp/Empty.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef _ROS_SERVICE_Empty_h -#define _ROS_SERVICE_Empty_h -#include -#include -#include -#include "ros/msg.h" - -namespace roscpp -{ - -static const char EMPTY[] = "roscpp/Empty"; - - class EmptyRequest : public ros::Msg - { - public: - - EmptyRequest() - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - return offset; - } - - const char * getType(){ return EMPTY; }; - const char * getMD5(){ return "d41d8cd98f00b204e9800998ecf8427e"; }; - - }; - - class EmptyResponse : public ros::Msg - { - public: - - EmptyResponse() - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - return offset; - } - - const char * getType(){ return EMPTY; }; - const char * getMD5(){ return "d41d8cd98f00b204e9800998ecf8427e"; }; - - }; - - class Empty { - public: - typedef EmptyRequest Request; - typedef EmptyResponse Response; - }; - -} -#endif diff --git a/lib/ros_lib/roscpp/GetLoggers.h b/lib/ros_lib/roscpp/GetLoggers.h deleted file mode 100644 index 35f67fb..0000000 --- a/lib/ros_lib/roscpp/GetLoggers.h +++ /dev/null @@ -1,96 +0,0 @@ -#ifndef _ROS_SERVICE_GetLoggers_h -#define _ROS_SERVICE_GetLoggers_h -#include -#include -#include -#include "ros/msg.h" -#include "roscpp/Logger.h" - -namespace roscpp -{ - -static const char GETLOGGERS[] = "roscpp/GetLoggers"; - - class GetLoggersRequest : public ros::Msg - { - public: - - GetLoggersRequest() - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - return offset; - } - - const char * getType(){ return GETLOGGERS; }; - const char * getMD5(){ return "d41d8cd98f00b204e9800998ecf8427e"; }; - - }; - - class GetLoggersResponse : public ros::Msg - { - public: - uint32_t loggers_length; - typedef roscpp::Logger _loggers_type; - _loggers_type st_loggers; - _loggers_type * loggers; - - GetLoggersResponse(): - loggers_length(0), loggers(NULL) - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - *(outbuffer + offset + 0) = (this->loggers_length >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (this->loggers_length >> (8 * 1)) & 0xFF; - *(outbuffer + offset + 2) = (this->loggers_length >> (8 * 2)) & 0xFF; - *(outbuffer + offset + 3) = (this->loggers_length >> (8 * 3)) & 0xFF; - offset += sizeof(this->loggers_length); - for( uint32_t i = 0; i < loggers_length; i++){ - offset += this->loggers[i].serialize(outbuffer + offset); - } - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - uint32_t loggers_lengthT = ((uint32_t) (*(inbuffer + offset))); - loggers_lengthT |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); - loggers_lengthT |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); - loggers_lengthT |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); - offset += sizeof(this->loggers_length); - if(loggers_lengthT > loggers_length) - this->loggers = (roscpp::Logger*)realloc(this->loggers, loggers_lengthT * sizeof(roscpp::Logger)); - loggers_length = loggers_lengthT; - for( uint32_t i = 0; i < loggers_length; i++){ - offset += this->st_loggers.deserialize(inbuffer + offset); - memcpy( &(this->loggers[i]), &(this->st_loggers), sizeof(roscpp::Logger)); - } - return offset; - } - - const char * getType(){ return GETLOGGERS; }; - const char * getMD5(){ return "32e97e85527d4678a8f9279894bb64b0"; }; - - }; - - class GetLoggers { - public: - typedef GetLoggersRequest Request; - typedef GetLoggersResponse Response; - }; - -} -#endif diff --git a/lib/ros_lib/roscpp/Logger.h b/lib/ros_lib/roscpp/Logger.h deleted file mode 100644 index 64c68f3..0000000 --- a/lib/ros_lib/roscpp/Logger.h +++ /dev/null @@ -1,72 +0,0 @@ -#ifndef _ROS_roscpp_Logger_h -#define _ROS_roscpp_Logger_h - -#include -#include -#include -#include "ros/msg.h" - -namespace roscpp -{ - - class Logger : public ros::Msg - { - public: - typedef const char* _name_type; - _name_type name; - typedef const char* _level_type; - _level_type level; - - Logger(): - name(""), - level("") - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - uint32_t length_name = strlen(this->name); - varToArr(outbuffer + offset, length_name); - offset += 4; - memcpy(outbuffer + offset, this->name, length_name); - offset += length_name; - uint32_t length_level = strlen(this->level); - varToArr(outbuffer + offset, length_level); - offset += 4; - memcpy(outbuffer + offset, this->level, length_level); - offset += length_level; - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - uint32_t length_name; - arrToVar(length_name, (inbuffer + offset)); - offset += 4; - for(unsigned int k= offset; k< offset+length_name; ++k){ - inbuffer[k-1]=inbuffer[k]; - } - inbuffer[offset+length_name-1]=0; - this->name = (char *)(inbuffer + offset-1); - offset += length_name; - uint32_t length_level; - arrToVar(length_level, (inbuffer + offset)); - offset += 4; - for(unsigned int k= offset; k< offset+length_level; ++k){ - inbuffer[k-1]=inbuffer[k]; - } - inbuffer[offset+length_level-1]=0; - this->level = (char *)(inbuffer + offset-1); - offset += length_level; - return offset; - } - - const char * getType(){ return "roscpp/Logger"; }; - const char * getMD5(){ return "a6069a2ff40db7bd32143dd66e1f408e"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/roscpp/SetLoggerLevel.h b/lib/ros_lib/roscpp/SetLoggerLevel.h deleted file mode 100644 index 64f2a24..0000000 --- a/lib/ros_lib/roscpp/SetLoggerLevel.h +++ /dev/null @@ -1,104 +0,0 @@ -#ifndef _ROS_SERVICE_SetLoggerLevel_h -#define _ROS_SERVICE_SetLoggerLevel_h -#include -#include -#include -#include "ros/msg.h" - -namespace roscpp -{ - -static const char SETLOGGERLEVEL[] = "roscpp/SetLoggerLevel"; - - class SetLoggerLevelRequest : public ros::Msg - { - public: - typedef const char* _logger_type; - _logger_type logger; - typedef const char* _level_type; - _level_type level; - - SetLoggerLevelRequest(): - logger(""), - level("") - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - uint32_t length_logger = strlen(this->logger); - varToArr(outbuffer + offset, length_logger); - offset += 4; - memcpy(outbuffer + offset, this->logger, length_logger); - offset += length_logger; - uint32_t length_level = strlen(this->level); - varToArr(outbuffer + offset, length_level); - offset += 4; - memcpy(outbuffer + offset, this->level, length_level); - offset += length_level; - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - uint32_t length_logger; - arrToVar(length_logger, (inbuffer + offset)); - offset += 4; - for(unsigned int k= offset; k< offset+length_logger; ++k){ - inbuffer[k-1]=inbuffer[k]; - } - inbuffer[offset+length_logger-1]=0; - this->logger = (char *)(inbuffer + offset-1); - offset += length_logger; - uint32_t length_level; - arrToVar(length_level, (inbuffer + offset)); - offset += 4; - for(unsigned int k= offset; k< offset+length_level; ++k){ - inbuffer[k-1]=inbuffer[k]; - } - inbuffer[offset+length_level-1]=0; - this->level = (char *)(inbuffer + offset-1); - offset += length_level; - return offset; - } - - const char * getType(){ return SETLOGGERLEVEL; }; - const char * getMD5(){ return "51da076440d78ca1684d36c868df61ea"; }; - - }; - - class SetLoggerLevelResponse : public ros::Msg - { - public: - - SetLoggerLevelResponse() - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - return offset; - } - - const char * getType(){ return SETLOGGERLEVEL; }; - const char * getMD5(){ return "d41d8cd98f00b204e9800998ecf8427e"; }; - - }; - - class SetLoggerLevel { - public: - typedef SetLoggerLevelRequest Request; - typedef SetLoggerLevelResponse Response; - }; - -} -#endif diff --git a/lib/ros_lib/rosserial_arduino/Adc.h b/lib/ros_lib/rosserial_arduino/Adc.h deleted file mode 100644 index 23e48d6..0000000 --- a/lib/ros_lib/rosserial_arduino/Adc.h +++ /dev/null @@ -1,92 +0,0 @@ -#ifndef _ROS_rosserial_arduino_Adc_h -#define _ROS_rosserial_arduino_Adc_h - -#include -#include -#include -#include "ros/msg.h" - -namespace rosserial_arduino -{ - - class Adc : public ros::Msg - { - public: - typedef uint16_t _adc0_type; - _adc0_type adc0; - typedef uint16_t _adc1_type; - _adc1_type adc1; - typedef uint16_t _adc2_type; - _adc2_type adc2; - typedef uint16_t _adc3_type; - _adc3_type adc3; - typedef uint16_t _adc4_type; - _adc4_type adc4; - typedef uint16_t _adc5_type; - _adc5_type adc5; - - Adc(): - adc0(0), - adc1(0), - adc2(0), - adc3(0), - adc4(0), - adc5(0) - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - *(outbuffer + offset + 0) = (this->adc0 >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (this->adc0 >> (8 * 1)) & 0xFF; - offset += sizeof(this->adc0); - *(outbuffer + offset + 0) = (this->adc1 >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (this->adc1 >> (8 * 1)) & 0xFF; - offset += sizeof(this->adc1); - *(outbuffer + offset + 0) = (this->adc2 >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (this->adc2 >> (8 * 1)) & 0xFF; - offset += sizeof(this->adc2); - *(outbuffer + offset + 0) = (this->adc3 >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (this->adc3 >> (8 * 1)) & 0xFF; - offset += sizeof(this->adc3); - *(outbuffer + offset + 0) = (this->adc4 >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (this->adc4 >> (8 * 1)) & 0xFF; - offset += sizeof(this->adc4); - *(outbuffer + offset + 0) = (this->adc5 >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (this->adc5 >> (8 * 1)) & 0xFF; - offset += sizeof(this->adc5); - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - this->adc0 = ((uint16_t) (*(inbuffer + offset))); - this->adc0 |= ((uint16_t) (*(inbuffer + offset + 1))) << (8 * 1); - offset += sizeof(this->adc0); - this->adc1 = ((uint16_t) (*(inbuffer + offset))); - this->adc1 |= ((uint16_t) (*(inbuffer + offset + 1))) << (8 * 1); - offset += sizeof(this->adc1); - this->adc2 = ((uint16_t) (*(inbuffer + offset))); - this->adc2 |= ((uint16_t) (*(inbuffer + offset + 1))) << (8 * 1); - offset += sizeof(this->adc2); - this->adc3 = ((uint16_t) (*(inbuffer + offset))); - this->adc3 |= ((uint16_t) (*(inbuffer + offset + 1))) << (8 * 1); - offset += sizeof(this->adc3); - this->adc4 = ((uint16_t) (*(inbuffer + offset))); - this->adc4 |= ((uint16_t) (*(inbuffer + offset + 1))) << (8 * 1); - offset += sizeof(this->adc4); - this->adc5 = ((uint16_t) (*(inbuffer + offset))); - this->adc5 |= ((uint16_t) (*(inbuffer + offset + 1))) << (8 * 1); - offset += sizeof(this->adc5); - return offset; - } - - const char * getType(){ return "rosserial_arduino/Adc"; }; - const char * getMD5(){ return "6d7853a614e2e821319068311f2af25b"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/rosserial_arduino/Test.h b/lib/ros_lib/rosserial_arduino/Test.h deleted file mode 100644 index cd806db..0000000 --- a/lib/ros_lib/rosserial_arduino/Test.h +++ /dev/null @@ -1,104 +0,0 @@ -#ifndef _ROS_SERVICE_Test_h -#define _ROS_SERVICE_Test_h -#include -#include -#include -#include "ros/msg.h" - -namespace rosserial_arduino -{ - -static const char TEST[] = "rosserial_arduino/Test"; - - class TestRequest : public ros::Msg - { - public: - typedef const char* _input_type; - _input_type input; - - TestRequest(): - input("") - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - uint32_t length_input = strlen(this->input); - varToArr(outbuffer + offset, length_input); - offset += 4; - memcpy(outbuffer + offset, this->input, length_input); - offset += length_input; - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - uint32_t length_input; - arrToVar(length_input, (inbuffer + offset)); - offset += 4; - for(unsigned int k= offset; k< offset+length_input; ++k){ - inbuffer[k-1]=inbuffer[k]; - } - inbuffer[offset+length_input-1]=0; - this->input = (char *)(inbuffer + offset-1); - offset += length_input; - return offset; - } - - const char * getType(){ return TEST; }; - const char * getMD5(){ return "39e92f1778057359c64c7b8a7d7b19de"; }; - - }; - - class TestResponse : public ros::Msg - { - public: - typedef const char* _output_type; - _output_type output; - - TestResponse(): - output("") - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - uint32_t length_output = strlen(this->output); - varToArr(outbuffer + offset, length_output); - offset += 4; - memcpy(outbuffer + offset, this->output, length_output); - offset += length_output; - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - uint32_t length_output; - arrToVar(length_output, (inbuffer + offset)); - offset += 4; - for(unsigned int k= offset; k< offset+length_output; ++k){ - inbuffer[k-1]=inbuffer[k]; - } - inbuffer[offset+length_output-1]=0; - this->output = (char *)(inbuffer + offset-1); - offset += length_output; - return offset; - } - - const char * getType(){ return TEST; }; - const char * getMD5(){ return "0825d95fdfa2c8f4bbb4e9c74bccd3fd"; }; - - }; - - class Test { - public: - typedef TestRequest Request; - typedef TestResponse Response; - }; - -} -#endif diff --git a/lib/ros_lib/rosserial_mbed/Adc.h b/lib/ros_lib/rosserial_mbed/Adc.h deleted file mode 100644 index d46fc40..0000000 --- a/lib/ros_lib/rosserial_mbed/Adc.h +++ /dev/null @@ -1,92 +0,0 @@ -#ifndef _ROS_rosserial_mbed_Adc_h -#define _ROS_rosserial_mbed_Adc_h - -#include -#include -#include -#include "ros/msg.h" - -namespace rosserial_mbed -{ - - class Adc : public ros::Msg - { - public: - typedef uint16_t _adc0_type; - _adc0_type adc0; - typedef uint16_t _adc1_type; - _adc1_type adc1; - typedef uint16_t _adc2_type; - _adc2_type adc2; - typedef uint16_t _adc3_type; - _adc3_type adc3; - typedef uint16_t _adc4_type; - _adc4_type adc4; - typedef uint16_t _adc5_type; - _adc5_type adc5; - - Adc(): - adc0(0), - adc1(0), - adc2(0), - adc3(0), - adc4(0), - adc5(0) - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - *(outbuffer + offset + 0) = (this->adc0 >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (this->adc0 >> (8 * 1)) & 0xFF; - offset += sizeof(this->adc0); - *(outbuffer + offset + 0) = (this->adc1 >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (this->adc1 >> (8 * 1)) & 0xFF; - offset += sizeof(this->adc1); - *(outbuffer + offset + 0) = (this->adc2 >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (this->adc2 >> (8 * 1)) & 0xFF; - offset += sizeof(this->adc2); - *(outbuffer + offset + 0) = (this->adc3 >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (this->adc3 >> (8 * 1)) & 0xFF; - offset += sizeof(this->adc3); - *(outbuffer + offset + 0) = (this->adc4 >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (this->adc4 >> (8 * 1)) & 0xFF; - offset += sizeof(this->adc4); - *(outbuffer + offset + 0) = (this->adc5 >> (8 * 0)) & 0xFF; - *(outbuffer + offset + 1) = (this->adc5 >> (8 * 1)) & 0xFF; - offset += sizeof(this->adc5); - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - this->adc0 = ((uint16_t) (*(inbuffer + offset))); - this->adc0 |= ((uint16_t) (*(inbuffer + offset + 1))) << (8 * 1); - offset += sizeof(this->adc0); - this->adc1 = ((uint16_t) (*(inbuffer + offset))); - this->adc1 |= ((uint16_t) (*(inbuffer + offset + 1))) << (8 * 1); - offset += sizeof(this->adc1); - this->adc2 = ((uint16_t) (*(inbuffer + offset))); - this->adc2 |= ((uint16_t) (*(inbuffer + offset + 1))) << (8 * 1); - offset += sizeof(this->adc2); - this->adc3 = ((uint16_t) (*(inbuffer + offset))); - this->adc3 |= ((uint16_t) (*(inbuffer + offset + 1))) << (8 * 1); - offset += sizeof(this->adc3); - this->adc4 = ((uint16_t) (*(inbuffer + offset))); - this->adc4 |= ((uint16_t) (*(inbuffer + offset + 1))) << (8 * 1); - offset += sizeof(this->adc4); - this->adc5 = ((uint16_t) (*(inbuffer + offset))); - this->adc5 |= ((uint16_t) (*(inbuffer + offset + 1))) << (8 * 1); - offset += sizeof(this->adc5); - return offset; - } - - const char * getType(){ return "rosserial_mbed/Adc"; }; - const char * getMD5(){ return "6d7853a614e2e821319068311f2af25b"; }; - - }; - -} -#endif diff --git a/lib/ros_lib/rosserial_mbed/Test.h b/lib/ros_lib/rosserial_mbed/Test.h deleted file mode 100644 index 6a2658f..0000000 --- a/lib/ros_lib/rosserial_mbed/Test.h +++ /dev/null @@ -1,104 +0,0 @@ -#ifndef _ROS_SERVICE_Test_h -#define _ROS_SERVICE_Test_h -#include -#include -#include -#include "ros/msg.h" - -namespace rosserial_mbed -{ - -static const char TEST[] = "rosserial_mbed/Test"; - - class TestRequest : public ros::Msg - { - public: - typedef const char* _input_type; - _input_type input; - - TestRequest(): - input("") - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - uint32_t length_input = strlen(this->input); - varToArr(outbuffer + offset, length_input); - offset += 4; - memcpy(outbuffer + offset, this->input, length_input); - offset += length_input; - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - uint32_t length_input; - arrToVar(length_input, (inbuffer + offset)); - offset += 4; - for(unsigned int k= offset; k< offset+length_input; ++k){ - inbuffer[k-1]=inbuffer[k]; - } - inbuffer[offset+length_input-1]=0; - this->input = (char *)(inbuffer + offset-1); - offset += length_input; - return offset; - } - - const char * getType(){ return TEST; }; - const char * getMD5(){ return "39e92f1778057359c64c7b8a7d7b19de"; }; - - }; - - class TestResponse : public ros::Msg - { - public: - typedef const char* _output_type; - _output_type output; - - TestResponse(): - output("") - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - uint32_t length_output = strlen(this->output); - varToArr(outbuffer + offset, length_output); - offset += 4; - memcpy(outbuffer + offset, this->output, length_output); - offset += length_output; - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - uint32_t length_output; - arrToVar(length_output, (inbuffer + offset)); - offset += 4; - for(unsigned int k= offset; k< offset+length_output; ++k){ - inbuffer[k-1]=inbuffer[k]; - } - inbuffer[offset+length_output-1]=0; - this->output = (char *)(inbuffer + offset-1); - offset += length_output; - return offset; - } - - const char * getType(){ return TEST; }; - const char * getMD5(){ return "0825d95fdfa2c8f4bbb4e9c74bccd3fd"; }; - - }; - - class Test { - public: - typedef TestRequest Request; - typedef TestResponse Response; - }; - -} -#endif diff --git a/lib/ros_lib/std_srvs/Empty.h b/lib/ros_lib/std_srvs/Empty.h deleted file mode 100644 index b040dd2..0000000 --- a/lib/ros_lib/std_srvs/Empty.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef _ROS_SERVICE_Empty_h -#define _ROS_SERVICE_Empty_h -#include -#include -#include -#include "ros/msg.h" - -namespace std_srvs -{ - -static const char EMPTY[] = "std_srvs/Empty"; - - class EmptyRequest : public ros::Msg - { - public: - - EmptyRequest() - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - return offset; - } - - const char * getType(){ return EMPTY; }; - const char * getMD5(){ return "d41d8cd98f00b204e9800998ecf8427e"; }; - - }; - - class EmptyResponse : public ros::Msg - { - public: - - EmptyResponse() - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - return offset; - } - - const char * getType(){ return EMPTY; }; - const char * getMD5(){ return "d41d8cd98f00b204e9800998ecf8427e"; }; - - }; - - class Empty { - public: - typedef EmptyRequest Request; - typedef EmptyResponse Response; - }; - -} -#endif diff --git a/lib/ros_lib/std_srvs/SetBool.h b/lib/ros_lib/std_srvs/SetBool.h deleted file mode 100644 index 1feb34e..0000000 --- a/lib/ros_lib/std_srvs/SetBool.h +++ /dev/null @@ -1,123 +0,0 @@ -#ifndef _ROS_SERVICE_SetBool_h -#define _ROS_SERVICE_SetBool_h -#include -#include -#include -#include "ros/msg.h" - -namespace std_srvs -{ - -static const char SETBOOL[] = "std_srvs/SetBool"; - - class SetBoolRequest : public ros::Msg - { - public: - typedef bool _data_type; - _data_type data; - - SetBoolRequest(): - data(0) - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - union { - bool real; - uint8_t base; - } u_data; - u_data.real = this->data; - *(outbuffer + offset + 0) = (u_data.base >> (8 * 0)) & 0xFF; - offset += sizeof(this->data); - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - union { - bool real; - uint8_t base; - } u_data; - u_data.base = 0; - u_data.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0); - this->data = u_data.real; - offset += sizeof(this->data); - return offset; - } - - const char * getType(){ return SETBOOL; }; - const char * getMD5(){ return "8b94c1b53db61fb6aed406028ad6332a"; }; - - }; - - class SetBoolResponse : public ros::Msg - { - public: - typedef bool _success_type; - _success_type success; - typedef const char* _message_type; - _message_type message; - - SetBoolResponse(): - success(0), - message("") - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - union { - bool real; - uint8_t base; - } u_success; - u_success.real = this->success; - *(outbuffer + offset + 0) = (u_success.base >> (8 * 0)) & 0xFF; - offset += sizeof(this->success); - uint32_t length_message = strlen(this->message); - varToArr(outbuffer + offset, length_message); - offset += 4; - memcpy(outbuffer + offset, this->message, length_message); - offset += length_message; - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - union { - bool real; - uint8_t base; - } u_success; - u_success.base = 0; - u_success.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0); - this->success = u_success.real; - offset += sizeof(this->success); - uint32_t length_message; - arrToVar(length_message, (inbuffer + offset)); - offset += 4; - for(unsigned int k= offset; k< offset+length_message; ++k){ - inbuffer[k-1]=inbuffer[k]; - } - inbuffer[offset+length_message-1]=0; - this->message = (char *)(inbuffer + offset-1); - offset += length_message; - return offset; - } - - const char * getType(){ return SETBOOL; }; - const char * getMD5(){ return "937c9679a518e3a18d831e57125ea522"; }; - - }; - - class SetBool { - public: - typedef SetBoolRequest Request; - typedef SetBoolResponse Response; - }; - -} -#endif diff --git a/lib/ros_lib/std_srvs/Trigger.h b/lib/ros_lib/std_srvs/Trigger.h deleted file mode 100644 index 34d1e48..0000000 --- a/lib/ros_lib/std_srvs/Trigger.h +++ /dev/null @@ -1,105 +0,0 @@ -#ifndef _ROS_SERVICE_Trigger_h -#define _ROS_SERVICE_Trigger_h -#include -#include -#include -#include "ros/msg.h" - -namespace std_srvs -{ - -static const char TRIGGER[] = "std_srvs/Trigger"; - - class TriggerRequest : public ros::Msg - { - public: - - TriggerRequest() - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - return offset; - } - - const char * getType(){ return TRIGGER; }; - const char * getMD5(){ return "d41d8cd98f00b204e9800998ecf8427e"; }; - - }; - - class TriggerResponse : public ros::Msg - { - public: - typedef bool _success_type; - _success_type success; - typedef const char* _message_type; - _message_type message; - - TriggerResponse(): - success(0), - message("") - { - } - - virtual int serialize(unsigned char *outbuffer) const - { - int offset = 0; - union { - bool real; - uint8_t base; - } u_success; - u_success.real = this->success; - *(outbuffer + offset + 0) = (u_success.base >> (8 * 0)) & 0xFF; - offset += sizeof(this->success); - uint32_t length_message = strlen(this->message); - varToArr(outbuffer + offset, length_message); - offset += 4; - memcpy(outbuffer + offset, this->message, length_message); - offset += length_message; - return offset; - } - - virtual int deserialize(unsigned char *inbuffer) - { - int offset = 0; - union { - bool real; - uint8_t base; - } u_success; - u_success.base = 0; - u_success.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0); - this->success = u_success.real; - offset += sizeof(this->success); - uint32_t length_message; - arrToVar(length_message, (inbuffer + offset)); - offset += 4; - for(unsigned int k= offset; k< offset+length_message; ++k){ - inbuffer[k-1]=inbuffer[k]; - } - inbuffer[offset+length_message-1]=0; - this->message = (char *)(inbuffer + offset-1); - offset += length_message; - return offset; - } - - const char * getType(){ return TRIGGER; }; - const char * getMD5(){ return "937c9679a518e3a18d831e57125ea522"; }; - - }; - - class Trigger { - public: - typedef TriggerRequest Request; - typedef TriggerResponse Response; - }; - -} -#endif From b97fe2b5e6c567c38f26a11c3bd74dfdfa991221 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Mon, 16 Dec 2019 23:57:23 +0100 Subject: [PATCH 29/58] Add activating and stopping gaits --- src/main.cpp | 76 +++++++++++++++++++++---------------------- src/state_machine.cpp | 24 ++++++++++---- 2 files changed, 56 insertions(+), 44 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 0b9660e..744fb17 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,9 +11,8 @@ #include #include #include +#include #include -#include -#include #include // Pin definitions @@ -69,15 +68,19 @@ ros::NodeHandle_ nh; ros::NodeHandle nh; #endif -bool received_gait_instruction_response; -bool gait_message_send; -void gaitInstructionResponseCallback(const std_msgs::Bool& msg) { - received_gait_instruction_response = true; +bool received_gait_instruction_response = false; +bool gait_message_send = false; +void gaitInstructionResponseCallback( + const march_shared_resources::GaitInstructionResponse& msg) { + if (msg.result == msg.GAIT_FINISHED) { + received_gait_instruction_response = true; + } } -ros::Subscriber gait_instruction_result_subscriber( - "/march/input_device/instruction_response", - &gaitInstructionResponseCallback); +ros::Subscriber + gait_instruction_result_subscriber( + "/march/input_device/instruction_response", + &gaitInstructionResponseCallback); march_shared_resources::GaitInstruction gait_instruction_msg; std_msgs::Time time_msg; @@ -159,53 +162,50 @@ void loop() { ButtonState joystick_state = joystick.getState(); ButtonState trigger_state = trigger.getState(); - // Set the effect to be played hoi - // Waveforms can be combined, to create new wavefroms, see driver datasheet - driver.setWaveform(0, effect); // Setup the waveform(s) - driver.setWaveform(1, 0); // end of waveform waveform - // When button is pressed, vibrate if (trigger_state == ButtonState::PUSH) { + // Waveforms can be combined, to create new wavefroms, see driver datasheet + driver.setWaveform(0, effect); // Setup the waveform(s) + driver.setWaveform(1, 0); // end of waveform waveform + driver.go(); } + bool state_has_changed = false; if (received_gait_instruction_response) { // This means gait instruction handled // trigger_state = "EXIT_GAIT"; received_gait_instruction_response = false; gait_message_send = false; - } - - bool state_has_changed = false; - if (joystick_position == JoystickPosition::LEFT) { - state_has_changed = state_machine.left(); - } else if (joystick_position == JoystickPosition::RIGHT) { - state_has_changed = state_machine.right(); - } else if (joystick_position == JoystickPosition::UP) { - state_has_changed = state_machine.up(); - } else if (joystick_position == JoystickPosition::DOWN) { - state_has_changed = state_machine.down(); - } else if (joystick_state == ButtonState::PUSH) { - state_has_changed = state_machine.select(); - } else if (joystick_state == ButtonState::DOUBLE) { - state_has_changed = state_machine.back(); - } else if (trigger_state == ButtonState::PUSH) { - state_has_changed = state_machine.activate(); + state_machine.activate(); + } else if (gait_message_send) { + if (joystick_state == ButtonState::PUSH) { + sendStopMessage(); + } + } else { + if (joystick_position == JoystickPosition::LEFT) { + state_has_changed = state_machine.left(); + } else if (joystick_position == JoystickPosition::RIGHT) { + state_has_changed = state_machine.right(); + } else if (joystick_position == JoystickPosition::UP) { + state_has_changed = state_machine.up(); + } else if (joystick_position == JoystickPosition::DOWN) { + state_has_changed = state_machine.down(); + } else if (joystick_state == ButtonState::PUSH) { + state_has_changed = state_machine.select(); + } else if (joystick_state == ButtonState::DOUBLE) { + state_has_changed = state_machine.back(); + } else if (trigger_state == ButtonState::PUSH) { + state_has_changed = state_machine.activate(); + } } drawCurrentImage(); if (state_has_changed) { std::string gait_name = state_machine.getCurrentGaitName(); - - // If there is a transition to a new screen which belongs to a gait send - // message with this gait. if (!gait_name.empty()) { sendGaitMessage(gait_name); - } else if (trigger_state == ButtonState::PUSH) { - // If the trigger press is not to select a gait, it's interpreted as a - // stop. - sendStopMessage(); } } diff --git a/src/state_machine.cpp b/src/state_machine.cpp index 29df1c8..353a3a6 100644 --- a/src/state_machine.cpp +++ b/src/state_machine.cpp @@ -3,19 +3,31 @@ void StateMachine::construct() { State& home_sit_start = this->createState(HomeSitStart_Hi, HomeSitStart_Lo); - State& home_sit_start_activated = this->createState(HomeSitStartActivated_Hi, HomeSitStartActivated_Lo, "home_sit"); - State& home_sit_start_selected = this->createState(HomeSitStartSelected_Hi, HomeSitStartSelected_Lo).withBack(&home_sit_start).withActivate(&home_sit_start_activated); + State& home_sit_start_activated = this->createState( + HomeSitStartActivated_Hi, HomeSitStartActivated_Lo, "home_sit"); + State& home_sit_start_selected = + this->createState(HomeSitStartSelected_Hi, HomeSitStartSelected_Lo) + .withBack(&home_sit_start) + .withActivate(&home_sit_start_activated); State& stand_up = this->createState(StandUp_Hi, StandUp_Lo).withLeft(&home_sit_start); - State& stand_up_activated = this->createState(StandUpActivated_Hi, StandUpActivated_Lo, "gait_sit"); - State& stand_up_selected = this->createState(StandUpSelected_Hi, StandUpSelected_Lo).withBack(&stand_up).withActivate(&stand_up_activated); + State& stand_up_activated = + this->createState(StandUpActivated_Hi, StandUpActivated_Lo, "gait_sit"); + State& stand_up_selected = + this->createState(StandUpSelected_Hi, StandUpSelected_Lo) + .withBack(&stand_up) + .withActivate(&stand_up_activated); State& home_stand_start = this->createState(HomeStandStart_Hi, HomeStandStart_Lo) .withLeft(&stand_up); - State& home_stand_activated = this->createState(HomeStandActivated_Hi, HomeStandActivated_Lo, "home_stand"); - State& home_stand_selected = this->createState(HomeStandSelected_Hi, HomeStandSelected_Lo).withBack(&home_stand_start).withActivate(&home_stand_activated); + State& home_stand_activated = this->createState( + HomeStandActivated_Hi, HomeStandActivated_Lo, "home_stand"); + State& home_stand_selected = + this->createState(HomeStandSelected_Hi, HomeStandSelected_Lo) + .withBack(&home_stand_start) + .withActivate(&home_stand_activated); State& power_off = this->createState(TurnOff_Hi, TurnOff_Lo) .withLeft(&home_stand_start) .withRight(&home_sit_start); From 7024bad666700ac71b782775c736ef0428c71fc2 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Tue, 17 Dec 2019 00:21:02 +0100 Subject: [PATCH 30/58] Refactor global constants --- .travis.yml | 2 +- platformio.ini | 2 ++ src/main.cpp | 79 +++++++++++++++++++++++--------------------------- src/screen.cpp | 7 +++-- 4 files changed, 44 insertions(+), 46 deletions(-) diff --git a/.travis.yml b/.travis.yml index d5821e7..5f87608 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,5 +23,5 @@ install: script: - platformio run - platformio test --environment native - - platformio check + - platformio check --fail-on-defect high - wget -qO- https://raw.githubusercontent.com/Sarcasm/run-clang-format/master/run-clang-format.py | python - -r src include test diff --git a/platformio.ini b/platformio.ini index ce8d778..c4cfb5a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -24,6 +24,8 @@ monitor_flags = check_tool = cppcheck, clangtidy check_severity = low, medium, high +check_flags = + clangtidy: --checks=*,-fuchsia-default-arguments,-fuchsia-statically-constructed-objects,-cert-err58-cpp check_patterns = include/*.h src/*.cpp diff --git a/src/main.cpp b/src/main.cpp index 744fb17..d9ac9cb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,24 +15,27 @@ #include #include -// Pin definitions -// Trigger -#define TRIGGER 26 -// Rocker Switch -#define ROCKER_UP 2 -#define ROCKER_DOWN 5 -// Joystick -#define JOYSTICK_LEFT 23 -#define JOYSTICK_RIGHT 14 -#define JOYSTICK_UP 12 -#define JOYSTICK_DOWN 19 -#define JOYSTICK_PUSH 18 -// Screen -#define UART_TX 32 // Software serial -#define UART_RX 34 // Software serial -#define RST 13 // Reset -#define BAUD_SCREEN 9600 - +namespace pins { +const uint8_t TRIGGER = 26; + +const uint8_t ROCKER_UP = 2; +const uint8_t ROCKER_DOWN = 5; + +const uint8_t JOYSTICK_LEFT = 23; +const uint8_t JOYSTICK_RIGHT = 14; +const uint8_t JOYSTICK_UP = 12; +const uint8_t JOYSTICK_DOWN = 19; +const uint8_t JOYSTICK_PUSH = 18; +const uint8_t UART_TX = 32; // Software serial +const uint8_t UART_RX = 34; // Software serial +const uint8_t RST = 13; // Reset +} // namespace pins + +const uint32_t BAUD_SCREEN = 9600; +const uint64_t BAUD_SERIAL = 57600; + +// Necessary, since the 4dsystems defines these +// and they clash with our joystick definitions #undef LEFT #undef RIGHT #undef UP @@ -40,26 +43,20 @@ //#define USE_WIRELESS // comment this to use wired connection. -// Trigger -Button trigger(TRIGGER); -// Rocker switch -RockerSwitch rocker(ROCKER_UP, ROCKER_DOWN); -// Joystick -Joystick joystick(JOYSTICK_LEFT, JOYSTICK_RIGHT, JOYSTICK_UP, JOYSTICK_DOWN, - JOYSTICK_PUSH); -// Serial communication between Lolin and Screen -SoftwareSerial screen_serial(UART_RX, UART_TX); -// Instance of the screen as in Goldelox_Serial library +Button trigger(pins::TRIGGER); +RockerSwitch rocker(pins::ROCKER_UP, pins::ROCKER_DOWN); +Joystick joystick(pins::JOYSTICK_LEFT, pins::JOYSTICK_RIGHT, pins::JOYSTICK_UP, + pins::JOYSTICK_DOWN, pins::JOYSTICK_PUSH); + +SoftwareSerial screen_serial(pins::UART_RX, pins::UART_TX); Goldelox_Serial_4DLib screen_goldelox(&screen_serial); -// Wrapper instance of the screen -Screen screen(&screen_goldelox, &screen_serial, RST, BAUD_SCREEN); -// State Machine +Screen screen(&screen_goldelox, &screen_serial, pins::RST, BAUD_SCREEN); + StateMachine state_machine; -// Haptic Driver Adafruit_DRV2605 driver; -uint8_t effect = - 14; // Select the desired effect, for now test effect "Buzz 100%" +// Select the desired effect, for now test effect "Buzz 100%" +const uint8_t EFFECT = 14; // Create ros nodehandle with publishers #ifdef USE_WIRELESS @@ -119,22 +116,20 @@ void drawCurrentImage() { } void setup() { - Serial.begin(57600); + Serial.begin(BAUD_SCREEN); #ifdef USE_WIRELESS setupWiFi(); #endif - // Set screen pins as either input or output - pinMode(UART_TX, OUTPUT); - pinMode(UART_RX, INPUT); + pinMode(pins::UART_TX, OUTPUT); + pinMode(pins::UART_RX, INPUT); // initialize screen by resetting, initing uSD card, clearing screen screen.init(); // Setup I2C protocol driver.begin(); - // Select the effect library driver.selectLibrary(2); // I2C trigger by sending 'go' command // default, internal trigger when sending GO command @@ -148,7 +143,7 @@ void setup() { // Reset the joystick right pin, this needed after the ROS node init pin 14 is // apparently used by ROS. - pinMode(JOYSTICK_RIGHT, INPUT_PULLUP); + pinMode(pins::JOYSTICK_RIGHT, INPUT_PULLUP); state_machine.construct(); @@ -165,7 +160,7 @@ void loop() { // When button is pressed, vibrate if (trigger_state == ButtonState::PUSH) { // Waveforms can be combined, to create new wavefroms, see driver datasheet - driver.setWaveform(0, effect); // Setup the waveform(s) + driver.setWaveform(0, EFFECT); // Setup the waveform(s) driver.setWaveform(1, 0); // end of waveform waveform driver.go(); @@ -174,7 +169,6 @@ void loop() { bool state_has_changed = false; if (received_gait_instruction_response) { // This means gait instruction handled - // trigger_state = "EXIT_GAIT"; received_gait_instruction_response = false; gait_message_send = false; state_machine.activate(); @@ -212,6 +206,5 @@ void loop() { // Average loop frequency is around 20hz. sendAliveMessage(); - // Spin ros node nh.spinOnce(); } diff --git a/src/screen.cpp b/src/screen.cpp index 44d0e98..8574254 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -2,7 +2,9 @@ #include "version.h" // 16-bit color March blue converted from 24bit 0x126287 -#define MARCH_COLOR 0x218B +const word MARCH_COLOR = 0x218B; + +const useconds_t MSECONDS_IN_SECOND = 1000; Screen::Screen(Goldelox_Serial_4DLib* screen, SoftwareSerial* screen_serial, uint8_t rst, uint32_t baud) @@ -43,7 +45,8 @@ void Screen::reset() { } void Screen::draw_image(word addr_hi, word addr_lo) { - if ((millis() - this->last_draw_time_) * 1000 > this->wait_time_ms_) { + if ((millis() - this->last_draw_time_) * MSECONDS_IN_SECOND > + this->wait_time_ms_) { this->screen_->media_SetSector(addr_hi, addr_lo); this->screen_->media_Image(0, 0); this->last_draw_time_ = millis(); From d22ea0ac56f162528eb261ed65c51e74d2c47131 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Tue, 17 Dec 2019 11:40:13 +0100 Subject: [PATCH 31/58] Finish refactor screen --- include/version.h | 2 +- src/main.cpp | 2 +- src/screen.cpp | 15 ++++++++------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/include/version.h b/include/version.h index 3e1188b..3f5b647 100644 --- a/include/version.h +++ b/include/version.h @@ -1,7 +1,7 @@ #ifndef VERSION_H #define VERSION_H -#define ORGANIZATION "Project March" +#define ORGANIZATION "Project\n\rMarch" #define PROJECT_NAME "input-device" #define VERSION "v2.0.0-beta.1" diff --git a/src/main.cpp b/src/main.cpp index d9ac9cb..f9aa9dc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -116,7 +116,7 @@ void drawCurrentImage() { } void setup() { - Serial.begin(BAUD_SCREEN); + Serial.begin(BAUD_SERIAL); #ifdef USE_WIRELESS setupWiFi(); diff --git a/src/screen.cpp b/src/screen.cpp index 8574254..1ec703f 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -13,11 +13,10 @@ Screen::Screen(Goldelox_Serial_4DLib* screen, SoftwareSerial* screen_serial, } void Screen::init() { - digitalWrite(this->rst_, 1); + this->reset(); this->serial_->begin(this->baud_); - this->reset(); this->clear(); this->screen_->gfx_ScreenMode(PORTRAIT); @@ -33,9 +32,12 @@ void Screen::init() { void Screen::clear() { this->screen_->gfx_Cls(); + usleep(this->wait_time_ms_); } void Screen::reset() { + digitalWrite(this->rst_, 1); + usleep(100000); digitalWrite(this->rst_, 0); usleep(this->wait_time_ms_); digitalWrite(this->rst_, 1); @@ -72,15 +74,14 @@ void Screen::printVersion() { void Screen::mountImages() { word initialized = this->screen_->media_Init(); - if (initialized == 0) { + if (initialized != Err4D_OK) { this->screen_->txt_FGcolour(RED); - this->screen_->print("Pls insert SD"); - while (initialized == 0) { + this->screen_->println("Pls insert SD"); + while (initialized != Err4D_OK) { sleep(1); - this->screen_->print('.'); initialized = this->screen_->media_Init(); } - this->screen_->println("Done"); this->screen_->txt_FGcolour(WHITE); + this->screen_->println("Done"); } } From 44aafb124ab0cb438e9e53d0da0a7a9e4b463020 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Tue, 17 Dec 2019 12:22:25 +0100 Subject: [PATCH 32/58] Add screen saver settings --- include/screen.h | 8 ++++++++ src/main.cpp | 4 +++- src/screen.cpp | 9 +++++---- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/include/screen.h b/include/screen.h index ed732b4..892ee0e 100644 --- a/include/screen.h +++ b/include/screen.h @@ -57,6 +57,14 @@ class Screen { // In microseconds. Needed for functioning, can still be optimized const useconds_t wait_time_ms_ = 500000; + + // Milliseconds, time to wait between drawing images + const useconds_t draw_speed_ms_ = 100; + + // Milliseconds, when the screen should start scrolling + const word screen_saver_timeout_ms_ = 10000; + // Must be value in 0-255 (fastest-slowest) + const word screen_saver_scroll_speed_ = 0; }; #endif // SCREEN_H \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index f9aa9dc..ecbbd87 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -147,6 +147,7 @@ void setup() { state_machine.construct(); + sleep(2); drawCurrentImage(); } @@ -194,9 +195,10 @@ void loop() { } } - drawCurrentImage(); if (state_has_changed) { + drawCurrentImage(); + std::string gait_name = state_machine.getCurrentGaitName(); if (!gait_name.empty()) { sendGaitMessage(gait_name); diff --git a/src/screen.cpp b/src/screen.cpp index 1ec703f..da5e4c3 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -4,8 +4,6 @@ // 16-bit color March blue converted from 24bit 0x126287 const word MARCH_COLOR = 0x218B; -const useconds_t MSECONDS_IN_SECOND = 1000; - Screen::Screen(Goldelox_Serial_4DLib* screen, SoftwareSerial* screen_serial, uint8_t rst, uint32_t baud) : screen_(screen), serial_(screen_serial), rst_(rst), baud_(baud) { @@ -17,6 +15,10 @@ void Screen::init() { this->serial_->begin(this->baud_); + // Set screen saver (SS) timeout and scroll speed + this->screen_->SSTimeout(this->screen_saver_timeout_ms_); + this->screen_->SSSpeed(this->screen_saver_scroll_speed_); + this->clear(); this->screen_->gfx_ScreenMode(PORTRAIT); @@ -47,8 +49,7 @@ void Screen::reset() { } void Screen::draw_image(word addr_hi, word addr_lo) { - if ((millis() - this->last_draw_time_) * MSECONDS_IN_SECOND > - this->wait_time_ms_) { + if ((millis() - this->last_draw_time_) > this->draw_speed_ms_) { this->screen_->media_SetSector(addr_hi, addr_lo); this->screen_->media_Image(0, 0); this->last_draw_time_ = millis(); From 9cbceb714935b1b125736d0c6f5bce5a1e8fe03b Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Tue, 17 Dec 2019 17:11:31 +0100 Subject: [PATCH 33/58] WIP: Add walk gait menu --- include/screen.h | 4 +- include/sd_sector_addresses.h | 402 +++++++++------------------------- include/state.h | 25 ++- include/state_machine.h | 6 +- src/main.cpp | 11 +- src/screen.cpp | 4 +- src/state_machine.cpp | 107 ++++++--- 7 files changed, 203 insertions(+), 356 deletions(-) diff --git a/include/screen.h b/include/screen.h index 892ee0e..b6b25b5 100644 --- a/include/screen.h +++ b/include/screen.h @@ -29,6 +29,8 @@ to the * * * * * */ #ifndef SCREEN_H #define SCREEN_H +#include "sd_sector_addresses.h" + #include #include #include @@ -40,7 +42,7 @@ class Screen { void init(); void clear(); - void draw_image(word addr_hi, word addr_lo); + void draw_image(SectorAddress address); private: void reset(); diff --git a/include/sd_sector_addresses.h b/include/sd_sector_addresses.h index e192675..0db5d2a 100644 --- a/include/sd_sector_addresses.h +++ b/include/sd_sector_addresses.h @@ -7,360 +7,168 @@ // - To load the desired images on the uSD card // - To find the sector addresses of said images (via generated .Gc file) -// HomeSitStart -#define HomeSitStart_Hi 0x0000 -#define HomeSitStart_Lo 0x0000 +// A sector address on the SD card is defined by +// an address consisting of two parts: high and low bits. +// Both parts specify 2 bytes of the complete address +// So, address = hi << 8 | lo +// These two are split, since that is how the 4dsystems +// serial library addresses images on the SD. +struct SectorAddress { + unsigned int hi; + unsigned int lo; +}; -// HomeSitStartSelected -#define HomeSitStartSelected_Hi 0x0000 -#define HomeSitStartSelected_Lo 0x00A2 +// clang-format off +#define HOME_SIT_START SectorAddress { 0x0000, 0x0000 } +#define HOME_SIT_START_SELECTED SectorAddress { 0x0000, 0x00A2 } +#define HOME_SIT_START_ACTIVATED SectorAddress { 0x0000, 0x0051 } -// HomeSitStartActivated -#define HomeSitStartActivated_Hi 0x0000 -#define HomeSitStartActivated_Lo 0x0051 +#define STAND_UP SectorAddress { 0x0000, 0x1209 } +#define STAND_UP_SELECTED SectorAddress { 0x0000, 0x12AB } +#define STAND_UP_ACTIVATED SectorAddress { 0x0000, 0x125A } -// StandUp -#define StandUp_Hi 0x0000 -#define StandUp_Lo 0x1209 +#define HOME_STAND_START SectorAddress { 0x0000, 0x01E6 } +#define HOME_STAND_START_SELECTED SectorAddress { 0x0000, 0x0288 } +#define HOME_STAND_START_ACTIVATED SectorAddress { 0x0000, 0x0237 } -// StandUpSelected -#define StandUpSelected_Hi 0x0000 -#define StandUpSelected_Lo 0x12AB +#define TURN_OFF_START SectorAddress { 0x0000, 0x14E2 } +#define TURN_OFF_START_SELECTED SectorAddress { 0x0000, 0x1584 } +#define TURN_OFF_START_ACTIVATED SectorAddress { 0x0000, 0x1533 } -// StandUpActivated -#define StandUpActivated_Hi 0x0000 -#define StandUpActivated_Lo 0x125A +// Walk menu gaits +#define WALK SectorAddress { 0x0000, 0x15D5 } +#define SIDE_STEP SectorAddress { 0x0000, 0x03CC } +#define SINGLE_STEP SectorAddress { 0x0000, 0x0603 } -// TurnOffStart -#define TurnOffStart_Hi 0x0000 -#define TurnOffStart_Lo 0x14E2 +// Walk sizes +#define WALK_SMALL SectorAddress { 0x0000, 0x1950 } +#define WALK_SMALL_SELECTED SectorAddress { 0x0000, 0x19F2 } +#define WALK_SMALL_ACTIVATED SectorAddress { 0x0000, 0x19A1 } -// TurnOffStartSelected -#define TurnOffStartSelected_Hi 0x0000 -#define TurnOffStartSelected_Lo 0x1584 +#define WALK_NORMAL SectorAddress { 0x0000, 0x1719 } +#define WALK_NORMAL_SELECTED SectorAddress { 0x0000, 0x17BB } +#define WALK_NORMAL_ACTIVATED SectorAddress { 0x0000, 0x176A } -// TurnOffStartActivated -#define TurnOffStartActivated_Hi 0x0000 -#define TurnOffStartActivated_Lo 0x1533 +#define WALK_LARGE SectorAddress { 0x0000, 0x1626 } +// Missing WALK_LARGE_SELECTED and WALK_LARGE_ACTIVATED -// HomeStandStart -#define HomeStandStart_Hi 0x0000 -#define HomeStandStart_Lo 0x01E6 +// Sidestep gaits +#define SIDE_STEP_LEFT SectorAddress { 0x0000, 0x041D } +#define SIDE_STEP_RIGHT SectorAddress { 0x0000, 0x0510 } -// HomeStandStartSelected unknown -#define HomeStandStartSelected_Hi 0x0000 -#define HomeStandStartSelected_Lo 0x0288 +// Side step left +#define SIDE_STEP_LEFT_SMALL SectorAddress { 0x0000, 0x2F76 } +#define SIDE_STEP_LEFT_SMALL_SELECTED SectorAddress { 0x0000, 0x3018 } +#define SIDE_STEP_LEFT_SMALL_ACTIVATED SectorAddress { 0x0000, 0x2FC7 } -// HomeStandStartActivated unknown -#define HomeStandStartActivated_Hi 0x0000 -#define HomeStandStartActivated_Lo 0x0237 +#define SIDE_STEP_LEFT_NORMAL SectorAddress { 0x0000, 0x2C9D } +#define SIDE_STEP_LEFT_NORMAL_SELECTED SectorAddress { 0x0000, 0x2D3F } +#define SIDE_STEP_LEFT_NORMAL_ACTIVATED SectorAddress { 0x0000, 0x2CEE } -// Sit -#define Sit_Hi 0x0000 -#define Sit_Lo 0x222C +// Side step right +#define SIDE_STEP_RIGHT_SMALL SectorAddress { 0x0000, 0x3069 } +#define SIDE_STEP_RIGHT_SMALL_SELECTED SectorAddress { 0x0000, 0x310B } +#define SIDE_STEP_RIGHT_SMALL_ACTIVATED SectorAddress { 0x0000, 0x30BA } -// SitSelected -#define SitSelected_Hi 0x0000 -#define SitSelected_Lo 0x0B13 +#define SIDE_STEP_RIGHT_NORMAL SectorAddress { 0x0000, 0x2D90 } +#define SIDE_STEP_RIGHT_NORMAL_SELECTED SectorAddress { 0x0000, 0x2E32 } +#define SIDE_STEP_RIGHT_NORMAL_ACTIVATED SectorAddress { 0x0000, 0x0000 } -// SitActivated -#define SitActivated_Hi 0x0000 -#define SitActivated_Lo 0x0AC2 +// Single steps +#define SINGLE_STEP_SMALL SectorAddress { 0x0000, 0x097E } +#define SINGLE_STEP_SMALL_SELECTED SectorAddress { 0x0000, 0x0A20 } +#define SINGLE_STEP_SMALL_ACTIVATED SectorAddress { 0x0000, 0x09CF } -// HomeSit -#define HomeSit_Hi 0x0000 -#define HomeSit_Lo 0x218A +#define SINGLE_STEP_NORMAL SectorAddress { 0x0000, 0x0747 } +#define SINGLE_STEP_NORMAL_SELECTED SectorAddress { 0x0000, 0x07E9 } +#define SINGLE_STEP_NORMAL_ACTIVATED SectorAddress { 0x0000, 0x0798 } -// HomeSitSelected -#define HomeSitSelected_Hi 0x0000 -#define HomeSitSelected_Lo 0x00A2 +#define SINGLE_STEP_LARGE SectorAddress { 0x0000, 0x0654 } -// HomeSitActivated -#define HomeSitActivated_Hi 0x0000 -#define HomeSitActivated_Lo 0x0051 +#define Sit SectorAddress { 0x0000, 0x222C } -// HomeStand -#define HomeStand_Hi 0x0000 -#define HomeStand_Lo 0x21DB +#define SitSelected SectorAddress { 0x0000, 0x0B13 } -// HomeStandSelected unknown -#define HomeStandSelected_Hi 0x0000 -#define HomeStandSelected_Lo 0x0288 - -// HomeStandActivated unknown -#define HomeStandActivated_Hi 0x0000 -#define HomeStandActivated_Lo 0x0237 - -// TurnOff -#define TurnOff_Hi 0x0000 -#define TurnOff_Lo 0x227D - -// TurnOffSelected -#define TurnOffSelected_Hi 0x0000 -#define TurnOffSelected_Lo 0x1491 - -// TurnOffActivated -#define TurnOffActivated_Hi 0x0000 -#define TurnOffActivated_Lo 0x1440 - -// Sofa -#define Sofa_Hi 0x0000 -#define Sofa_Lo 0x2505 - -// SofaSit -#define SofaSit_Hi 0x0000 -#define SofaSit_Lo 0x25F8 - -// SofaSitSelected -#define SofaSitSelected_Hi 0x0000 -#define SofaSitSelected_Lo 0x0E8E - -// SofaSitActivated -#define SofaSitActivated_Hi 0x0000 -#define SofaSitActivated_Lo 0x0E3D - -// SofaStandUp -#define SofaStandUp_Hi 0x0000 -#define SofaStandUp_Lo 0x2649 - -// SofaStandUpSelected -#define SofaStandUpSelected_Hi 0x0000 -#define SofaStandUpSelected_Lo 0x0F81 - -// SofaStandUpActivated -#define SofaStandUpActivated_Hi 0x0000 -#define SofaStandUpActivated_Lo 0x0F30 - -// Stairs -#define Stairs_Hi 0x0000 -#define Stairs_Lo 0x2556 - -// StairsUp -#define StairsUp_Hi 0x0000 -#define StairsUp_Lo 0x26EB - -// StairsUpSelected -#define StairsUpSelected_Hi 0x0000 -#define StairsUpSelected_Lo 0x11B8 - -// StairsUpActivated -#define StairsUpActivated_Hi 0x0000 -#define StairsUpActivated_Lo 0x1167 +#define SitActivated SectorAddress { 0x0000, 0x0AC2 } -// StairsDown -#define StairsDown_Hi 0x0000 -#define StairsDown_Lo 0x269A +#define HomeSit SectorAddress { 0x0000, 0x218A } -// StairsDownSelected, -#define StairsDownSelected_Hi 0x0000 -#define StairsDownSelected_Lo 0x10C5 +#define HomeSitSelected SectorAddress { 0x0000, 0x00A2 } -// StairsDownActivated -#define StairsDownActivated_Hi 0x0000 -#define StairsDownActivated_Lo 0x1074 +#define HomeSitActivated SectorAddress { 0x0000, 0x0051 } -// WalkObstacle -#define WalkObstacle_Hi 0x0000 -#define WalkObstacle_Lo 0x180C +#define HomeStand SectorAddress { 0x0000, 0x21DB } -// WalkObstacleSmall -#define WalkObstacleSmall_Hi 0x0000 -#define WalkObstacleSmall_Lo 0x18FF - -// WalkObstacleNormal -#define WalkObstacleNormal_Hi 0x0000 -#define WalkObstacleNormal_Lo 0x18AE - -// WalkObstacleLarge -#define WalkObstacleLarge_Hi 0x0000 -#define WalkObstacleLarge_Lo 0x185D - -// WalkObstacleSmallSelected -#define WalkObstacleSmallSelected_Hi 0x0000 -#define WalkObstacleSmallSelected_Lo 0x19F2 - -// WalkObstacleNormalSelected -#define WalkObstacleNormalSelected_Hi 0x0000 -#define WalkObstacleNormalSelected_Lo 0x17BB - -// WalkObstacleSmallActivated -#define WalkObstacleSmallActivated_Hi 0x0000 -#define WalkObstacleSmallActivated_Lo 0x19A1 - -// WalkObstacleNormalActivated -#define WalkObstacleNormalActivated_Hi 0x0000 -#define WalkObstacleNormalActivated_Lo 0x176A - -// SingleStepObstacle -#define SingleStepObstacle_Hi 0x0000 -#define SingleStepObstacle_Lo 0x083A - -// SingleStepObstacleSmall -#define SingleStepObstacleSmall_Hi 0x0000 -#define SingleStepObstacleSmall_Lo 0x092D - -// SingleStepObstacleNormal -#define SingleStepObstacleNormal_Hi 0x0000 -#define SingleStepObstacleNormal_Lo 0x08DC - -// SingleStepObstacleLarge -#define SingleStepObstacleLarge_Hi 0x0000 -#define SingleStepObstacleLarge_Lo 0x088B - -// SingleStepObstacleSmallSelected -#define SingleStepObstacleSmallSelected_Hi 0x0000 -#define SingleStepObstacleSmallSelected_Lo 0x0A20 - -// SingleStepObstacleNormalSelected -#define SingleStepObstacleNormalSelected_Hi 0x0000 -#define SingleStepObstacleNormalSelected_Lo 0x07E9 - -// SingleStepObstacleSmallActivated -#define SingleStepObstacleSmallActivated_Hi 0x0000 -#define SingleStepObstacleSmallActivated_Lo 0x09CF - -// SingleStepObstacleNormalActivated -#define SingleStepObstacleNormalActivated_Hi 0x0000 -#define SingleStepObstacleNormalActivated_Lo 0x0798 - -// Walk -#define Walk_Hi 0x0000 -#define Walk_Lo 0x15D5 +// HomeStandSelected unknown +#define HomeStandSelected SectorAddress { 0x0000, 0x0288 } -// WalkSmall -#define WalkSmall_Hi 0x0000 -#define WalkSmall_Lo 0x1950 +// HomeStandActivated unknown +#define HomeStandActivated SectorAddress { 0x0000, 0x0237 } -// WalkNormal -#define WalkNormal_Hi 0x0000 -#define WalkNormal_Lo 0x1719 +#define TurnOff SectorAddress { 0x0000, 0x227D } -// WalkLarge -#define WalkLarge_Hi 0x0000 -#define WalkLarge_Lo 0x1626 +#define TurnOffSelected SectorAddress { 0x0000, 0x1491 } -// WalkNormalSelected -#define WalkNormalSelected_Hi 0x0000 -#define WalkNormalSelected_Lo 0x17BB +#define TurnOffActivated SectorAddress { 0x0000, 0x1440 } -// WalkNormalActivated -#define WalkNormalActivated_Hi 0x0000 -#define WalkNormalActivated_Lo 0x176A +#define Sofa SectorAddress { 0x0000, 0x2505 } -// WalkSmallSelected -#define WalkSmallSelected_Hi 0x0000 -#define WalkSmallSelected_Lo 0x19F2 +#define SofaSit SectorAddress { 0x0000, 0x25F8 } -// WalkSmallActivated -#define WalkSmallActivated_Hi 0x0000 -#define WalkSmallActivated_Lo 0x19A1 +#define SofaSitSelected SectorAddress { 0x0000, 0x0E8E } -// SingleStep -#define SingleStep_Hi 0x0000 -#define SingleStep_Lo 0x0603 +#define SofaSitActivated SectorAddress { 0x0000, 0x0E3D } -// SingleStepSmall -#define SingleStepSmall_Hi 0x0000 -#define SingleStepSmall_Lo 0x097E +#define SofaStandUp SectorAddress { 0x0000, 0x2649 } -// SingleStepNormal -#define SingleStepNormal_Hi 0x0000 -#define SingleStepNormal_Lo 0x0747 +#define SofaStandUpSelected SectorAddress { 0x0000, 0x0F81 } -// SingleStepLarge -#define SingleStepLarge_Hi 0x0000 -#define SingleStepLarge_Lo 0x0654 +#define SofaStandUpActivated SectorAddress { 0x0000, 0x0F30 } -// SingleStepSmallSelected -#define SingleStepSmallSelected_Hi 0x0000 -#define SingleStepSmallSelected_Lo 0x0A20 +#define Stairs SectorAddress { 0x0000, 0x2556 } -// SingleStepNormalSelected -#define SingleStepNormalSelected_Hi 0x0000 -#define SingleStepNormalSelected_Lo 0x07E9 +#define StairsUp SectorAddress { 0x0000, 0x26EB } -// SingleStepSmallActivated -#define SingleStepSmallActivated_Hi 0x0000 -#define SingleStepSmallActivated_Lo 0x09CF +#define StairsUpSelected SectorAddress { 0x0000, 0x11B8 } -// SingleStepNormalActivated -#define SingleStepNormalActivated_Hi 0x0000 -#define SingleStepNormalActivated_Lo 0x0798 +#define StairsUpActivated SectorAddress { 0x0000, 0x1167 } -// SideStep -#define SideStep_Hi 0x0000 -#define SideStep_Lo 0x03CC +#define StairsDown SectorAddress { 0x0000, 0x269A } -// SideStepLeft -#define SideStepLeft_Hi 0x0000 -#define SideStepLeft_Lo 0x041D +#define StairsDownSelected SectorAddress { 0x0000, 0x10C5 } -// SideStepRight -#define SideStepRight_Hi 0x0000 -#define SideStepRight_Lo 0x0510 +#define StairsDownActivated SectorAddress { 0x0000, 0x1074 } -// SideStepLeftSelected -#define SideStepLeftSelected_Hi 0x0000 -#define SideStepLeftSelected_Lo 0x04BF +#define WalkObstacle SectorAddress { 0x0000, 0x180C } -// SideStepRightSelected -#define SideStepRightSelected_Hi 0x0000 -#define SideStepRightSelected_Lo 0x05B2 +#define WalkObstacleSmall SectorAddress { 0x0000, 0x18FF } -// SideStepLeftActivated -#define SideStepLeftActivated_Hi 0x0000 -#define SideStepLeftActivated_Lo 0x046E +#define WalkObstacleNormal SectorAddress { 0x0000, 0x18AE } -// SideStepRightActivated -#define SideStepRightActivated_Hi 0x0000 -#define SideStepRightActivated_Lo 0x0561 +#define WalkObstacleLarge SectorAddress { 0x0000, 0x185D } -// SiderStepLeftSmall -#define SideStepLeftSmall_Hi 0x0000 -#define SideStepLeftSmall_Lo 0x2F76 +#define WalkObstacleSmallSelected SectorAddress { 0x0000, 0x19F2 } -// SideStepLeftSmallSelected -#define SideStepLeftSmallSelected_Hi 0x0000 -#define SideStepLeftSmallSelected_Lo 0x3018 +#define WalkObstacleNormalSelected SectorAddress { 0x0000, 0x17BB } -// SideStepLeftSmallActivated -#define SideStepLeftSmallActivated_Hi 0x0000 -#define SideStepLeftSmallActivated_Lo 0x2FC7 +#define WalkObstacleSmallActivated SectorAddress { 0x0000, 0x19A1 } -// SideStepLeftNormal -#define SideStepLeftNormal_Hi 0x0000 -#define SideStepLeftNormal_Lo 0x2C9D +#define WalkObstacleNormalActivated SectorAddress { 0x0000, 0x176A } -// SideStepLeftNormalSelected -#define SideStepLeftNormalSelected_Hi 0x0000 -#define SideStepLeftNormalSelected_Lo 0x2D3F +#define SingleStepObstacle SectorAddress { 0x0000, 0x083A } -// SideStepLeftNormalActivated -#define SideStepLeftNormalActivated_Hi 0x0000 -#define SideStepLeftNormalActivated_Lo 0x2CEE +#define SingleStepObstacleSmall SectorAddress { 0x0000, 0x092D } -// SiderStepRightSmall -#define SideStepRightSmall_Hi 0x0000 -#define SideStepRightSmall_Lo 0x3069 +#define SingleStepObstacleNormal SectorAddress { 0x0000, 0x08DC } -// SideStepRightRightSelected -#define SideStepRightSmallSelected_Hi 0x0000 -#define SideStepRightSmallSelected_Lo 0x310B +#define SingleStepObstacleLarge SectorAddress { 0x0000, 0x088B } -// SideStepRightSmallActivated -#define SideStepRightSmallActivated_Hi 0x0000 -#define SideStepRightSmallActivated_Lo 0x30BA +#define SingleStepObstacleSmallSelected SectorAddress { 0x0000, 0x0A20 } -// SideStepRightNormal -#define SideStepRightNormal_Hi 0x0000 -#define SideStepRightNormal_Lo 0x2D90 +#define SingleStepObstacleNormalSelected SectorAddress { 0x0000, 0x07E9 } -// SideStepRightNormalSelected -#define SideStepRightNormalSelected_Hi 0x0000 -#define SideStepRightNormalSelected_Lo 0x2E32 +#define SingleStepObstacleSmallActivated SectorAddress { 0x0000, 0x09CF } -// SideStepRightNormalActivated -#define SideStepRightNormalActivated_Hi 0x0000 -#define SideStepRightNormalActivated_Lo +#define SingleStepObstacleNormalActivated SectorAddress { 0x0000, 0x0798 } #endif // SD_SECTOR_ADDRESSES_H diff --git a/include/state.h b/include/state.h index 64d2356..c5048fb 100644 --- a/include/state.h +++ b/include/state.h @@ -1,23 +1,20 @@ #ifndef STATE_H #define STATE_H +#include "sd_sector_addresses.h" + #include class State { public: - State(const unsigned int address_hi, const unsigned int address_lo, - const std::string& gait) - : gait_(gait), image_address_hi_(address_hi), - image_address_lo_(address_lo) {} + State(SectorAddress address, const std::string& gait) + : gait_(gait), address_(address) {} - State(const unsigned int address_hi, const unsigned int address_lo) - : State(address_hi, address_lo, "") {} + State(SectorAddress address) : State(address, "") {} const std::string& getGaitName() const { return this->gait_; } - void getImage(unsigned int& image_address_hi, - unsigned int& image_address_lo) const { - image_address_hi = this->image_address_hi_; - image_address_lo = this->image_address_lo_; + void getImage(SectorAddress& image_address) const { + image_address = this->address_; }; const State* left() const { return this->left_; } @@ -59,6 +56,11 @@ class State { return *this; } + State& backFrom(State* from) { + from->back_ = this; + return *this; + } + State& withSelect(State* select) { this->select_ = select; select->back_ = this; @@ -72,8 +74,7 @@ class State { private: const std::string gait_; - const unsigned int image_address_hi_; - const unsigned int image_address_lo_; + const SectorAddress address_; const State* left_ = this; const State* right_ = this; diff --git a/include/state_machine.h b/include/state_machine.h index dacff0b..2328250 100644 --- a/include/state_machine.h +++ b/include/state_machine.h @@ -13,8 +13,7 @@ class StateMachine { std::string getCurrentGaitName() const; - void getCurrentImage(unsigned int& address_hi, - unsigned int& address_lo) const; + void getCurrentImage(SectorAddress& address) const; size_t size() const; @@ -31,8 +30,7 @@ class StateMachine { bool hasState() const; bool setCurrentState(const State* new_state); - State& createState(const unsigned int address_hi, - const unsigned int address_lo, + State& createState(const SectorAddress address, const std::string& gait_name = ""); std::list states_; diff --git a/src/main.cpp b/src/main.cpp index ecbbd87..1ad7810 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -92,6 +92,7 @@ void sendGaitMessage(const std::string& name) { gait_instruction_publisher.publish(&gait_instruction_msg); gait_message_send = true; #ifdef DEMO_INPUT_DEVICE + sleep(1); received_gait_instruction_response = true; #endif } @@ -109,10 +110,9 @@ void sendAliveMessage() { } void drawCurrentImage() { - word address_hi = 0; - word address_lo = 0; - state_machine.getCurrentImage(address_hi, address_lo); - screen.draw_image(address_hi, address_lo); + SectorAddress address; + state_machine.getCurrentImage(address); + screen.draw_image(address); } void setup() { @@ -172,7 +172,7 @@ void loop() { // This means gait instruction handled received_gait_instruction_response = false; gait_message_send = false; - state_machine.activate(); + state_has_changed = state_machine.activate(); } else if (gait_message_send) { if (joystick_state == ButtonState::PUSH) { sendStopMessage(); @@ -195,7 +195,6 @@ void loop() { } } - if (state_has_changed) { drawCurrentImage(); diff --git a/src/screen.cpp b/src/screen.cpp index da5e4c3..d5c96ed 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -48,9 +48,9 @@ void Screen::reset() { sleep(3); } -void Screen::draw_image(word addr_hi, word addr_lo) { +void Screen::draw_image(SectorAddress address) { if ((millis() - this->last_draw_time_) > this->draw_speed_ms_) { - this->screen_->media_SetSector(addr_hi, addr_lo); + this->screen_->media_SetSector(address.hi, address.lo); this->screen_->media_Image(0, 0); this->last_draw_time_ = millis(); } diff --git a/src/state_machine.cpp b/src/state_machine.cpp index 353a3a6..445037e 100644 --- a/src/state_machine.cpp +++ b/src/state_machine.cpp @@ -2,37 +2,78 @@ #include "sd_sector_addresses.h" void StateMachine::construct() { - State& home_sit_start = this->createState(HomeSitStart_Hi, HomeSitStart_Lo); - State& home_sit_start_activated = this->createState( - HomeSitStartActivated_Hi, HomeSitStartActivated_Lo, "home_sit"); - State& home_sit_start_selected = - this->createState(HomeSitStartSelected_Hi, HomeSitStartSelected_Lo) - .withBack(&home_sit_start) - .withActivate(&home_sit_start_activated); - - State& stand_up = - this->createState(StandUp_Hi, StandUp_Lo).withLeft(&home_sit_start); + State& walk_small = this->createState(WALK_SMALL); + State& walk_normal = this->createState(WALK_NORMAL).withLeft(&walk_small); + State& walk_large = this->createState(WALK_LARGE) + .withLeft(&walk_normal) + .withRight(&walk_small); + + State& side_step_left = this->createState(SIDE_STEP_LEFT); + State& side_step_right = this->createState(SIDE_STEP_RIGHT) + .withLeft(&side_step_left) + .withRight(&side_step_left); + + State& single_step_small = this->createState(SINGLE_STEP_SMALL); + State& single_step_normal = + this->createState(SINGLE_STEP_NORMAL).withLeft(&single_step_small); + State& single_step_large = this->createState(SINGLE_STEP_LARGE) + .withLeft(&single_step_normal) + .withRight(&single_step_small); + + State& side_step_left_small = this->createState(SIDE_STEP_LEFT_SMALL); + State& side_step_left_small_selected = + this->createState(SIDE_STEP_LEFT_SMALL_SELECTED); + State& side_step_left_small_activated = + this->createState(SIDE_STEP_LEFT_SMALL_ACTIVATED); + + State& side_step_left_normal = this->createState(SIDE_STEP_LEFT_NORMAL); + State& side_step_left_normal_selected = + this->createState(SIDE_STEP_LEFT_NORMAL_SELECTED); + State& side_step_left_normal_activated = + this->createState(SIDE_STEP_LEFT_NORMAL_ACTIVATED); + + State& walk = this->createState(WALK) + .withSelect(&walk_normal) + .backFrom(&walk_small) + .backFrom(&walk_large); + State& side_step = this->createState(SIDE_STEP) + .withRight(&walk) + .withSelect(&side_step_left) + .backFrom(&side_step_right); + State& single_step = this->createState(SINGLE_STEP) + .withLeft(&walk) + .withRight(&side_step) + .withSelect(&single_step_normal) + .backFrom(&single_step_small) + .backFrom(&single_step_large); + + State& home_sit_start = this->createState(HOME_SIT_START); + State& home_sit_start_activated = + this->createState(HOME_SIT_START_ACTIVATED, "home_sit"); + State& home_sit_start_selected = this->createState(HOME_SIT_START_SELECTED) + .withBack(&home_sit_start) + .withActivate(&home_sit_start_activated); + + State& stand_up = this->createState(STAND_UP).withLeft(&home_sit_start); State& stand_up_activated = - this->createState(StandUpActivated_Hi, StandUpActivated_Lo, "gait_sit"); - State& stand_up_selected = - this->createState(StandUpSelected_Hi, StandUpSelected_Lo) - .withBack(&stand_up) - .withActivate(&stand_up_activated); + this->createState(STAND_UP_ACTIVATED).withActivate(&walk); + State& stand_up_selected = this->createState(STAND_UP_SELECTED) + .withBack(&stand_up) + .withActivate(&stand_up_activated); State& home_stand_start = - this->createState(HomeStandStart_Hi, HomeStandStart_Lo) - .withLeft(&stand_up); - State& home_stand_activated = this->createState( - HomeStandActivated_Hi, HomeStandActivated_Lo, "home_stand"); - State& home_stand_selected = - this->createState(HomeStandSelected_Hi, HomeStandSelected_Lo) - .withBack(&home_stand_start) - .withActivate(&home_stand_activated); - State& power_off = this->createState(TurnOff_Hi, TurnOff_Lo) - .withLeft(&home_stand_start) - .withRight(&home_sit_start); - - this->current_state_ = &this->states_.front(); + this->createState(HOME_STAND_START).withLeft(&stand_up); + State& home_stand_activated = + this->createState(HOME_STAND_START_ACTIVATED, "home_stand") + .withActivate(&walk); + State& home_stand_selected = this->createState(HOME_STAND_START_SELECTED) + .withBack(&home_stand_start) + .withActivate(&home_stand_activated); + State& turn_off = this->createState(TURN_OFF_START) + .withLeft(&home_stand_start) + .withRight(&home_sit_start); + + this->current_state_ = &home_sit_start; } std::string StateMachine::getCurrentGaitName() const { @@ -42,10 +83,9 @@ std::string StateMachine::getCurrentGaitName() const { return std::string(); } -void StateMachine::getCurrentImage(unsigned int& address_hi, - unsigned int& address_lo) const { +void StateMachine::getCurrentImage(SectorAddress& address) const { if (this->hasState()) { - this->current_state_->getImage(address_hi, address_lo); + this->current_state_->getImage(address); } } @@ -97,9 +137,8 @@ bool StateMachine::setCurrentState(const State* new_state) { return has_changed; } -State& StateMachine::createState(const unsigned int address_hi, - const unsigned int address_lo, +State& StateMachine::createState(const SectorAddress address, const std::string& gait_name) { - this->states_.emplace_back(address_hi, address_lo, gait_name); + this->states_.emplace_back(address, gait_name); return this->states_.back(); } \ No newline at end of file From 7e18afc3fe7007bdcab35d4ae0c03ae86a8bd9f8 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Tue, 17 Dec 2019 17:21:25 +0100 Subject: [PATCH 34/58] Fix state test --- test/test_state/test_state.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/test/test_state/test_state.cpp b/test/test_state/test_state.cpp index 23435c9..b1cf5c8 100644 --- a/test/test_state/test_state.cpp +++ b/test/test_state/test_state.cpp @@ -6,24 +6,22 @@ void test_state_get_gait_name() { std::string gait("test"); - State state(0, 0, gait); + State state({ 0, 0 }, gait); TEST_ASSERT_EQUAL_STRING(gait.c_str(), state.getGaitName().c_str()); } void test_state_get_address() { - unsigned int expected_hi = 7; - unsigned int expected_lo = 8; - State state(expected_hi, expected_lo); - - unsigned int hi = 0; - unsigned int lo = 0; - state.getImage(hi, lo); - TEST_ASSERT_EQUAL(expected_hi, hi); - TEST_ASSERT_EQUAL(expected_lo, lo); + SectorAddress expected = { 7, 8 }; + State state(expected); + + SectorAddress address; + state.getImage(address); + TEST_ASSERT_EQUAL(expected.hi, address.hi); + TEST_ASSERT_EQUAL(expected.lo, address.lo); } void test_state_default_transitions() { - State state(0, 0); + State state({ 0, 0 }); TEST_ASSERT_EQUAL(&state, state.left()); TEST_ASSERT_EQUAL(&state, state.right()); TEST_ASSERT_EQUAL(&state, state.up()); From fd40cc6e14dc2a88be6b5dec353edc458278ce08 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Tue, 17 Dec 2019 22:09:12 +0100 Subject: [PATCH 35/58] Fix clang format --- test/test_state/test_state.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/test_state/test_state.cpp b/test/test_state/test_state.cpp index b1cf5c8..e09524e 100644 --- a/test/test_state/test_state.cpp +++ b/test/test_state/test_state.cpp @@ -6,12 +6,12 @@ void test_state_get_gait_name() { std::string gait("test"); - State state({ 0, 0 }, gait); + State state({0, 0}, gait); TEST_ASSERT_EQUAL_STRING(gait.c_str(), state.getGaitName().c_str()); } void test_state_get_address() { - SectorAddress expected = { 7, 8 }; + SectorAddress expected = {7, 8}; State state(expected); SectorAddress address; @@ -21,7 +21,7 @@ void test_state_get_address() { } void test_state_default_transitions() { - State state({ 0, 0 }); + State state({0, 0}); TEST_ASSERT_EQUAL(&state, state.left()); TEST_ASSERT_EQUAL(&state, state.right()); TEST_ASSERT_EQUAL(&state, state.up()); From 4b89eccb1794cc43375c02e5c7fb70c731739e07 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Tue, 17 Dec 2019 22:44:00 +0100 Subject: [PATCH 36/58] Fix state machine test --- platformio.ini | 5 +++-- test/test_state_machine/test_state_machine.cpp | 18 +++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/platformio.ini b/platformio.ini index c4cfb5a..819833d 100644 --- a/platformio.ini +++ b/platformio.ini @@ -63,5 +63,6 @@ build_flags = -std=c++11 -O3 -D RELEASE [env:native] platform = native test_build_project_src = true -test_filter = test_state -src_filter = + +test_filter = test_state, test_state_machine +src_filter = + + diff --git a/test/test_state_machine/test_state_machine.cpp b/test/test_state_machine/test_state_machine.cpp index e025583..3aac458 100644 --- a/test/test_state_machine/test_state_machine.cpp +++ b/test/test_state_machine/test_state_machine.cpp @@ -12,13 +12,11 @@ void test_get_gait_name() { void test_get_image() { StateMachine state_machine; - unsigned int expected_hi = 2; - unsigned int expected_lo = 3; - unsigned int hi = expected_hi; - unsigned int lo = expected_lo; - state_machine.getCurrentImage(hi, lo); - TEST_ASSERT_EQUAL(expected_hi, hi); - TEST_ASSERT_EQUAL(expected_lo, lo); + SectorAddress expected({2, 3}); + SectorAddress address = expected; + state_machine.getCurrentImage(address); + TEST_ASSERT_EQUAL(expected.hi, address.hi); + TEST_ASSERT_EQUAL(expected.lo, address.lo); } void test_state_machine_default_no_transitions() { @@ -32,11 +30,17 @@ void test_state_machine_default_no_transitions() { TEST_ASSERT_FALSE(state_machine.activate()); } +void test_default_empty() { + StateMachine state_machine; + TEST_ASSERT_EQUAL(0, state_machine.size()); +} + int main(int argc, char** argv) { UNITY_BEGIN(); RUN_TEST(test_get_gait_name); RUN_TEST(test_get_image); RUN_TEST(test_state_machine_default_no_transitions); + RUN_TEST(test_default_empty); UNITY_END(); return 0; From bf9f7fe730a77b1b57ed8f00a40af62b73cf211b Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Tue, 17 Dec 2019 22:46:27 +0100 Subject: [PATCH 37/58] Complete refactor sd sector addresses --- include/sd_sector_addresses.h | 122 +++++++++++++--------------------- 1 file changed, 45 insertions(+), 77 deletions(-) diff --git a/include/sd_sector_addresses.h b/include/sd_sector_addresses.h index 0db5d2a..4a8b8ce 100644 --- a/include/sd_sector_addresses.h +++ b/include/sd_sector_addresses.h @@ -19,6 +19,10 @@ struct SectorAddress { }; // clang-format off + +/********** + * Start menu + **********/ #define HOME_SIT_START SectorAddress { 0x0000, 0x0000 } #define HOME_SIT_START_SELECTED SectorAddress { 0x0000, 0x00A2 } #define HOME_SIT_START_ACTIVATED SectorAddress { 0x0000, 0x0051 } @@ -34,8 +38,11 @@ struct SectorAddress { #define TURN_OFF_START SectorAddress { 0x0000, 0x14E2 } #define TURN_OFF_START_SELECTED SectorAddress { 0x0000, 0x1584 } #define TURN_OFF_START_ACTIVATED SectorAddress { 0x0000, 0x1533 } +/***** Start menu *****/ -// Walk menu gaits +/********** + * Walk menu + **********/ #define WALK SectorAddress { 0x0000, 0x15D5 } #define SIDE_STEP SectorAddress { 0x0000, 0x03CC } #define SINGLE_STEP SectorAddress { 0x0000, 0x0603 } @@ -52,7 +59,7 @@ struct SectorAddress { #define WALK_LARGE SectorAddress { 0x0000, 0x1626 } // Missing WALK_LARGE_SELECTED and WALK_LARGE_ACTIVATED -// Sidestep gaits +// Sidestep #define SIDE_STEP_LEFT SectorAddress { 0x0000, 0x041D } #define SIDE_STEP_RIGHT SectorAddress { 0x0000, 0x0510 } @@ -84,91 +91,52 @@ struct SectorAddress { #define SINGLE_STEP_NORMAL_ACTIVATED SectorAddress { 0x0000, 0x0798 } #define SINGLE_STEP_LARGE SectorAddress { 0x0000, 0x0654 } +/***** Walk menu *****/ -#define Sit SectorAddress { 0x0000, 0x222C } - -#define SitSelected SectorAddress { 0x0000, 0x0B13 } - -#define SitActivated SectorAddress { 0x0000, 0x0AC2 } - -#define HomeSit SectorAddress { 0x0000, 0x218A } - -#define HomeSitSelected SectorAddress { 0x0000, 0x00A2 } - -#define HomeSitActivated SectorAddress { 0x0000, 0x0051 } - -#define HomeStand SectorAddress { 0x0000, 0x21DB } - -// HomeStandSelected unknown -#define HomeStandSelected SectorAddress { 0x0000, 0x0288 } - -// HomeStandActivated unknown -#define HomeStandActivated SectorAddress { 0x0000, 0x0237 } - -#define TurnOff SectorAddress { 0x0000, 0x227D } - -#define TurnOffSelected SectorAddress { 0x0000, 0x1491 } - -#define TurnOffActivated SectorAddress { 0x0000, 0x1440 } - -#define Sofa SectorAddress { 0x0000, 0x2505 } - -#define SofaSit SectorAddress { 0x0000, 0x25F8 } - -#define SofaSitSelected SectorAddress { 0x0000, 0x0E8E } - -#define SofaSitActivated SectorAddress { 0x0000, 0x0E3D } - -#define SofaStandUp SectorAddress { 0x0000, 0x2649 } - -#define SofaStandUpSelected SectorAddress { 0x0000, 0x0F81 } - -#define SofaStandUpActivated SectorAddress { 0x0000, 0x0F30 } - -#define Stairs SectorAddress { 0x0000, 0x2556 } - -#define StairsUp SectorAddress { 0x0000, 0x26EB } - -#define StairsUpSelected SectorAddress { 0x0000, 0x11B8 } - -#define StairsUpActivated SectorAddress { 0x0000, 0x1167 } - -#define StairsDown SectorAddress { 0x0000, 0x269A } - -#define StairsDownSelected SectorAddress { 0x0000, 0x10C5 } - -#define StairsDownActivated SectorAddress { 0x0000, 0x1074 } - -#define WalkObstacle SectorAddress { 0x0000, 0x180C } - -#define WalkObstacleSmall SectorAddress { 0x0000, 0x18FF } - -#define WalkObstacleNormal SectorAddress { 0x0000, 0x18AE } - -#define WalkObstacleLarge SectorAddress { 0x0000, 0x185D } - -#define WalkObstacleSmallSelected SectorAddress { 0x0000, 0x19F2 } - -#define WalkObstacleNormalSelected SectorAddress { 0x0000, 0x17BB } +/********** + * Sit menu + **********/ +#define SIT SectorAddress { 0x0000, 0x222C } +#define SIT_SELECTED SectorAddress { 0x0000, 0x0B13 } +#define SIT_ACTIVATED SectorAddress { 0x0000, 0x0AC2 } -#define WalkObstacleSmallActivated SectorAddress { 0x0000, 0x19A1 } +#define HOME_SIT SectorAddress { 0x0000, 0x218A } +#define HOME_SIT_SELECTED SectorAddress { 0x0000, 0x00A2 } +#define HOME_SIT_ACTIVATED SectorAddress { 0x0000, 0x0051 } -#define WalkObstacleNormalActivated SectorAddress { 0x0000, 0x176A } +#define HOME_STAND SectorAddress { 0x0000, 0x21DB } +#define HOME_STAND_SELECTED SectorAddress { 0x0000, 0x0288 } +#define HOME_STAND_ACTIVATED SectorAddress { 0x0000, 0x0237 } -#define SingleStepObstacle SectorAddress { 0x0000, 0x083A } +#define TURN_OFF SectorAddress { 0x0000, 0x227D } +#define TURN_OFF_SELECTED SectorAddress { 0x0000, 0x1491 } +#define TURN_OFF_ACTIVATED SectorAddress { 0x0000, 0x1440 } +/***** Sit menu *****/ -#define SingleStepObstacleSmall SectorAddress { 0x0000, 0x092D } +/********** + * Obstacle menu + **********/ +#define SOFA SectorAddress { 0x0000, 0x2505 } -#define SingleStepObstacleNormal SectorAddress { 0x0000, 0x08DC } +#define SOFA_SIT SectorAddress { 0x0000, 0x25F8 } +#define SOFA_SIT_SELECTED SectorAddress { 0x0000, 0x0E8E } +#define SOFA_SIT_ACTIVATED SectorAddress { 0x0000, 0x0E3D } -#define SingleStepObstacleLarge SectorAddress { 0x0000, 0x088B } +#define SOFA_STANDUP SectorAddress { 0x0000, 0x2649 } +#define SOFA_STANDUP_SELECTED SectorAddress { 0x0000, 0x0F81 } +#define SOFA_STANDUP_ACTIVATED SectorAddress { 0x0000, 0x0F30 } -#define SingleStepObstacleSmallSelected SectorAddress { 0x0000, 0x0A20 } +#define STAIRS SectorAddress { 0x0000, 0x2556 } -#define SingleStepObstacleNormalSelected SectorAddress { 0x0000, 0x07E9 } +#define STAIRS_UP SectorAddress { 0x0000, 0x26EB } +#define STAIRS_UP_SELECTED SectorAddress { 0x0000, 0x11B8 } +#define STAIRS_UP_ACTIVATED SectorAddress { 0x0000, 0x1167 } -#define SingleStepObstacleSmallActivated SectorAddress { 0x0000, 0x09CF } +#define STAIRS_DOWN SectorAddress { 0x0000, 0x269A } +#define STAIRS_DOWN_SELECTED SectorAddress { 0x0000, 0x10C5 } +#define STAIRS_DOWN_ACTIVATED SectorAddress { 0x0000, 0x1074 } +/***** Obstacle menu *****/ -#define SingleStepObstacleNormalActivated SectorAddress { 0x0000, 0x0798 } +// clang-format on #endif // SD_SECTOR_ADDRESSES_H From 8e609c046e5a4a7f0c3aa40b2f87cc41d460d815 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Tue, 17 Dec 2019 23:35:07 +0100 Subject: [PATCH 38/58] Add all states to construct --- src/state_machine.cpp | 104 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 86 insertions(+), 18 deletions(-) diff --git a/src/state_machine.cpp b/src/state_machine.cpp index 445037e..c3793c2 100644 --- a/src/state_machine.cpp +++ b/src/state_machine.cpp @@ -3,7 +3,15 @@ void StateMachine::construct() { State& walk_small = this->createState(WALK_SMALL); + State& walk_small_selected = this->createState(WALK_SMALL_SELECTED); + State& walk_small_activated = + this->createState(WALK_SMALL_ACTIVATED, "gait_walk_small"); State& walk_normal = this->createState(WALK_NORMAL).withLeft(&walk_small); + State& walk_normal_selected = + this->createState(WALK_NORMAL_SELECTED).withLeft(&walk_small); + State& walk_normal_activated = + this->createState(WALK_NORMAL_ACTIVATED, "gait_walk") + .withLeft(&walk_small); State& walk_large = this->createState(WALK_LARGE) .withLeft(&walk_normal) .withRight(&walk_small); @@ -13,24 +21,44 @@ void StateMachine::construct() { .withLeft(&side_step_left) .withRight(&side_step_left); - State& single_step_small = this->createState(SINGLE_STEP_SMALL); - State& single_step_normal = - this->createState(SINGLE_STEP_NORMAL).withLeft(&single_step_small); - State& single_step_large = this->createState(SINGLE_STEP_LARGE) - .withLeft(&single_step_normal) - .withRight(&single_step_small); - State& side_step_left_small = this->createState(SIDE_STEP_LEFT_SMALL); State& side_step_left_small_selected = this->createState(SIDE_STEP_LEFT_SMALL_SELECTED); - State& side_step_left_small_activated = - this->createState(SIDE_STEP_LEFT_SMALL_ACTIVATED); + State& side_step_left_small_activated = this->createState( + SIDE_STEP_LEFT_SMALL_ACTIVATED, "gait_side_step_left_small"); State& side_step_left_normal = this->createState(SIDE_STEP_LEFT_NORMAL); State& side_step_left_normal_selected = this->createState(SIDE_STEP_LEFT_NORMAL_SELECTED); State& side_step_left_normal_activated = - this->createState(SIDE_STEP_LEFT_NORMAL_ACTIVATED); + this->createState(SIDE_STEP_LEFT_NORMAL_ACTIVATED, "gait_side_step_left"); + + State& side_step_right_small = this->createState(SIDE_STEP_RIGHT_SMALL); + State& side_step_right_small_selected = + this->createState(SIDE_STEP_RIGHT_SMALL_SELECTED); + State& side_step_right_small_activated = this->createState( + SIDE_STEP_RIGHT_SMALL_ACTIVATED, "gait_side_step_right_small"); + + State& side_step_right_normal = this->createState(SIDE_STEP_RIGHT_NORMAL); + State& side_step_right_normal_selected = + this->createState(SIDE_STEP_RIGHT_NORMAL_SELECTED); + State& side_step_right_normal_activated = this->createState( + SIDE_STEP_RIGHT_NORMAL_ACTIVATED, "gait_side_step_right"); + + State& single_step_small = this->createState(SINGLE_STEP_SMALL); + State& single_step_small_selected = + this->createState(SINGLE_STEP_SMALL_SELECTED); + State& single_step_small_activated = + this->createState(SINGLE_STEP_SMALL_ACTIVATED, "gait_single_step_normal"); + State& single_step_normal = + this->createState(SINGLE_STEP_NORMAL).withLeft(&single_step_small); + State& single_step_normal_selected = + this->createState(SINGLE_STEP_NORMAL_SELECTED); + State& single_step_normal_activated = this->createState( + SINGLE_STEP_NORMAL_ACTIVATED, "gait_single_step_normal"); + State& single_step_large = this->createState(SINGLE_STEP_LARGE) + .withLeft(&single_step_normal) + .withRight(&single_step_small); State& walk = this->createState(WALK) .withSelect(&walk_normal) @@ -47,6 +75,45 @@ void StateMachine::construct() { .backFrom(&single_step_small) .backFrom(&single_step_large); + State& sit = this->createState(SIT); + State& sit_selected = this->createState(SIT_SELECTED); + State& sit_activated = this->createState(SIT_ACTIVATED, "gait_sit"); + + State& home_sit = this->createState(HOME_SIT); + State& home_sit_selected = this->createState(HOME_SIT_SELECTED); + State& home_sit_activated = this->createState(HOME_SIT_ACTIVATED, "home_sit"); + + State& home_stand = this->createState(HOME_STAND); + State& home_stand_selected = this->createState(HOME_STAND_SELECTED); + State& home_stand_activated = + this->createState(HOME_STAND_ACTIVATED, "home_stand"); + + State& turn_off = this->createState(TURN_OFF); + + State& sofa_sit = this->createState(SOFA_SIT); + State& sofa_sit_selected = this->createState(SOFA_SIT_SELECTED); + State& sofa_sit_activated = + this->createState(SOFA_SIT_ACTIVATED, "gait_sofa_sit"); + + State& sofa_standup = this->createState(SOFA_STANDUP); + State& sofa_standup_selected = this->createState(SOFA_STANDUP_SELECTED); + State& sofa_standup_activated = + this->createState(SOFA_STANDUP_ACTIVATED, "gait_sofa_stand"); + + State& stairs_up = this->createState(STAIRS_UP); + State& stairs_up_selected = this->createState(STAIRS_UP_SELECTED); + State& stairs_up_activated = + this->createState(STAIRS_UP_ACTIVATED, "gait_stairs_up"); + + State& stairs_down = this->createState(STAIRS_DOWN); + State& stairs_down_selected = this->createState(STAIRS_DOWN_SELECTED); + State& stairs_down_activated = + this->createState(STAIRS_DOWN_ACTIVATED, "gait_stairs_down"); + + State& sofa = this->createState(SOFA); + + State& stairs = this->createState(STAIRS); + State& home_sit_start = this->createState(HOME_SIT_START); State& home_sit_start_activated = this->createState(HOME_SIT_START_ACTIVATED, "home_sit"); @@ -56,22 +123,23 @@ void StateMachine::construct() { State& stand_up = this->createState(STAND_UP).withLeft(&home_sit_start); State& stand_up_activated = - this->createState(STAND_UP_ACTIVATED).withActivate(&walk); + this->createState(STAND_UP_ACTIVATED, "gait_stand").withActivate(&walk); State& stand_up_selected = this->createState(STAND_UP_SELECTED) .withBack(&stand_up) .withActivate(&stand_up_activated); State& home_stand_start = this->createState(HOME_STAND_START).withLeft(&stand_up); - State& home_stand_activated = + State& home_stand_start_activated = this->createState(HOME_STAND_START_ACTIVATED, "home_stand") .withActivate(&walk); - State& home_stand_selected = this->createState(HOME_STAND_START_SELECTED) - .withBack(&home_stand_start) - .withActivate(&home_stand_activated); - State& turn_off = this->createState(TURN_OFF_START) - .withLeft(&home_stand_start) - .withRight(&home_sit_start); + State& home_stand_start_selected = + this->createState(HOME_STAND_START_SELECTED) + .withBack(&home_stand_start) + .withActivate(&home_stand_start_activated); + State& turn_off_start = this->createState(TURN_OFF_START) + .withLeft(&home_stand_start) + .withRight(&home_sit_start); this->current_state_ = &home_sit_start; } From db5c4333978ae385eba958abef14006b94f8af77 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Tue, 17 Dec 2019 23:50:53 +0100 Subject: [PATCH 39/58] Added c++11 on native build --- platformio.ini | 4 ++++ src/state_machine.cpp | 2 ++ 2 files changed, 6 insertions(+) diff --git a/platformio.ini b/platformio.ini index 819833d..ddc9de6 100644 --- a/platformio.ini +++ b/platformio.ini @@ -62,7 +62,11 @@ build_flags = -std=c++11 -O3 -D RELEASE [env:native] platform = native +build_flags = -std=c++11 test_build_project_src = true test_filter = test_state, test_state_machine src_filter = + + + + + + + diff --git a/src/state_machine.cpp b/src/state_machine.cpp index c3793c2..0bc9a36 100644 --- a/src/state_machine.cpp +++ b/src/state_machine.cpp @@ -1,6 +1,8 @@ #include "state_machine.h" #include "sd_sector_addresses.h" +#include + void StateMachine::construct() { State& walk_small = this->createState(WALK_SMALL); State& walk_small_selected = this->createState(WALK_SMALL_SELECTED); From c486e2e893fc18d352e482f96044c024bb779846 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Wed, 18 Dec 2019 16:12:18 +0100 Subject: [PATCH 40/58] Finish all menus --- include/sd_sector_addresses.h | 2 +- include/state.h | 18 ++- include/state_machine.h | 10 ++ src/state_machine.cpp | 272 +++++++++++++++++++--------------- 4 files changed, 174 insertions(+), 128 deletions(-) diff --git a/include/sd_sector_addresses.h b/include/sd_sector_addresses.h index 4a8b8ce..af3df70 100644 --- a/include/sd_sector_addresses.h +++ b/include/sd_sector_addresses.h @@ -79,7 +79,7 @@ struct SectorAddress { #define SIDE_STEP_RIGHT_NORMAL SectorAddress { 0x0000, 0x2D90 } #define SIDE_STEP_RIGHT_NORMAL_SELECTED SectorAddress { 0x0000, 0x2E32 } -#define SIDE_STEP_RIGHT_NORMAL_ACTIVATED SectorAddress { 0x0000, 0x0000 } +#define SIDE_STEP_RIGHT_NORMAL_ACTIVATED SectorAddress { 0x0000, 0x0561 } // Single steps #define SINGLE_STEP_SMALL SectorAddress { 0x0000, 0x097E } diff --git a/include/state.h b/include/state.h index c5048fb..aca94cd 100644 --- a/include/state.h +++ b/include/state.h @@ -44,20 +44,30 @@ class State { return *this; } + State& upTo(const State* up) { + this->up_ = up; + return *this; + } + State& withDown(State* down) { this->down_ = down; down->up_ = this; return *this; } + State& downTo(const State* down) { + this->down_ = down; + return *this; + } + State& withBack(State* back) { this->back_ = back; back->select_ = this; return *this; } - State& backFrom(State* from) { - from->back_ = this; + State& backTo(const State* back) { + this->back_ = back; return *this; } @@ -67,12 +77,12 @@ class State { return *this; } - State& withActivate(State* activate) { + State& withActivate(const State* activate) { this->activate_ = activate; return *this; } -private: +protected: const std::string gait_; const SectorAddress address_; diff --git a/include/state_machine.h b/include/state_machine.h index 2328250..e6b680c 100644 --- a/include/state_machine.h +++ b/include/state_machine.h @@ -27,12 +27,22 @@ class StateMachine { bool activate(); private: + void constructWalkMenu(State* from); + void constructSideStepMenu(State* from); + void constructStepMenu(State* from); + bool hasState() const; bool setCurrentState(const State* new_state); State& createState(const SectorAddress address, const std::string& gait_name = ""); + State& createGaitState(const SectorAddress addr, + const SectorAddress addr_selected, + const SectorAddress addr_activated, + const std::string& gait_name, + const State* result = nullptr); + std::list states_; const State* current_state_ = nullptr; }; diff --git a/src/state_machine.cpp b/src/state_machine.cpp index 0bc9a36..9358835 100644 --- a/src/state_machine.cpp +++ b/src/state_machine.cpp @@ -4,148 +4,158 @@ #include void StateMachine::construct() { - State& walk_small = this->createState(WALK_SMALL); - State& walk_small_selected = this->createState(WALK_SMALL_SELECTED); - State& walk_small_activated = - this->createState(WALK_SMALL_ACTIVATED, "gait_walk_small"); - State& walk_normal = this->createState(WALK_NORMAL).withLeft(&walk_small); - State& walk_normal_selected = - this->createState(WALK_NORMAL_SELECTED).withLeft(&walk_small); - State& walk_normal_activated = - this->createState(WALK_NORMAL_ACTIVATED, "gait_walk") - .withLeft(&walk_small); - State& walk_large = this->createState(WALK_LARGE) - .withLeft(&walk_normal) - .withRight(&walk_small); + // Walk menu + State& walk = this->createState(WALK); + State& side_step = this->createState(SIDE_STEP).withRight(&walk); + State& single_step = + this->createState(SINGLE_STEP).withLeft(&walk).withRight(&side_step); + + this->constructWalkMenu(&walk); + this->constructSideStepMenu(&side_step); + this->constructStepMenu(&single_step); + + // Sit menu + State& sit = + this->createGaitState(SIT, SIT_SELECTED, SIT_ACTIVATED, "gait_sit"); + State& home_sit = this->createGaitState(HOME_SIT, HOME_SIT_SELECTED, + HOME_SIT_ACTIVATED, "home_sit"); + State& home_stand = this->createGaitState(HOME_STAND, HOME_STAND_SELECTED, + HOME_STAND_ACTIVATED, "home_stand"); + State& turn_off = this->createState(TURN_OFF); - State& side_step_left = this->createState(SIDE_STEP_LEFT); - State& side_step_right = this->createState(SIDE_STEP_RIGHT) - .withLeft(&side_step_left) - .withRight(&side_step_left); - - State& side_step_left_small = this->createState(SIDE_STEP_LEFT_SMALL); - State& side_step_left_small_selected = - this->createState(SIDE_STEP_LEFT_SMALL_SELECTED); - State& side_step_left_small_activated = this->createState( - SIDE_STEP_LEFT_SMALL_ACTIVATED, "gait_side_step_left_small"); - - State& side_step_left_normal = this->createState(SIDE_STEP_LEFT_NORMAL); - State& side_step_left_normal_selected = - this->createState(SIDE_STEP_LEFT_NORMAL_SELECTED); - State& side_step_left_normal_activated = - this->createState(SIDE_STEP_LEFT_NORMAL_ACTIVATED, "gait_side_step_left"); - - State& side_step_right_small = this->createState(SIDE_STEP_RIGHT_SMALL); - State& side_step_right_small_selected = - this->createState(SIDE_STEP_RIGHT_SMALL_SELECTED); - State& side_step_right_small_activated = this->createState( - SIDE_STEP_RIGHT_SMALL_ACTIVATED, "gait_side_step_right_small"); - - State& side_step_right_normal = this->createState(SIDE_STEP_RIGHT_NORMAL); - State& side_step_right_normal_selected = - this->createState(SIDE_STEP_RIGHT_NORMAL_SELECTED); - State& side_step_right_normal_activated = this->createState( - SIDE_STEP_RIGHT_NORMAL_ACTIVATED, "gait_side_step_right"); - - State& single_step_small = this->createState(SINGLE_STEP_SMALL); - State& single_step_small_selected = - this->createState(SINGLE_STEP_SMALL_SELECTED); - State& single_step_small_activated = - this->createState(SINGLE_STEP_SMALL_ACTIVATED, "gait_single_step_normal"); - State& single_step_normal = - this->createState(SINGLE_STEP_NORMAL).withLeft(&single_step_small); - State& single_step_normal_selected = - this->createState(SINGLE_STEP_NORMAL_SELECTED); - State& single_step_normal_activated = this->createState( - SINGLE_STEP_NORMAL_ACTIVATED, "gait_single_step_normal"); - State& single_step_large = this->createState(SINGLE_STEP_LARGE) - .withLeft(&single_step_normal) - .withRight(&single_step_small); - - State& walk = this->createState(WALK) - .withSelect(&walk_normal) - .backFrom(&walk_small) - .backFrom(&walk_large); - State& side_step = this->createState(SIDE_STEP) - .withRight(&walk) - .withSelect(&side_step_left) - .backFrom(&side_step_right); - State& single_step = this->createState(SINGLE_STEP) - .withLeft(&walk) - .withRight(&side_step) - .withSelect(&single_step_normal) - .backFrom(&single_step_small) - .backFrom(&single_step_large); - - State& sit = this->createState(SIT); - State& sit_selected = this->createState(SIT_SELECTED); - State& sit_activated = this->createState(SIT_ACTIVATED, "gait_sit"); - - State& home_sit = this->createState(HOME_SIT); - State& home_sit_selected = this->createState(HOME_SIT_SELECTED); - State& home_sit_activated = this->createState(HOME_SIT_ACTIVATED, "home_sit"); - - State& home_stand = this->createState(HOME_STAND); - State& home_stand_selected = this->createState(HOME_STAND_SELECTED); - State& home_stand_activated = - this->createState(HOME_STAND_ACTIVATED, "home_stand"); + sit.withRight(&home_sit).upTo(&walk); + home_sit.withRight(&home_stand).upTo(&walk); + home_stand.withRight(&turn_off).upTo(&walk); + turn_off.withRight(&sit).upTo(&walk); - State& turn_off = this->createState(TURN_OFF); + walk.downTo(&sit); + side_step.downTo(&sit); + single_step.downTo(&sit); + + // Obstacle menu + State& sofa = this->createState(SOFA); + State& stairs = this->createState(STAIRS); - State& sofa_sit = this->createState(SOFA_SIT); - State& sofa_sit_selected = this->createState(SOFA_SIT_SELECTED); - State& sofa_sit_activated = - this->createState(SOFA_SIT_ACTIVATED, "gait_sofa_sit"); + sofa.withRight(&stairs).downTo(&walk); + stairs.withRight(&sofa).downTo(&walk); - State& sofa_standup = this->createState(SOFA_STANDUP); - State& sofa_standup_selected = this->createState(SOFA_STANDUP_SELECTED); - State& sofa_standup_activated = - this->createState(SOFA_STANDUP_ACTIVATED, "gait_sofa_stand"); + walk.upTo(&stairs); + side_step.upTo(&stairs); + single_step.upTo(&stairs); - State& stairs_up = this->createState(STAIRS_UP); - State& stairs_up_selected = this->createState(STAIRS_UP_SELECTED); - State& stairs_up_activated = - this->createState(STAIRS_UP_ACTIVATED, "gait_stairs_up"); + State& sofa_standup = + this->createGaitState(SOFA_STANDUP, SOFA_STANDUP_SELECTED, + SOFA_STANDUP_ACTIVATED, "gait_sofa_stand", &walk); + State& sofa_sit = + this->createGaitState(SOFA_SIT, SOFA_SIT_SELECTED, SOFA_SIT_ACTIVATED, + "gait_sofa_sit", &sofa_standup); - State& stairs_down = this->createState(STAIRS_DOWN); - State& stairs_down_selected = this->createState(STAIRS_DOWN_SELECTED); - State& stairs_down_activated = - this->createState(STAIRS_DOWN_ACTIVATED, "gait_stairs_down"); + sofa_sit.backTo(&sofa).withRight(&sofa_standup); + sofa_standup.backTo(&sofa).withRight(&sofa_sit); + sofa.withSelect(&sofa_sit); - State& sofa = this->createState(SOFA); + State& stairs_up = + this->createGaitState(STAIRS_UP, STAIRS_UP_SELECTED, STAIRS_UP_ACTIVATED, + "gait_stairs_up", &walk); + State& stairs_down = + this->createGaitState(STAIRS_DOWN, STAIRS_DOWN_SELECTED, + STAIRS_DOWN_ACTIVATED, "gait_stairs_down", &walk); - State& stairs = this->createState(STAIRS); + stairs_up.backTo(&stairs).withRight(&stairs_down); + stairs_down.backTo(&stairs).withRight(&stairs_up); + stairs.withSelect(&stairs_up); - State& home_sit_start = this->createState(HOME_SIT_START); - State& home_sit_start_activated = - this->createState(HOME_SIT_START_ACTIVATED, "home_sit"); - State& home_sit_start_selected = this->createState(HOME_SIT_START_SELECTED) - .withBack(&home_sit_start) - .withActivate(&home_sit_start_activated); + // Start menu + State& stand_up = this->createGaitState( + STAND_UP, STAND_UP_SELECTED, STAND_UP_ACTIVATED, "gait_stand", &walk); - State& stand_up = this->createState(STAND_UP).withLeft(&home_sit_start); - State& stand_up_activated = - this->createState(STAND_UP_ACTIVATED, "gait_stand").withActivate(&walk); - State& stand_up_selected = this->createState(STAND_UP_SELECTED) - .withBack(&stand_up) - .withActivate(&stand_up_activated); + State& home_sit_start = + this->createGaitState(HOME_SIT_START, HOME_SIT_START_SELECTED, + HOME_SIT_START_ACTIVATED, "home_sit", &stand_up) + .withRight(&stand_up); State& home_stand_start = - this->createState(HOME_STAND_START).withLeft(&stand_up); - State& home_stand_start_activated = - this->createState(HOME_STAND_START_ACTIVATED, "home_stand") - .withActivate(&walk); - State& home_stand_start_selected = - this->createState(HOME_STAND_START_SELECTED) - .withBack(&home_stand_start) - .withActivate(&home_stand_start_activated); + this->createGaitState(HOME_STAND_START, HOME_STAND_START_SELECTED, + HOME_STAND_START_ACTIVATED, "home_stand", &walk) + .withLeft(&stand_up); State& turn_off_start = this->createState(TURN_OFF_START) .withLeft(&home_stand_start) .withRight(&home_sit_start); + // Set start state this->current_state_ = &home_sit_start; } +void StateMachine::constructWalkMenu(State* from) { + State& walk_small = + this->createGaitState(WALK_SMALL, WALK_SMALL_SELECTED, + WALK_SMALL_ACTIVATED, "gait_walk_small", from); + State& walk_normal = + this->createGaitState(WALK_NORMAL, WALK_NORMAL_SELECTED, + WALK_NORMAL_ACTIVATED, "gait_walk", from); + State& walk_large = this->createState(WALK_LARGE); + + walk_small.backTo(from); + walk_normal.backTo(from).withLeft(&walk_small); + walk_large.backTo(from).withLeft(&walk_normal).withRight(&walk_small); + + from->withSelect(&walk_normal); +} + +void StateMachine::constructSideStepMenu(State* from) { + State& side_step_left = this->createState(SIDE_STEP_LEFT); + State& side_step_right = this->createState(SIDE_STEP_RIGHT); + + State& side_step_left_small = this->createGaitState( + SIDE_STEP_LEFT_SMALL, SIDE_STEP_LEFT_SMALL_SELECTED, + SIDE_STEP_LEFT_SMALL_ACTIVATED, "gait_side_step_left_small", from); + + State& side_step_left_normal = this->createGaitState( + SIDE_STEP_LEFT_NORMAL, SIDE_STEP_LEFT_NORMAL_SELECTED, + SIDE_STEP_LEFT_NORMAL_ACTIVATED, "gait_side_step_left", from); + + State& side_step_right_small = this->createGaitState( + SIDE_STEP_RIGHT_SMALL, SIDE_STEP_RIGHT_SMALL_SELECTED, + SIDE_STEP_RIGHT_SMALL_ACTIVATED, "gait_side_step_right_small", from); + + State& side_step_right_normal = this->createGaitState( + SIDE_STEP_RIGHT_NORMAL, SIDE_STEP_RIGHT_NORMAL_SELECTED, + SIDE_STEP_RIGHT_NORMAL_ACTIVATED, "gait_side_step_right", from); + + side_step_left.backTo(from) + .withRight(&side_step_right) + .withSelect(&side_step_left_normal); + side_step_right.backTo(from) + .withRight(&side_step_left) + .withSelect(&side_step_right_normal); + + side_step_left_small.backTo(&side_step_left) + .withRight(&side_step_left_normal); + side_step_left_normal.withRight(&side_step_left_small); + + side_step_right_small.backTo(&side_step_right) + .withRight(&side_step_right_normal); + side_step_right_normal.withRight(&side_step_right_small); + + from->withSelect(&side_step_left); +} + +void StateMachine::constructStepMenu(State* from) { + State& single_step_small = this->createGaitState( + SINGLE_STEP_SMALL, SINGLE_STEP_SMALL_SELECTED, + SINGLE_STEP_SMALL_ACTIVATED, "gait_single_step_normal", from); + State& single_step_normal = this->createGaitState( + SINGLE_STEP_NORMAL, SINGLE_STEP_NORMAL_SELECTED, + SINGLE_STEP_NORMAL_ACTIVATED, "gait_single_step_normal", from); + State& single_step_large = this->createState(SINGLE_STEP_LARGE); + + single_step_small.backTo(from).withRight(&single_step_normal); + single_step_normal.backTo(from).withRight(&single_step_large); + single_step_large.backTo(from).withRight(&single_step_small); + + from->withSelect(&single_step_normal); +} + std::string StateMachine::getCurrentGaitName() const { if (this->hasState()) { return this->current_state_->getGaitName(); @@ -211,4 +221,20 @@ State& StateMachine::createState(const SectorAddress address, const std::string& gait_name) { this->states_.emplace_back(address, gait_name); return this->states_.back(); +} + +State& StateMachine::createGaitState(const SectorAddress addr, + const SectorAddress addr_selected, + const SectorAddress addr_activated, + const std::string& gait_name, + const State* result) { + State& normal = this->createState(addr); + State& selected = this->createState(addr_selected); + State& activated = this->createState(addr_activated, gait_name); + + normal.withSelect(&selected); + selected.withActivate(&activated); + activated.withActivate(result == nullptr ? &normal : result); + + return normal; } \ No newline at end of file From 7adde8b373bbbe9b3a41a8751d94faf95719f8fd Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Wed, 18 Dec 2019 16:48:20 +0100 Subject: [PATCH 41/58] Fix stop button --- src/main.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1ad7810..ac1e97d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -66,10 +66,11 @@ ros::NodeHandle nh; #endif bool received_gait_instruction_response = false; +bool gait_rejected = false; bool gait_message_send = false; void gaitInstructionResponseCallback( const march_shared_resources::GaitInstructionResponse& msg) { - if (msg.result == msg.GAIT_FINISHED) { + if (msg.result == msg.GAIT_FINISHED || msg.result == msg.GAIT_REJECTED) { received_gait_instruction_response = true; } } @@ -174,7 +175,7 @@ void loop() { gait_message_send = false; state_has_changed = state_machine.activate(); } else if (gait_message_send) { - if (joystick_state == ButtonState::PUSH) { + if (trigger_state == ButtonState::PUSH) { sendStopMessage(); } } else { From d5004be85dffc8c5a2b4b343e528894eadc288f2 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Wed, 18 Dec 2019 17:15:56 +0100 Subject: [PATCH 42/58] Add some comments --- include/button.h | 8 ++++---- include/joystick.h | 12 +++++++----- include/state_machine.h | 3 +++ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/include/button.h b/include/button.h index c13e016..7b21290 100644 --- a/include/button.h +++ b/include/button.h @@ -15,10 +15,10 @@ class Button { ButtonState last_position_ = ButtonState::NEUTRAL; unsigned long last_print_time_ = 0; - const useconds_t bounce_time_ = - 20000; // us. May introduce unwanted behaviour if changed - const unsigned long hold_time_ = - 1000; // ms. Determines how often 'push' is returned if the button is held + // us. May introduce unwanted behaviour if changed + const useconds_t bounce_time_ = 20000; + // ms. Determines how often 'push' is returned if the button is held + const unsigned long hold_time_ = 1000; }; #endif // BUTTON_H diff --git a/include/joystick.h b/include/joystick.h index 3bd0d57..ac6befb 100644 --- a/include/joystick.h +++ b/include/joystick.h @@ -38,11 +38,13 @@ class Joystick { unsigned long last_push_release_time_ = 0; unsigned long last_double_click_time_ = 0; - const useconds_t bounce_time_ = - 5000; // us. May introduce unwanted behaviour if changed - const unsigned long hold_time_ = - 1000; // ms. Determines how often up or down - // are returned if the joystick is held. + // us. May introduce unwanted behaviour if changed + const useconds_t bounce_time_ = 5000; + + // ms. Determines how often up or down + // are returned if the joystick is held. + const unsigned long hold_time_ = 1000; + const unsigned long double_click_time_ = 300; // ms. const unsigned long double_click_timeout_time_ = 500; // ms }; diff --git a/include/state_machine.h b/include/state_machine.h index e6b680c..259aba5 100644 --- a/include/state_machine.h +++ b/include/state_machine.h @@ -43,6 +43,9 @@ class StateMachine { const std::string& gait_name, const State* result = nullptr); + // This must be list, since that does not reallocate + // Items when it resizes, which a vector does. + // Otherwise all pointers in states would become invalid :) std::list states_; const State* current_state_ = nullptr; }; From a53f6274879cf29d7f0e2b3475e6da3e8d094d94 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Thu, 19 Dec 2019 09:55:41 +0100 Subject: [PATCH 43/58] Remove timer between image drawing --- include/screen.h | 3 --- src/screen.cpp | 8 +++----- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/include/screen.h b/include/screen.h index b6b25b5..296d3a3 100644 --- a/include/screen.h +++ b/include/screen.h @@ -60,9 +60,6 @@ class Screen { // In microseconds. Needed for functioning, can still be optimized const useconds_t wait_time_ms_ = 500000; - // Milliseconds, time to wait between drawing images - const useconds_t draw_speed_ms_ = 100; - // Milliseconds, when the screen should start scrolling const word screen_saver_timeout_ms_ = 10000; // Must be value in 0-255 (fastest-slowest) diff --git a/src/screen.cpp b/src/screen.cpp index d5c96ed..7c83095 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -49,11 +49,9 @@ void Screen::reset() { } void Screen::draw_image(SectorAddress address) { - if ((millis() - this->last_draw_time_) > this->draw_speed_ms_) { - this->screen_->media_SetSector(address.hi, address.lo); - this->screen_->media_Image(0, 0); - this->last_draw_time_ = millis(); - } + this->screen_->media_SetSector(address.hi, address.lo); + this->screen_->media_Image(0, 0); + this->last_draw_time_ = millis(); } void Screen::printVersion() { From ccea17628c9a7f699e5447d7f0ea54c40cc905b1 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Thu, 19 Dec 2019 10:31:51 +0100 Subject: [PATCH 44/58] Add time out for screen commands --- include/screen.h | 2 ++ src/screen.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/include/screen.h b/include/screen.h index 296d3a3..e8bab7a 100644 --- a/include/screen.h +++ b/include/screen.h @@ -64,6 +64,8 @@ class Screen { const word screen_saver_timeout_ms_ = 10000; // Must be value in 0-255 (fastest-slowest) const word screen_saver_scroll_speed_ = 0; + // Sets the time out limit for screen serial commands to 2 seconds. + const unsigned long time_limit_ = 2000; }; #endif // SCREEN_H \ No newline at end of file diff --git a/src/screen.cpp b/src/screen.cpp index 7c83095..051a30d 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -19,6 +19,8 @@ void Screen::init() { this->screen_->SSTimeout(this->screen_saver_timeout_ms_); this->screen_->SSSpeed(this->screen_saver_scroll_speed_); + this->screen_->TimeLimit4D = this->time_limit_; + this->clear(); this->screen_->gfx_ScreenMode(PORTRAIT); From eed2c9ee4a0f34ebaa4e330d0bb89ac698efe2f7 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Thu, 19 Dec 2019 10:31:57 +0100 Subject: [PATCH 45/58] Fix mounting screen --- src/screen.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/screen.cpp b/src/screen.cpp index 051a30d..5ead5b1 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -25,10 +25,10 @@ void Screen::init() { this->screen_->gfx_ScreenMode(PORTRAIT); this->printVersion(); + sleep(5); this->mountImages(); this->screen_->gfx_ScreenMode(LANDSCAPE); - sleep(5); this->clear(); this->last_draw_time_ = millis(); @@ -75,10 +75,11 @@ void Screen::printVersion() { void Screen::mountImages() { word initialized = this->screen_->media_Init(); - if (initialized != Err4D_OK) { + + if (initialized == 0) { this->screen_->txt_FGcolour(RED); this->screen_->println("Pls insert SD"); - while (initialized != Err4D_OK) { + while (initialized == 0) { sleep(1); initialized = this->screen_->media_Init(); } From dad591c539d28f3d3bbc032aa97d481412380692 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Thu, 19 Dec 2019 11:26:52 +0100 Subject: [PATCH 46/58] Add newlines to end of files --- include/screen.h | 2 +- src/state_machine.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/screen.h b/include/screen.h index e8bab7a..a2a726f 100644 --- a/include/screen.h +++ b/include/screen.h @@ -68,4 +68,4 @@ class Screen { const unsigned long time_limit_ = 2000; }; -#endif // SCREEN_H \ No newline at end of file +#endif // SCREEN_H diff --git a/src/state_machine.cpp b/src/state_machine.cpp index 9358835..1b6548b 100644 --- a/src/state_machine.cpp +++ b/src/state_machine.cpp @@ -237,4 +237,4 @@ State& StateMachine::createGaitState(const SectorAddress addr, activated.withActivate(result == nullptr ? &normal : result); return normal; -} \ No newline at end of file +} From 9157e3e93b349a800cf35f7484af322e9675390e Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Thu, 19 Dec 2019 11:34:47 +0100 Subject: [PATCH 47/58] Move enums to seperate files --- include/joystick.h | 10 +--------- include/joystick_position.h | 13 +++++++++++++ include/rocker_switch.h | 10 ++-------- include/rocker_switch_state.h | 12 ++++++++++++ 4 files changed, 28 insertions(+), 17 deletions(-) create mode 100644 include/joystick_position.h create mode 100644 include/rocker_switch_state.h diff --git a/include/joystick.h b/include/joystick.h index ac6befb..2229687 100644 --- a/include/joystick.h +++ b/include/joystick.h @@ -1,18 +1,10 @@ #ifndef JOYSTICK_H #define JOYSTICK_H #include "button_state.h" +#include "joystick_position.h" #include -enum class JoystickPosition { - LEFT, - RIGHT, - UP, - DOWN, - NEUTRAL, - HOLDING, -}; - class Joystick { public: explicit Joystick(uint8_t left_pin, uint8_t right_pin, uint8_t up_pin, diff --git a/include/joystick_position.h b/include/joystick_position.h new file mode 100644 index 0000000..e5c7de7 --- /dev/null +++ b/include/joystick_position.h @@ -0,0 +1,13 @@ +#ifndef JOYSTICK_POSITION_H +#define JOYSTICK_POSITION_H + +enum class JoystickPosition { + LEFT, + RIGHT, + UP, + DOWN, + NEUTRAL, + HOLDING, +}; + +#endif // JOYSTICK_POSITION_H diff --git a/include/rocker_switch.h b/include/rocker_switch.h index df89412..452eea8 100644 --- a/include/rocker_switch.h +++ b/include/rocker_switch.h @@ -1,14 +1,8 @@ #ifndef ROCKER_SWITCH_H #define ROCKER_SWITCH_H -#include +#include "rocker_switch_state.h" -enum class RockerSwitchState { - UP, - HOLDING_UP, - DOWN, - HOLDING_DOWN, - NEUTRAL, -}; +#include class RockerSwitch { public: diff --git a/include/rocker_switch_state.h b/include/rocker_switch_state.h new file mode 100644 index 0000000..ac7e511 --- /dev/null +++ b/include/rocker_switch_state.h @@ -0,0 +1,12 @@ +#ifndef ROCKER_SWITCH_STATE_H +#define ROCKER_SWITCH_STATE_H + +enum class RockerSwitchState { + UP, + HOLDING_UP, + DOWN, + HOLDING_DOWN, + NEUTRAL, +}; + +#endif // ROCKER_SWITCH_STATE_H From f0c70fd4df3317a9b2bbe8c24316aa3fdc0d0d80 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Thu, 2 Jan 2020 10:04:54 +0100 Subject: [PATCH 48/58] Fix requested changes --- include/state.h | 6 +-- include/state_machine.h | 2 + src/main.cpp | 31 +++++++---- src/state_machine.cpp | 110 ++++++++++++++++++++-------------------- 4 files changed, 82 insertions(+), 67 deletions(-) diff --git a/include/state.h b/include/state.h index aca94cd..93cb28d 100644 --- a/include/state.h +++ b/include/state.h @@ -71,9 +71,9 @@ class State { return *this; } - State& withSelect(State* select) { - this->select_ = select; - select->back_ = this; + State& withSelect(State* with_select) { + this->select_ = with_select; + with_select->back_ = this; return *this; } diff --git a/include/state_machine.h b/include/state_machine.h index 259aba5..31ee6f9 100644 --- a/include/state_machine.h +++ b/include/state_machine.h @@ -30,6 +30,8 @@ class StateMachine { void constructWalkMenu(State* from); void constructSideStepMenu(State* from); void constructStepMenu(State* from); + void constructSofaMenu(State* from); + void constructStairsMenu(State* from); bool hasState() const; bool setCurrentState(const State* new_state); diff --git a/src/main.cpp b/src/main.cpp index ac1e97d..4e2a3aa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -179,20 +179,31 @@ void loop() { sendStopMessage(); } } else { - if (joystick_position == JoystickPosition::LEFT) { + switch (joystick_position) { + case JoystickPosition::LEFT: state_has_changed = state_machine.left(); - } else if (joystick_position == JoystickPosition::RIGHT) { + break; + case JoystickPosition::RIGHT: state_has_changed = state_machine.right(); - } else if (joystick_position == JoystickPosition::UP) { + break; + case JoystickPosition::UP: state_has_changed = state_machine.up(); - } else if (joystick_position == JoystickPosition::DOWN) { + break; + case JoystickPosition::DOWN: state_has_changed = state_machine.down(); - } else if (joystick_state == ButtonState::PUSH) { - state_has_changed = state_machine.select(); - } else if (joystick_state == ButtonState::DOUBLE) { - state_has_changed = state_machine.back(); - } else if (trigger_state == ButtonState::PUSH) { - state_has_changed = state_machine.activate(); + break; + default: + break; + } + + if (!state_has_changed) { + if (joystick_state == ButtonState::PUSH) { + state_has_changed = state_machine.back(); + } else if (joystick_state == ButtonState::DOUBLE) { + state_has_changed = state_machine.back(); + } else if (trigger_state == ButtonState::PUSH) { + state_has_changed = state_machine.activate(); + } } } diff --git a/src/state_machine.cpp b/src/state_machine.cpp index 1b6548b..0b7ea33 100644 --- a/src/state_machine.cpp +++ b/src/state_machine.cpp @@ -6,13 +6,8 @@ void StateMachine::construct() { // Walk menu State& walk = this->createState(WALK); - State& side_step = this->createState(SIDE_STEP).withRight(&walk); - State& single_step = - this->createState(SINGLE_STEP).withLeft(&walk).withRight(&side_step); - - this->constructWalkMenu(&walk); - this->constructSideStepMenu(&side_step); - this->constructStepMenu(&single_step); + State& side_step = this->createState(SIDE_STEP); + State& single_step = this->createState(SINGLE_STEP); // Sit menu State& sit = @@ -23,64 +18,45 @@ void StateMachine::construct() { HOME_STAND_ACTIVATED, "home_stand"); State& turn_off = this->createState(TURN_OFF); - sit.withRight(&home_sit).upTo(&walk); - home_sit.withRight(&home_stand).upTo(&walk); - home_stand.withRight(&turn_off).upTo(&walk); - turn_off.withRight(&sit).upTo(&walk); - - walk.downTo(&sit); - side_step.downTo(&sit); - single_step.downTo(&sit); - // Obstacle menu State& sofa = this->createState(SOFA); State& stairs = this->createState(STAIRS); - sofa.withRight(&stairs).downTo(&walk); - stairs.withRight(&sofa).downTo(&walk); - - walk.upTo(&stairs); - side_step.upTo(&stairs); - single_step.upTo(&stairs); - - State& sofa_standup = - this->createGaitState(SOFA_STANDUP, SOFA_STANDUP_SELECTED, - SOFA_STANDUP_ACTIVATED, "gait_sofa_stand", &walk); - State& sofa_sit = - this->createGaitState(SOFA_SIT, SOFA_SIT_SELECTED, SOFA_SIT_ACTIVATED, - "gait_sofa_sit", &sofa_standup); - - sofa_sit.backTo(&sofa).withRight(&sofa_standup); - sofa_standup.backTo(&sofa).withRight(&sofa_sit); - sofa.withSelect(&sofa_sit); - - State& stairs_up = - this->createGaitState(STAIRS_UP, STAIRS_UP_SELECTED, STAIRS_UP_ACTIVATED, - "gait_stairs_up", &walk); - State& stairs_down = - this->createGaitState(STAIRS_DOWN, STAIRS_DOWN_SELECTED, - STAIRS_DOWN_ACTIVATED, "gait_stairs_down", &walk); - - stairs_up.backTo(&stairs).withRight(&stairs_down); - stairs_down.backTo(&stairs).withRight(&stairs_up); - stairs.withSelect(&stairs_up); - // Start menu State& stand_up = this->createGaitState( STAND_UP, STAND_UP_SELECTED, STAND_UP_ACTIVATED, "gait_stand", &walk); - State& home_sit_start = this->createGaitState(HOME_SIT_START, HOME_SIT_START_SELECTED, - HOME_SIT_START_ACTIVATED, "home_sit", &stand_up) - .withRight(&stand_up); - + HOME_SIT_START_ACTIVATED, "home_sit", &stand_up); State& home_stand_start = this->createGaitState(HOME_STAND_START, HOME_STAND_START_SELECTED, - HOME_STAND_START_ACTIVATED, "home_stand", &walk) - .withLeft(&stand_up); - State& turn_off_start = this->createState(TURN_OFF_START) - .withLeft(&home_stand_start) - .withRight(&home_sit_start); + HOME_STAND_START_ACTIVATED, "home_stand", &walk); + State& turn_off_start = this->createState(TURN_OFF_START); + + // Sub-menus + this->constructWalkMenu(&walk); + this->constructSideStepMenu(&side_step); + this->constructStepMenu(&single_step); + this->constructSofaMenu(&sofa); + this->constructStairsMenu(&stairs); + + // Menu transitions + walk.withRight(&single_step).upTo(&stairs).downTo(&sit); + single_step.withRight(&side_step).upTo(&stairs).downTo(&sit); + side_step.withRight(&walk).upTo(&stairs).downTo(&sit); + + sit.withRight(&home_sit).upTo(&walk); + home_sit.withRight(&home_stand).upTo(&walk); + home_stand.withRight(&turn_off).upTo(&walk); + turn_off.withRight(&sit).upTo(&walk); + + sofa.withRight(&stairs).downTo(&walk); + stairs.withRight(&sofa).downTo(&walk); + + home_sit_start.withRight(&stand_up); + stand_up.withRight(&home_stand_start); + home_stand_start.withRight(&turn_off_start); + turn_off_start.withRight(&home_sit_start); // Set start state this->current_state_ = &home_sit_start; @@ -156,6 +132,32 @@ void StateMachine::constructStepMenu(State* from) { from->withSelect(&single_step_normal); } +void StateMachine::constructSofaMenu(State* from) { + State& sofa_standup = + this->createGaitState(SOFA_STANDUP, SOFA_STANDUP_SELECTED, + SOFA_STANDUP_ACTIVATED, "gait_sofa_stand", from); + State& sofa_sit = + this->createGaitState(SOFA_SIT, SOFA_SIT_SELECTED, SOFA_SIT_ACTIVATED, + "gait_sofa_sit", &sofa_standup); + + sofa_sit.backTo(from).withRight(&sofa_standup); + sofa_standup.backTo(from).withRight(&sofa_sit); + from->withSelect(&sofa_sit); +} + +void StateMachine::constructStairsMenu(State* from) { + State& stairs_up = + this->createGaitState(STAIRS_UP, STAIRS_UP_SELECTED, STAIRS_UP_ACTIVATED, + "gait_stairs_up", from); + State& stairs_down = + this->createGaitState(STAIRS_DOWN, STAIRS_DOWN_SELECTED, + STAIRS_DOWN_ACTIVATED, "gait_stairs_down", from); + + stairs_up.backTo(from).withRight(&stairs_down); + stairs_down.backTo(from).withRight(&stairs_up); + from->withSelect(&stairs_up); +} + std::string StateMachine::getCurrentGaitName() const { if (this->hasState()) { return this->current_state_->getGaitName(); From 371445ea7c05cd16094c7c892fe613fbd06db01d Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Thu, 2 Jan 2020 10:11:42 +0100 Subject: [PATCH 49/58] Apply ROS style --- .clang-format | 72 ++++++- include/button.h | 5 +- include/button_state.h | 5 +- include/joystick.h | 12 +- include/joystick_position.h | 5 +- include/rocker_switch.h | 5 +- include/rocker_switch_state.h | 5 +- include/screen.h | 8 +- include/sd_sector_addresses.h | 5 +- include/state.h | 87 ++++++--- include/state_machine.h | 14 +- include/version.h | 2 +- include/wireless_connection.h | 27 ++- src/button.cpp | 21 ++- src/joystick.cpp | 117 +++++++----- src/main.cpp | 122 +++++++----- src/rocker_switch.cpp | 34 ++-- src/screen.cpp | 30 +-- src/state_machine.cpp | 176 +++++++++--------- test/test_state/test_state.cpp | 18 +- .../test_state_machine/test_state_machine.cpp | 17 +- 21 files changed, 485 insertions(+), 302 deletions(-) diff --git a/.clang-format b/.clang-format index b5f4fd5..b39ac68 100644 --- a/.clang-format +++ b/.clang-format @@ -1,9 +1,65 @@ --- -BasedOnStyle: LLVM ---- -Language: Cpp -DerivePointerAlignment: false -PointerAlignment: Left -AllowShortFunctionsOnASingleLine: Inline -AllowShortBlocksOnASingleLine: false ---- +BasedOnStyle: Google +AccessModifierOffset: -2 +ConstructorInitializerIndentWidth: 2 +AlignEscapedNewlinesLeft: false +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AlwaysBreakTemplateDeclarations: true +AlwaysBreakBeforeMultilineStrings: false +BreakBeforeBinaryOperators: false +BreakBeforeTernaryOperators: false +BreakConstructorInitializersBeforeComma: true +BinPackParameters: true +ColumnLimit: 120 +ConstructorInitializerAllOnOneLineOrOnePerLine: true +DerivePointerBinding: false +PointerBindsToType: true +ExperimentalAutoDetectBinPacking: false +IndentCaseLabels: true +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCSpaceBeforeProtocolList: true +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 60 +PenaltyBreakString: 1 +PenaltyBreakFirstLessLess: 1000 +PenaltyExcessCharacter: 1000 +PenaltyReturnTypeOnItsOwnLine: 90 +SpacesBeforeTrailingComments: 2 +Cpp11BracedListStyle: false +Standard: Auto +IndentWidth: 2 +TabWidth: 2 +UseTab: Never +IndentFunctionDeclarationAfterType: false +SpacesInParentheses: false +SpacesInAngles: false +SpaceInEmptyParentheses: false +SpacesInCStyleCastParentheses: false +SpaceAfterControlStatementKeyword: true +SpaceBeforeAssignmentOperators: true +ContinuationIndentWidth: 4 +SortIncludes: false +SpaceAfterCStyleCast: false + +# Configure each individual brace in BraceWrapping +BreakBeforeBraces: Custom + +# Control of individual brace wrapping cases +BraceWrapping: { + AfterClass: 'true' + AfterControlStatement: 'true' + AfterEnum : 'true' + AfterFunction : 'true' + AfterNamespace : 'true' + AfterStruct : 'true' + AfterUnion : 'true' + BeforeCatch : 'true' + BeforeElse : 'true' + IndentBraces : 'false' +} +... diff --git a/include/button.h b/include/button.h index 7b21290..f58562d 100644 --- a/include/button.h +++ b/include/button.h @@ -4,7 +4,8 @@ #include -class Button { +class Button +{ public: explicit Button(uint8_t pin); @@ -21,4 +22,4 @@ class Button { const unsigned long hold_time_ = 1000; }; -#endif // BUTTON_H +#endif // BUTTON_H diff --git a/include/button_state.h b/include/button_state.h index 94bd71a..0c2e89a 100644 --- a/include/button_state.h +++ b/include/button_state.h @@ -1,11 +1,12 @@ #ifndef BUTTON_STATE_H #define BUTTON_STATE_H -enum class ButtonState { +enum class ButtonState +{ NEUTRAL, HOLDING, PUSH, DOUBLE, }; -#endif // BUTTON_STATE_H +#endif // BUTTON_STATE_H diff --git a/include/joystick.h b/include/joystick.h index 2229687..a0cb79e 100644 --- a/include/joystick.h +++ b/include/joystick.h @@ -5,10 +5,10 @@ #include -class Joystick { +class Joystick +{ public: - explicit Joystick(uint8_t left_pin, uint8_t right_pin, uint8_t up_pin, - uint8_t down_pin, uint8_t press_pin); + Joystick(uint8_t left_pin, uint8_t right_pin, uint8_t up_pin, uint8_t down_pin, uint8_t press_pin); JoystickPosition getPosition(); ButtonState getState(); @@ -37,8 +37,8 @@ class Joystick { // are returned if the joystick is held. const unsigned long hold_time_ = 1000; - const unsigned long double_click_time_ = 300; // ms. - const unsigned long double_click_timeout_time_ = 500; // ms + const unsigned long double_click_time_ = 300; // ms. + const unsigned long double_click_timeout_time_ = 500; // ms }; -#endif // JOYSTICK_H +#endif // JOYSTICK_H diff --git a/include/joystick_position.h b/include/joystick_position.h index e5c7de7..37aa788 100644 --- a/include/joystick_position.h +++ b/include/joystick_position.h @@ -1,7 +1,8 @@ #ifndef JOYSTICK_POSITION_H #define JOYSTICK_POSITION_H -enum class JoystickPosition { +enum class JoystickPosition +{ LEFT, RIGHT, UP, @@ -10,4 +11,4 @@ enum class JoystickPosition { HOLDING, }; -#endif // JOYSTICK_POSITION_H +#endif // JOYSTICK_POSITION_H diff --git a/include/rocker_switch.h b/include/rocker_switch.h index 452eea8..03c4500 100644 --- a/include/rocker_switch.h +++ b/include/rocker_switch.h @@ -4,7 +4,8 @@ #include -class RockerSwitch { +class RockerSwitch +{ public: explicit RockerSwitch(uint8_t up_pin, uint8_t down_pin); @@ -24,4 +25,4 @@ class RockerSwitch { const unsigned long hold_time_ = 1000; }; -#endif // ROCKER_SWITCH_H +#endif // ROCKER_SWITCH_H diff --git a/include/rocker_switch_state.h b/include/rocker_switch_state.h index ac7e511..932bdc2 100644 --- a/include/rocker_switch_state.h +++ b/include/rocker_switch_state.h @@ -1,7 +1,8 @@ #ifndef ROCKER_SWITCH_STATE_H #define ROCKER_SWITCH_STATE_H -enum class RockerSwitchState { +enum class RockerSwitchState +{ UP, HOLDING_UP, DOWN, @@ -9,4 +10,4 @@ enum class RockerSwitchState { NEUTRAL, }; -#endif // ROCKER_SWITCH_STATE_H +#endif // ROCKER_SWITCH_STATE_H diff --git a/include/screen.h b/include/screen.h index a2a726f..079a040 100644 --- a/include/screen.h +++ b/include/screen.h @@ -35,10 +35,10 @@ to the * #include #include -class Screen { +class Screen +{ public: - Screen(Goldelox_Serial_4DLib* screen, SoftwareSerial* screen_serial, - uint8_t rst, uint32_t baud); + Screen(Goldelox_Serial_4DLib* screen, SoftwareSerial* screen_serial, uint8_t rst, uint32_t baud); void init(); void clear(); @@ -68,4 +68,4 @@ class Screen { const unsigned long time_limit_ = 2000; }; -#endif // SCREEN_H +#endif // SCREEN_H diff --git a/include/sd_sector_addresses.h b/include/sd_sector_addresses.h index af3df70..eeaeabf 100644 --- a/include/sd_sector_addresses.h +++ b/include/sd_sector_addresses.h @@ -13,7 +13,8 @@ // So, address = hi << 8 | lo // These two are split, since that is how the 4dsystems // serial library addresses images on the SD. -struct SectorAddress { +struct SectorAddress +{ unsigned int hi; unsigned int lo; }; @@ -139,4 +140,4 @@ struct SectorAddress { // clang-format on -#endif // SD_SECTOR_ADDRESSES_H +#endif // SD_SECTOR_ADDRESSES_H diff --git a/include/state.h b/include/state.h index 93cb28d..e1fd42e 100644 --- a/include/state.h +++ b/include/state.h @@ -4,80 +4,119 @@ #include -class State { +class State +{ public: - State(SectorAddress address, const std::string& gait) - : gait_(gait), address_(address) {} + State(SectorAddress address, const std::string& gait) : gait_(gait), address_(address) + { + } - State(SectorAddress address) : State(address, "") {} + State(SectorAddress address) : State(address, "") + { + } - const std::string& getGaitName() const { return this->gait_; } + const std::string& getGaitName() const + { + return this->gait_; + } - void getImage(SectorAddress& image_address) const { + void getImage(SectorAddress& image_address) const + { image_address = this->address_; }; - const State* left() const { return this->left_; } - const State* right() const { return this->right_; } - const State* up() const { return this->up_; } - const State* down() const { return this->down_; } + const State* left() const + { + return this->left_; + } + const State* right() const + { + return this->right_; + } + const State* up() const + { + return this->up_; + } + const State* down() const + { + return this->down_; + } - const State* back() const { return this->back_; } - const State* select() const { return this->select_; } - const State* activate() const { return this->activate_; } + const State* back() const + { + return this->back_; + } + const State* select() const + { + return this->select_; + } + const State* activate() const + { + return this->activate_; + } - State& withLeft(State* left) { + State& withLeft(State* left) + { this->left_ = left; left->right_ = this; return *this; } - State& withRight(State* right) { + State& withRight(State* right) + { this->right_ = right; right->left_ = this; return *this; } - State& withUp(State* up) { + State& withUp(State* up) + { this->up_ = up; up->down_ = this; return *this; } - State& upTo(const State* up) { + State& upTo(const State* up) + { this->up_ = up; return *this; } - State& withDown(State* down) { + State& withDown(State* down) + { this->down_ = down; down->up_ = this; return *this; } - State& downTo(const State* down) { + State& downTo(const State* down) + { this->down_ = down; return *this; } - State& withBack(State* back) { + State& withBack(State* back) + { this->back_ = back; back->select_ = this; return *this; } - State& backTo(const State* back) { + State& backTo(const State* back) + { this->back_ = back; return *this; } - State& withSelect(State* with_select) { + State& withSelect(State* with_select) + { this->select_ = with_select; with_select->back_ = this; return *this; } - State& withActivate(const State* activate) { + State& withActivate(const State* activate) + { this->activate_ = activate; return *this; } @@ -96,4 +135,4 @@ class State { const State* activate_ = this; }; -#endif // STATE_H +#endif // STATE_H diff --git a/include/state_machine.h b/include/state_machine.h index 31ee6f9..845707f 100644 --- a/include/state_machine.h +++ b/include/state_machine.h @@ -5,7 +5,8 @@ #include #include -class StateMachine { +class StateMachine +{ public: StateMachine() = default; @@ -36,13 +37,10 @@ class StateMachine { bool hasState() const; bool setCurrentState(const State* new_state); - State& createState(const SectorAddress address, - const std::string& gait_name = ""); + State& createState(const SectorAddress address, const std::string& gait_name = ""); - State& createGaitState(const SectorAddress addr, - const SectorAddress addr_selected, - const SectorAddress addr_activated, - const std::string& gait_name, + State& createGaitState(const SectorAddress addr, const SectorAddress addr_selected, + const SectorAddress addr_activated, const std::string& gait_name, const State* result = nullptr); // This must be list, since that does not reallocate @@ -52,4 +50,4 @@ class StateMachine { const State* current_state_ = nullptr; }; -#endif // STATE_MACHINE_H +#endif // STATE_MACHINE_H diff --git a/include/version.h b/include/version.h index 3f5b647..5ecb6b3 100644 --- a/include/version.h +++ b/include/version.h @@ -5,4 +5,4 @@ #define PROJECT_NAME "input-device" #define VERSION "v2.0.0-beta.1" -#endif // VERSION_H +#endif // VERSION_H diff --git a/include/wireless_connection.h b/include/wireless_connection.h index 706597e..72366e4 100644 --- a/include/wireless_connection.h +++ b/include/wireless_connection.h @@ -11,44 +11,53 @@ const char* ssid = "OnePlus5"; const char* password = "timisdik"; -IPAddress server(192, 168, 43, 83); // ip of your ROS server +IPAddress server(192, 168, 43, 83); // ip of your ROS server IPAddress ip_address; // int status = WL_IDLE_STATUS; WiFiClient client; -void setupWiFi() { +void setupWiFi() +{ WiFi.begin(ssid, password); - while (WiFi.status() != WL_CONNECTED) { + while (WiFi.status() != WL_CONNECTED) + { delay(500); } } -class WiFiHardware { +class WiFiHardware +{ public: WiFiHardware(){}; - void init() { + void init() + { // Initialization of TCP server/client setup client.connect(server, 11411); } // read a byte from the serial port. -1 = failure - int read() { + int read() + { // Read byte from the TCP connection and returns it. returns -1 when not // working return client.read(); } // write data to the connection to ROS - void write(uint8_t* data, int length) { + void write(uint8_t* data, int length) + { // write arguments to TCP connection for (int i = 0; i < length; i++) client.write(data[i]); } // returns milliseconds since start of program - unsigned long time() { return millis(); } + unsigned long time() + { + return millis(); + } }; -#endif // WIRELESS_CONNECTION_H +#endif // WIRELESS_CONNECTION_H diff --git a/src/button.cpp b/src/button.cpp index aa6dd9f..3e97191 100644 --- a/src/button.cpp +++ b/src/button.cpp @@ -1,23 +1,30 @@ #include "button.h" -Button::Button(uint8_t pin) : input_pin_(pin) { +Button::Button(uint8_t pin) : input_pin_(pin) +{ pinMode(pin, INPUT_PULLUP); } // Returns either "NEUTRAL", "PUSH" or "HOLDING" // It is advised to treat "HOLDING" the same as "NEUTRAL" outside this function -ButtonState Button::getState() { +ButtonState Button::getState() +{ ButtonState state; - if (digitalRead(this->input_pin_) == LOW) { - if (this->last_position_ != ButtonState::PUSH || - (millis() - this->last_print_time_) > this->hold_time_) { + if (digitalRead(this->input_pin_) == LOW) + { + if (this->last_position_ != ButtonState::PUSH || (millis() - this->last_print_time_) > this->hold_time_) + { this->last_print_time_ = millis(); this->last_position_ = ButtonState::PUSH; state = ButtonState::PUSH; - } else { + } + else + { state = ButtonState::HOLDING; } - } else { + } + else + { this->last_position_ = ButtonState::NEUTRAL; state = ButtonState::NEUTRAL; } diff --git a/src/joystick.cpp b/src/joystick.cpp index d58b7e0..367e7ed 100644 --- a/src/joystick.cpp +++ b/src/joystick.cpp @@ -1,9 +1,8 @@ #include "joystick.h" -Joystick::Joystick(uint8_t left_pin, uint8_t right_pin, uint8_t up_pin, - uint8_t down_pin, uint8_t press_pin) - : left_pin_(left_pin), right_pin_(right_pin), up_pin_(up_pin), - down_pin_(down_pin), press_pin_(press_pin) { +Joystick::Joystick(uint8_t left_pin, uint8_t right_pin, uint8_t up_pin, uint8_t down_pin, uint8_t press_pin) + : left_pin_(left_pin), right_pin_(right_pin), up_pin_(up_pin), down_pin_(down_pin), press_pin_(press_pin) +{ pinMode(left_pin, INPUT_PULLUP); pinMode(right_pin, INPUT_PULLUP); pinMode(up_pin, INPUT_PULLUP); @@ -13,45 +12,63 @@ Joystick::Joystick(uint8_t left_pin, uint8_t right_pin, uint8_t up_pin, // Returns either "NEUTRAL", "[DIRECTION]" or "HOLDING" // It is advised to treat "HOLDING" the same as "NEUTRAL" outside this function -JoystickPosition Joystick::getPosition() { +JoystickPosition Joystick::getPosition() +{ JoystickPosition position; - if (digitalRead(this->left_pin_) == LOW) { - if (this->last_position_ != JoystickPosition::LEFT || - (millis() - this->last_print_time_) > this->hold_time_) { + if (digitalRead(this->left_pin_) == LOW) + { + if (this->last_position_ != JoystickPosition::LEFT || (millis() - this->last_print_time_) > this->hold_time_) + { position = JoystickPosition::LEFT; this->last_print_time_ = millis(); this->last_position_ = JoystickPosition::LEFT; - } else { + } + else + { position = JoystickPosition::HOLDING; } - } else if (digitalRead(this->right_pin_) == LOW) { - if (this->last_position_ != JoystickPosition::RIGHT || - (millis() - this->last_print_time_) > this->hold_time_) { + } + else if (digitalRead(this->right_pin_) == LOW) + { + if (this->last_position_ != JoystickPosition::RIGHT || (millis() - this->last_print_time_) > this->hold_time_) + { position = JoystickPosition::RIGHT; this->last_print_time_ = millis(); this->last_position_ = JoystickPosition::RIGHT; - } else { + } + else + { position = JoystickPosition::HOLDING; } - } else if (digitalRead(this->up_pin_) == LOW) { - if (this->last_position_ != JoystickPosition::UP || - (millis() - this->last_print_time_) > this->hold_time_) { + } + else if (digitalRead(this->up_pin_) == LOW) + { + if (this->last_position_ != JoystickPosition::UP || (millis() - this->last_print_time_) > this->hold_time_) + { position = JoystickPosition::UP; this->last_print_time_ = millis(); this->last_position_ = JoystickPosition::UP; - } else { + } + else + { position = JoystickPosition::HOLDING; } - } else if (digitalRead(this->down_pin_) == LOW) { - if (this->last_position_ != JoystickPosition::DOWN || - (millis() - this->last_print_time_) > this->hold_time_) { + } + else if (digitalRead(this->down_pin_) == LOW) + { + if (this->last_position_ != JoystickPosition::DOWN || (millis() - this->last_print_time_) > this->hold_time_) + { position = JoystickPosition::DOWN; this->last_print_time_ = millis(); this->last_position_ = JoystickPosition::DOWN; - } else { + } + else + { position = JoystickPosition::HOLDING; } - } else { + } + else + { position = JoystickPosition::NEUTRAL; this->last_position_ = JoystickPosition::NEUTRAL; } @@ -61,43 +78,55 @@ JoystickPosition Joystick::getPosition() { } // Returns either "NEUTRAL", "PUSH" or "DOUBLE" -ButtonState Joystick::getState() { +ButtonState Joystick::getState() +{ ButtonState state; - if (this->recent_double_click_) { - if (millis() - this->last_double_click_time_ > - this->double_click_timeout_time_) { - this->recent_double_click_ = - false; // Go back to an mode where we can publish stuff + if (this->recent_double_click_) + { + if (millis() - this->last_double_click_time_ > this->double_click_timeout_time_) + { + this->recent_double_click_ = false; // Go back to an mode where we can publish stuff } } - if (this->recent_initial_click_ && !this->recent_double_click_) { - if (millis() - this->last_push_release_time_ > this->double_click_time_ && - digitalRead(this->press_pin_) == - HIGH) { // Enough time has elapsed since last - // push release time and not pressed + if (this->recent_initial_click_ && !this->recent_double_click_) + { + if (millis() - this->last_push_release_time_ > this->double_click_time_ && digitalRead(this->press_pin_) == HIGH) + { // Enough time has elapsed since last + // push release time and not pressed this->last_push_ = false; - state = ButtonState::PUSH; // No second click, so publish the single click + state = ButtonState::PUSH; // No second click, so publish the single click this->recent_initial_click_ = false; - } else if (digitalRead(this->press_pin_) == LOW) { // Joystick is pressed + } + else if (digitalRead(this->press_pin_) == LOW) + { // Joystick is pressed this->last_push_ = true; - state = - ButtonState::DOUBLE; // A second click, so publish the double click + state = ButtonState::DOUBLE; // A second click, so publish the double click this->recent_initial_click_ = false; this->recent_double_click_ = true; this->last_double_click_time_ = millis(); - } else { // Joystick not pressed, not just released and recent enough - // initial click + } + else + { // Joystick not pressed, not just released and recent enough + // initial click this->last_push_ = false; state = ButtonState::NEUTRAL; } - } else { // No recent initial click or a recent double click - if (digitalRead(this->press_pin_) == LOW) { // Pressed + } + else + { // No recent initial click or a recent double click + if (digitalRead(this->press_pin_) == LOW) + { // Pressed this->last_push_ = true; - } else { // Not pressed - if (this->last_push_) { // Just released + } + else + { // Not pressed + if (this->last_push_) + { // Just released this->recent_initial_click_ = true; this->last_push_release_time_ = millis(); - } else { + } + else + { this->recent_initial_click_ = false; } this->last_push_ = false; diff --git a/src/main.cpp b/src/main.cpp index 4e2a3aa..7fa5d0e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,7 +15,8 @@ #include #include -namespace pins { +namespace pins +{ const uint8_t TRIGGER = 26; const uint8_t ROCKER_UP = 2; @@ -26,10 +27,10 @@ const uint8_t JOYSTICK_RIGHT = 14; const uint8_t JOYSTICK_UP = 12; const uint8_t JOYSTICK_DOWN = 19; const uint8_t JOYSTICK_PUSH = 18; -const uint8_t UART_TX = 32; // Software serial -const uint8_t UART_RX = 34; // Software serial -const uint8_t RST = 13; // Reset -} // namespace pins +const uint8_t UART_TX = 32; // Software serial +const uint8_t UART_RX = 34; // Software serial +const uint8_t RST = 13; // Reset +} // namespace pins const uint32_t BAUD_SCREEN = 9600; const uint64_t BAUD_SERIAL = 57600; @@ -45,8 +46,8 @@ const uint64_t BAUD_SERIAL = 57600; Button trigger(pins::TRIGGER); RockerSwitch rocker(pins::ROCKER_UP, pins::ROCKER_DOWN); -Joystick joystick(pins::JOYSTICK_LEFT, pins::JOYSTICK_RIGHT, pins::JOYSTICK_UP, - pins::JOYSTICK_DOWN, pins::JOYSTICK_PUSH); +Joystick joystick(pins::JOYSTICK_LEFT, pins::JOYSTICK_RIGHT, pins::JOYSTICK_UP, pins::JOYSTICK_DOWN, + pins::JOYSTICK_PUSH); SoftwareSerial screen_serial(pins::UART_RX, pins::UART_TX); Goldelox_Serial_4DLib screen_goldelox(&screen_serial); @@ -68,26 +69,26 @@ ros::NodeHandle nh; bool received_gait_instruction_response = false; bool gait_rejected = false; bool gait_message_send = false; -void gaitInstructionResponseCallback( - const march_shared_resources::GaitInstructionResponse& msg) { - if (msg.result == msg.GAIT_FINISHED || msg.result == msg.GAIT_REJECTED) { +void gaitInstructionResponseCallback(const march_shared_resources::GaitInstructionResponse& msg) +{ + if (msg.result == msg.GAIT_FINISHED || msg.result == msg.GAIT_REJECTED) + { received_gait_instruction_response = true; } } ros::Subscriber - gait_instruction_result_subscriber( - "/march/input_device/instruction_response", - &gaitInstructionResponseCallback); + gait_instruction_result_subscriber("/march/input_device/instruction_response", &gaitInstructionResponseCallback); march_shared_resources::GaitInstruction gait_instruction_msg; std_msgs::Time time_msg; -ros::Publisher gait_instruction_publisher("/march/input_device/instruction", - &gait_instruction_msg); +ros::Publisher gait_instruction_publisher("/march/input_device/instruction", &gait_instruction_msg); ros::Publisher ping_publisher("/march/input_device/alive", &time_msg); -void sendGaitMessage(const std::string& name) { - if (!name.empty() && !gait_message_send) { +void sendGaitMessage(const std::string& name) +{ + if (!name.empty() && !gait_message_send) + { gait_instruction_msg.type = march_shared_resources::GaitInstruction::GAIT; gait_instruction_msg.gait_name = name.c_str(); gait_instruction_publisher.publish(&gait_instruction_msg); @@ -99,24 +100,28 @@ void sendGaitMessage(const std::string& name) { } } -void sendStopMessage() { +void sendStopMessage() +{ gait_instruction_msg.type = march_shared_resources::GaitInstruction::STOP; gait_instruction_msg.gait_name = ""; gait_instruction_publisher.publish(&gait_instruction_msg); } -void sendAliveMessage() { +void sendAliveMessage() +{ time_msg.data = nh.now(); ping_publisher.publish(&time_msg); } -void drawCurrentImage() { +void drawCurrentImage() +{ SectorAddress address; state_machine.getCurrentImage(address); screen.draw_image(address); } -void setup() { +void setup() +{ Serial.begin(BAUD_SERIAL); #ifdef USE_WIRELESS @@ -152,7 +157,8 @@ void setup() { drawCurrentImage(); } -void loop() { +void loop() +{ // Get button states // RockerSwitchState rocker_switch_state = rocker.getState(); JoystickPosition joystick_position = joystick.getPosition(); @@ -160,58 +166,74 @@ void loop() { ButtonState trigger_state = trigger.getState(); // When button is pressed, vibrate - if (trigger_state == ButtonState::PUSH) { + if (trigger_state == ButtonState::PUSH) + { // Waveforms can be combined, to create new wavefroms, see driver datasheet - driver.setWaveform(0, EFFECT); // Setup the waveform(s) - driver.setWaveform(1, 0); // end of waveform waveform + driver.setWaveform(0, EFFECT); // Setup the waveform(s) + driver.setWaveform(1, 0); // end of waveform waveform driver.go(); } bool state_has_changed = false; - if (received_gait_instruction_response) { + if (received_gait_instruction_response) + { // This means gait instruction handled received_gait_instruction_response = false; gait_message_send = false; state_has_changed = state_machine.activate(); - } else if (gait_message_send) { - if (trigger_state == ButtonState::PUSH) { + } + else if (gait_message_send) + { + if (trigger_state == ButtonState::PUSH) + { sendStopMessage(); } - } else { - switch (joystick_position) { - case JoystickPosition::LEFT: - state_has_changed = state_machine.left(); - break; - case JoystickPosition::RIGHT: - state_has_changed = state_machine.right(); - break; - case JoystickPosition::UP: - state_has_changed = state_machine.up(); - break; - case JoystickPosition::DOWN: - state_has_changed = state_machine.down(); - break; - default: - break; + } + else + { + switch (joystick_position) + { + case JoystickPosition::LEFT: + state_has_changed = state_machine.left(); + break; + case JoystickPosition::RIGHT: + state_has_changed = state_machine.right(); + break; + case JoystickPosition::UP: + state_has_changed = state_machine.up(); + break; + case JoystickPosition::DOWN: + state_has_changed = state_machine.down(); + break; + default: + break; } - if (!state_has_changed) { - if (joystick_state == ButtonState::PUSH) { + if (!state_has_changed) + { + if (joystick_state == ButtonState::PUSH) + { state_has_changed = state_machine.back(); - } else if (joystick_state == ButtonState::DOUBLE) { + } + else if (joystick_state == ButtonState::DOUBLE) + { state_has_changed = state_machine.back(); - } else if (trigger_state == ButtonState::PUSH) { + } + else if (trigger_state == ButtonState::PUSH) + { state_has_changed = state_machine.activate(); } } } - if (state_has_changed) { + if (state_has_changed) + { drawCurrentImage(); std::string gait_name = state_machine.getCurrentGaitName(); - if (!gait_name.empty()) { + if (!gait_name.empty()) + { sendGaitMessage(gait_name); } } diff --git a/src/rocker_switch.cpp b/src/rocker_switch.cpp index b4f030d..a82d1b9 100644 --- a/src/rocker_switch.cpp +++ b/src/rocker_switch.cpp @@ -1,7 +1,7 @@ #include "rocker_switch.h" -RockerSwitch::RockerSwitch(uint8_t up_pin, uint8_t down_pin) - : up_pin_(up_pin), down_pin_(down_pin) { +RockerSwitch::RockerSwitch(uint8_t up_pin, uint8_t down_pin) : up_pin_(up_pin), down_pin_(down_pin) +{ pinMode(up_pin, INPUT_PULLUP); pinMode(down_pin, INPUT_PULLUP); } @@ -9,29 +9,39 @@ RockerSwitch::RockerSwitch(uint8_t up_pin, uint8_t down_pin) // Returns either "NEUTRAL", "UP", "HOLDING UP", "DOWN" or "HOLDING DOWN" // It is advised to treat "HOLDING X" the same as "NEUTRAL" outside this // function -RockerSwitchState RockerSwitch::getState() { +RockerSwitchState RockerSwitch::getState() +{ RockerSwitchState state; - if (digitalRead(this->up_pin_) == LOW) { - if (this->last_position_ != RockerSwitchState::UP || - (millis() - this->last_print_time_) > this->hold_time_) { + if (digitalRead(this->up_pin_) == LOW) + { + if (this->last_position_ != RockerSwitchState::UP || (millis() - this->last_print_time_) > this->hold_time_) + { // reset lastPrintTime this->last_print_time_ = millis(); this->last_position_ = RockerSwitchState::UP; state = RockerSwitchState::UP; - } else { + } + else + { state = RockerSwitchState::HOLDING_UP; } - } else if (digitalRead(this->down_pin_) == LOW) { - if (this->last_position_ != RockerSwitchState::DOWN || - (millis() - this->last_print_time_) > this->hold_time_) { + } + else if (digitalRead(this->down_pin_) == LOW) + { + if (this->last_position_ != RockerSwitchState::DOWN || (millis() - this->last_print_time_) > this->hold_time_) + { // reset lastPrintTime this->last_print_time_ = millis(); this->last_position_ = RockerSwitchState::DOWN; state = RockerSwitchState::DOWN; - } else { + } + else + { state = RockerSwitchState::HOLDING_DOWN; } - } else { + } + else + { this->last_position_ = RockerSwitchState::NEUTRAL; state = RockerSwitchState::NEUTRAL; } diff --git a/src/screen.cpp b/src/screen.cpp index 5ead5b1..0888bb8 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -4,13 +4,14 @@ // 16-bit color March blue converted from 24bit 0x126287 const word MARCH_COLOR = 0x218B; -Screen::Screen(Goldelox_Serial_4DLib* screen, SoftwareSerial* screen_serial, - uint8_t rst, uint32_t baud) - : screen_(screen), serial_(screen_serial), rst_(rst), baud_(baud) { +Screen::Screen(Goldelox_Serial_4DLib* screen, SoftwareSerial* screen_serial, uint8_t rst, uint32_t baud) + : screen_(screen), serial_(screen_serial), rst_(rst), baud_(baud) +{ pinMode(rst, OUTPUT); } -void Screen::init() { +void Screen::init() +{ this->reset(); this->serial_->begin(this->baud_); @@ -34,12 +35,14 @@ void Screen::init() { this->last_draw_time_ = millis(); } -void Screen::clear() { +void Screen::clear() +{ this->screen_->gfx_Cls(); usleep(this->wait_time_ms_); } -void Screen::reset() { +void Screen::reset() +{ digitalWrite(this->rst_, 1); usleep(100000); digitalWrite(this->rst_, 0); @@ -50,13 +53,15 @@ void Screen::reset() { sleep(3); } -void Screen::draw_image(SectorAddress address) { +void Screen::draw_image(SectorAddress address) +{ this->screen_->media_SetSector(address.hi, address.lo); this->screen_->media_Image(0, 0); this->last_draw_time_ = millis(); } -void Screen::printVersion() { +void Screen::printVersion() +{ this->screen_->txt_Bold(ON); this->screen_->txt_Width(2); this->screen_->txt_Height(2); @@ -73,13 +78,16 @@ void Screen::printVersion() { this->screen_->println(""); } -void Screen::mountImages() { +void Screen::mountImages() +{ word initialized = this->screen_->media_Init(); - if (initialized == 0) { + if (initialized == 0) + { this->screen_->txt_FGcolour(RED); this->screen_->println("Pls insert SD"); - while (initialized == 0) { + while (initialized == 0) + { sleep(1); initialized = this->screen_->media_Init(); } diff --git a/src/state_machine.cpp b/src/state_machine.cpp index 0b7ea33..2972d02 100644 --- a/src/state_machine.cpp +++ b/src/state_machine.cpp @@ -3,19 +3,17 @@ #include -void StateMachine::construct() { +void StateMachine::construct() +{ // Walk menu State& walk = this->createState(WALK); State& side_step = this->createState(SIDE_STEP); State& single_step = this->createState(SINGLE_STEP); // Sit menu - State& sit = - this->createGaitState(SIT, SIT_SELECTED, SIT_ACTIVATED, "gait_sit"); - State& home_sit = this->createGaitState(HOME_SIT, HOME_SIT_SELECTED, - HOME_SIT_ACTIVATED, "home_sit"); - State& home_stand = this->createGaitState(HOME_STAND, HOME_STAND_SELECTED, - HOME_STAND_ACTIVATED, "home_stand"); + State& sit = this->createGaitState(SIT, SIT_SELECTED, SIT_ACTIVATED, "gait_sit"); + State& home_sit = this->createGaitState(HOME_SIT, HOME_SIT_SELECTED, HOME_SIT_ACTIVATED, "home_sit"); + State& home_stand = this->createGaitState(HOME_STAND, HOME_STAND_SELECTED, HOME_STAND_ACTIVATED, "home_stand"); State& turn_off = this->createState(TURN_OFF); // Obstacle menu @@ -23,14 +21,11 @@ void StateMachine::construct() { State& stairs = this->createState(STAIRS); // Start menu - State& stand_up = this->createGaitState( - STAND_UP, STAND_UP_SELECTED, STAND_UP_ACTIVATED, "gait_stand", &walk); + State& stand_up = this->createGaitState(STAND_UP, STAND_UP_SELECTED, STAND_UP_ACTIVATED, "gait_stand", &walk); State& home_sit_start = - this->createGaitState(HOME_SIT_START, HOME_SIT_START_SELECTED, - HOME_SIT_START_ACTIVATED, "home_sit", &stand_up); - State& home_stand_start = - this->createGaitState(HOME_STAND_START, HOME_STAND_START_SELECTED, - HOME_STAND_START_ACTIVATED, "home_stand", &walk); + this->createGaitState(HOME_SIT_START, HOME_SIT_START_SELECTED, HOME_SIT_START_ACTIVATED, "home_sit", &stand_up); + State& home_stand_start = this->createGaitState(HOME_STAND_START, HOME_STAND_START_SELECTED, + HOME_STAND_START_ACTIVATED, "home_stand", &walk); State& turn_off_start = this->createState(TURN_OFF_START); // Sub-menus @@ -62,13 +57,12 @@ void StateMachine::construct() { this->current_state_ = &home_sit_start; } -void StateMachine::constructWalkMenu(State* from) { +void StateMachine::constructWalkMenu(State* from) +{ State& walk_small = - this->createGaitState(WALK_SMALL, WALK_SMALL_SELECTED, - WALK_SMALL_ACTIVATED, "gait_walk_small", from); + this->createGaitState(WALK_SMALL, WALK_SMALL_SELECTED, WALK_SMALL_ACTIVATED, "gait_walk_small", from); State& walk_normal = - this->createGaitState(WALK_NORMAL, WALK_NORMAL_SELECTED, - WALK_NORMAL_ACTIVATED, "gait_walk", from); + this->createGaitState(WALK_NORMAL, WALK_NORMAL_SELECTED, WALK_NORMAL_ACTIVATED, "gait_walk", from); State& walk_large = this->createState(WALK_LARGE); walk_small.backTo(from); @@ -78,51 +72,43 @@ void StateMachine::constructWalkMenu(State* from) { from->withSelect(&walk_normal); } -void StateMachine::constructSideStepMenu(State* from) { +void StateMachine::constructSideStepMenu(State* from) +{ State& side_step_left = this->createState(SIDE_STEP_LEFT); State& side_step_right = this->createState(SIDE_STEP_RIGHT); - State& side_step_left_small = this->createGaitState( - SIDE_STEP_LEFT_SMALL, SIDE_STEP_LEFT_SMALL_SELECTED, - SIDE_STEP_LEFT_SMALL_ACTIVATED, "gait_side_step_left_small", from); + State& side_step_left_small = + this->createGaitState(SIDE_STEP_LEFT_SMALL, SIDE_STEP_LEFT_SMALL_SELECTED, SIDE_STEP_LEFT_SMALL_ACTIVATED, + "gait_side_step_left_small", from); - State& side_step_left_normal = this->createGaitState( - SIDE_STEP_LEFT_NORMAL, SIDE_STEP_LEFT_NORMAL_SELECTED, - SIDE_STEP_LEFT_NORMAL_ACTIVATED, "gait_side_step_left", from); + State& side_step_left_normal = this->createGaitState(SIDE_STEP_LEFT_NORMAL, SIDE_STEP_LEFT_NORMAL_SELECTED, + SIDE_STEP_LEFT_NORMAL_ACTIVATED, "gait_side_step_left", from); - State& side_step_right_small = this->createGaitState( - SIDE_STEP_RIGHT_SMALL, SIDE_STEP_RIGHT_SMALL_SELECTED, - SIDE_STEP_RIGHT_SMALL_ACTIVATED, "gait_side_step_right_small", from); + State& side_step_right_small = + this->createGaitState(SIDE_STEP_RIGHT_SMALL, SIDE_STEP_RIGHT_SMALL_SELECTED, SIDE_STEP_RIGHT_SMALL_ACTIVATED, + "gait_side_step_right_small", from); - State& side_step_right_normal = this->createGaitState( - SIDE_STEP_RIGHT_NORMAL, SIDE_STEP_RIGHT_NORMAL_SELECTED, - SIDE_STEP_RIGHT_NORMAL_ACTIVATED, "gait_side_step_right", from); + State& side_step_right_normal = this->createGaitState(SIDE_STEP_RIGHT_NORMAL, SIDE_STEP_RIGHT_NORMAL_SELECTED, + SIDE_STEP_RIGHT_NORMAL_ACTIVATED, "gait_side_step_right", from); - side_step_left.backTo(from) - .withRight(&side_step_right) - .withSelect(&side_step_left_normal); - side_step_right.backTo(from) - .withRight(&side_step_left) - .withSelect(&side_step_right_normal); + side_step_left.backTo(from).withRight(&side_step_right).withSelect(&side_step_left_normal); + side_step_right.backTo(from).withRight(&side_step_left).withSelect(&side_step_right_normal); - side_step_left_small.backTo(&side_step_left) - .withRight(&side_step_left_normal); + side_step_left_small.backTo(&side_step_left).withRight(&side_step_left_normal); side_step_left_normal.withRight(&side_step_left_small); - side_step_right_small.backTo(&side_step_right) - .withRight(&side_step_right_normal); + side_step_right_small.backTo(&side_step_right).withRight(&side_step_right_normal); side_step_right_normal.withRight(&side_step_right_small); from->withSelect(&side_step_left); } -void StateMachine::constructStepMenu(State* from) { - State& single_step_small = this->createGaitState( - SINGLE_STEP_SMALL, SINGLE_STEP_SMALL_SELECTED, - SINGLE_STEP_SMALL_ACTIVATED, "gait_single_step_normal", from); - State& single_step_normal = this->createGaitState( - SINGLE_STEP_NORMAL, SINGLE_STEP_NORMAL_SELECTED, - SINGLE_STEP_NORMAL_ACTIVATED, "gait_single_step_normal", from); +void StateMachine::constructStepMenu(State* from) +{ + State& single_step_small = this->createGaitState(SINGLE_STEP_SMALL, SINGLE_STEP_SMALL_SELECTED, + SINGLE_STEP_SMALL_ACTIVATED, "gait_single_step_normal", from); + State& single_step_normal = this->createGaitState(SINGLE_STEP_NORMAL, SINGLE_STEP_NORMAL_SELECTED, + SINGLE_STEP_NORMAL_ACTIVATED, "gait_single_step_normal", from); State& single_step_large = this->createState(SINGLE_STEP_LARGE); single_step_small.backTo(from).withRight(&single_step_normal); @@ -132,104 +118,108 @@ void StateMachine::constructStepMenu(State* from) { from->withSelect(&single_step_normal); } -void StateMachine::constructSofaMenu(State* from) { +void StateMachine::constructSofaMenu(State* from) +{ State& sofa_standup = - this->createGaitState(SOFA_STANDUP, SOFA_STANDUP_SELECTED, - SOFA_STANDUP_ACTIVATED, "gait_sofa_stand", from); + this->createGaitState(SOFA_STANDUP, SOFA_STANDUP_SELECTED, SOFA_STANDUP_ACTIVATED, "gait_sofa_stand", from); State& sofa_sit = - this->createGaitState(SOFA_SIT, SOFA_SIT_SELECTED, SOFA_SIT_ACTIVATED, - "gait_sofa_sit", &sofa_standup); + this->createGaitState(SOFA_SIT, SOFA_SIT_SELECTED, SOFA_SIT_ACTIVATED, "gait_sofa_sit", &sofa_standup); sofa_sit.backTo(from).withRight(&sofa_standup); sofa_standup.backTo(from).withRight(&sofa_sit); from->withSelect(&sofa_sit); } -void StateMachine::constructStairsMenu(State* from) { - State& stairs_up = - this->createGaitState(STAIRS_UP, STAIRS_UP_SELECTED, STAIRS_UP_ACTIVATED, - "gait_stairs_up", from); +void StateMachine::constructStairsMenu(State* from) +{ + State& stairs_up = this->createGaitState(STAIRS_UP, STAIRS_UP_SELECTED, STAIRS_UP_ACTIVATED, "gait_stairs_up", from); State& stairs_down = - this->createGaitState(STAIRS_DOWN, STAIRS_DOWN_SELECTED, - STAIRS_DOWN_ACTIVATED, "gait_stairs_down", from); + this->createGaitState(STAIRS_DOWN, STAIRS_DOWN_SELECTED, STAIRS_DOWN_ACTIVATED, "gait_stairs_down", from); stairs_up.backTo(from).withRight(&stairs_down); stairs_down.backTo(from).withRight(&stairs_up); from->withSelect(&stairs_up); } -std::string StateMachine::getCurrentGaitName() const { - if (this->hasState()) { +std::string StateMachine::getCurrentGaitName() const +{ + if (this->hasState()) + { return this->current_state_->getGaitName(); } return std::string(); } -void StateMachine::getCurrentImage(SectorAddress& address) const { - if (this->hasState()) { +void StateMachine::getCurrentImage(SectorAddress& address) const +{ + if (this->hasState()) + { this->current_state_->getImage(address); } } -size_t StateMachine::size() const { +size_t StateMachine::size() const +{ return this->states_.size(); } -bool StateMachine::left() { - return this->hasState() && - this->setCurrentState(this->current_state_->left()); +bool StateMachine::left() +{ + return this->hasState() && this->setCurrentState(this->current_state_->left()); } -bool StateMachine::right() { - return this->hasState() && - this->setCurrentState(this->current_state_->right()); +bool StateMachine::right() +{ + return this->hasState() && this->setCurrentState(this->current_state_->right()); } -bool StateMachine::up() { +bool StateMachine::up() +{ return this->hasState() && this->setCurrentState(this->current_state_->up()); } -bool StateMachine::down() { - return this->hasState() && - this->setCurrentState(this->current_state_->down()); +bool StateMachine::down() +{ + return this->hasState() && this->setCurrentState(this->current_state_->down()); } -bool StateMachine::back() { - return this->hasState() && - this->setCurrentState(this->current_state_->back()); +bool StateMachine::back() +{ + return this->hasState() && this->setCurrentState(this->current_state_->back()); } -bool StateMachine::select() { - return this->hasState() && - this->setCurrentState(this->current_state_->select()); +bool StateMachine::select() +{ + return this->hasState() && this->setCurrentState(this->current_state_->select()); } -bool StateMachine::activate() { - return this->hasState() && - this->setCurrentState(this->current_state_->activate()); +bool StateMachine::activate() +{ + return this->hasState() && this->setCurrentState(this->current_state_->activate()); } -bool StateMachine::hasState() const { +bool StateMachine::hasState() const +{ return this->current_state_ != nullptr; } -bool StateMachine::setCurrentState(const State* new_state) { +bool StateMachine::setCurrentState(const State* new_state) +{ bool has_changed = this->current_state_ != new_state; this->current_state_ = new_state; return has_changed; } -State& StateMachine::createState(const SectorAddress address, - const std::string& gait_name) { +State& StateMachine::createState(const SectorAddress address, const std::string& gait_name) +{ this->states_.emplace_back(address, gait_name); return this->states_.back(); } -State& StateMachine::createGaitState(const SectorAddress addr, - const SectorAddress addr_selected, - const SectorAddress addr_activated, - const std::string& gait_name, - const State* result) { +State& StateMachine::createGaitState(const SectorAddress addr, const SectorAddress addr_selected, + const SectorAddress addr_activated, const std::string& gait_name, + const State* result) +{ State& normal = this->createState(addr); State& selected = this->createState(addr_selected); State& activated = this->createState(addr_activated, gait_name); diff --git a/test/test_state/test_state.cpp b/test/test_state/test_state.cpp index e09524e..3c46add 100644 --- a/test/test_state/test_state.cpp +++ b/test/test_state/test_state.cpp @@ -4,14 +4,16 @@ #include -void test_state_get_gait_name() { +void test_state_get_gait_name() +{ std::string gait("test"); - State state({0, 0}, gait); + State state({ 0, 0 }, gait); TEST_ASSERT_EQUAL_STRING(gait.c_str(), state.getGaitName().c_str()); } -void test_state_get_address() { - SectorAddress expected = {7, 8}; +void test_state_get_address() +{ + SectorAddress expected = { 7, 8 }; State state(expected); SectorAddress address; @@ -20,8 +22,9 @@ void test_state_get_address() { TEST_ASSERT_EQUAL(expected.lo, address.lo); } -void test_state_default_transitions() { - State state({0, 0}); +void test_state_default_transitions() +{ + State state({ 0, 0 }); TEST_ASSERT_EQUAL(&state, state.left()); TEST_ASSERT_EQUAL(&state, state.right()); TEST_ASSERT_EQUAL(&state, state.up()); @@ -31,7 +34,8 @@ void test_state_default_transitions() { TEST_ASSERT_EQUAL(&state, state.activate()); } -int main(int argc, char** argv) { +int main(int argc, char** argv) +{ UNITY_BEGIN(); RUN_TEST(test_state_get_gait_name); RUN_TEST(test_state_get_address); diff --git a/test/test_state_machine/test_state_machine.cpp b/test/test_state_machine/test_state_machine.cpp index 3aac458..5e0e741 100644 --- a/test/test_state_machine/test_state_machine.cpp +++ b/test/test_state_machine/test_state_machine.cpp @@ -4,22 +4,25 @@ #include -void test_get_gait_name() { +void test_get_gait_name() +{ StateMachine state_machine; std::string gait_name = state_machine.getCurrentGaitName(); TEST_ASSERT_EQUAL_STRING("", gait_name.c_str()); } -void test_get_image() { +void test_get_image() +{ StateMachine state_machine; - SectorAddress expected({2, 3}); + SectorAddress expected({ 2, 3 }); SectorAddress address = expected; state_machine.getCurrentImage(address); TEST_ASSERT_EQUAL(expected.hi, address.hi); TEST_ASSERT_EQUAL(expected.lo, address.lo); } -void test_state_machine_default_no_transitions() { +void test_state_machine_default_no_transitions() +{ StateMachine state_machine; TEST_ASSERT_FALSE(state_machine.left()); TEST_ASSERT_FALSE(state_machine.right()); @@ -30,12 +33,14 @@ void test_state_machine_default_no_transitions() { TEST_ASSERT_FALSE(state_machine.activate()); } -void test_default_empty() { +void test_default_empty() +{ StateMachine state_machine; TEST_ASSERT_EQUAL(0, state_machine.size()); } -int main(int argc, char** argv) { +int main(int argc, char** argv) +{ UNITY_BEGIN(); RUN_TEST(test_get_gait_name); RUN_TEST(test_get_image); From db27e9b580cf51d75fd0a79be29fe31c65acb1cf Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Thu, 2 Jan 2020 15:11:06 +0100 Subject: [PATCH 50/58] Fix select bug --- src/main.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 7fa5d0e..2d66585 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -210,11 +210,10 @@ void loop() break; } - if (!state_has_changed) - { + if (!state_has_changed) { if (joystick_state == ButtonState::PUSH) { - state_has_changed = state_machine.back(); + state_has_changed = state_machine.select(); } else if (joystick_state == ButtonState::DOUBLE) { From 2f37347cea0d474723ccfc962245af65eb8e29e2 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Thu, 2 Jan 2020 15:15:08 +0100 Subject: [PATCH 51/58] Fix styling --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 2d66585..c5c344a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -210,7 +210,8 @@ void loop() break; } - if (!state_has_changed) { + if (!state_has_changed) + { if (joystick_state == ButtonState::PUSH) { state_has_changed = state_machine.select(); From 67b87be7d4095af849d42c0c7ebd98161522bd67 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Fri, 3 Jan 2020 09:38:53 +0100 Subject: [PATCH 52/58] Fixed consistency comments --- include/button.h | 4 +-- include/button_state.h | 2 ++ include/joystick.h | 12 ++++--- include/rocker_switch.h | 4 +-- include/rocker_switch_state.h | 8 +++-- include/screen.h | 61 +++++++++++++++++------------------ src/button.cpp | 2 -- src/joystick.cpp | 3 -- src/rocker_switch.cpp | 3 -- src/screen.cpp | 6 ++-- 10 files changed, 51 insertions(+), 54 deletions(-) diff --git a/include/button.h b/include/button.h index f58562d..a2e6291 100644 --- a/include/button.h +++ b/include/button.h @@ -16,9 +16,9 @@ class Button ButtonState last_position_ = ButtonState::NEUTRAL; unsigned long last_print_time_ = 0; - // us. May introduce unwanted behaviour if changed + // Microseconds. May introduce unwanted behaviour if changed const useconds_t bounce_time_ = 20000; - // ms. Determines how often 'push' is returned if the button is held + // Milliseconds. Determines how often 'push' is returned if the button is held const unsigned long hold_time_ = 1000; }; diff --git a/include/button_state.h b/include/button_state.h index 0c2e89a..358f37f 100644 --- a/include/button_state.h +++ b/include/button_state.h @@ -4,6 +4,8 @@ enum class ButtonState { NEUTRAL, + // It is advised to treat HOLDING the same as NEUTRAL + // as it is only used internally. HOLDING, PUSH, DOUBLE, diff --git a/include/joystick.h b/include/joystick.h index a0cb79e..4fa82fc 100644 --- a/include/joystick.h +++ b/include/joystick.h @@ -30,15 +30,19 @@ class Joystick unsigned long last_push_release_time_ = 0; unsigned long last_double_click_time_ = 0; - // us. May introduce unwanted behaviour if changed + // Microseconds. May introduce unwanted behaviour if changed const useconds_t bounce_time_ = 5000; - // ms. Determines how often up or down + // Milliseconds. Determines how often up or down // are returned if the joystick is held. const unsigned long hold_time_ = 1000; - const unsigned long double_click_time_ = 300; // ms. - const unsigned long double_click_timeout_time_ = 500; // ms + // Milliseconds. The duration before a second press is registered + // as a double click. + const unsigned long double_click_time_ = 300; + // Milliseconds. Timeout after a double click was registered + // before other commands can be registered. + const unsigned long double_click_timeout_time_ = 500; }; #endif // JOYSTICK_H diff --git a/include/rocker_switch.h b/include/rocker_switch.h index 03c4500..4fef8ea 100644 --- a/include/rocker_switch.h +++ b/include/rocker_switch.h @@ -17,10 +17,10 @@ class RockerSwitch RockerSwitchState last_position_ = RockerSwitchState::NEUTRAL; unsigned long last_print_time_ = 0; - // us. May introduce unwanted behaviour if changed + // Microseconds. May introduce unwanted behaviour if changed const useconds_t bounce_time_ = 20000; - // ms. Determines how often up or down are returned if the rocker + // Milliseconds. Determines how often up or down are returned if the rocker // switch is held up or down. const unsigned long hold_time_ = 1000; }; diff --git a/include/rocker_switch_state.h b/include/rocker_switch_state.h index 932bdc2..a184c31 100644 --- a/include/rocker_switch_state.h +++ b/include/rocker_switch_state.h @@ -3,11 +3,13 @@ enum class RockerSwitchState { - UP, + NEUTRAL, + // It is advised to treat HOLDING X the same as NEUTRAL + // outside this function. HOLDING_UP, - DOWN, HOLDING_DOWN, - NEUTRAL, + UP, + DOWN, }; #endif // ROCKER_SWITCH_STATE_H diff --git a/include/screen.h b/include/screen.h index 079a040..812a5ef 100644 --- a/include/screen.h +++ b/include/screen.h @@ -1,32 +1,29 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -* * * * *\ +/* * Library implementing the software interface for a 4D Systems uOLED-160G2 -microOLED * - * GOLDELOX Display. * - * Hardware consists of a screen with a set of ten pins on the back. * - * Pins "+5V" and "GND" should be connected to their respective voltages. * - * Pin "RES" should be connected to a digital output pin. * - * Pins "RX" and "TX" should be connected to the pins of a UART peripheral -* - * interface. Note that the "RX" pin of the screen should be connected -to the * - * "TX" pin of the UART interface, and vice versa. * - * The other pins should be unconnected. * - * ┌────────────────────┐ * - * │ 3.3V ──O O─┼── RES * - * │ GND ──O O─┼── GND * - * │ IO1 ──O O─┼── RX * - * │ IO2 ──O O─┼── TX * - * │ 5V OUT ──O O─┼── +5V * - * │ │ * - * │ │ * - * │ │ * - * └────────────────────┘ * - * * - * Created by P. Verton and M. van der Marel for Project MARCH * - * Date: 27-MAR-2018 * -\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -* * * * */ + * microOLED GOLDELOX Display. + * + * Hardware consists of a screen with a set of ten pins on the back. + * + * * Pins "+5V" and "GND" should be connected to their respective voltages. + * * Pin "RES" should be connected to a digital output pin. + * * Pins "RX" and "TX" should be connected to the pins of a UART peripheral + * interface. Note that the "RX" pin of the screen should be connected + * to the "TX" pin of the UART interface, and vice versa. + * * The other pins should be unconnected. + * ┌────────────────────┐ + * │ 3.3V ──O O─┼── RES + * │ GND ──O O─┼── GND + * │ IO1 ──O O─┼── RX + * │ IO2 ──O O─┼── TX + * │ 5V OUT ──O O─┼── +5V + * │ │ + * │ │ + * │ │ + * └────────────────────┘ + * + * Created by P. Verton and M. van der Marel for Project MARCH + * Date: 27-MAR-2018 + */ #ifndef SCREEN_H #define SCREEN_H #include "sd_sector_addresses.h" @@ -57,14 +54,14 @@ class Screen const uint8_t rst_; const uint32_t baud_; - // In microseconds. Needed for functioning, can still be optimized - const useconds_t wait_time_ms_ = 500000; + // Microseconds. Needed for functioning, can still be optimized + const useconds_t wait_time_ = 500000; // Milliseconds, when the screen should start scrolling - const word screen_saver_timeout_ms_ = 10000; + const word screen_saver_timeout_ = 10000; // Must be value in 0-255 (fastest-slowest) const word screen_saver_scroll_speed_ = 0; - // Sets the time out limit for screen serial commands to 2 seconds. + // Milliseconds. Sets the time out limit for screen serial commands to 2 seconds. const unsigned long time_limit_ = 2000; }; diff --git a/src/button.cpp b/src/button.cpp index 3e97191..5a04cd9 100644 --- a/src/button.cpp +++ b/src/button.cpp @@ -5,8 +5,6 @@ Button::Button(uint8_t pin) : input_pin_(pin) pinMode(pin, INPUT_PULLUP); } -// Returns either "NEUTRAL", "PUSH" or "HOLDING" -// It is advised to treat "HOLDING" the same as "NEUTRAL" outside this function ButtonState Button::getState() { ButtonState state; diff --git a/src/joystick.cpp b/src/joystick.cpp index 367e7ed..16c60d6 100644 --- a/src/joystick.cpp +++ b/src/joystick.cpp @@ -10,8 +10,6 @@ Joystick::Joystick(uint8_t left_pin, uint8_t right_pin, uint8_t up_pin, uint8_t pinMode(press_pin, INPUT_PULLUP); } -// Returns either "NEUTRAL", "[DIRECTION]" or "HOLDING" -// It is advised to treat "HOLDING" the same as "NEUTRAL" outside this function JoystickPosition Joystick::getPosition() { JoystickPosition position; @@ -77,7 +75,6 @@ JoystickPosition Joystick::getPosition() return position; } -// Returns either "NEUTRAL", "PUSH" or "DOUBLE" ButtonState Joystick::getState() { ButtonState state; diff --git a/src/rocker_switch.cpp b/src/rocker_switch.cpp index a82d1b9..5e423a0 100644 --- a/src/rocker_switch.cpp +++ b/src/rocker_switch.cpp @@ -6,9 +6,6 @@ RockerSwitch::RockerSwitch(uint8_t up_pin, uint8_t down_pin) : up_pin_(up_pin), pinMode(down_pin, INPUT_PULLUP); } -// Returns either "NEUTRAL", "UP", "HOLDING UP", "DOWN" or "HOLDING DOWN" -// It is advised to treat "HOLDING X" the same as "NEUTRAL" outside this -// function RockerSwitchState RockerSwitch::getState() { RockerSwitchState state; diff --git a/src/screen.cpp b/src/screen.cpp index 0888bb8..c78c59a 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -17,7 +17,7 @@ void Screen::init() this->serial_->begin(this->baud_); // Set screen saver (SS) timeout and scroll speed - this->screen_->SSTimeout(this->screen_saver_timeout_ms_); + this->screen_->SSTimeout(this->screen_saver_timeout_); this->screen_->SSSpeed(this->screen_saver_scroll_speed_); this->screen_->TimeLimit4D = this->time_limit_; @@ -38,7 +38,7 @@ void Screen::init() void Screen::clear() { this->screen_->gfx_Cls(); - usleep(this->wait_time_ms_); + usleep(this->wait_time_); } void Screen::reset() @@ -46,7 +46,7 @@ void Screen::reset() digitalWrite(this->rst_, 1); usleep(100000); digitalWrite(this->rst_, 0); - usleep(this->wait_time_ms_); + usleep(this->wait_time_); digitalWrite(this->rst_, 1); // Let the display start up From c4af710c9ef310c44236572724971cddd453e41f Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Mon, 6 Jan 2020 09:37:28 +0100 Subject: [PATCH 53/58] Remove unused variable --- include/screen.h | 1 - src/screen.cpp | 2 -- 2 files changed, 3 deletions(-) diff --git a/include/screen.h b/include/screen.h index 812a5ef..7e7f4fb 100644 --- a/include/screen.h +++ b/include/screen.h @@ -49,7 +49,6 @@ class Screen Goldelox_Serial_4DLib* screen_; SoftwareSerial* serial_; - unsigned long last_draw_time_ = 0; const uint8_t rst_; const uint32_t baud_; diff --git a/src/screen.cpp b/src/screen.cpp index c78c59a..44925cc 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -32,7 +32,6 @@ void Screen::init() this->clear(); - this->last_draw_time_ = millis(); } void Screen::clear() @@ -57,7 +56,6 @@ void Screen::draw_image(SectorAddress address) { this->screen_->media_SetSector(address.hi, address.lo); this->screen_->media_Image(0, 0); - this->last_draw_time_ = millis(); } void Screen::printVersion() From 3f36cab1c0f8d701fd95276e8ebf3bdb961f3e89 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Mon, 6 Jan 2020 09:42:07 +0100 Subject: [PATCH 54/58] Fix get address function signature --- include/screen.h | 2 +- include/state.h | 4 ++-- include/state_machine.h | 2 +- src/main.cpp | 3 +-- src/screen.cpp | 3 +-- src/state_machine.cpp | 5 +++-- test/test_state/test_state.cpp | 3 +-- test/test_state_machine/test_state_machine.cpp | 8 +++----- 8 files changed, 13 insertions(+), 17 deletions(-) diff --git a/include/screen.h b/include/screen.h index 7e7f4fb..f3342dd 100644 --- a/include/screen.h +++ b/include/screen.h @@ -39,7 +39,7 @@ class Screen void init(); void clear(); - void draw_image(SectorAddress address); + void draw_image(const SectorAddress& address); private: void reset(); diff --git a/include/state.h b/include/state.h index e1fd42e..6a7d337 100644 --- a/include/state.h +++ b/include/state.h @@ -20,9 +20,9 @@ class State return this->gait_; } - void getImage(SectorAddress& image_address) const + SectorAddress getImage() const { - image_address = this->address_; + return this->address_; }; const State* left() const diff --git a/include/state_machine.h b/include/state_machine.h index 845707f..0ad73a5 100644 --- a/include/state_machine.h +++ b/include/state_machine.h @@ -14,7 +14,7 @@ class StateMachine std::string getCurrentGaitName() const; - void getCurrentImage(SectorAddress& address) const; + SectorAddress getCurrentImage() const; size_t size() const; diff --git a/src/main.cpp b/src/main.cpp index c5c344a..569b186 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -115,8 +115,7 @@ void sendAliveMessage() void drawCurrentImage() { - SectorAddress address; - state_machine.getCurrentImage(address); + const SectorAddress& address = state_machine.getCurrentImage(); screen.draw_image(address); } diff --git a/src/screen.cpp b/src/screen.cpp index 44925cc..5b77e4f 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -31,7 +31,6 @@ void Screen::init() this->screen_->gfx_ScreenMode(LANDSCAPE); this->clear(); - } void Screen::clear() @@ -52,7 +51,7 @@ void Screen::reset() sleep(3); } -void Screen::draw_image(SectorAddress address) +void Screen::draw_image(const SectorAddress& address) { this->screen_->media_SetSector(address.hi, address.lo); this->screen_->media_Image(0, 0); diff --git a/src/state_machine.cpp b/src/state_machine.cpp index 2972d02..d7119ce 100644 --- a/src/state_machine.cpp +++ b/src/state_machine.cpp @@ -150,12 +150,13 @@ std::string StateMachine::getCurrentGaitName() const return std::string(); } -void StateMachine::getCurrentImage(SectorAddress& address) const +SectorAddress StateMachine::getCurrentImage() const { if (this->hasState()) { - this->current_state_->getImage(address); + return this->current_state_->getImage(); } + return SectorAddress{ 0, 0 }; } size_t StateMachine::size() const diff --git a/test/test_state/test_state.cpp b/test/test_state/test_state.cpp index 3c46add..413f3c6 100644 --- a/test/test_state/test_state.cpp +++ b/test/test_state/test_state.cpp @@ -16,8 +16,7 @@ void test_state_get_address() SectorAddress expected = { 7, 8 }; State state(expected); - SectorAddress address; - state.getImage(address); + SectorAddress address = state.getImage(); TEST_ASSERT_EQUAL(expected.hi, address.hi); TEST_ASSERT_EQUAL(expected.lo, address.lo); } diff --git a/test/test_state_machine/test_state_machine.cpp b/test/test_state_machine/test_state_machine.cpp index 5e0e741..8f1e3d9 100644 --- a/test/test_state_machine/test_state_machine.cpp +++ b/test/test_state_machine/test_state_machine.cpp @@ -14,11 +14,9 @@ void test_get_gait_name() void test_get_image() { StateMachine state_machine; - SectorAddress expected({ 2, 3 }); - SectorAddress address = expected; - state_machine.getCurrentImage(address); - TEST_ASSERT_EQUAL(expected.hi, address.hi); - TEST_ASSERT_EQUAL(expected.lo, address.lo); + SectorAddress address = state_machine.getCurrentImage(); + TEST_ASSERT_EQUAL(0, address.hi); + TEST_ASSERT_EQUAL(0, address.lo); } void test_state_machine_default_no_transitions() From 5508fdf6f6ce5ae6fcf2e8d8975be6ed9bb1d566 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Mon, 6 Jan 2020 10:32:46 +0100 Subject: [PATCH 55/58] Rename joystick position to state --- include/joystick.h | 8 +++---- include/joystick_position.h | 14 ------------- include/joystick_state.h | 16 ++++++++++++++ src/joystick.cpp | 42 ++++++++++++++++++------------------- src/main.cpp | 18 ++++++++-------- 5 files changed, 50 insertions(+), 48 deletions(-) delete mode 100644 include/joystick_position.h create mode 100644 include/joystick_state.h diff --git a/include/joystick.h b/include/joystick.h index 4fa82fc..dd0aa70 100644 --- a/include/joystick.h +++ b/include/joystick.h @@ -1,7 +1,7 @@ #ifndef JOYSTICK_H #define JOYSTICK_H #include "button_state.h" -#include "joystick_position.h" +#include "joystick_state.h" #include @@ -10,8 +10,8 @@ class Joystick public: Joystick(uint8_t left_pin, uint8_t right_pin, uint8_t up_pin, uint8_t down_pin, uint8_t press_pin); - JoystickPosition getPosition(); - ButtonState getState(); + JoystickState getState(); + ButtonState getButtonState(); private: const uint8_t left_pin_; @@ -20,7 +20,7 @@ class Joystick const uint8_t down_pin_; const uint8_t press_pin_; - JoystickPosition last_position_ = JoystickPosition::NEUTRAL; + JoystickState last_position_ = JoystickState::NEUTRAL; ButtonState last_push_position_ = ButtonState::NEUTRAL; unsigned long last_print_time_ = 0; unsigned long last_push_print_time_ = 0; diff --git a/include/joystick_position.h b/include/joystick_position.h deleted file mode 100644 index 37aa788..0000000 --- a/include/joystick_position.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef JOYSTICK_POSITION_H -#define JOYSTICK_POSITION_H - -enum class JoystickPosition -{ - LEFT, - RIGHT, - UP, - DOWN, - NEUTRAL, - HOLDING, -}; - -#endif // JOYSTICK_POSITION_H diff --git a/include/joystick_state.h b/include/joystick_state.h new file mode 100644 index 0000000..e76eff5 --- /dev/null +++ b/include/joystick_state.h @@ -0,0 +1,16 @@ +#ifndef JOYSTICK_STATE_H +#define JOYSTICK_STATE_H + +enum class JoystickState +{ + LEFT, + RIGHT, + UP, + DOWN, + NEUTRAL, + // It is advised to treat HOLDING the same as NEUTRAL + // as it is only used internally. + HOLDING, +}; + +#endif // JOYSTICK_STATE_H diff --git a/src/joystick.cpp b/src/joystick.cpp index 16c60d6..786540e 100644 --- a/src/joystick.cpp +++ b/src/joystick.cpp @@ -10,72 +10,72 @@ Joystick::Joystick(uint8_t left_pin, uint8_t right_pin, uint8_t up_pin, uint8_t pinMode(press_pin, INPUT_PULLUP); } -JoystickPosition Joystick::getPosition() +JoystickState Joystick::getState() { - JoystickPosition position; + JoystickState position; if (digitalRead(this->left_pin_) == LOW) { - if (this->last_position_ != JoystickPosition::LEFT || (millis() - this->last_print_time_) > this->hold_time_) + if (this->last_position_ != JoystickState::LEFT || (millis() - this->last_print_time_) > this->hold_time_) { - position = JoystickPosition::LEFT; + position = JoystickState::LEFT; this->last_print_time_ = millis(); - this->last_position_ = JoystickPosition::LEFT; + this->last_position_ = JoystickState::LEFT; } else { - position = JoystickPosition::HOLDING; + position = JoystickState::HOLDING; } } else if (digitalRead(this->right_pin_) == LOW) { - if (this->last_position_ != JoystickPosition::RIGHT || (millis() - this->last_print_time_) > this->hold_time_) + if (this->last_position_ != JoystickState::RIGHT || (millis() - this->last_print_time_) > this->hold_time_) { - position = JoystickPosition::RIGHT; + position = JoystickState::RIGHT; this->last_print_time_ = millis(); - this->last_position_ = JoystickPosition::RIGHT; + this->last_position_ = JoystickState::RIGHT; } else { - position = JoystickPosition::HOLDING; + position = JoystickState::HOLDING; } } else if (digitalRead(this->up_pin_) == LOW) { - if (this->last_position_ != JoystickPosition::UP || (millis() - this->last_print_time_) > this->hold_time_) + if (this->last_position_ != JoystickState::UP || (millis() - this->last_print_time_) > this->hold_time_) { - position = JoystickPosition::UP; + position = JoystickState::UP; this->last_print_time_ = millis(); - this->last_position_ = JoystickPosition::UP; + this->last_position_ = JoystickState::UP; } else { - position = JoystickPosition::HOLDING; + position = JoystickState::HOLDING; } } else if (digitalRead(this->down_pin_) == LOW) { - if (this->last_position_ != JoystickPosition::DOWN || (millis() - this->last_print_time_) > this->hold_time_) + if (this->last_position_ != JoystickState::DOWN || (millis() - this->last_print_time_) > this->hold_time_) { - position = JoystickPosition::DOWN; + position = JoystickState::DOWN; this->last_print_time_ = millis(); - this->last_position_ = JoystickPosition::DOWN; + this->last_position_ = JoystickState::DOWN; } else { - position = JoystickPosition::HOLDING; + position = JoystickState::HOLDING; } } else { - position = JoystickPosition::NEUTRAL; - this->last_position_ = JoystickPosition::NEUTRAL; + position = JoystickState::NEUTRAL; + this->last_position_ = JoystickState::NEUTRAL; } // To prevent multiple prints per action due to bouncing usleep(this->bounce_time_); return position; } -ButtonState Joystick::getState() +ButtonState Joystick::getButtonState() { ButtonState state; if (this->recent_double_click_) diff --git a/src/main.cpp b/src/main.cpp index 569b186..9a15b28 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -160,8 +160,8 @@ void loop() { // Get button states // RockerSwitchState rocker_switch_state = rocker.getState(); - JoystickPosition joystick_position = joystick.getPosition(); - ButtonState joystick_state = joystick.getState(); + JoystickState joystick_state = joystick.getState(); + ButtonState joystick_button_state = joystick.getButtonState(); ButtonState trigger_state = trigger.getState(); // When button is pressed, vibrate @@ -191,18 +191,18 @@ void loop() } else { - switch (joystick_position) + switch (joystick_state) { - case JoystickPosition::LEFT: + case JoystickState::LEFT: state_has_changed = state_machine.left(); break; - case JoystickPosition::RIGHT: + case JoystickState::RIGHT: state_has_changed = state_machine.right(); break; - case JoystickPosition::UP: + case JoystickState::UP: state_has_changed = state_machine.up(); break; - case JoystickPosition::DOWN: + case JoystickState::DOWN: state_has_changed = state_machine.down(); break; default: @@ -211,11 +211,11 @@ void loop() if (!state_has_changed) { - if (joystick_state == ButtonState::PUSH) + if (joystick_button_state == ButtonState::PUSH) { state_has_changed = state_machine.select(); } - else if (joystick_state == ButtonState::DOUBLE) + else if (joystick_button_state == ButtonState::DOUBLE) { state_has_changed = state_machine.back(); } From 7eebd958cde67f39c184cfbac0f07aeb5b3b91dd Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Mon, 6 Jan 2020 11:06:50 +0100 Subject: [PATCH 56/58] Update examples --- examples/Button_example.cpp | 21 -- examples/Joystick_example.cpp | 34 -- examples/RockerSwitch+Screen_example.cpp | 79 ----- examples/Rockerswitch_example.cpp | 22 -- examples/SD_sector_addresses3.h | 327 ------------------ examples/button_example.cpp | 28 ++ examples/joystick_example.cpp | 56 +++ examples/rocker_switch_example.cpp | 31 ++ ...{Screen_example.cpp => screen_example.cpp} | 34 +- .../{Serial_test.cpp => serial_example.cpp} | 6 +- ...tion_example.cpp => vibration_example.cpp} | 11 +- 11 files changed, 143 insertions(+), 506 deletions(-) delete mode 100644 examples/Button_example.cpp delete mode 100644 examples/Joystick_example.cpp delete mode 100644 examples/RockerSwitch+Screen_example.cpp delete mode 100644 examples/Rockerswitch_example.cpp delete mode 100644 examples/SD_sector_addresses3.h create mode 100644 examples/button_example.cpp create mode 100644 examples/joystick_example.cpp create mode 100644 examples/rocker_switch_example.cpp rename examples/{Screen_example.cpp => screen_example.cpp} (66%) rename examples/{Serial_test.cpp => serial_example.cpp} (89%) rename examples/{Vibration_example.cpp => vibration_example.cpp} (81%) diff --git a/examples/Button_example.cpp b/examples/Button_example.cpp deleted file mode 100644 index ecd4e1f..0000000 --- a/examples/Button_example.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include "Button.h" - -// Define Pin for button -#define Pin_button 26 - -Button button(Pin_button); - -int button_state; - - -void setup() { - Serial.begin(9600); -} - -void loop() { - // When button is pressed, print - if (button.read_state() == "PUSH") { - Serial.println("Push detected!"); - } -} diff --git a/examples/Joystick_example.cpp b/examples/Joystick_example.cpp deleted file mode 100644 index d73f49e..0000000 --- a/examples/Joystick_example.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include -#include "Joystick.h" - -// Pin definitions -// Joystick -#define JOYSTICK_LEFT 23 -#define JOYSTICK_RIGHT 22 -#define JOYSTICK_UP 21 -#define JOYSTICK_DOWN 19 -#define JOYSTICK_PUSH 18 - -// Create instances -// Joystick -Joystick joystick(JOYSTICK_LEFT, JOYSTICK_RIGHT, JOYSTICK_UP, JOYSTICK_DOWN, JOYSTICK_PUSH); - -void setup() { - Serial.begin(9600); -} - -void loop() { - String pos = joystick.get_position(); - String press = joystick.get_press(); - - if (pos != "HOLDING" && pos != "NEUTRAL"){ - Serial.print("Joystick position: "); - Serial.print(pos); - Serial.print("\n"); - } - if (press != "HOLDING" && press != "NEUTRAL"){ - Serial.print("Joystick press: "); - Serial.print(press); - Serial.print("\n"); - } -} diff --git a/examples/RockerSwitch+Screen_example.cpp b/examples/RockerSwitch+Screen_example.cpp deleted file mode 100644 index bcb5829..0000000 --- a/examples/RockerSwitch+Screen_example.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include "RockerSwitch.h" -#include "SoftwareSerial.h" -#include "Goldelox_Serial_4DLib.h" -#include "Screen.h" -#include "SD_sector_addresses.h" - -// Pin definitions -#define ROCKER_UP 2 -#define ROCKER_DOWN 5 -#define UART_TX 32 //software serial -#define UART_RX 34 //software serial -#define RST 13 -#define BAUD_SCREEN 9600 - -// Rocker switch -RockerSwitch rocker(ROCKER_UP, ROCKER_DOWN); -// Serial communication between Lolin and Screen -SoftwareSerial screenSerial(UART_RX, UART_TX); -// Instance of the screen as in Goldelox_Serial library -Goldelox_Serial_4DLib screenGoldelox(&screenSerial); -// Wrapper instance of the screen -Screen screen(&screenGoldelox, &screenSerial, RST, BAUD_SCREEN); - -int pictureList[] = { SOFA_ADDRESS_HI, SOFA_ADDRESS_LO, - CUP_ADDRESS_HI, CUP_ADDRESS_LO, - SLOPE_ADDRESS_HI, SLOPE_ADDRESS_LO, - STAIRS_ADDRESS_HI, STAIRS_ADDRESS_LO, - SIT_ADDRESS_HI, SIT_ADDRESS_LO}; - -int currentPicture = 4; - -void setup(){ - Serial.begin(9600); - Serial.println("Rockerswitch + screen test"); - - // Set pins as either input or output - pinMode(RST, OUTPUT); - pinMode(UART_TX, OUTPUT); - pinMode(UART_RX, INPUT); - - // initialize screen by resetting, initing uSD card, clearing screen - screen.initialize(); - screen.draw_image(SLOPE_ADDRESS_HI, SLOPE_ADDRESS_LO); - sleep(1); -} - -void loop(){ - String rockerStatus = rocker.get_position(); - if(rockerStatus != "NEUTRAL" && rockerStatus != "HOLDING UP" && rockerStatus != "HOLDING DOWN"){ - Serial.print("Rocker status: "); - Serial.print(rockerStatus); - Serial.print("\n"); - - if(rockerStatus == "UP"){ - // Show picture above current picture - if(currentPicture >= 8){ - currentPicture = 0; - } - else{ - currentPicture += 2; - } - screen.draw_image(pictureList[currentPicture], pictureList[currentPicture+1]); - } - if(rockerStatus == "DOWN"){ - // Show picture below current picture - if(currentPicture <= 0){ - currentPicture = 8; - } - else{ - currentPicture -= 2; - } - screen.draw_image(pictureList[currentPicture], pictureList[currentPicture+1]); - } - } - else{ - screen.draw_image(pictureList[currentPicture], pictureList[currentPicture+1]); - } -} \ No newline at end of file diff --git a/examples/Rockerswitch_example.cpp b/examples/Rockerswitch_example.cpp deleted file mode 100644 index 9199a94..0000000 --- a/examples/Rockerswitch_example.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include "RockerSwitch.h" - -// Pin definitions -#define ROCKER_UP 0 -#define ROCKER_DOWN 5 - -RockerSwitch rocker(ROCKER_UP, ROCKER_DOWN); - -void setup(){ - Serial.begin(9600); - Serial.println("Started Serial communication"); -} - -void loop(){ - String rockerStatus = rocker.get_position(); - if(rockerStatus != "NEUTRAL" && rockerStatus != "HOLDING UP" && rockerStatus != "HOLDING DOWN"){ - Serial.print("Rocker status: "); - Serial.print(rockerStatus); - Serial.print("\n"); - } -} \ No newline at end of file diff --git a/examples/SD_sector_addresses3.h b/examples/SD_sector_addresses3.h deleted file mode 100644 index 823c626..0000000 --- a/examples/SD_sector_addresses3.h +++ /dev/null @@ -1,327 +0,0 @@ -#ifndef SD_ADDRESSES_H -#define SD_ADDRESSES_H - -//Version 3!!! - -// This file defines the sector addresses of the images to be loaded on the screen -// The sector addresses can be found via the 4D Systems Workshop 4D IDE -// The Graphics Composer of this software should be used: -// - To load the desired images on the uSD card -// - To find the sector addresses of said images (via generated .Gc file) - - -// 3HomeSit -#define HomeSit_Hi 0x0000 -#define HomeSit_Lo 0x0A71 - -// 3StandUp -#define StandUp_Hi 0x0000 -#define StandUp_Lo 0x10C5 - -// 3StandUpSelected -#define StandUpSelected_Hi 0x0000 -#define StandUpSelected_Lo 0x1167 - -// 3StandUpActivated -#define StandUpActivated_Hi 0x0000 -#define StandUpActivated_Lo 0x1116 - -// 3TurnOffStart -#define TurnOffStart_Hi 0x0000 -#define TurnOffStart_Lo 0x12AB - -// 3HomeStandStart -#define HomeStandStart_Hi 0x0000 -#define HomeStandStart_Lo 0x0B13 - -// 3Sit -#define Sit_Hi 0x0000 -#define Sit_Lo 0x0C06 - -// 3SitSelected -#define SitSelected_Hi 0x0000 -#define SitSelected_Lo 0x0CA8 - -// 3SitActivated -#define SitActivated_Hi 0x0000 -#define SitActivated_Lo 0x0C57 - -// 3HomeStand -#define HomeStand_Hi 0x0000 -#define HomeStand_Lo 0x0AC2 - -// 3TurnOff -#define TurnOff_Hi 0x0000 -#define TurnOff_Lo 0x125A - -// 3Stairs -#define Stairs_Hi 0x0000 -#define Stairs_Lo 0x0D9B - -// 3StairsUp -#define StairsUp_Hi 0x0000 -#define StairsUp_Lo 0x0EDF - -// 3StairsUpSelected -#define StairsUpSelected_Hi 0x0000 -#define StairsUpSelected_Lo 0x0F81 - -// 3StairsUpActivated -#define StairsUpActivated_Hi 0x0000 -#define StairsUpActivated_Lo 0x0F30 - -// 3StairWalk -#define WalkObstacle_Hi 0x0000 -#define WalkObstacle_Lo 0x0FD2 - -// 3StairWalkSelected, -#define WalkObstacleSelected_Hi 0x0000 -#define WalkObstacleSelected_Lo 0x1074 - -// 3StairWalkActivated, -#define WalkObstacleActivated_Hi 0x0000 -#define WalkObstacleActivated_Lo 0x1023 - -// 3StairsDown, -#define StairsDown_Hi 0x0000 -#define StairsDown_Lo 0x0DEC - -// 3StairsDownSelected, -#define StairsDownSelected_Hi 0x0000 -#define StairsDownSelected_Lo 0x0E8E - -// 3StairsDownActivated -#define StairsDownACtivated_Hi 0x0000 -#define StairsDownActivated_Lo 0x0E3D - -// 3Walk -#define Walk_Hi 0x0000 -#define Walk_Lo 0x12FC - -// 3WalkSmall -#define WalkSmall_Hi 0x0000 -#define WalkSmall_Lo 0x1491 - -// 3WalkNormal -#define WalkNormal_Hi 0x0000 -#define WalkNormal_Lo 0x129E - -// 3WalkLarge -#define WalkLarge_Hi 0x0000 -#define WalkLarge_Lo 0x124D - -// 3WalkNormalSelected -#define WalkNormalSelected_Hi 0x0000 -#define WalkNormalSelected_Lo 0x1440 - -// 3WalkNormalActivated -#define WalkNormalActivated_Hi 0x0000 -#define WalkNormalActivated_Lo 0x13EF - -// SideStep -#define SideStep_Hi 0x0000 -#define SideStep_Lo 0x11B8 - -// Slope -#define Slope_Hi 0x0000 -#define Slope_Lo 0x0CF9 - -// TiltedPath -#define TiltedPath_Hi 0x0000 -#define TiltedPath_Lo 0x1209 - -// RoughTerrain -#define RoughTerrain_Hi 0x0000 -#define RoughTerrain_Lo 0x0B64 - -// Sofa -#define Sofa_Hi 0x0000 -#define Sofa_Lo 0x0D4A - -// SingleStep -#define SingleStep_Hi 0x0000 -#define SingleStep_Lo 0x0BB5 - -// HomeSitSelected unknown -#define HomeSitSelected_Hi 0x0000 -#define HomeSitSelected_Lo 0x14E2 - -// HomeSitActivated unknown -#define HomeSitActivated_Hi 0x0000 -#define HomeSitActivated_Lo 0x14E2 - -// TurnOffStartSelected unknown -#define TurnOffStartSelected_Hi 0x0000 -#define TurnOffStartSelected_Lo 0x14E2 - -// TurnOffStartActivated unknown -#define TurnOffStartActivated_Hi 0x0000 -#define TurnOffStartActivated_Lo 0x14E2 - -// HomeStandStartSelected unknown -#define HomeStandStartSelected_Hi 0x0000 -#define HomeStandStartSelected_Lo 0x14E2 - -// HomeStandStartActivated unknown -#define HomeStandStartActivated_Hi 0x0000 -#define HomeStandStartActivated_Lo 0x14E2 - -// HomeStandSelected unknown -#define HomeStandSelected_Hi 0x0000 -#define HomeStandSelected_Lo 0x14E2 - -// HomeStandActivated unknown -#define HomeStandActivated_Hi 0x0000 -#define HomeStandActivated_Lo 0x14E2 - -// TurnOffSelected unknown -#define TurnOffSelected_Hi 0x0000 -#define TurnOffSelected_Lo 0x14E2 - -// TurnOffActivated unknown -#define TurnOffActivated_Hi 0x0000 -#define TurnOffActivated_Lo 0x14E2 - -// WalkSmallSelected unknown -#define WalkSmallSelected_Hi 0x0000 -#define WalkSmallSelected_Lo 0x14E2 - -// WalkLargeSelected unknown -#define WalkLargeSelected_Hi 0x0000 -#define WalkLargeSelected_Lo 0x14E2 - -// WalkSmallActivated unknown -#define WalkSmallActivated_Hi 0x0000 -#define WalkSmallActivated_Lo 0x14E2 - -// WalkLargeActivated unknown -#define WalkLargeActivated_Hi 0x0000 -#define WalkLargeActivated_Lo 0x14E2 - -// SingleStepSmall unknown -#define SingleStepSmall_Hi 0x0000 -#define SingleStepSmall_Lo 0x14E2 - -// SingleStepNormal unknown -#define SingleStepNormal_Hi 0x0000 -#define SingleStepNormal_Lo 0x14E2 - -// SingleStepLarge unknown -#define SingleStepLarge_Hi 0x0000 -#define SingleStepLarge_Lo 0x14E2 - -// SingleStepSmallSelected unknown -#define SingleStepSmallSelected_Hi 0x0000 -#define SingleStepSmallSelected_Lo 0x14E2 - -// SingleStepNormalSelected unknown -#define SingleStepNormalSelected_Hi 0x0000 -#define SingleStepNormalSelected_Lo 0x14E2 - -// SingleStepLargeSelected unknown -#define SingleStepLargeSelected_Hi 0x0000 -#define SingleStepLargeSelected_Lo 0x14E2 - -// SingleStepSmallActivated unknown -#define SingleStepSmallActivated_Hi 0x0000 -#define SingleStepSmallActivated_Lo 0x14E2 - -// SingleStepNormalActivated unknown -#define SingleStepNormalActivated_Hi 0x0000 -#define SingleStepNormalActivated_Lo 0x14E2 - -// SingleStepLargeActivated unknown -#define SingleStepLargeActivated_Hi 0x0000 -#define SingleStepLargeActivated_Lo 0x14E2 - -// SideStepLeft unknown -#define SideStepLeft_Hi 0x0000 -#define SideStepLeft_Lo 0x14E2 - -// SideStepRight unknown -#define SideStepRight_Hi 0x0000 -#define SideStepRight_Lo 0x14E2 - -// SideStepLeftSelected unknown -#define SideStepLeftSelected_Hi 0x0000 -#define SideStepLeftSelected_Lo 0x14E2 - -// SideStepRightSelected unknown -#define SideStepRightSelected_Hi 0x0000 -#define SideStepRightSelected_Lo 0x14E2 - -// SideStepLeftActivated unknown -#define SideStepLeftActivated_Hi 0x0000 -#define SideStepLeftActivated_Lo 0x14E2 - -// SideStepRightActivated unknown -#define SideStepRightActivated_Hi 0x0000 -#define SideStepRightActivated_Lo 0x14E2 - -// SofaSit unknown -#define SofaSit_Hi 0x0000 -#define SofaSit_Lo 0x14E2 - -// SofaSitSelected unknown -#define SofaSitSelected_Hi 0x0000 -#define SofaSitSelected_Lo 0x14E2 - -// SofaSitActivated unknown -#define SofaSitActivated_Hi 0x0000 -#define SofaSitActivated_Lo 0x14E2 - -// SofaStandUp uknonwn -#define SofaStandUp_Hi 0x0000 -#define SofaStandUp_Lo 0x14E2 - -// SofaStandUpSelected uknonwn -#define SofaStandUpSelected_Hi 0x0000 -#define SofaStandUpSelected_Lo 0x14E2 - -// SofaStandUpActivated unknown -#define SofaStandUpActivated_Hi 0x0000 -#define SofaStandUpActivated_Lo 0x14E2 - -// SlopeUp unknown -#define SlopeUp_Hi 0x0000 -#define SlopeUp_Lo 0x14E2 - -// SlopeUpSelected unknown -#define SlopeUpSelected_Hi 0x0000 -#define SlopeUpSelected_Lo 0x14E2 - -// SlopeUpActivated unknown -#define SlopeUpActivated_Hi 0x0000 -#define SlopeUpActivated_Lo 0x14E2 - -// SlopeDown unknown -#define SlopeDown_Hi 0x0000 -#define SlopeDown_Lo 0x14E2 - -// SlopeDownSelected unknown -#define SlopeDownSelected_Hi 0x0000 -#define SlopeDownSelected_Lo 0x14E2 - -// SlopeDownActivated unknown -#define SlopeDownActivated_Hi 0x0000 -#define SlopeDownActivated_Lo 0x14E2 - - - -// RoughTerrainSelected unknown -#define RoughTerrainSelected_Hi 0x0000 -#define RoughTerrainSelected_Lo 0x14E2 - -// RoughTerrainActivated unknown -#define RoughTerrainActivated_Hi 0x0000 -#define RoughTerrainActivated_Lo 0x14E2 - -// TiltedPathSelected unknown -#define TiltedPathSelected_Hi 0x0000 -#define TiltedPathSelected_Lo 0x14E2 - -// TiltedPathActivated unknown -#define TiltedPathActivated_Hi 0x0000 -#define TiltedPathActivated_Lo 0x14E2 - -#endif //SD_ADDRESSES_H \ No newline at end of file diff --git a/examples/button_example.cpp b/examples/button_example.cpp new file mode 100644 index 0000000..59796df --- /dev/null +++ b/examples/button_example.cpp @@ -0,0 +1,28 @@ +#include "button.h" + +#include + +// Define Pin for button +#define Pin_button 26 + +Button button(Pin_button); + +int button_state; + +void setup() +{ + Serial.begin(9600); +} + +void loop() +{ + // When button is pressed, print + if (button.getState() == ButtonState::PUSH) + { + Serial.println("Push detected!"); + } + if (button.getState() == ButtonState::DOUBLE) + { + Serial.println("Double push detected!"); + } +} diff --git a/examples/joystick_example.cpp b/examples/joystick_example.cpp new file mode 100644 index 0000000..a606045 --- /dev/null +++ b/examples/joystick_example.cpp @@ -0,0 +1,56 @@ +#include "joystick.h" + +#include + +// Pin definitions +// Joystick +#define JOYSTICK_LEFT 23 +#define JOYSTICK_RIGHT 22 +#define JOYSTICK_UP 21 +#define JOYSTICK_DOWN 19 +#define JOYSTICK_PUSH 18 + +// Create instances +// Joystick +Joystick joystick(JOYSTICK_LEFT, JOYSTICK_RIGHT, JOYSTICK_UP, JOYSTICK_DOWN, JOYSTICK_PUSH); + +void setup() +{ + Serial.begin(9600); +} + +void loop() +{ + JoystickState pos = joystick.getState(); + ButtonState press = joystick.getButtonState(); + + switch (pos) + { + case JoystickState::LEFT: + Serial.print("Joystick left"); + break; + case JoystickState::RIGHT: + Serial.print("Joystick right"); + break; + case JoystickState::UP: + Serial.print("Joystick up"); + break; + case JoystickState::DOWN: + Serial.print("Joystick down"); + break; + default: + break; + } + + switch (press) + { + case ButtonState::PUSH: + Serial.println("Joystick pressed"); + break; + case ButtonState::DOUBLE: + Serial.println("Joystick double pressed"); + break; + default: + break; + } +} diff --git a/examples/rocker_switch_example.cpp b/examples/rocker_switch_example.cpp new file mode 100644 index 0000000..7a24e81 --- /dev/null +++ b/examples/rocker_switch_example.cpp @@ -0,0 +1,31 @@ +#include "rocker_switch.h" + +#include + +// Pin definitions +#define ROCKER_UP 0 +#define ROCKER_DOWN 5 + +RockerSwitch rocker(ROCKER_UP, ROCKER_DOWN); + +void setup() +{ + Serial.begin(9600); + Serial.println("Started Serial communication"); +} + +void loop() +{ + RockerSwitchState status = rocker.getState(); + switch (status) + { + case RockerSwitchState::UP: + Serial.println("rocker switch up"); + break; + case RockerSwitchState::DOWN: + Serial.println("rocker switch down"); + break; + default: + break; + } +} \ No newline at end of file diff --git a/examples/Screen_example.cpp b/examples/screen_example.cpp similarity index 66% rename from examples/Screen_example.cpp rename to examples/screen_example.cpp index ea054d8..345bc1c 100644 --- a/examples/Screen_example.cpp +++ b/examples/screen_example.cpp @@ -1,8 +1,9 @@ +#include "screen.h" +#include "sd_sector_addresses.h" + #include -#include "SoftwareSerial.h" -#include "Goldelox_Serial_4DLib.h" -#include "Screen.h" -#include "SD_sector_addresses.h" +#include +#include // Developed by M. van der Marel for Project MARCH // Required tools for running this code: @@ -12,11 +13,10 @@ // A uSD card set up with the 4D Systems software with images, placed in the uOLED-160G2 board // The sector addresses returned by the 4D Systems software can be placed in 'SD_sector_addresses.h' for easy access - -#define UART_TX 32 //software serial -#define UART_RX 34 //software serial -#define RST 13 -#define BAUD_SCREEN 9600 +#define UART_TX 32 // software serial +#define UART_RX 34 // software serial +#define RST 13 +#define BAUD_SCREEN 9600 // Serial communication between Lolin and Screen SoftwareSerial screenSerial(UART_RX, UART_TX); @@ -25,24 +25,26 @@ Goldelox_Serial_4DLib screenGoldelox(&screenSerial); // Wrapper instance of the screen Screen screen(&screenGoldelox, &screenSerial, RST, BAUD_SCREEN); -void setup() { +void setup() +{ // Set pins as either input or output pinMode(RST, OUTPUT); pinMode(UART_TX, OUTPUT); pinMode(UART_RX, INPUT); // initialize screen by resetting, initing uSD card, clearing screen - screen.initialize(); + screen.init(); } -void loop(void) { +void loop(void) +{ // Draw different images from the uSD card in a loop - screen.draw_image(CUP_ADDRESS_HI, CUP_ADDRESS_LO); + screen.draw_image(STAIRS); sleep(1); - screen.draw_image(STAIRS_ADDRESS_HI, STAIRS_ADDRESS_LO); + screen.draw_image(SIT); sleep(1); - screen.draw_image(SIT_ADDRESS_HI, SIT_ADDRESS_LO); + screen.draw_image(HOME_STAND); sleep(1); - screen.draw_image(SOFA_ADDRESS_HI, SOFA_ADDRESS_LO); + screen.draw_image(SOFA); sleep(1); } diff --git a/examples/Serial_test.cpp b/examples/serial_example.cpp similarity index 89% rename from examples/Serial_test.cpp rename to examples/serial_example.cpp index 24c7fdd..98ed772 100644 --- a/examples/Serial_test.cpp +++ b/examples/serial_example.cpp @@ -3,12 +3,14 @@ // This is a minimal working version for the Lolin D32 Pro // See the examples folder for examples with different peripherals -void setup(){ +void setup() +{ Serial.begin(9600); Serial.println("Setup"); } -void loop(){ +void loop() +{ Serial.println("Loop"); sleep(1); } \ No newline at end of file diff --git a/examples/Vibration_example.cpp b/examples/vibration_example.cpp similarity index 81% rename from examples/Vibration_example.cpp rename to examples/vibration_example.cpp index 635a52d..ae4918f 100644 --- a/examples/Vibration_example.cpp +++ b/examples/vibration_example.cpp @@ -1,11 +1,12 @@ +#include #include -#include "Adafruit_DRV2605.h" Adafruit_DRV2605 driver; -uint8_t effect; // Select the desired effect, for now test effect "Buzz 100%" +uint8_t effect; // Select the desired effect, for now test effect "Buzz 100%" -void setup() { +void setup() +{ Serial.begin(9600); // Setup I2C protocol @@ -21,7 +22,8 @@ void setup() { effect = 47; } -void loop() { +void loop() +{ // Set the effect to be played // Waveforms can be combined, to create new wavefroms, see driver datasheet driver.setWaveform(0, effect); // Setup the waveform(s) @@ -31,5 +33,4 @@ void loop() { driver.go(); sleep(1); - } \ No newline at end of file From 26a185a8b284b19afc6b42f4db00787ae195493a Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Mon, 6 Jan 2020 11:25:45 +0100 Subject: [PATCH 57/58] Add whitelines add end of files --- examples/rocker_switch_example.cpp | 3 +-- examples/serial_example.cpp | 2 +- examples/vibration_example.cpp | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/examples/rocker_switch_example.cpp b/examples/rocker_switch_example.cpp index 7a24e81..527523f 100644 --- a/examples/rocker_switch_example.cpp +++ b/examples/rocker_switch_example.cpp @@ -11,7 +11,6 @@ RockerSwitch rocker(ROCKER_UP, ROCKER_DOWN); void setup() { Serial.begin(9600); - Serial.println("Started Serial communication"); } void loop() @@ -28,4 +27,4 @@ void loop() default: break; } -} \ No newline at end of file +} diff --git a/examples/serial_example.cpp b/examples/serial_example.cpp index 98ed772..12a7fa7 100644 --- a/examples/serial_example.cpp +++ b/examples/serial_example.cpp @@ -13,4 +13,4 @@ void loop() { Serial.println("Loop"); sleep(1); -} \ No newline at end of file +} diff --git a/examples/vibration_example.cpp b/examples/vibration_example.cpp index ae4918f..7ef8ad2 100644 --- a/examples/vibration_example.cpp +++ b/examples/vibration_example.cpp @@ -33,4 +33,4 @@ void loop() driver.go(); sleep(1); -} \ No newline at end of file +} From cc051978d1a9fff77bea1a586746a9eb7aceae97 Mon Sep 17 00:00:00 2001 From: Olav de Haas Date: Mon, 6 Jan 2020 11:26:32 +0100 Subject: [PATCH 58/58] Remove void parameter --- examples/screen_example.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/screen_example.cpp b/examples/screen_example.cpp index 345bc1c..009c85d 100644 --- a/examples/screen_example.cpp +++ b/examples/screen_example.cpp @@ -36,7 +36,7 @@ void setup() screen.init(); } -void loop(void) +void loop() { // Draw different images from the uSD card in a loop screen.draw_image(STAIRS);