diff --git a/Application/Inc/DAC.hpp b/Application/Inc/DAC.hpp index ac38f9c..f2736ba 100644 --- a/Application/Inc/DAC.hpp +++ b/Application/Inc/DAC.hpp @@ -15,6 +15,7 @@ class CustomDAC { enum State { s_off, s_on, + s_breath, } m_state; void setLevel(double); @@ -26,6 +27,9 @@ class CustomDAC { void on(); void off(); + void breath(); + + void schedule(); private: void applyLevel(); @@ -35,6 +39,8 @@ class CustomDAC { double m_level{0.0}; double m_vref{3.3}; + uint32_t m_breeath_period{325}; + /** * @brief Using HAL predefined bit mask for DAC output options * Options: DAC_CHANNEL_1, DAC_CHANNEL_2 diff --git a/Application/Src/CLI.cpp b/Application/Src/CLI.cpp index f448b2c..daa49c0 100644 --- a/Application/Src/CLI.cpp +++ b/Application/Src/CLI.cpp @@ -120,16 +120,24 @@ int32_t CLI::cmd_motor(int32_t argc, char** argv) { // Detailed Menu const char* help_text = "\nDAC Functions:\n" + " breath \tBreathing DAC\n" " level #value\tSet DAC level\n" " add #value\tIncrease or Decrease DAC level\n\n"; // Sub Command if (argc == 2) { - if (!strcmp(argv[1], "help")) + if (!strcmp(argv[1], "help")) { serialCOM.sendString(help_text); - else + } else if (!strcmp(argv[1], "on")) { + motor_dac.on(); + } else if (!strcmp(argv[1], "off")) { + motor_dac.off(); + } else if (!strcmp(argv[1], "breath")) { + motor_dac.breath(); + } else { serialCOM.sendString("Unknown Command\n"); - } + } + } if (argc == 3) { if (!strcmp(argv[1], "level")) { motor_dac.setLevel(atof(argv[2])); diff --git a/Application/Src/DAC.cpp b/Application/Src/DAC.cpp index 11b48aa..59eb02b 100644 --- a/Application/Src/DAC.cpp +++ b/Application/Src/DAC.cpp @@ -1,6 +1,7 @@ #include "DAC.hpp" #include "Instances.hpp" +#include "cmath" CustomDAC::CustomDAC() {} @@ -33,6 +34,15 @@ void CustomDAC::on() { setState(CustomDAC::State::s_on); } void CustomDAC::off() { setState(CustomDAC::State::s_off); } +void CustomDAC::breath() { setState(CustomDAC::State::s_breath); } + +void CustomDAC::schedule() { + if (m_state == CustomDAC::State::s_breath) { + m_level = abs(sin(HAL_GetTick() % m_breeath_period)) * 3.3; + } + applyLevel(); +} + void CustomDAC::setState(uint8_t cmd) { setState(static_cast(cmd)); } uint8_t CustomDAC::getState() { return static_cast(m_state); } @@ -54,6 +64,9 @@ void CustomDAC::setState(CustomDAC::State cmd) { case CustomDAC::State::s_on: applyLevel(); break; + case CustomDAC::State::s_breath: + zeroLevel(); + break; } m_state = cmd; } diff --git a/Application/Src/Thread.cpp b/Application/Src/Thread.cpp index 8822169..3843525 100644 --- a/Application/Src/Thread.cpp +++ b/Application/Src/Thread.cpp @@ -15,11 +15,11 @@ Thread::Thread() { auto t2 = [](void *arg) { static_cast(arg)->init(); }; xTaskCreate(t2, "system init", 256, this, 6, &init_handle); - // auto t3 = [](void *arg) { static_cast(arg)->utilities(); }; - // xTaskCreate(t3, "utilities", 64, this, 1, &utilities_handle); + auto t3 = [](void *arg) { static_cast(arg)->utilities(); }; + xTaskCreate(t3, "utilities", 128, this, 1, &utilities_handle); auto a2 = [](void *arg) { static_cast(arg)->app_dac(); }; - xTaskCreate(a2, "dac + adc", 64, this, 0, &app_dac_handle); + xTaskCreate(a2, "dac + adc", 128, this, 0, &app_dac_handle); auto s1 = [](void *arg) { static_cast(arg)->schedule_20Hz(); }; xTaskCreate(s1, "schedule 20Hz", 64, this, 5, &schedule_20Hz_handle); @@ -48,27 +48,21 @@ void Thread::init() { void Thread::utilities() { while (1) { - vTaskSuspend(NULL); + serialCOM.sendString("\nDAC Target Value: "); + serialCOM.sendNumber(motor_dac.getLevel()); + serialCOM.sendString("\nADC Sensing Value: "); + serialCOM.sendNumber(sensor_adc.getVolt()); + serialCOM.sendLn(); + // vTaskSuspend(NULL); + vTaskDelay(1000); } } void Thread::app_dac() { while (1) { - // ADC + DAC - - // if (sensor_adc.getValue() > 3000) - // motor_dac.setLevel(0); - // else - // motor_dac.addLevel(0.1); - - // serialCOM.sendString("DAC value: "); - // serialCOM.sendNumber(motor_dac.getLevel()); - // serialCOM.sendString("\nADC value: "); - // serialCOM.sendNumber(sensor_adc.getVolt()); - // serialCOM.sendLn(); - - vTaskSuspend(NULL); - // vTaskDelay(10000); + motor_dac.schedule(); + // vTaskSuspend(NULL); + vTaskDelay(1000); } }