Ok, so I've started to look over some of the code that the MIT kids produced and in an OOP world, I think some of the code is flawed. I understand why things were done like they were but I'm not sure if I'd recode them that way.
One quick issue I found right away is the mash_data function is a char array when it in actuality is an integer array. I used about 90% of their code for this function actually.
When I was about to start to write the constructor, I was reviewing how some of the code is written and was thinking it needs to be tweaked.
A dance floor contains modules.
So you have a Dance floor object and a module object. What would need to happen on a Dance floor write is each module is given it's data then sent out. What I'd do is have a thread built into each module object that reads from the buffer within that module. This will eliminate the need for the thread to be recreated everytime and since it is just a starter function for the thread, my belief (not betting money on this ) that it will be faster and provide the benefit of threading. What would be nice I guess also would be maybe a thread function within WriteToFloor that would know if all the threads have finished up. Could do a delegate or event raising event too I suppose.
so the code would be something like this. Please note I'm coding this in TextEdit on a mac on a crappy connection so syntax chances are is not correct ... along with my spelling. I lacked access to my best buddy MSDN.
ddf.WriteToFloor( );
----------------------------------------------
DanceFloor
{
Module[] moduleArray;
int[] buffer;
public void WriteToFloor()
{
// mutex lock possibly
this.SegmentBuffer( ); // module array is part of dancefloor
for( int i = 0; i < moduleArray.Length; i++)
{
moduleArray[i].OutputBuffer();
}
// some form of knowing all threads are done would be nice here.
// mutex end lock
}
public void SegmentBuffer()
{
// for loop segmenting buffer for each module.
// moduleArray[i].buffer = buffer[ x to z ]; ...
}
}
module
{
Thread thread;
int[] buffer;
SerialPort comPort;
module( string SerialPortName )
{
comPort = new SerialPort( SerialPortName ); // example, need way more for this to be properly set up
thread = new Thread( new ThreadStart( this.threadOutputBuffer ) );
}
private void threadOutputBuffer()
{
comPort.Write( buffer ); // buffer may need to be translated or something to a straight string in hex.
}
public void OutputBuffer()
{
thread.Start();
}
}