From 3e94b0f0d825a67f0b8c01036e6ad1fc53e41a4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Bourdeauducq?= Date: Mon, 20 Jan 2025 11:58:27 +0800 Subject: [PATCH] add servo state, init params --- sndlock.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/sndlock.cpp b/sndlock.cpp index 16cfb89..66f363f 100644 --- a/sndlock.cpp +++ b/sndlock.cpp @@ -251,16 +251,29 @@ static const char *kirdies[SND_PCHAN][2] = { {"192.168.1.126", "1337"}, }; -static std::atomic laser_temp[SND_PCHAN]; +static std::atomic servo_enable[SND_PCHAN]; +static std::atomic servo_state[SND_PCHAN]; +static std::atomic laser_temp[SND_PCHAN]; +static std::atomic init_current_cooling[SND_PCHAN]; +static std::atomic init_current_heating[SND_PCHAN]; +static std::atomic init_temp[SND_PCHAN]; static void servo_thread(int channel) { Clocker clocker = Clocker(std::chrono::milliseconds(100)); Kirdy kirdy = Kirdy(kirdies[channel][0], kirdies[channel][1]); - while(!shutdown_threads) { - clocker.tick(); - laser_temp[channel] = kirdy.get_laser_temp(); - kirdy.set_tec_current(0.01); + float temp; + + while(true) { + servo_state[channel] = "DISABLED"; + while(!servo_enable[channel]) { + clocker.tick(); + if(shutdown_threads) + return; + laser_temp[channel] = temp = kirdy.get_laser_temp(); + } + + servo_state[channel] = "INIT"; } } @@ -304,6 +317,10 @@ int main(int argc, char* argv[]) amplitude[i] = 1.0; multiplier[i] = 1; lpf_bandwidth[i] = 10.0; + servo_state[i] = "DISABLED"; + init_current_cooling[i] = 100.0f; + init_current_heating[i] = 30.0f; + init_temp[i] = 25.0f; } static std::thread dsp_thread_h = std::thread(dsp_thread); @@ -433,7 +450,32 @@ int main(int argc, char* argv[]) char str[64]; sprintf(str, "Channel %d", i); ImGui::SeparatorText(str); - ImGui::Text("laser temperature: %.4f", (float)laser_temp[i]); + bool servo_enable_l = servo_enable[i]; + sprintf(str, "enable##%d", i); + ImGui::Checkbox(str, &servo_enable_l); + servo_enable[i] = servo_enable_l; + ImGui::Text("servo state: %s", (const char *)servo_state[i]); + ImGui::Text("laser temperature: %.4f °C", (float)laser_temp[i]); + + ImGui::AlignTextToFramePadding(); + ImGui::Text("init:"); + ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x / 6.0f); + ImGui::SameLine(); + sprintf(str, "cooling mA##%d", i); + float init_current_cooling_l = init_current_cooling[i]; + ImGui::InputFloat(str, &init_current_cooling_l, 1.0f, 500.0f, "%.3f"); + init_current_cooling[i] = init_current_cooling_l; + ImGui::SameLine(); + sprintf(str, "heating mA##%d", i); + float init_current_heating_l = init_current_heating[i]; + ImGui::InputFloat(str, &init_current_heating_l, 1.0f, 500.0f, "%.3f"); + init_current_heating[i] = init_current_heating_l; + ImGui::SameLine(); + sprintf(str, "temp °C##%d", i); + float init_temp_l = init_temp[i]; + ImGui::InputFloat(str, &init_temp_l, 1.0f, 500.0f, "%.4f"); + init_temp[i] = init_temp_l; + ImGui::PopItemWidth(); } }