From 7089b68e52ef6819513a21dc22cb9f0eb2b1aea8 Mon Sep 17 00:00:00 2001 From: Kadah Date: Sat, 25 Aug 2018 14:53:48 -0700 Subject: [PATCH] Added output enable/disable back to ApiClient --- ApiClient.cpp | 15 ++++++++++++--- ApiClient.h | 3 +++ Configuration.h | 1 + 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/ApiClient.cpp b/ApiClient.cpp index 873a835..2badb95 100644 --- a/ApiClient.cpp +++ b/ApiClient.cpp @@ -25,7 +25,6 @@ void ApiClient::setup(){ motors.push_back(Motor(Configuration::PIN_MOTOR_B_FWD, Configuration::PIN_MOTOR_B_BACK)); motors.push_back(Motor(Configuration::PIN_MOTOR_C_FWD, Configuration::PIN_MOTOR_C_BACK)); motors.push_back(Motor(Configuration::PIN_MOTOR_D_FWD, Configuration::PIN_MOTOR_D_BACK)); - // Attach event handlers // For simplicity, events are always attached regardless @@ -34,6 +33,8 @@ void ApiClient::setup(){ _socket.on("vib", std::bind(&ApiClient::event_vib, this, _1, _2)); _socket.on("p", std::bind(&ApiClient::event_p, this, _1, _2)); + pinMode(Configuration::PIN_NSLEEP, OUTPUT); + } @@ -60,7 +61,7 @@ void ApiClient::event_connect( const char * payload, size_t length ){ _connected = true; _socket.emit("id", ("\"" + (String)userSettings.deviceid + "\"").c_str()); statusLED.setState(StatusLED::STATE_RUNNING); - //pwm.enable(); TODO: Kadah, figure out the enable thing + output_enable(); } @@ -71,7 +72,7 @@ void ApiClient::event_disconnect( const char * payload, size_t length ){ Serial.println("ApiClient::event_disconnect"); statusLED.setState(StatusLED::STATE_SOCKET_ERR); _connected = false; - //pwm.disable(); TODO: Kadah, figure out the enable thing + output_disable(); } @@ -182,5 +183,13 @@ void ApiClient::loop() { } +// Enables/Disables motor drivers (sets DRV8833's nSLEEP pin high/low) +void ApiClient::output_enable(){ + digitalWrite(Configuration::PIN_NSLEEP, HIGH); +} +void ApiClient::output_disable(){ + digitalWrite(Configuration::PIN_NSLEEP, LOW); +} + ApiClient apiClient = ApiClient(); diff --git a/ApiClient.h b/ApiClient.h index 4f16398..b088bbe 100644 --- a/ApiClient.h +++ b/ApiClient.h @@ -33,6 +33,9 @@ class ApiClient { void event_vib(const char * payload, size_t length); void event_p(const char * payload, size_t length); + void output_enable(); + void output_disable(); + bool _connected; bool _running; diff --git a/Configuration.h b/Configuration.h index 5e001b3..57b8020 100644 --- a/Configuration.h +++ b/Configuration.h @@ -27,6 +27,7 @@ namespace Configuration{ const uint8_t PIN_SLED_G = 19; const uint8_t PIN_SLED_B = 22; const uint8_t PIN_CONFIG_BUTTON = 18; // Configuration pin. Use a pull-up resistor + const uint8_t PIN_NSLEEP = 13; const uint8_t PIN_MOTOR_A_FWD = 15; const uint8_t PIN_MOTOR_A_BACK = 2; const uint8_t PIN_MOTOR_B_FWD = 0;