Skip to content

Commit

Permalink
blink1control: no this time it actually does sorta work with multiple…
Browse files Browse the repository at this point in the history
… blink1s, on windows & mac
  • Loading branch information
todbot committed Sep 18, 2014
1 parent 611b0fa commit 7274191
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 19 deletions.
10 changes: 10 additions & 0 deletions commandline/blink1-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ int blink1_getCacheIndexByPath( const char* path )
return -1;
}

int blink1_getCacheIndexById( uint32_t i )
{
if( i > blink1_max_devices ) { // then i is a serial number not an array index
char serialstr[serialstrmax];
sprintf( serialstr, "%X", i); // convert to wchar_t*
return blink1_getCacheIndexBySerial( serialstr );
}
return i;
}

int blink1_getCacheIndexBySerial( const char* serial )
{
for( int i=0; i< cache_max; i++ ) {
Expand Down
6 changes: 6 additions & 0 deletions commandline/blink1-lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,12 @@ const char* blink1_getCachedSerial(int i);
* @return cache index or -1 if not found
*/
int blink1_getCacheIndexByPath( const char* path );
/**
* Return cache index for a given blink1 id (0-max or serial number as uint32)
* @param i blink1 id (0-blink1_max_devices or serial as uint32)
* @return cache index or -1 if not found
*/
int blink1_getCacheIndexById( uint32_t i );
/**
* Return cache index for a given blink1 serial number.
* @param path platform-specific path string
Expand Down
15 changes: 8 additions & 7 deletions qt/blink1control/httpserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,15 @@ void HttpServer::startRead(){
status = "fadeToRGB: "+cstr+" t:"+QString::number(time);
for( int i=0; i<ids.size(); i++ ) {
QString id = ids.at(i);
if( id == mw->getBlinkKey() ) { // FIXME: ugh this is so hacky
mw->stopPattern(mw->getActivePatternName());
mw->setColorToBlinkN( c,time*1000,ledn);
}
else {
//blink1_getCacheIndexById(
//if( id == mw->getBlinkKey() ) { // FIXME: ugh this is so hacky
// mw->stopPattern(mw->getActivePatternName());
// mw->setColorToBlinkN( c,time*1000,ledn);
//}
//else {
//mw->blink1SetColorById( c, time*1000, id, ledn );
emit blink1SetColorById( c, time*1000, id, ledn );
}
emit blink1SetColorById( c, time*1000, id, ledn );
//}
}
} else {
status = "fadeToRGB: invalid color";
Expand Down
29 changes: 17 additions & 12 deletions qt/blink1control/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ MainWindow::MainWindow(QWidget *parent) :
this, SLOT(blink1SetColorById(QColor,int,QString,int)) );

blink1_enumerate();
blink1dev = blink1_open(); // do initial enumerate and open so refreshBlink1State works FIXME
//blink1dev = blink1_open(); // do initial enumerate and open so refreshBlink1State works FIXME

loadSettings();

Expand Down Expand Up @@ -212,8 +212,8 @@ void MainWindow::refreshBlink1State()
}
qDebug() << "--- refreshBlink1State: refreshing:" << refreshCounter++;

blink1_close(blink1dev); // blink1_close checks for null
blink1dev=NULL;
//blink1_close(blink1dev); // blink1_close checks for null
//blink1dev=NULL;
// close all blink1s
for( int i=0; i<blink1devcount; i++) {
blink1_close( blink1devs[i] );
Expand All @@ -227,7 +227,9 @@ void MainWindow::refreshBlink1State()
}

qDebug() << " refreshBlink1State: opening blink1Index:" << QString::number(blink1Index,16);
blink1dev = blink1_openById( blink1Index );
//blink1dev = blink1_openById( blink1Index );
int blid = blink1_getCacheIndexById( blink1Index );
blink1dev = blink1devs[ blid ];

qDebug() << " refreshBlink1State: opened";
if( blink1dev ) {
Expand Down Expand Up @@ -292,16 +294,19 @@ void MainWindow::blink1SetColorById( QColor color, int millis, QString blink1ser
//if( blink1serialstr=="" ) return;
qDebug() << "*** blink1SetColorById:"<< blink1serialstr<< "color:"<<color << " ms:"<<millis << "blink1Id:"<<blink1Id;
bool ok;
int blink1ser = blink1serialstr.toLong(&ok,16);
if( blink1ser > blink1_max_devices ) { // serial not id
blink1ser = blink1_getCacheIndexBySerial( blink1serialstr.toStdString().c_str() );
if( blink1ser == -1 ) blink1ser = 0; // in case bad serial provided
}
int blid = blink1serialstr.toLong(&ok,16);

blid = blink1_getCacheIndexById( blid );

bool ismaindev = ( blink1serialstr == blink1Id || blink1ser==0 ) ;
qDebug() << "blink1SetColorById: blink1ser:"<<blink1ser<< " ismaindev:"<<ismaindev;
bool ismaindev = ( blink1serialstr == blink1Id || blid==0 ) ;
qDebug() << "blink1SetColorById: blid:"<<blid<< " ismaindev:"<<ismaindev;

blink1_device* bdev = (!ismaindev) ? blink1devs[ blink1ser ] : blink1dev;
if( ismaindev ) {
setColorToBlinkN( color,millis, ledn);
return;
}
blink1_device* bdev = blink1devs[ blid ];
//blink1_device* bdev = (!ismaindev) ? blink1devs[ blink1ser ] : blink1dev;
//blink1_device* bdev = (!ismaindev) ? blink1_openById( blink1ser ) : blink1dev;
if( bdev ) {
qDebug() << "blink1SetColorById: fading";
Expand Down

0 comments on commit 7274191

Please sign in to comment.