73 lines
2.1 KiB
C++
73 lines
2.1 KiB
C++
#include "sdkconfig.h"
|
|
#include "Arduino.h"
|
|
#include "steppers.hpp"
|
|
#include "uartprint.hpp"
|
|
#include "storage/vfs.hpp"
|
|
#include "recovery/bootsequence.hpp"
|
|
#include "bluetooth/serial.hpp"
|
|
#include "pins.hpp"
|
|
#include "led.hpp"
|
|
#include "motorcontrol.hpp"
|
|
|
|
void motor_loop(void* parameters);
|
|
SerialBluetooth* serialbt = nullptr;
|
|
|
|
void app_main_cpp(){
|
|
auto* onboard_led = new GPIOOutputPin(5, true);
|
|
onboard_led->write(true);
|
|
setup_uart();
|
|
Serial.begin(9600);
|
|
uart_print("\rUART has been set up successfully!\n");
|
|
LED* rld = new LED(PIN_LED2_R, PIN_LED2_G, PIN_LED2_B);
|
|
BootSequence* bs = new BootSequence(rld);
|
|
LED* led = new LED(PIN_LED1_R, PIN_LED1_G, PIN_LED1_B);
|
|
led->color('w');
|
|
usleep(300);
|
|
bs->choose_from_pin();
|
|
if(bs->has_pending_action()){
|
|
bs->do_action(nullptr);
|
|
return;
|
|
}
|
|
led->color('r');
|
|
VFS* vfs = new VFS();
|
|
bs->choose_from_storage(vfs);
|
|
if(bs->has_pending_action()){
|
|
bs->remove_from_storage(vfs);
|
|
bs->do_action(vfs);
|
|
return;
|
|
} else {
|
|
led->color('g');
|
|
SmartStepper* lstp = get_left_stepper();
|
|
lstp->disengage();
|
|
SmartStepper* rstp = get_right_stepper();
|
|
rstp->disengage();
|
|
MotorControl* motor_control = new MotorControl();
|
|
motor_control->onboard_led = onboard_led;
|
|
motor_control->primary_led = led;
|
|
motor_control->secondary_led = rld;
|
|
motor_control->left_stepper = lstp;
|
|
motor_control->right_stepper = rstp;
|
|
motor_control->motor_logic = new MotorLogic(vfs, motor_control);
|
|
led->color('b');
|
|
serialbt = new SerialBluetooth(vfs, motor_control);
|
|
led->color('w');
|
|
onboard_led->write(false);
|
|
led->color('k');
|
|
auto* th = new xTaskHandle();
|
|
xTaskCreatePinnedToCore(motor_loop, "Steppers", 64*1024, motor_control, 2, th, 1);
|
|
}
|
|
}
|
|
|
|
void motor_loop(void* parameters){
|
|
MotorControl* motor_control = static_cast<MotorControl*>(parameters);
|
|
motor_control->motor_logic->mainloop();
|
|
vTaskDelete(NULL);
|
|
}
|
|
|
|
void setup(){
|
|
app_main_cpp();
|
|
}
|
|
|
|
void loop(){
|
|
serialbt->mainloop();
|
|
} |