improvements to console and how the frames are stored

master
Bartosz Kostrzewa 2010-11-17 12:38:53 +01:00
parent dbfb3ecc2c
commit b5af4d6a86
4 changed files with 141 additions and 46 deletions

View File

@ -26,33 +26,26 @@ segments = open('segments','r')
alpha = 1 alpha = 1
z_buffer = "1" + "\n" z_buffer = chr(1) + "\n"
width = 7 width = 7
height = 12 height = 12
# Send messages # Send messages
sleeptime = 0.04 sleeptime = 0.03
t = 0 t = 0
frequency = 2*pi/40 frequency = 2*pi/200
max = 0.0
while (1): while (1):
#zero out the data buffer #zero out the data buffer
data = z_buffer data = z_buffer
for i in range(0,width): for i in range(0,width):
for j in range(0,height): for j in range(0,height):
pixel = sin(1.5*pi*(float(i)/width)+t*frequency)*sin(1.5*pi*(float(j)/height)+t*frequency) pixel = fabs(sin(2*pi*(float(i)/width)+t*frequency)*sin(2*pi*(float(j)/height)+t*frequency))
if pixel < 0.25: data = data + chr(int(254*pixel)) + chr(alpha)
pixel = '.'
elif pixel < 0.5:
pixel = '-'
elif pixel < 0.75:
pixel = '+'
elif pixel <= 1.0:
pixel = '#'
else:
pixel = '*'
data = data + pixel + str(alpha)
data = data + "\n" data = data + "\n"
t+=1 t+=1
#print( data )
#data += segments.read() #data += segments.read()
if not data: if not data:
break break

View File

