Fixed Missing Graph Feature
This commit is contained in:
parent
32136bb93a
commit
4c14c62c05
|
|
@ -36,6 +36,15 @@ dependencies = [
|
||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ansi_term"
|
||||||
|
version = "0.11.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
|
||||||
|
dependencies = [
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anyhow"
|
name = "anyhow"
|
||||||
version = "1.0.32"
|
version = "1.0.32"
|
||||||
|
|
@ -68,6 +77,17 @@ dependencies = [
|
||||||
"system-deps",
|
"system-deps",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "atty"
|
||||||
|
version = "0.2.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
||||||
|
dependencies = [
|
||||||
|
"hermit-abi",
|
||||||
|
"libc",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "1.2.1"
|
version = "1.2.1"
|
||||||
|
|
@ -124,6 +144,21 @@ version = "1.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap"
|
||||||
|
version = "2.33.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002"
|
||||||
|
dependencies = [
|
||||||
|
"ansi_term",
|
||||||
|
"atty",
|
||||||
|
"bitflags",
|
||||||
|
"strsim",
|
||||||
|
"textwrap",
|
||||||
|
"unicode-width",
|
||||||
|
"vec_map",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crc32fast"
|
name = "crc32fast"
|
||||||
version = "1.2.0"
|
version = "1.2.0"
|
||||||
|
|
@ -471,6 +506,15 @@ dependencies = [
|
||||||
"unicode-segmentation",
|
"unicode-segmentation",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hermit-abi"
|
||||||
|
version = "0.1.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itertools"
|
name = "itertools"
|
||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
|
|
@ -847,6 +891,12 @@ version = "0.4.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
|
checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "strsim"
|
||||||
|
version = "0.8.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "strum"
|
name = "strum"
|
||||||
version = "0.18.0"
|
version = "0.18.0"
|
||||||
|
|
@ -893,9 +943,11 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tarangam"
|
name = "tarangam"
|
||||||
version = "0.1.1"
|
version = "0.1.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cairo-rs",
|
"cairo-rs",
|
||||||
|
"clap",
|
||||||
|
"gdk",
|
||||||
"gio",
|
"gio",
|
||||||
"glib",
|
"glib",
|
||||||
"gtk",
|
"gtk",
|
||||||
|
|
@ -905,6 +957,15 @@ dependencies = [
|
||||||
"serialport",
|
"serialport",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "textwrap"
|
||||||
|
version = "0.11.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-width",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thiserror"
|
name = "thiserror"
|
||||||
version = "1.0.20"
|
version = "1.0.20"
|
||||||
|
|
@ -949,12 +1010,24 @@ version = "1.6.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0"
|
checksum = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-width"
|
||||||
|
version = "0.1.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-xid"
|
name = "unicode-xid"
|
||||||
version = "0.2.1"
|
version = "0.2.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
|
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "vec_map"
|
||||||
|
version = "0.8.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "version-compare"
|
name = "version-compare"
|
||||||
version = "0.0.10"
|
version = "0.0.10"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "tarangam"
|
name = "tarangam"
|
||||||
version = "0.1.1"
|
version = "0.1.2"
|
||||||
authors = ["PiyushXCoder <piyush.raj.kit@gmail.com>"]
|
authors = ["PiyushXCoder <piyush.raj.kit@gmail.com>"]
|
||||||
license = "GPL 3.0"
|
license = "GPL 3.0"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
@ -12,10 +12,12 @@ keywords = ["plotter","serial","serialplotter","arduino","gtk"]
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
[dependencies]
|
[dependencies]
|
||||||
gtk = "0.9.2"
|
gtk = "0.9.2"
|
||||||
|
gdk = "0.13.2"
|
||||||
gio = "0.9.1"
|
gio = "0.9.1"
|
||||||
glib = "0.10.3"
|
glib = "0.10.3"
|
||||||
png = "0.16.8"
|
png = "0.16.8"
|
||||||
cairo-rs = { version = "0.9.1", features = ["png"] }
|
cairo-rs = { version = "0.9.1", features = ["png"] }
|
||||||
rand = "0.8.1"
|
rand = "0.8.1"
|
||||||
libmath = "0.2.1"
|
libmath = "0.2.1"
|
||||||
serialport = "4.0.0"
|
serialport = "4.0.0"
|
||||||
|
clap = "2.33.3"
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
This file is part of Tarangam.
|
||||||
|
|
||||||
|
Tarangam is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Tarangam is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Tarangam. If not, see <https://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
|
||||||
|
//! Feel free to see through codes. Application is not written to be used as a library for other app. :)
|
||||||
|
|
||||||
|
pub struct Config {
|
||||||
|
pub ui_file: String
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Config {
|
||||||
|
pub fn generate() -> Self {
|
||||||
|
let ui_file = std::env::var("TARANGAM_UI_FILE");
|
||||||
|
|
||||||
|
Config {
|
||||||
|
ui_file: match ui_file {
|
||||||
|
Ok(val) => val,
|
||||||
|
Err(_) => std::env::current_exe().unwrap().parent().unwrap()
|
||||||
|
.join("ui.glade").to_str().unwrap().to_owned()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -24,6 +24,7 @@ use std::rc::Rc;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
/// A single line
|
/// A single line
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct Line {
|
pub struct Line {
|
||||||
pub points: Vec<(f64,f64)>,
|
pub points: Vec<(f64,f64)>,
|
||||||
pub color: (f64, f64, f64)
|
pub color: (f64, f64, f64)
|
||||||
|
|
|
||||||
32
src/lib.rs
32
src/lib.rs
|
|
@ -58,21 +58,23 @@ impl Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For communication between mpsc of graph and serial port
|
/// For communication between mpsc of graph and serial port
|
||||||
|
#[derive(Debug)]
|
||||||
enum MessageSerialThread {
|
enum MessageSerialThread {
|
||||||
Msg(String, MessageSerialThreadMsgType),
|
Msg(String, MessageSerialThreadMsgType),
|
||||||
Points(Vec<(String, f64)>),
|
Points(Vec<(String, f64)>),
|
||||||
Status(String)
|
Status(String)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
enum MessageSerialThreadMsgType {
|
enum MessageSerialThreadMsgType {
|
||||||
Point,
|
Point,
|
||||||
Log
|
Log
|
||||||
}
|
}
|
||||||
|
|
||||||
// Building and configuring GUI
|
// Building and configuring GUI
|
||||||
pub fn build_ui(app: >k::Application) {
|
pub fn build_ui(app: >k::Application, ui_file: &str) {
|
||||||
let config = Arc::new(Mutex::new(Config::new()));
|
let config = Arc::new(Mutex::new(Config::new()));
|
||||||
let builder = gtk::Builder::from_file(std::env::current_exe().unwrap().parent().unwrap().join("ui.glade"));
|
let builder = gtk::Builder::from_file(ui_file);
|
||||||
|
|
||||||
let win = builder.get_object::<gtk::ApplicationWindow>("win").expect("Resource file missing!");
|
let win = builder.get_object::<gtk::ApplicationWindow>("win").expect("Resource file missing!");
|
||||||
win.set_application(Some(app));
|
win.set_application(Some(app));
|
||||||
|
|
@ -107,7 +109,7 @@ pub fn build_ui(app: >k::Application) {
|
||||||
let about_menu = builder.get_object::<gtk::MenuItem>("about_menu").expect("Resource file missing!");
|
let about_menu = builder.get_object::<gtk::MenuItem>("about_menu").expect("Resource file missing!");
|
||||||
let about_window = builder.get_object::<gtk::AboutDialog>("about_window").expect("Resource file missing!");
|
let about_window = builder.get_object::<gtk::AboutDialog>("about_window").expect("Resource file missing!");
|
||||||
about_window.set_transient_for(Some(&win));
|
about_window.set_transient_for(Some(&win));
|
||||||
|
about_window.set_version(Some(env!("CARGO_PKG_VERSION")));
|
||||||
about_window.connect_delete_event(|win,_| {
|
about_window.connect_delete_event(|win,_| {
|
||||||
win.hide();
|
win.hide();
|
||||||
Inhibit(true)
|
Inhibit(true)
|
||||||
|
|
@ -389,6 +391,7 @@ pub fn build_ui(app: >k::Application) {
|
||||||
|
|
||||||
// Reciver for MessageSerialThread from the "Thread to manage Serial Port" and works accordingly
|
// Reciver for MessageSerialThread from the "Thread to manage Serial Port" and works accordingly
|
||||||
let full_log = builder.get_object::<gtk::CheckButton>("full_log").expect("Resource file missing!");
|
let full_log = builder.get_object::<gtk::CheckButton>("full_log").expect("Resource file missing!");
|
||||||
|
let graph_data = builder.get_object::<gtk::TextView>("graph_data").expect("Resource file missing!");
|
||||||
let tmp_graph = Rc::clone(&graph);
|
let tmp_graph = Rc::clone(&graph);
|
||||||
receiver.attach(None, move |msg| {
|
receiver.attach(None, move |msg| {
|
||||||
match msg {
|
match msg {
|
||||||
|
|
@ -396,7 +399,7 @@ pub fn build_ui(app: >k::Application) {
|
||||||
receiver_for_msg(text, &msg_type, &full_log, &log_area);
|
receiver_for_msg(text, &msg_type, &full_log, &log_area);
|
||||||
},
|
},
|
||||||
MessageSerialThread::Points(points) => {
|
MessageSerialThread::Points(points) => {
|
||||||
receiver_for_points(points, &tmp_graph);
|
receiver_for_points(points, &tmp_graph, &graph_data);
|
||||||
}
|
}
|
||||||
MessageSerialThread::Status(text) => {
|
MessageSerialThread::Status(text) => {
|
||||||
bar.push(1, &text);
|
bar.push(1, &text);
|
||||||
|
|
@ -499,7 +502,7 @@ fn receiver_for_msg(text: String, msg_type: &MessageSerialThreadMsgType, full_lo
|
||||||
}
|
}
|
||||||
|
|
||||||
// Receives MessageSerialThread from Serial Port managing thread and add points to draw on graph
|
// Receives MessageSerialThread from Serial Port managing thread and add points to draw on graph
|
||||||
fn receiver_for_points(points: Vec<(String, f64)>, graph: &Rc<RefCell<Graph>>) {
|
fn receiver_for_points(points: Vec<(String, f64)>, graph: &Rc<RefCell<Graph>>, graph_data: >k::TextView) {
|
||||||
for (line, point) in points {
|
for (line, point) in points {
|
||||||
let mut gp = graph.borrow_mut();
|
let mut gp = graph.borrow_mut();
|
||||||
|
|
||||||
|
|
@ -511,6 +514,25 @@ fn receiver_for_points(points: Vec<(String, f64)>, graph: &Rc<RefCell<Graph>>) {
|
||||||
let v = vec![(sankhya, point)];
|
let v = vec![(sankhya, point)];
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
gp.lines.insert(line, graph::Line::new(rng.gen_range(0.0..1.0), 0.0, rng.gen_range(0.0..1.0), v));
|
gp.lines.insert(line, graph::Line::new(rng.gen_range(0.0..1.0), 0.0, rng.gen_range(0.0..1.0), v));
|
||||||
|
let buf = graph_data.get_buffer().expect("Couldn't get graph_data");
|
||||||
|
buf.set_text("");
|
||||||
|
gp.lines.iter().for_each(|(key, line)| {
|
||||||
|
buf.insert(&mut buf.get_end_iter(), "##");
|
||||||
|
|
||||||
|
let tag = gtk::TextTag::new(None);
|
||||||
|
let rgba = gdk::RGBA {
|
||||||
|
red: line.color.0,
|
||||||
|
green: line.color.1,
|
||||||
|
blue: line.color.2,
|
||||||
|
alpha: 1.0
|
||||||
|
};
|
||||||
|
tag.set_property_background_rgba(Some(&rgba));
|
||||||
|
tag.set_property_foreground_rgba(Some(&rgba));
|
||||||
|
buf.get_tag_table().unwrap().add(&tag);
|
||||||
|
buf.apply_tag(&tag, &buf.get_iter_at_offset(buf.get_end_iter().get_offset() - 2), &buf.get_end_iter());
|
||||||
|
buf.insert(&mut buf.get_end_iter(), &format!(" {}, ", key));
|
||||||
|
});
|
||||||
|
graph_data.queue_draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gp.redraw();
|
gp.redraw();
|
||||||
|
|
|
||||||
|
|
@ -13,15 +13,19 @@
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
mod config;
|
||||||
|
|
||||||
use gio::prelude::*;
|
use gio::prelude::*;
|
||||||
use std::env::args;
|
use std::env::args;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
let conf = config::Config::generate();
|
||||||
|
|
||||||
let app = gtk::Application::new(Some("sng.tarangm"), Default::default())
|
let app = gtk::Application::new(Some("sng.tarangm"), Default::default())
|
||||||
.expect("Failed to initiate gtk");
|
.expect("Failed to initiate gtk");
|
||||||
|
|
||||||
app.connect_activate(move |app| {
|
app.connect_activate(move |app| {
|
||||||
tarangam::build_ui(app);
|
tarangam::build_ui(app, &conf.ui_file);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.run(&args().collect::<Vec<_>>());
|
app.run(&args().collect::<Vec<_>>());
|
||||||
|
|
|
||||||
29
ui.glade
29
ui.glade
|
|
@ -8,7 +8,6 @@
|
||||||
<property name="icon">chitra.svg</property>
|
<property name="icon">chitra.svg</property>
|
||||||
<property name="type-hint">dialog</property>
|
<property name="type-hint">dialog</property>
|
||||||
<property name="program-name">Tarangam (तरंगम्)</property>
|
<property name="program-name">Tarangam (तरंगम्)</property>
|
||||||
<property name="version">0.1.1</property>
|
|
||||||
<property name="comments" translatable="yes">A simple serial plotter.
|
<property name="comments" translatable="yes">A simple serial plotter.
|
||||||
एक सरल सीरीय्ल पलौटर।</property>
|
एक सरल सीरीय्ल पलौटर।</property>
|
||||||
<property name="website">https://github.com/PiyushXCoder/Tarangam</property>
|
<property name="website">https://github.com/PiyushXCoder/Tarangam</property>
|
||||||
|
|
@ -422,6 +421,30 @@
|
||||||
<property name="position">0</property>
|
<property name="position">0</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkScrolledWindow">
|
||||||
|
<property name="height-request">35</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">True</property>
|
||||||
|
<property name="vscrollbar-policy">never</property>
|
||||||
|
<property name="shadow-type">in</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkTextView" id="graph_data">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">True</property>
|
||||||
|
<property name="editable">False</property>
|
||||||
|
<property name="left-margin">5</property>
|
||||||
|
<property name="top-margin">7</property>
|
||||||
|
<property name="cursor-visible">False</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkDrawingArea" id="draw_area">
|
<object class="GtkDrawingArea" id="draw_area">
|
||||||
<property name="width-request">500</property>
|
<property name="width-request">500</property>
|
||||||
|
|
@ -434,7 +457,7 @@
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
<property name="fill">True</property>
|
<property name="fill">True</property>
|
||||||
<property name="position">1</property>
|
<property name="position">2</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
|
|
@ -540,7 +563,7 @@
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
<property name="fill">True</property>
|
<property name="fill">True</property>
|
||||||
<property name="position">2</property>
|
<property name="position">3</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue