From 6f32058a7bbc8aae6f3ea8583c5d8334a954ea74 Mon Sep 17 00:00:00 2001 From: Steffen Pohle Date: Sat, 28 Jan 2023 00:18:03 +0100 Subject: [PATCH] adding basic tty support --- posctl.cc | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/posctl.cc b/posctl.cc index 6fdf34f..b56d11c 100644 --- a/posctl.cc +++ b/posctl.cc @@ -382,6 +382,7 @@ void posctl_gui_update() { strfromd (txt, sizeof(txt-1), (const char *)"%f", posctl.calib_axis2_lenma); gtk_entry_set_text (GTK_ENTRY(e_cal_a2lenma), txt); + gtk_entry_set_text (GTK_ENTRY(e_posdevice), posctl.GetDevice().c_str()); strfromd (txt, sizeof(txt-1), (const char *)"%f", posctl.out[0]); gtk_label_set_text(GTK_LABEL(a1_out), txt); strfromd (txt, sizeof(txt-1), (const char *)"%f", posctl.out[1]); @@ -598,7 +599,7 @@ void PosCtl::Loop (int posx, int posy) { void PosCtl::SetDevice (std::string d) { - printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__); + printf ("%s:%d %s new device:%s\n", __FILE__, __LINE__, __FUNCTION__, d.c_str()); OutputClose(); device = d; }; @@ -613,19 +614,50 @@ void PosCtl::OutputClose() { void PosCtl::OutputOpen() { printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__); + if (device_fd > 0) return; + + device_fd = open (device.c_str(), O_RDWR); + if (device_fd < 0) { + printf ("%s:%d could not open device:%s Error:%s\n", __FILE__, __LINE__, + device.c_str(), strerror(errno)); + } }; void PosCtl::OutputWriteValue (int axis, double value) { + char outbuf[255]; + ssize_t len; printf ("%s:%d %s Axis %d Value:%f\n", __FILE__, __LINE__, __FUNCTION__, axis, value); -} + + if (device_fd <= 0) OutputOpen(); + + // + // save language setting and set to plain C + std::string s = setlocale(LC_ALL, NULL); + setlocale (LC_ALL, "C"); + + snprintf(outbuf, 254, "FIXME: dd:%f\n", value); + outbuf[254] = 0; + + // reset language setting to default + setlocale (LC_ALL, s.c_str()); + + len = write (device_fd, outbuf, strlen(outbuf)); + if ((size_t) len != strlen(outbuf) || len < 0) + printf ("%s:%d could not open device:%s Error:%s\n", __FILE__, __LINE__, + device.c_str(), strerror(errno)); +}; void PosCtl::OutputWriteStop (int axis) { printf ("%s:%d %s Axis %d\n", __FILE__, __LINE__, __FUNCTION__, axis); + + if (device_fd <= 0) OutputOpen(); } void PosCtl::OutputWriteStart (int axis) { printf ("%s:%d %s Axis %d\n", __FILE__, __LINE__, __FUNCTION__, axis); + + if (device_fd <= 0) OutputOpen(); }