mirror of
https://github.com/gosticks/growme.git
synced 2025-10-16 11:45:38 +00:00
feat: add slower motor movement speed
This commit is contained in:
parent
f97b57d9c9
commit
7c8a0e786b
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user