|
| 1 | +/************************************************************************************** |
| 2 | + * INCLUDE |
| 3 | + **************************************************************************************/ |
| 4 | + |
| 5 | +#include "AppState.h" |
| 6 | + |
| 7 | +#include <Braccio++.h> |
| 8 | + |
| 9 | +/************************************************************************************** |
| 10 | + * TYPEDEF |
| 11 | + **************************************************************************************/ |
| 12 | + |
| 13 | +enum BUTTONS { |
| 14 | + BTN_UP = 1, |
| 15 | + BTN_DOWN = 7, |
| 16 | + BTN_LEFT = 3, |
| 17 | + BTN_RIGHT = 5, |
| 18 | +}; |
| 19 | + |
| 20 | +/************************************************************************************** |
| 21 | + * EXTERN |
| 22 | + **************************************************************************************/ |
| 23 | + |
| 24 | +extern lv_obj_t * label; |
| 25 | +extern lv_obj_t * direction_btnm; |
| 26 | + |
| 27 | +/************************************************************************************** |
| 28 | + * GLOBAL VARIABLES |
| 29 | + **************************************************************************************/ |
| 30 | + |
| 31 | +static auto gripper = Braccio.get(1); |
| 32 | +static auto wristRoll = Braccio.get(2); |
| 33 | +static auto wristPitch = Braccio.get(3); |
| 34 | +static auto elbow = Braccio.get(4); |
| 35 | +static auto shoulder = Braccio.get(5); |
| 36 | +static auto base = Braccio.get(6); |
| 37 | + |
| 38 | +/************************************************************************************** |
| 39 | + * ShoulderState |
| 40 | + **************************************************************************************/ |
| 41 | + |
| 42 | +ShoulderState::ShoulderState() |
| 43 | +{ |
| 44 | + Braccio.lvgl_lock(); |
| 45 | + lv_label_set_text(label, "Shoulder"); |
| 46 | + Braccio.lvgl_unlock(); |
| 47 | +} |
| 48 | + |
| 49 | +State * ShoulderState::handle_OnEnter() |
| 50 | +{ |
| 51 | + return new ElbowState(); |
| 52 | +} |
| 53 | + |
| 54 | +State * ShoulderState::handle_OnUp() |
| 55 | +{ |
| 56 | + shoulder.move().to(shoulder.position() + 5.0f); |
| 57 | + return this; |
| 58 | +} |
| 59 | + |
| 60 | +State * ShoulderState::handle_OnDown() |
| 61 | +{ |
| 62 | + shoulder.move().to(shoulder.position() - 5.0f); |
| 63 | + return this; |
| 64 | +} |
| 65 | + |
| 66 | +State * ShoulderState::handle_OnLeft() |
| 67 | +{ |
| 68 | + base.move().to(base.position() + 5.0f); |
| 69 | + return this; |
| 70 | +} |
| 71 | + |
| 72 | +State * ShoulderState::handle_OnRight() |
| 73 | +{ |
| 74 | + base.move().to(base.position() - 5.0f); |
| 75 | + return this; |
| 76 | +} |
| 77 | + |
| 78 | +/************************************************************************************** |
| 79 | + * ElbowState |
| 80 | + **************************************************************************************/ |
| 81 | + |
| 82 | +ElbowState::ElbowState() |
| 83 | +{ |
| 84 | + Braccio.lvgl_lock(); |
| 85 | + lv_label_set_text(label, "Elbow"); |
| 86 | + lv_btnmatrix_set_btn_ctrl(direction_btnm, BTN_LEFT, LV_BTNMATRIX_CTRL_HIDDEN); |
| 87 | + lv_btnmatrix_set_btn_ctrl(direction_btnm, BTN_RIGHT, LV_BTNMATRIX_CTRL_HIDDEN); |
| 88 | + Braccio.lvgl_unlock(); |
| 89 | +} |
| 90 | + |
| 91 | +ElbowState::~ElbowState() |
| 92 | +{ |
| 93 | + Braccio.lvgl_lock(); |
| 94 | + lv_btnmatrix_clear_btn_ctrl(direction_btnm, BTN_LEFT, LV_BTNMATRIX_CTRL_HIDDEN); |
| 95 | + lv_btnmatrix_clear_btn_ctrl(direction_btnm, BTN_RIGHT, LV_BTNMATRIX_CTRL_HIDDEN); |
| 96 | + Braccio.lvgl_unlock(); |
| 97 | +} |
| 98 | + |
| 99 | +State * ElbowState::handle_OnEnter() |
| 100 | +{ |
| 101 | + return new WristState(); |
| 102 | +} |
| 103 | + |
| 104 | +State * ElbowState::handle_OnUp() |
| 105 | +{ |
| 106 | + elbow.move().to(elbow.position() + 5.0f); |
| 107 | + return this; |
| 108 | +} |
| 109 | + |
| 110 | +State * ElbowState::handle_OnDown() |
| 111 | +{ |
| 112 | + elbow.move().to(elbow.position() - 5.0f); |
| 113 | + return this; |
| 114 | +} |
| 115 | + |
| 116 | +/************************************************************************************** |
| 117 | + * WristState |
| 118 | + **************************************************************************************/ |
| 119 | + |
| 120 | +WristState::WristState() |
| 121 | +{ |
| 122 | + Braccio.lvgl_lock(); |
| 123 | + lv_label_set_text(label, "Wrist"); |
| 124 | + Braccio.lvgl_unlock(); |
| 125 | +} |
| 126 | + |
| 127 | +State * WristState::handle_OnEnter() |
| 128 | +{ |
| 129 | + return new PinchState(); |
| 130 | +} |
| 131 | + |
| 132 | +State * WristState::handle_OnUp() |
| 133 | +{ |
| 134 | + wristPitch.move().to(wristPitch.position() + 5.0f); |
| 135 | + return this; |
| 136 | +} |
| 137 | + |
| 138 | +State * WristState::handle_OnDown() |
| 139 | +{ |
| 140 | + wristPitch.move().to(wristPitch.position() - 5.0f); |
| 141 | + return this; |
| 142 | +} |
| 143 | + |
| 144 | +State * WristState::handle_OnLeft() |
| 145 | +{ |
| 146 | + wristRoll.move().to(wristRoll.position() + 10.0f); |
| 147 | + return this; |
| 148 | +} |
| 149 | + |
| 150 | +State * WristState::handle_OnRight() |
| 151 | +{ |
| 152 | + wristRoll.move().to(wristRoll.position() - 10.0f); |
| 153 | + return this; |
| 154 | +} |
| 155 | + |
| 156 | +/************************************************************************************** |
| 157 | + * PinchState |
| 158 | + **************************************************************************************/ |
| 159 | + |
| 160 | +PinchState::PinchState() |
| 161 | +{ |
| 162 | + Braccio.lvgl_lock(); |
| 163 | + lv_label_set_text(label, "Pinch"); |
| 164 | + lv_btnmatrix_set_btn_ctrl(direction_btnm, BTN_UP, LV_BTNMATRIX_CTRL_HIDDEN); |
| 165 | + lv_btnmatrix_set_btn_ctrl(direction_btnm, BTN_DOWN, LV_BTNMATRIX_CTRL_HIDDEN); |
| 166 | + Braccio.lvgl_unlock(); |
| 167 | +} |
| 168 | + |
| 169 | +PinchState::~PinchState() |
| 170 | +{ |
| 171 | + Braccio.lvgl_lock(); |
| 172 | + lv_btnmatrix_clear_btn_ctrl(direction_btnm, BTN_UP, LV_BTNMATRIX_CTRL_HIDDEN); |
| 173 | + lv_btnmatrix_clear_btn_ctrl(direction_btnm, BTN_DOWN, LV_BTNMATRIX_CTRL_HIDDEN); |
| 174 | + Braccio.lvgl_unlock(); |
| 175 | +} |
| 176 | + |
| 177 | +State * PinchState::handle_OnEnter() |
| 178 | +{ |
| 179 | + return new ShoulderState(); |
| 180 | +} |
| 181 | + |
| 182 | +State * PinchState::handle_OnLeft() |
| 183 | +{ |
| 184 | + gripper.move().to(gripper.position() + 5.0f); |
| 185 | + return this; |
| 186 | +} |
| 187 | + |
| 188 | +State * PinchState::handle_OnRight() |
| 189 | +{ |
| 190 | + gripper.move().to(gripper.position() - 5.0f); |
| 191 | + return this; |
| 192 | +} |
0 commit comments