Ajout driver boitier V1

This commit is contained in:
tzim 2013-05-09 19:10:23 +00:00
parent 63dbe7676b
commit bb4d376e87
9 changed files with 213 additions and 5 deletions

View file

@ -21,6 +21,8 @@ namespace DMX2
List<Circuit> circuits = new List<Circuit>(); List<Circuit> circuits = new List<Circuit>();
List<UniversDMX> univers = new List<UniversDMX>(); List<UniversDMX> univers = new List<UniversDMX>();
List<DriverDMX> drivers = new List<DriverDMX>();
public Conduite() public Conduite()
{ {
@ -78,6 +80,12 @@ namespace DMX2
} }
} }
public List<DriverDMX> Drivers {
get {
return drivers;
}
}
int IComparer<Circuit>.Compare (Circuit x, Circuit y) int IComparer<Circuit>.Compare (Circuit x, Circuit y)
{ {
return Conduite.Courante.circuits.IndexOf(x) - return Conduite.Courante.circuits.IndexOf(x) -
@ -151,6 +159,8 @@ namespace DMX2
disposed=true; disposed=true;
if(timer!=null) if(timer!=null)
timer.Dispose(); timer.Dispose();
foreach(var driver in Drivers)
driver.Dispose();
timer=null; timer=null;
} }

View file

@ -104,6 +104,8 @@
<Compile Include="gtk-gui\DMX2.SelSeqCircuits.cs" /> <Compile Include="gtk-gui\DMX2.SelSeqCircuits.cs" />
<Compile Include="EditionUnivers.cs" /> <Compile Include="EditionUnivers.cs" />
<Compile Include="gtk-gui\DMX2.EditionUnivers.cs" /> <Compile Include="gtk-gui\DMX2.EditionUnivers.cs" />
<Compile Include="DriverDMX.cs" />
<Compile Include="DriverBoitierV1.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project> </Project>

139
DMX-2.0/DriverBoitierV1.cs Normal file
View file

@ -0,0 +1,139 @@
using System;
using System.Threading;
using System.IO.Ports;
namespace DMX2
{
public class DriverBoitierV1 : DriverDMX
{
// tampons Entrée/Sortie
byte[] inputbuffer = new byte[1];
byte[] outputbuffer = new byte[260];
//Thread de boucle
Thread loopthread=null;
volatile bool running=true;
UniversDMX patch=null;
string portname = "/dev/ttyUSB0";
SerialPort serial = null;
public DriverBoitierV1 ()
{
patch = Conduite.Courante.Patches[0];
Start();
outputbuffer[0]=27;
outputbuffer[1]=68;
outputbuffer[4]=255;
}
void Start ()
{
OpenPort();
if (loopthread == null) {
loopthread = new Thread(new ThreadStart(MainLoop));
loopthread.Start();
}
}
void OpenPort ()
{
if (serial != null) {
serial.Close();
}
serial = new SerialPort(portname, 460800,Parity.None,8,StopBits.One);
serial.DtrEnable = false;
serial.ReadTimeout = 15;
serial.WriteTimeout = 200;
serial.Open();
}
bool CheckPortStatus ()
{
if(serial.IsOpen) return true;
OpenPort();
return false;
}
void MainLoop ()
{
DateTime prochainEnvoi= DateTime.Now;
TimeSpan sleeptime;
while (running) {
lock(Conduite.Courante)
{
patch.CalculUnivers(outputbuffer,5,255);
}
if(!CheckPortStatus())
{
Thread.Sleep(1000);
continue;
}
sleeptime = prochainEnvoi - DateTime.Now;
if(sleeptime.TotalMilliseconds>1)
Thread.Sleep(sleeptime);
prochainEnvoi = DateTime.Now.AddMilliseconds(22);
Envoi();
Reception();
}
}
void Envoi ()
{
try {
if(!serial.IsOpen) return;
serial.Write(outputbuffer,0,outputbuffer.Length);
} catch (TimeoutException ex) {
serial.Close();
}
}
void Reception ()
{
try {
if(!serial.IsOpen) return;
serial.Read(inputbuffer,0,inputbuffer.Length);
Console.WriteLine(inputbuffer[0]);
} catch (TimeoutException ex) {
serial.Close();
}
}
#region implemented abstract members of DMX2.DriverDMX
public override Gtk.Window GetDialog ()
{
return null;
}
#endregion
public override void Dispose ()
{
disposed = true;
running = false;
loopthread.Join();
loopthread=null;
//TODO : Close Port
if(serial != null)
serial.Close();
}
}
}

