Browse files

can work?

  • Loading branch information...
1 parent d104cb9 commit e1dac42800be39ffae45f8cf76e998f58b9ff411 @cibomahto cibomahto committed Jun 29, 2012
Showing with 20 additions and 16 deletions.
  1. +5 −9 c++_host/LedStrip.cpp
  2. +15 −7 c++_host/host.cpp
View
14 c++_host/LedStrip.cpp
@@ -18,27 +18,20 @@ void LedStrip::Connect(std::string portname)
perror(portname.c_str());
exit(1); // TODO: Should we actually exit here?
}
-
}
void LedStrip::SendBytes64(char* data) {
int return_code;
- int count = 0;
-
+ // TODO: we should check if our file disappears.
do {
return_code = write(m_fd, data, 64);
// If a write error occurs, it is probably because the buffer is full.
// Force it to drain, then try again.
if (return_code < 0) {
tcdrain(m_fd);
- count++;
}
}
while (return_code < 0);
-
-// if (count > 0) {
-// std::cerr << "count=" << count << std::endl;
-// }
}
void LedStrip::ConvertColor24(char* output_data, char* input_data) {
@@ -66,7 +59,10 @@ void LedStrip::LoadData(char* input_data) {
// Increment input for these reasons:
// 3*m_offset - LED strip offset
// 3*m_image_width*row - current row
- ConvertColor24(output_data+row*24, input_data+3*m_offset+3*m_image_width*row); // TODO: fix this.
+ ConvertColor24(
+ output_data+row*24,
+ input_data+3*m_offset+3*m_image_width*row
+ );
}
// Write out the appropriate amount of data
View
22 c++_host/host.cpp
@@ -22,7 +22,7 @@ void * dataloader(void * arg)
pthread_mutex_unlock(&load_mutex);
strip->Flip();
- strip->LoadData(global_data);
+ strip->LoadData(global_data + 1);
}
return NULL;
@@ -33,31 +33,39 @@ int main( int argc, const char* argv[] ) {
std::vector<pthread_t*> threads;
// Connect to a LED strip
- std::vector<LedStrip> strips;
+ std::vector<LedStrip*> strips;
// Specify the screen geometry and strips on the command line, like this:
// host 160 40 /dev/ttyACM0 0 /dev/ttyACM1 8
int display_height = atoi(argv[1]);
int display_width = atoi(argv[2]);
+ std::cout << "Initializing display"
+ << ", width=" << display_width
+ << ", height=" << display_height
+ << std::endl;
+
// Init a data buffer, let's only make this once. TODO: WTF!
global_data = new char[display_width*display_height*3+1];
for(int i = 3; i < argc; i+=2) {
- strips.push_back(LedStrip(
+ std::cout << "Adding output device, port=" << argv[i]
+ << ", offset=" << atoi(argv[i+1])
+ << std::endl;
+ strips.push_back(new LedStrip(
display_width,
display_height,
atoi(argv[i+1]))
);
- strips.back().Connect(argv[i]);
+ strips.back()->Connect(argv[i]);
threads.push_back(new pthread_t);
pthread_create(
threads.back(),
NULL,
dataloader,
- (void *)&(strips.back())
+ (void *)(strips.back())
);
}
@@ -70,9 +78,9 @@ int main( int argc, const char* argv[] ) {
display_width*display_height*3+1
);
if (status == 0) {
- pthread_mutex_unlock(&load_mutex);
+// pthread_mutex_unlock(&load_mutex);
pthread_cond_broadcast(&load_signal);
- pthread_mutex_lock(&load_mutex);
+// pthread_mutex_lock(&load_mutex);
}
}
}

0 comments on commit e1dac42

Please sign in to comment.