@ -6,6 +6,8 @@ Server::Server(int _port )
displaycounter = 0; displaycounter = 0;
packetcounter = 0; packetcounter = 0;
consoleinit = false; consoleinit = false;
mode = FRAME;
//test();
} }
Server::~Server() Server::~Server()
@ -50,7 +52,7 @@ void Server::listen()
while (1) while (1)
{ {
// creating the buffer each time is faster than zeroing it out // creating the buffer each time is faster than zeroing it out
boost::array<char, BUFLEN> recv_buf; boost::array<unsigned char, BUFLEN> recv_buf;
udp::endpoint remote_endpoint; udp::endpoint remote_endpoint;
boost::system::error_code error; boost::system::error_code error;
@ -95,14 +97,6 @@ void Server::listen()
continue; continue;
} }
if( packetcounter % 10000 == 0 )
{
//cout << endl << "packets received " << packetcounter << endl;
/*cout << remote_endpoint << endl;
for(int i = 0; i < BUFLEN; i++)
cout << recv_buf[i];
cout << endl;//*/
}
packetcounter++; packetcounter++;
frame.z = recv_buf[0]; frame.z = recv_buf[0];
@ -113,6 +107,7 @@ void Server::listen()
for(int a = 0; a < CHANNELS; a++) for(int a = 0; a < CHANNELS; a++)
{ {
frame.windows[i][j][a] = recv_buf[HEADEROFFSET+ i*(CHANNELS*WIDTH+1) + j*CHANNELS + a]; frame.windows[i][j][a] = recv_buf[HEADEROFFSET+ i*(CHANNELS*WIDTH+1) + j*CHANNELS + a];
//cout << int( recv_buf[HEADEROFFSET+ i*(CHANNELS*WIDTH+1) + j*CHANNELS + a] ) << endl;
} }
} }
} }
@ -227,20 +222,20 @@ void Server::mix()
} }
} }
/*if( counter % 100 == 0 && x == size-1 )
/* if( counter % 100 == 0 && x == size-1 )
{ {
cout << counter << endl;
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++)
{ {
cout << frame.windows[i][j][0]; cout << brtoc(frame.windows[i][j][0]);
} }
cout << endl; //cout << endl;
} }
cout << endl; //cout << endl;
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++)
{ {
@ -273,13 +268,17 @@ 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\t %d \t| F1 Frame | F2 Stats | F3 Clients | input: %d ", buffers.size(),console_input ); mvprintw(0,0,"Clients %d | F2 Frame | F3 Values | F4 Stats | F5 Clients | input: %d ", buffers.size(),console_input );
switch(console_input) switch(mode)
{ {
case KEY_F(1): case FRAME:
console_printframe(); console_printframe(frame);
break;
case FRAME_VALUES:
console_printframe_values(frame);
break;
default: default:
console_printframe(); console_printframe(frame);
} }
refresh(); /* Print it on to the real screen */ refresh(); /* Print it on to the real screen */
} }
@ -299,36 +298,59 @@ void Server::input()
// now we need to lock data structure because we're going to use shared objects // now we need to lock data structure because we're going to use shared objects
{ {
Glib::Mutex::Lock lock(mutex_); Glib::Mutex::Lock lock(mutex_);
switch(c)
{
case KEY_F(2):
mode = FRAME;
clear();
break;
case KEY_F(3):
mode = FRAME_VALUES;
clear();
break;
default:
console_input = c; console_input = c;
} }
}
} }
} }
/* the console functions should only be used in the console thread, they don't /* the console functions should only be used in the console thread, they don't
* implement their own locking and they need ncurses to be initialised */ * implement their own locking and they need ncurses to be initialised */
void Server::console_printframe() void Server::console_printframe(frame_t _frame)
{ {
// output the current screen contents // output the current screen contents
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++)
{ {
mvprintw(i+2,j,"%c",frame.windows[i][j][0]); mvprintw(i+2,j,"%c", brtoc(_frame.windows[i][j][0]) );
} }
} }
//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++)
{ {
for(int a = 0; a < SEGCHANNELS; a++) for(int a = 0; a < SEGCHANNELS; a++)
{ {
mvprintw(HEIGHT+3+w,(n*SEGCHANNELS)+a,"%c",frame.segments[w][n][a]); mvprintw(HEIGHT+3+w,(n*SEGCHANNELS)+a,"%c", _frame.segments[w][n][a]);
} }
} }
} }
}
void Server::console_printframe_values(frame_t _frame)
{
// output the current screen contents
for(int i = 0; i < HEIGHT; i++)
{
for(int j = 0; j < WIDTH; j++)
{
mvprintw(i*2+2,j*4," %d ", brtoi(_frame.windows[i][j][0]) );
}
}
} }
void Server::console_printstats() void Server::console_printstats()
@ -370,3 +392,68 @@ void Server::expire()
usleep( 1000000 ); usleep( 1000000 );
} }
} }
int Server::brtoi(unsigned char br)
{
return (int)br;
}
// converts a given brightness value (0-255) to a character
// relatively efficiently
char Server::brtoc(unsigned char br)
{
static char chars[11] = " ._-~:+*#@";
if(br > 124)
{
if( br > 202 )
{
if( br > 228 )
return chars[9];
else
return chars[8];
}
else
{
if( br > 176 )
return chars[7];
else
return chars[6];
}
}
else
{
if( br > 72 )
{
if( br > 124 )
return chars[5];
if( br > 98 )
return chars[4];
else
return chars[3];
}
else
{
if( br > 46 )
return chars[2];
if( br > 20 )
return chars[1];
else
return chars[0];
}
}
}
// implementation dependent behaviour of unsigned char?!
void Server::test()
{
char i = 0;
unsigned char j = 0;
while(1)
{
cout << int(i) << endl;
cout << int(j) << endl;
i--;
j = i;
usleep(20000);
}
}

View File

@ -32,7 +32,13 @@ public:
private: private:
void console(); void console();
void input(); void input();
void console_printframe(); void test();
char brtoc(unsigned char);
int brtoi(unsigned char);
void console_printframe(frame_t _frame);
void console_printframe_values(frame_t _frame);
void console_printstats(); void console_printstats();
void listen(); void listen();
@ -58,6 +64,7 @@ private:
frame_t frame; frame_t frame;
int port; int port;
char mode;
}; };
#endif #endif

View File

@ -26,11 +26,19 @@
// not used for simplicity // not used for simplicity
//#define SEGHEIGHT 1 //#define SEGHEIGHT 1
struct frame_t struct frame_t
{ {
char z; unsigned char z;
char windows[HEIGHT][WIDTH][CHANNELS]; unsigned char windows[HEIGHT][WIDTH][CHANNELS];
char segments[SEGWIDTH][SEGNUM][SEGCHANNELS]; unsigned char segments[SEGWIDTH][SEGNUM][SEGCHANNELS];
};
enum modes
{
FRAME,
FRAME_VALUES
}; };
#endif #endif