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

View File

@ -159,6 +159,7 @@ void Server::mix()
{
int size = 0;
int counter = 0;
int pixel = 0;
while(1)
{
@ -178,8 +179,10 @@ void Server::mix()
{
for(int a = 0; a < CHANNELS; a++)
{
// do something interesting here
frame.windows[i][j][a] = 0;
if( a == CHANNELS-1 )
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++)
{
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
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 j = 0; j < WIDTH; j++)
@ -206,7 +212,11 @@ void Server::mix()
for(int a = 0; a < CHANNELS-1; a++)
{
// 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++)
{
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;
} //*/
}
}
usleep( 25000 );
// temp frame has validity in the loop only so it can be safely used without locking the whole object
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()
{
initscr();
@ -272,7 +271,7 @@ void Server::console()
{
// we'll be accessing some data to provide statistics, lock the Server
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)
{
case FRAME:
@ -281,6 +280,9 @@ void Server::console()
case FRAME_VALUES:
console_printframe_values(frame);
break;
case CLIENTS:
console_printclients();
break;
default:
console_printframe(frame);
}
@ -312,6 +314,11 @@ void Server::input()
mode = FRAME_VALUES;
clear();
break;
case KEY_F(4):
mode = CLIENTS;
clear();
break;
case '0':
default:
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 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)
{
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()
{
}

View File

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

View File

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

View File

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