33
DMX-2.0/DriverDMX.cs Normal file
View file

@ -0,0 +1,33 @@
using System;
using System.Threading;
namespace DMX2
{
public abstract class DriverDMX: IDisposable
{
public DriverDMX ()
{
}
public abstract Gtk.Window GetDialog();
protected bool disposed = false;
#region IDisposable implementation
public virtual void Dispose()
{
disposed = true;
}
void IDisposable.Dispose ()
{
if(!disposed)
Dispose();
}
#endregion
}
}

View file

@ -14,6 +14,9 @@ namespace DMX2
win.Show (); win.Show ();
Application.Run (); Application.Run ();
if (Conduite.Courante != null) {
Conduite.Courante.Dispose();
}
} }
} }
} }

View file

@ -188,6 +188,13 @@ namespace DMX2
seqUiVbox.Add(s.GetUI()); seqUiVbox.Add(s.GetUI());
} }
protected void OnConnectActionActivated (object sender, EventArgs e)
{
Conduite.Courante.Drivers.Add( new DriverBoitierV1());
}
} }

View file

@ -59,14 +59,14 @@ namespace DMX2
{ {
} }
public void CalculUnivers(byte[] valeurs) public void CalculUnivers(byte[] valeurs, int offset, int count)
{ {
Dimmer g; Dimmer g;
Debug.Assert(valeurs.Length == _dimmers.Length); Debug.Assert(valeurs.Length == _dimmers.Length);
for(int i = 0 ; i<512; i++) for(int i = 0 ; i<count; i++)
{ {
if(allumageForce[i]) { if(allumageForce[i]) {
valeurs[i] = 255; valeurs[i+offset] = 255;
break; break;
} }
@ -74,7 +74,10 @@ namespace DMX2
switch (g.fonctionTransfert) { switch (g.fonctionTransfert) {
case FTransfer.lineaire: case FTransfer.lineaire:
valeurs[i] = (byte)( g.circuitAssocié.ValeurCourante * g.param1 /100); if(g.circuitAssocié !=null)
valeurs[i+offset] = (byte)( g.circuitAssocié.ValeurCourante * g.param1 /100);
else
valeurs[i+offset] = 0;
break; break;
case FTransfer.log: case FTransfer.log:
break; break;

View file

@ -20,6 +20,7 @@ namespace DMX2
private global::Gtk.Action fullscreenAction1; private global::Gtk.Action fullscreenAction1;
private global::Gtk.Action showAllAction; private global::Gtk.Action showAllAction;
private global::Gtk.Action universAction; private global::Gtk.Action universAction;
private global::Gtk.Action connectAction;
private global::Gtk.VBox vbox1; private global::Gtk.VBox vbox1;
private global::Gtk.HBox hbox1; private global::Gtk.HBox hbox1;
private global::Gtk.VBox vbox2; private global::Gtk.VBox vbox2;
@ -94,6 +95,8 @@ namespace DMX2
this.universAction.Sensitive = false; this.universAction.Sensitive = false;
this.universAction.ShortLabel = global::Mono.Unix.Catalog.GetString ("Univers"); this.universAction.ShortLabel = global::Mono.Unix.Catalog.GetString ("Univers");
w1.Add (this.universAction, null); w1.Add (this.universAction, null);
this.connectAction = new global::Gtk.Action ("connectAction", null, null, "gtk-connect");
w1.Add (this.connectAction, null);
this.UIManager.InsertActionGroup (w1, 0); this.UIManager.InsertActionGroup (w1, 0);
this.AddAccelGroup (this.UIManager.AccelGroup); this.AddAccelGroup (this.UIManager.AccelGroup);
this.Name = "DMX2.MainWindow"; this.Name = "DMX2.MainWindow";
@ -341,7 +344,7 @@ namespace DMX2
this.hbox4.Name = "hbox4"; this.hbox4.Name = "hbox4";
this.hbox4.Spacing = 6; this.hbox4.Spacing = 6;
// Container child hbox4.Gtk.Box+BoxChild // Container child hbox4.Gtk.Box+BoxChild
this.UIManager.AddUiFromString ("<ui><toolbar name='toolbar7'><toolitem name='circAction' action='circAction'/><toolitem name='seqLinAction' action='seqLinAction'/><separator/><toolitem name='showAllAction' action='showAllAction'/><toolitem name='fullscreenAction1' action='fullscreenAction1'/><toolitem name='universAction' action='universAction'/></toolbar></ui>"); this.UIManager.AddUiFromString ("<ui><toolbar name='toolbar7'><toolitem name='circAction' action='circAction'/><toolitem name='seqLinAction' action='seqLinAction'/><separator/><toolitem name='showAllAction' action='showAllAction'/><toolitem name='fullscreenAction1' action='fullscreenAction1'/><toolitem name='universAction' action='universAction'/><toolitem name='connectAction' action='connectAction'/></toolbar></ui>");
this.toolbar7 = ((global::Gtk.Toolbar)(this.UIManager.GetWidget ("/toolbar7"))); this.toolbar7 = ((global::Gtk.Toolbar)(this.UIManager.GetWidget ("/toolbar7")));
this.toolbar7.Name = "toolbar7"; this.toolbar7.Name = "toolbar7";
this.toolbar7.ShowArrow = false; this.toolbar7.ShowArrow = false;
@ -389,6 +392,7 @@ namespace DMX2
this.fullscreenAction1.Activated += new global::System.EventHandler (this.OnFullscreenAction1Activated); this.fullscreenAction1.Activated += new global::System.EventHandler (this.OnFullscreenAction1Activated);
this.showAllAction.Activated += new global::System.EventHandler (this.OnShowAllActionActivated); this.showAllAction.Activated += new global::System.EventHandler (this.OnShowAllActionActivated);
this.universAction.Activated += new global::System.EventHandler (this.OnUniversActionActivated); this.universAction.Activated += new global::System.EventHandler (this.OnUniversActionActivated);
this.connectAction.Activated += new global::System.EventHandler (this.OnConnectActionActivated);
this.masterScale.ValueChanged += new global::System.EventHandler (this.OnMasterScaleValueChanged); this.masterScale.ValueChanged += new global::System.EventHandler (this.OnMasterScaleValueChanged);
} }
} }

View file

@ -159,6 +159,12 @@
<property name="StockId">gtk-execute</property> <property name="StockId">gtk-execute</property>
<signal name="Activated" handler="OnUniversActionActivated" /> <signal name="Activated" handler="OnUniversActionActivated" />
</action> </action>
<action id="connectAction">
<property name="Type">Action</property>
<property name="Label" translatable="yes" />
<property name="StockId">gtk-connect</property>
<signal name="Activated" handler="OnConnectActionActivated" />
</action>
</action-group> </action-group>
<property name="MemberName" /> <property name="MemberName" />
<property name="Title" translatable="yes">MainWindow</property> <property name="Title" translatable="yes">MainWindow</property>
@ -424,6 +430,7 @@
<node type="Toolitem" action="showAllAction" /> <node type="Toolitem" action="showAllAction" />
<node type="Toolitem" action="fullscreenAction1" /> <node type="Toolitem" action="fullscreenAction1" />
<node type="Toolitem" action="universAction" /> <node type="Toolitem" action="universAction" />
<node type="Toolitem" action="connectAction" />
</node> </node>
</widget> </widget>
<packing> <packing>