Merge branch 'bartek1' of ssh://source.hacker.lu/var/repo/projects/syndilights into bartek1

master
Bartosz Kostrzewa 2010-11-17 17:24:19 +01:00
commit ce8c4e74ae
5 changed files with 68 additions and 48 deletions

View File

@ -24,7 +24,7 @@ UDPSock.bind((outgoing_if, local_port))
segments = open('segments','r') segments = open('segments','r')
alpha = chr(155) alpha = chr(255)
z_buffer = chr(1) + "\n" z_buffer = chr(1) + "\n"
@ -38,6 +38,9 @@ segchannels = 4
# Send messages # Send messages
sleeptime = 0.03 sleeptime = 0.03
t = 0 t = 0
#timer will hold the elapsed time in seconds
timer = 0
frequency = 2*pi/200 frequency = 2*pi/200
max = 0.0 max = 0.0
@ -55,6 +58,7 @@ while (1):
data += chr(254) data += chr(254)
data += "\n" data += "\n"
t+=1 t+=1
timer = t*sleeptime
#print( data ) #print( data )
#data += segments.read() #data += segments.read()
if not data: if not data:

View File

@ -159,6 +159,7 @@ void Server::mix()
{ {
int size = 0; int size = 0;
int counter = 0; int counter = 0;
int pixel = 0;
while(1) while(1)
{ {
@ -178,8 +179,10 @@ void Server::mix()
{ {
for(int a = 0; a < CHANNELS; a++) for(int a = 0; a < CHANNELS; a++)
{ {
// do something interesting here if( a == CHANNELS-1 )
frame.windows[i][j][a] = 0; frame.windows[i][j][a] = 255;
else
frame.windows[i][j][a] = 0;
} }
} }
} }
@ -190,15 +193,18 @@ void Server::mix()
{ {
for(int a = 0; a < SEGCHANNELS; a++) for(int a = 0; a < SEGCHANNELS; a++)
{ {
frame.segments[w][n][a] = 0; if(a == SEGCHANNELS-1 )
frame.segments[w][n][a] = 255;
else
frame.segments[w][n][a] = 0;
} }
} }
} // zero out frame } // zero out frame
for(int x = 0; x < size; x++) for(int x = 0; x < size; x++)
{ {
temp_frame = buffers[x]->get(); temp_frame = buffers[x]->get();
for(int i = 0; i < HEIGHT; i++) for(int i = 0; i < HEIGHT; i++)
{ {
for(int j = 0; j < WIDTH; j++) for(int j = 0; j < WIDTH; j++)
@ -206,7 +212,11 @@ void Server::mix()
for(int a = 0; a < CHANNELS-1; a++) for(int a = 0; a < CHANNELS-1; a++)
{ {
// do something interesting here // do something interesting here
frame.windows[i][j][a] = frame.windows[i][j][a] + (float)temp_frame.windows[i][j][CHANNELS-1]/254*temp_frame.windows[i][j][a]; pixel = frame.windows[i][j][a] + (float)temp_frame.windows[i][j][CHANNELS-1]/255*temp_frame.windows[i][j][a];
if( pixel >= 255 )
frame.windows[i][j][a] = 255;
else
frame.windows[i][j][a] = pixel;
} }
} }
} }
@ -217,40 +227,29 @@ void Server::mix()
{ {
for(int a = 0; a < SEGCHANNELS-1; a++) for(int a = 0; a < SEGCHANNELS-1; a++)
{ {
frame.segments[w][n][a] = frame.segments[w][n][a] + (float)temp_frame.segments[w][n][SEGCHANNELS-1]/254*temp_frame.segments[w][n][a]; pixel = frame.segments[w][n][a] + (float)temp_frame.segments[w][n][SEGCHANNELS-1]/255*temp_frame.segments[w][n][a];
if( pixel >= 255 )
frame.segments[w][n][a] = 255;
else
frame.segments[w][n][a] = pixel;
} }
} }
} }
/* if( counter % 100 == 0 && x == size-1 )
{
for(int i = 0; i < HEIGHT; i++)
{
for(int j = 0; j < WIDTH; j++)
{
cout << brtoc(frame.windows[i][j][0]);
}
//cout << endl;
}
//cout << endl;
/*for(int w = 0; w < SEGWIDTH; w++)
{
for(int n = 0; n < SEGNUM; n++)
{
cout << frame.segments[w][n][0];
}
cout << endl;
}
cout << endl << endl;
} //*/
} }
} // temp frame has validity in the loop only so it can be safely used without locking the whole object
usleep( 25000 ); temp_frame = frame;
} // release lock and send off to hardware
output(temp_frame);
} }
} }
// output to hardware using OLA
void Server::output(frame_t _frame)
{
// pretend we're doing something
usleep( 25000 );
}
void Server::console() void Server::console()
{ {
initscr(); initscr();
@ -272,7 +271,7 @@ void Server::console()
{ {
// we'll be accessing some data to provide statistics, lock the Server // we'll be accessing some data to provide statistics, lock the Server
Glib::Mutex::Lock lock(mutex_); Glib::Mutex::Lock lock(mutex_);
mvprintw(0,0,"Clients %d | F2 Frame | F3 Values | F4 Stats | F5 Clients | input: %d ", buffers.size(),console_input ); mvprintw(0,0,"Clients %d | F2 Frame | F3 Values | F4 Clients | F5 Stats | input: %d ", buffers.size(),console_input );
switch(mode) switch(mode)
{ {
case FRAME: case FRAME:
@ -281,6 +280,9 @@ void Server::console()
case FRAME_VALUES: case FRAME_VALUES:
console_printframe_values(frame); console_printframe_values(frame);
break; break;
case CLIENTS:
console_printclients();
break;
default: default:
console_printframe(frame); console_printframe(frame);
} }
@ -312,6 +314,11 @@ void Server::input()
mode = FRAME_VALUES; mode = FRAME_VALUES;
clear(); clear();
break; break;
case KEY_F(4):
mode = CLIENTS;
clear();
break;
case '0':
default: default:
console_input = c; console_input = c;
} }
@ -333,11 +340,12 @@ void Server::console_printframe(frame_t _frame)
} }
} }
//TODO print a nicer 7 segment display with colours and brightness
for(int w = 0; w < SEGWIDTH; w++) for(int w = 0; w < SEGWIDTH; w++)
{ {
for(int n = 0; n < SEGNUM; n++) for(int n = 0; n < SEGNUM; n++)
{ {
// the segments of a display are numbered from bottom to top
// in a clockwise manner (6'o clock = 0)
switch(n) switch(n)
{ {
case 0: case 0:
@ -418,6 +426,13 @@ void Server::console_printframe_values(frame_t _frame)
} }
} }
void Server::console_printclients()
{
for(int i = 0; i < buffers.size(); i++)
mvprintw(i+2,0,"(%3d) %s\n", i,buffers[i]->get_id().c_str() );
}
void Server::console_printstats() void Server::console_printstats()
{ {
} }

View File

@ -17,6 +17,12 @@
#include "Buffer.h" #include "Buffer.h"
#include "defines.h" #include "defines.h"
enum modes
{
FRAME,
FRAME_VALUES,
CLIENTS
};
using boost::asio::ip::udp; using boost::asio::ip::udp;
using namespace std; using namespace std;
@ -30,6 +36,8 @@ public:
void launch_threads(); void launch_threads();
private: private:
Glib::Mutex mutex_;
void console(); void console();
void input(); void input();
void test(); void test();
@ -40,14 +48,15 @@ private:
void console_printframe(frame_t _frame); void console_printframe(frame_t _frame);
void console_printframe_values(frame_t _frame); void console_printframe_values(frame_t _frame);
void console_printstats(); void console_printstats();
void console_printclients();
void listen(); void listen();
void mix(); void mix();
void output(frame_t);
int get_size(); int get_size();
void expire(); void expire();
Glib::Mutex mutex_;
bool consoleinit; bool consoleinit;
int console_input; int console_input;

View File

@ -26,8 +26,6 @@
// not used for simplicity // not used for simplicity
//#define SEGHEIGHT 1 //#define SEGHEIGHT 1
struct frame_t struct frame_t
{ {
unsigned char z; unsigned char z;
@ -35,10 +33,4 @@ struct frame_t
unsigned char segments[SEGWIDTH][SEGNUM][SEGCHANNELS]; unsigned char segments[SEGWIDTH][SEGNUM][SEGCHANNELS];
}; };
enum modes
{
FRAME,
FRAME_VALUES
};
#endif #endif

View File

@ -29,7 +29,7 @@ data = z_buffer + display.read()
random.seed() random.seed()
# Send messages # Send messages
sleeptime = 0.0001 sleeptime = 0.01
frequency = 1/sleeptime frequency = 1/sleeptime
i = random.randint(0,frequency-1) i = random.randint(0,frequency-1)
while (1): while (1):