From 7c8a0e786b52d6294f63edbc96b63bbf40305aa7 Mon Sep 17 00:00:00 2001 From: Wlad Meixner Date: Thu, 29 Sep 2022 20:49:36 +0200 Subject: [PATCH] feat: add slower motor movement speed --- growme/include/MotorControl.hpp | 2 +- growme/src/MotorControl.cpp | 13 ++++++++++--- growme/src/main.cpp | 2 ++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/growme/include/MotorControl.hpp b/growme/include/MotorControl.hpp index 6f421ea..735cfed 100644 --- a/growme/include/MotorControl.hpp +++ b/growme/include/MotorControl.hpp @@ -11,7 +11,7 @@ #include "pb_encode.h" // using a 200-step motor (most common) -#define MOTOR_STEPS 200 +#define MOTOR_STEPS 50 struct MotorControl { uint8_t index; diff --git a/growme/src/MotorControl.cpp b/growme/src/MotorControl.cpp index df810fd..5741786 100644 --- a/growme/src/MotorControl.cpp +++ b/growme/src/MotorControl.cpp @@ -41,12 +41,14 @@ struct RepeatedStatus { }; bool status_encode(pb_ostream_t *stream, const pb_field_t *field, void *const *arg) { + ESP_LOGI(TAG, "write callback stated"); + RepeatedStatus *def = (RepeatedStatus *)*arg; while (def->index < def->max_size) { int32_t status = def->status[def->index]; ++def->index; - if (!pb_encode_tag(stream, PB_WT_STRING, field->tag)) { + if (!pb_encode_tag(stream, PB_WT_VARINT, field->tag)) { ESP_LOGE(TAG, "failed to encode: %s", PB_GET_ERROR(stream)); return false; } @@ -59,6 +61,8 @@ bool status_encode(pb_ostream_t *stream, const pb_field_t *field, void *const *a ESP_LOGI(TAG, "written value %d", status); } + ESP_LOGI(TAG, "write callback completed"); + return true; } @@ -71,12 +75,15 @@ void CustomBLEMotorInfoCallback::onRead(BLECharacteristic *characteristic) { for (int i = 0; i < this->numMotors; i++) { status[i] = this->motors[i]->currentPosition; } + + ESP_LOGI(TAG, "status items %d", numMotors); + struct RepeatedStatus args = {.status = status, .index = 0, .max_size = this->numMotors}; msg.status.arg = &args; msg.status.funcs.encode = status_encode; - if (!pb_encode(&stream, Command_fields, &this->msg)) { + if (!pb_encode(&stream, Command_fields, &msg)) { ESP_LOGE(TAG, "failed to encode: %s", PB_GET_ERROR(&stream)); return; } @@ -89,7 +96,7 @@ void CustomBLEMotorInfoCallback::onRead(BLECharacteristic *characteristic) { }; MotorControl::MotorControl(uint8_t index, short dir, short step) { - this->stepper = new A4988(MOTOR_STEPS, dir, step); + this->stepper = new A4988(MOTOR_STEPS, dir, step, 5); this->index = index; int address = index * 8; diff --git a/growme/src/main.cpp b/growme/src/main.cpp index e8af1f7..1db531f 100644 --- a/growme/src/main.cpp +++ b/growme/src/main.cpp @@ -151,8 +151,10 @@ void controlTask(void *pvParameter) { // parse movement direction if (digitalRead(UP_BTN_PIN) == HIGH) { direction = 1; + ESP_LOGI("MAIN", "down"); } else if (digitalRead(DOWN_BTN_PIN) == HIGH) { direction = -1; + ESP_LOGI("MAIN", "up"); } else { direction = 0; }