Skip to content

Commit

Permalink
Added output enable/disable back to ApiClient
Browse files Browse the repository at this point in the history
  • Loading branch information
Kadah committed Aug 25, 2018
1 parent 9af62c8 commit 7089b68
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
15 changes: 12 additions & 3 deletions ApiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);

}


Expand All @@ -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();

}

Expand All @@ -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();

}

Expand Down Expand Up @@ -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();
3 changes: 3 additions & 0 deletions ApiClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7089b68

Please sign in to comment.