report laser temperatures

This commit is contained in:
Sébastien Bourdeauducq 2025-01-19 18:22:51 +08:00
parent cff46a5799
commit 1490334f87
4 changed files with 68 additions and 2 deletions

View File

@ -1,5 +1,5 @@
PROG= sndlock PROG= sndlock
SRCS= imgui_impl_glfw.cpp imgui_impl_opengl3.cpp imgui_draw.cpp imgui_widgets.cpp imgui_tables.cpp imgui.cpp sndlock.cpp SRCS= imgui_impl_glfw.cpp imgui_impl_opengl3.cpp imgui_draw.cpp imgui_widgets.cpp imgui_tables.cpp imgui.cpp kirdy.cpp sndlock.cpp
CXXOPTS= -Wall `pkg-config --cflags glfw3 gl` CXXOPTS= -Wall `pkg-config --cflags glfw3 gl`
LDFLAGS= `pkg-config --libs glfw3 gl` LDFLAGS= `pkg-config --libs glfw3 gl`
LDADD= -lsndio -lm LDADD= -lsndio -lm

33
kirdy.cpp Normal file
View File

@ -0,0 +1,33 @@
#include <asio.hpp>
#include <nlohmann/json.hpp>
#include "kirdy.hpp"
Kirdy::Kirdy(asio::string_view host, asio::string_view service)
{
asio::ip::tcp::resolver resolver(io_context);
asio::ip::tcp::resolver::results_type endpoints = resolver.resolve(host, service);
socket = new asio::ip::tcp::socket(io_context);
asio::connect(*socket, endpoints);
}
Kirdy::~Kirdy()
{
delete socket;
}
nlohmann::json Kirdy::command(nlohmann::json &request)
{
std::string reply;
asio::write(*socket, asio::buffer(request.dump() + "\n"));
asio::read_until(*socket, asio::dynamic_buffer(reply, 1024), '\n');
return nlohmann::json::parse(reply);
}
float Kirdy::get_laser_temp()
{
nlohmann::json json;
json["device_cmd"] = "GetStatusReport";
auto reply = command(json);
return reply["thermostat"]["temperature"];
}

15
kirdy.hpp Normal file
View File

@ -0,0 +1,15 @@
#pragma once
#include <asio.hpp>
#include <nlohmann/json.hpp>
class Kirdy {
private:
asio::io_context io_context;
asio::ip::tcp::socket *socket;
nlohmann::json command(nlohmann::json &request);
public:
Kirdy(asio::string_view host, asio::string_view service);
~Kirdy();
float get_laser_temp();
};

View File

@ -16,6 +16,7 @@
#include "dsp_lib.hpp" #include "dsp_lib.hpp"
#include "fifo.hpp" #include "fifo.hpp"
#include "kirdy.hpp"
#define SND_BITS 24 #define SND_BITS 24
#define SND_PCHAN 2 #define SND_PCHAN 2
@ -245,12 +246,20 @@ static void dsp_thread()
sio_close(hdl); sio_close(hdl);
} }
static const char *kirdies[SND_PCHAN][2] = {
{"192.168.1.128", "1337"},
{"192.168.1.126", "1337"},
};
static std::atomic<double> laser_temp[SND_PCHAN];
static void servo_thread(int channel) static void servo_thread(int channel)
{ {
Clocker clocker = Clocker(std::chrono::milliseconds(100)); Clocker clocker = Clocker(std::chrono::milliseconds(100));
Kirdy kirdy = Kirdy(kirdies[channel][0], kirdies[channel][1]);
while(!shutdown_threads) { while(!shutdown_threads) {
clocker.tick(); clocker.tick();
std::cout << "servo thread tick " << channel << std::endl; laser_temp[channel] = kirdy.get_laser_temp();
} }
} }
@ -418,6 +427,15 @@ int main(int argc, char* argv[])
} }
} }
if(ImGui::CollapsingHeader("Laser servo")) {
for(int i=0;i<SND_PCHAN;i++) {
char str[64];
sprintf(str, "Channel %d", i);
ImGui::SeparatorText(str);
ImGui::Text("laser temperature: %.4f", (float)laser_temp[i]);
}
}
ImGui::End(); ImGui::End();
ImGui::PopStyleVar(1); ImGui::PopStyleVar(1);