Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
eyr1n committed Oct 29, 2024
1 parent 34b58c5 commit 8b25825
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion include/tutrc_harurobo_lib/encoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace tutrc_harurobo_lib {

class Encoder {
public:
Encoder(TIM_HandleTypeDef *htim, uint16_t ppr, float period);
bool init(TIM_HandleTypeDef *htim, uint16_t ppr, float period);
void update();
float get_rps();
float get_rpm();
Expand Down
2 changes: 1 addition & 1 deletion include/tutrc_harurobo_lib/gpio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace tutrc_harurobo_lib {

class GPIO {
public:
GPIO(GPIO_TypeDef *port, uint16_t pin);
bool init(GPIO_TypeDef *port, uint16_t pin);
void write(bool state);
bool read();
void toggle();
Expand Down
5 changes: 4 additions & 1 deletion include/tutrc_harurobo_lib/ps3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ class PS3 {
SELECT,
};

PS3(UART *uart) : uart_(uart) {}
bool init(UART *uart) {
uart_ = uart;
return true;
}

void update() {
keys_prev_ = keys_;
Expand Down
10 changes: 5 additions & 5 deletions src/encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

namespace tutrc_harurobo_lib {

Encoder::Encoder(TIM_HandleTypeDef *htim, uint16_t ppr, float period)
: htim_(htim), ppr_(ppr), period_(period) {
if (HAL_TIM_Encoder_Start(htim_, TIM_CHANNEL_ALL) != HAL_OK) {
Error_Handler();
}
bool Encoder::init(TIM_HandleTypeDef *htim, uint16_t ppr, float period) {
htim_ = htim;
ppr_ = ppr;
period_ = period;
return HAL_TIM_Encoder_Start(htim_, TIM_CHANNEL_ALL) == HAL_OK;
}

void Encoder::update() {
Expand Down
5 changes: 1 addition & 4 deletions src/fdcan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ bool FDCAN::init(FDCAN_HandleTypeDef *hfdcan, size_t rx_queue_size) {
return false;
}

if (HAL_FDCAN_Start(hfdcan_) != HAL_OK) {
return false;
}
return true;
return HAL_FDCAN_Start(hfdcan_) == HAL_OK;
}

bool FDCAN::transmit(const CANMessage *msg) {
Expand Down
5 changes: 4 additions & 1 deletion src/gpio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ namespace tutrc_harurobo_lib {
std::unordered_map<uint16_t, tutrc_harurobo_lib::GPIO *>
tutrc_harurobo_lib::GPIO::instances_;

GPIO::GPIO(GPIO_TypeDef *port, uint16_t pin) : port_(port), pin_(pin) {
bool GPIO::init(GPIO_TypeDef *port, uint16_t pin) {
port_ = port;
pin_ = pin;
instances_[pin_] = this;
return true;
}

void GPIO::write(bool state) {
Expand Down

0 comments on commit 8b25825

Please sign in to comment.