[chronojump] All firmware Auto methods on Chronopic window
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] All firmware Auto methods on Chronopic window
- Date: Sat, 13 Sep 2014 00:18:50 +0000 (UTC)
commit 8a60c7b1c2535a64f0ce72cb8a37fd4805812ae0
Author: Xavier de Blas <xaviblas gmail com>
Date: Sat Sep 13 02:18:15 2014 +0200
All firmware Auto methods on Chronopic window
src/chronopic.cs | 74 +++++++++++++++++++++++++++++++++++++++++++------
src/gui/chronopic.cs | 16 ++++++-----
2 files changed, 74 insertions(+), 16 deletions(-)
---
diff --git a/src/chronopic.cs b/src/chronopic.cs
index 74902b7..5908b1a 100644
--- a/src/chronopic.cs
+++ b/src/chronopic.cs
@@ -419,21 +419,27 @@ Console.Write(" o3 ");
public abstract class ChronopicAuto
{
protected SerialPort sp;
- protected internal abstract string ReadValue();
+ protected int sendNum;
+ protected internal abstract string Communicate();
+ private string str;
- //'template method'
- public string Read(SerialPort sp)
+ private void make(SerialPort sp)
{
this.sp = sp;
- if (sp == null) {
+ if (sp == null)
sp.Open();
- }
- string str = "";
+ str = "";
+ }
+ //'template method'
+ public string Read(SerialPort sp)
+ {
+ make(sp);
+
try {
- str = ReadValue();
+ str = Communicate();
} catch {
//this.error=ErrorType.Timeout;
Console.WriteLine("Error or Timeout. This is not Chronopic-Automatic-Firmware");
@@ -442,11 +448,38 @@ public abstract class ChronopicAuto
return str;
}
+
+ //'template method'
+ public string Write(SerialPort sp, int num)
+ {
+ make(sp);
+ sendNum = num;
+
+ try {
+ str = Communicate();
+ } catch {
+ //this.error=ErrorType.Timeout;
+ Console.WriteLine("Error or Timeout. This is not Chronopic-Automatic-Firmware");
+ str = "Error";
+ }
+
+ return str;
+ }
+}
+
+public class ChronopicAutoCheck : ChronopicAuto
+{
+ protected internal override string Communicate()
+ {
+ sp.Write("J");
+ bool isChronopicAuto = ( (char) sp.ReadByte() == 'J');
+ return isChronopicAuto.ToString();
+ }
}
public class ChronopicAutoVersion : ChronopicAuto
{
- protected internal override string ReadValue()
+ protected internal override string Communicate()
{
sp.Write("V");
int major = (char) sp.ReadByte() - '0';
@@ -456,5 +489,28 @@ public class ChronopicAutoVersion : ChronopicAuto
}
}
-//go on with the rest of classes
+public class ChronopicAutoCheckDebounce : ChronopicAuto
+{
+ protected internal override string Communicate()
+ {
+ sp.Write("a");
+ int debounce = ( sp.ReadByte() - '0' ) * 10;
+ return debounce.ToString();
+ }
+}
+
+public class ChronopicAutoChangeDebounce : ChronopicAuto
+{
+ protected internal override string Communicate()
+ {
+ int debounce = sendNum / 10; //50 -> 5
+
+ //byte[] bytesToSend = new byte[2] { 0x62, 0x05 }; //b, 05 //this works
+ byte[] bytesToSend = new byte[2] { 0x62, BitConverter.GetBytes(debounce)[0] }; //b, 05
+ sp.Write(bytesToSend,0,2);
+
+ return "Changed to " + sendNum.ToString();
+ }
+}
+
diff --git a/src/gui/chronopic.cs b/src/gui/chronopic.cs
index ce64777..b99c368 100644
--- a/src/gui/chronopic.cs
+++ b/src/gui/chronopic.cs
@@ -701,26 +701,28 @@ Log.WriteLine("bbb");
private void on_button_auto_check_auto_clicked (object o, EventArgs args)
{
+ ChronopicAuto ca = new ChronopicAutoCheck();
+ label_auto_check_auto.Text = ca.Read(sp);
}
private void on_button_auto_check_version_clicked (object o, EventArgs args)
{
- if(cp == null)
- Log.WriteLine("cp == NULL");
- else {
- //label_auto_check_version.Text = cp.Read_variables_automatic_version();
- ChronopicAuto ca = new ChronopicAutoVersion();
- label_auto_check_version.Text = ca.Read(sp);
- }
+ ChronopicAuto ca = new ChronopicAutoVersion();
+ label_auto_check_version.Text = ca.Read(sp);
}
private void on_button_auto_check_debounce_clicked (object o, EventArgs args)
{
+ ChronopicAuto ca = new ChronopicAutoCheckDebounce();
+ label_auto_check_debounce.Text = ca.Read(sp);
}
private void on_button_auto_change_debounce_clicked (object o, EventArgs args)
{
+ ChronopicAuto ca = new ChronopicAutoChangeDebounce();
+ label_auto_change_debounce.Text = ca.Write(sp, (int) spin_auto_change_debounce.Value);
}
+
// end of Chronopic Automatic Firmware ---------------
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]