[moserial] Add serial status. Manual patched code from danny-source fork.
- From: Michael J. Chudobiak <mjc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [moserial] Add serial status. Manual patched code from danny-source fork.
- Date: Sat, 16 Jan 2021 13:47:23 +0000 (UTC)
commit 27e92298b2042b5009828d0914463af77b4d8815
Author: Mictronics <github mictronics de>
Date: Sat Apr 25 17:23:30 2020 +0200
Add serial status. Manual patched code from danny-source fork.
data/ui/mainwindow.ui | 30 +++++++++++++-------
src/MainWindow.vala | 70 +++++++++++++++++++++++++++++++++++++++++++++--
src/SerialConnection.vala | 60 +++++++++++++++++++++++++++++++++++++++-
3 files changed, 146 insertions(+), 14 deletions(-)
---
diff --git a/data/ui/mainwindow.ui b/data/ui/mainwindow.ui
index e6542fc..a9f01b3 100644
--- a/data/ui/mainwindow.ui
+++ b/data/ui/mainwindow.ui
@@ -2,7 +2,6 @@
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.20"/>
- <!-- interface-naming-policy toplevel-contextual -->
<object class="GtkAccelGroup" id="accelgroup1"/>
<object class="GtkWindow" id="window">
<property name="can_focus">False</property>
@@ -504,8 +503,6 @@
<property name="invisible_char">●</property>
<property name="primary_icon_activatable">False</property>
<property name="secondary_icon_activatable">False</property>
- <property name="primary_icon_sensitive">True</property>
- <property name="secondary_icon_sensitive">True</property>
</object>
<packing>
<property name="expand">True</property>
@@ -592,20 +589,23 @@
</packing>
</child>
<child>
- <object class="GtkHBox" id="hbox-control">
+ <object class="GtkBox" id="hbox-control">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">2</property>
+ <property name="homogeneous">True</property>
<child>
<object class="GtkLabel" id="labelStatusDTR">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">DTR</property>
+ <property name="width_chars">4</property>
+ <property name="max_width_chars">4</property>
<property name="track_visited_links">False</property>
</object>
<packing>
- <property name="expand">True</property>
+ <property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
@@ -616,10 +616,12 @@
<property name="sensitive">False</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">RTS</property>
+ <property name="width_chars">4</property>
+ <property name="max_width_chars">4</property>
<property name="track_visited_links">False</property>
</object>
<packing>
- <property name="expand">True</property>
+ <property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
@@ -630,10 +632,12 @@
<property name="sensitive">False</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">CTS</property>
+ <property name="width_chars">4</property>
+ <property name="max_width_chars">4</property>
<property name="track_visited_links">False</property>
</object>
<packing>
- <property name="expand">True</property>
+ <property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
@@ -644,10 +648,12 @@
<property name="sensitive">False</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">CD</property>
+ <property name="width_chars">4</property>
+ <property name="max_width_chars">4</property>
<property name="track_visited_links">False</property>
</object>
<packing>
- <property name="expand">True</property>
+ <property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
@@ -658,10 +664,12 @@
<property name="sensitive">False</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">DSR</property>
+ <property name="width_chars">4</property>
+ <property name="max_width_chars">4</property>
<property name="track_visited_links">False</property>
</object>
<packing>
- <property name="expand">True</property>
+ <property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
@@ -672,10 +680,12 @@
<property name="sensitive">False</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">RI</property>
+ <property name="width_chars">4</property>
+ <property name="max_width_chars">4</property>
<property name="track_visited_links">False</property>
</object>
<packing>
- <property name="expand">True</property>
+ <property name="expand">False</property>
<property name="fill">True</property>
<property name="position">5</property>
</packing>
diff --git a/src/MainWindow.vala b/src/MainWindow.vala
index e9e9ac3..5703add 100644
--- a/src/MainWindow.vala
+++ b/src/MainWindow.vala
@@ -24,7 +24,7 @@ public class moserial.MainWindow : Gtk.Window // Have to extend Gtk.Winow to get
{
const string[] authors = {
"Michael J. Chudobiak <mjc svn gnome org>",
- "marlodavampire",
+ "mdarlodavampire",
null
};
const string translators = N_ ("translator-credits");
@@ -101,6 +101,8 @@ public class moserial.MainWindow : Gtk.Window // Have to extend Gtk.Winow to get
private const string recentGroup = "moserial-configs";
private Gtk.RecentData recentData;
+ // RTS status
+ private Label SerialStatusSignals[6];
public MainWindow (string ? profileFilename) {
GLib.Object (startupProfileFilename: profileFilename);
@@ -112,7 +114,7 @@ public class moserial.MainWindow : Gtk.Window // Have to extend Gtk.Winow to get
gtkWindow = (Gtk.Window)builder.get_object ("window");
ag = (Gtk.AccelGroup)builder.get_object ("accelgroup1");
gtkWindow.add_accel_group (ag);
-
+ // gtkWindow.add_accelerator(gtkWindow, "<Control>b", signal="backspace")
gtkWindow.destroy.connect (quitSave);
gtkWindow.delete_event.connect (deleteSaveSize);
gtkWindow.key_press_event.connect (keyPress);
@@ -301,6 +303,28 @@ public class moserial.MainWindow : Gtk.Window // Have to extend Gtk.Winow to get
Gtk.MenuItem recentFileItem = (Gtk.MenuItem)builder.get_object ("menubar_open_recent");
recentFileItem.set_submenu (recentChooserMenu);
+ // setup status bar for serial
+ Label label = (Label) builder.get_object ("labelStatusRI");
+ label.set_sensitive (false);
+ SerialStatusSignals[0] = label;
+ label = (Label) builder.get_object ("labelStatusDSR");
+ label.set_sensitive (false);
+ SerialStatusSignals[1] = label;
+ label = (Label) builder.get_object ("labelStatusCD");
+ label.set_sensitive (false);
+ SerialStatusSignals[2] = label;
+ label = (Label) builder.get_object ("labelStatusCTS");
+ label.set_sensitive (false);
+ SerialStatusSignals[3] = label;
+ label = (Label) builder.get_object ("labelStatusRTS");
+ label.set_sensitive (false);
+ SerialStatusSignals[4] = label;
+ label = (Label) builder.get_object ("labelStatusDTR");
+ label.set_sensitive (false);
+ SerialStatusSignals[5] = label;
+ // public uint add (uint interval, owned SourceFunc function, int priority = DEFAULT)
+ GLib.Timeout.add (200, (GLib.SourceFunc)showSerialStatus, 0);
+
// load and apply preferences
currentPreferences = Preferences.loadFromProfile (profile);
updatePreferences (null, currentPreferences);
@@ -655,16 +679,37 @@ public class moserial.MainWindow : Gtk.Window // Have to extend Gtk.Winow to get
serialConnection.newData.disconnect (this.updateIncoming);
bytecountbar.pop (bytecountbarContext);
bytecountbar.push (bytecountbarContext, serialConnection.getBytecountbarString ());
- // serialConnection = new SerialConnection();
statusbar.pop (statusbarContext);
statusbar.push (statusbarContext, currentSettings.getStatusbarString (false));
button.set_label_widget (connectLabel);
+ SerialStatusSignals[0].set_sensitive (false);
+ SerialStatusSignals[1].set_sensitive (false);
+ SerialStatusSignals[2].set_sensitive (false);
+ SerialStatusSignals[3].set_sensitive (false);
+ SerialStatusSignals[4].set_sensitive (false);
+ SerialStatusSignals[5].set_sensitive (false);
if (recordButton.get_active ())
recordButton.set_active (false);
}
}
+ private bool showSerialStatus () {
+ if (!serialConnection.isConnected ()) {
+
+ return true;
+ }
+
+ bool[] state = serialConnection.getStatus ();
+ SerialStatusSignals[0].set_sensitive (state[0]);
+ SerialStatusSignals[1].set_sensitive (state[1]);
+ SerialStatusSignals[2].set_sensitive (state[2]);
+ SerialStatusSignals[3].set_sensitive (state[3]);
+ SerialStatusSignals[4].set_sensitive (state[4]);
+ SerialStatusSignals[5].set_sensitive (state[5]);
+ return true;
+ }
+
private void updateIncoming (SerialConnection sc, uchar[] data, int size) {
if (rz.running) {
for (int x = 0; x < size; x++) {
@@ -785,6 +830,7 @@ public class moserial.MainWindow : Gtk.Window // Have to extend Gtk.Winow to get
}
private bool keyPress (Widget widget, EventKey key) {
+ // GLib.print("key:%x\r\n",key.keyval);
if (key.keyval == Gdk.keyval_from_name ("Escape")) {
AutoScroll.scroll (va1);
AutoScroll.scroll (va2);
@@ -795,6 +841,24 @@ public class moserial.MainWindow : Gtk.Window // Have to extend Gtk.Winow to get
return true;
}
+ if (key.keyval == Gdk.keyval_from_name ("F7")) {
+ bool[] state = serialConnection.getStatus ();
+ if (state[5] && serialConnection.isConnected ())
+ serialConnection.controlDTR (false);
+ else
+ serialConnection.controlDTR (true);
+ return true;
+ }
+
+ if (key.keyval == Gdk.keyval_from_name ("F8")) {
+ bool[] state = serialConnection.getStatus ();
+ if (state[4] && serialConnection.isConnected ())
+ serialConnection.controlRTS (false);
+ else
+ serialConnection.controlRTS (true);
+ return true;
+ }
+
return false;
}
diff --git a/src/SerialConnection.vala b/src/SerialConnection.vala
index d4788dc..ff20bc0 100644
--- a/src/SerialConnection.vala
+++ b/src/SerialConnection.vala
@@ -121,6 +121,10 @@ public class moserial.SerialConnection : GLib.Object {
}
}
+ public bool isConnected () {
+ return connected;
+ }
+
private bool readBytes (GLib.IOChannel source, GLib.IOCondition condition) {
uchar[] m_buf = new uchar[max_buf_size];
int bytesRead = (int) Posix.read (m_fd, m_buf, max_buf_size);
@@ -258,7 +262,7 @@ public class moserial.SerialConnection : GLib.Object {
// Some other port settings from minicom.
-// newtio.c_iflag &= ~(IGNBRK | IGNCR | INLCR | ICRNL | IUCLC | IXANY | IXON | IXOFF | INPCK | ISTRIP);
+ // newtio.c_iflag &= ~(IGNBRK | IGNCR | INLCR | ICRNL | IUCLC | IXANY | IXON | IXOFF | INPCK |
ISTRIP);
// newtio.c_iflag &= ~(Posix.IGNBRK | Posix.IGNCR | Posix.InputMode.INLCR | Posix.InputMode.ICRNL |
Posix.IXANY | Posix.IXON | Posix.IXOFF | Posix.INPCK | Posix.ISTRIP);
// newtio.c_iflag |= (Posix.BRKINT | Posix.IGNPAR);
// newtio.c_oflag &= ~Posix.OPOST;
@@ -279,6 +283,60 @@ public class moserial.SerialConnection : GLib.Object {
newtio.c_cflag &= ~Linux.Termios.CRTSCTS;
}
+ public void controlDTR (bool y) {
+ int mcs = 0;
+ Posix.ioctl (m_fd, Linux.Termios.TIOCMGET, out mcs);
+ if (y) {
+ mcs |= Linux.Termios.TIOCM_DTR;
+ } else {
+ mcs &= ~Linux.Termios.TIOCM_DTR;
+ }
+ Posix.ioctl (m_fd, Linux.Termios.TIOCMSET, out mcs);
+ }
+
+ public void controlRTS (bool y) {
+ int mcs = 0;
+ Posix.ioctl (m_fd, Linux.Termios.TIOCMGET, out mcs);
+ if (y) {
+ mcs |= Linux.Termios.TIOCM_RTS;
+ } else {
+ mcs &= ~Linux.Termios.TIOCM_RTS;
+ }
+ Posix.ioctl (m_fd, Linux.Termios.TIOCMSET, out mcs);
+ }
+
+ public bool[] getStatus () {
+ bool mcs[6];
+ int stat;
+ Posix.ioctl (m_fd, Linux.Termios.TIOCMGET, out stat);
+ // GLib.print("stat%x\r\n",stat);
+ if ((stat & 0x080) == 0) // Linux.Termios.TIOCM_RI=0x080
+ mcs[0] = false;
+ else
+ mcs[0] = true;
+ if ((stat & Linux.Termios.TIOCM_DSR) == 0)
+ mcs[1] = false;
+ else
+ mcs[1] = true;
+ if ((stat & 0x040) == 0) // Linux.Termios.TIOCM_CD=0x040
+ mcs[2] = false;
+ else
+ mcs[2] = true;
+ if ((stat & Linux.Termios.TIOCM_CTS) == 0)
+ mcs[3] = false;
+ else
+ mcs[3] = true;
+ if ((stat & Linux.Termios.TIOCM_RTS) == 0)
+ mcs[4] = false;
+ else
+ mcs[4] = true;
+ if ((stat & Linux.Termios.TIOCM_DTR) == 0)
+ mcs[5] = false;
+ else
+ mcs[5] = true;
+ return mcs;
+ }
+
public string getBytecountbarString () {
string r;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]