Skip to content

Commit 7274191

Browse files
committed
blink1control: no this time it actually does sorta work with multiple blink1s, on windows & mac
1 parent 611b0fa commit 7274191

File tree

4 files changed

+41
-19
lines changed

4 files changed

+41
-19
lines changed

commandline/blink1-lib.c

+10
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ int blink1_getCacheIndexByPath( const char* path )
9898
return -1;
9999
}
100100

101+
int blink1_getCacheIndexById( uint32_t i )
102+
{
103+
if( i > blink1_max_devices ) { // then i is a serial number not an array index
104+
char serialstr[serialstrmax];
105+
sprintf( serialstr, "%X", i); // convert to wchar_t*
106+
return blink1_getCacheIndexBySerial( serialstr );
107+
}
108+
return i;
109+
}
110+
101111
int blink1_getCacheIndexBySerial( const char* serial )
102112
{
103113
for( int i=0; i< cache_max; i++ ) {

commandline/blink1-lib.h

+6
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,12 @@ const char* blink1_getCachedSerial(int i);
360360
* @return cache index or -1 if not found
361361
*/
362362
int blink1_getCacheIndexByPath( const char* path );
363+
/**
364+
* Return cache index for a given blink1 id (0-max or serial number as uint32)
365+
* @param i blink1 id (0-blink1_max_devices or serial as uint32)
366+
* @return cache index or -1 if not found
367+
*/
368+
int blink1_getCacheIndexById( uint32_t i );
363369
/**
364370
* Return cache index for a given blink1 serial number.
365371
* @param path platform-specific path string

qt/blink1control/httpserver.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,15 @@ void HttpServer::startRead(){
144144
status = "fadeToRGB: "+cstr+" t:"+QString::number(time);
145145
for( int i=0; i<ids.size(); i++ ) {
146146
QString id = ids.at(i);
147-
if( id == mw->getBlinkKey() ) { // FIXME: ugh this is so hacky
148-
mw->stopPattern(mw->getActivePatternName());
149-
mw->setColorToBlinkN( c,time*1000,ledn);
150-
}
151-
else {
147+
//blink1_getCacheIndexById(
148+
//if( id == mw->getBlinkKey() ) { // FIXME: ugh this is so hacky
149+
// mw->stopPattern(mw->getActivePatternName());
150+
// mw->setColorToBlinkN( c,time*1000,ledn);
151+
//}
152+
//else {
152153
//mw->blink1SetColorById( c, time*1000, id, ledn );
153-
emit blink1SetColorById( c, time*1000, id, ledn );
154-
}
154+
emit blink1SetColorById( c, time*1000, id, ledn );
155+
//}
155156
}
156157
} else {
157158
status = "fadeToRGB: invalid color";

qt/blink1control/mainwindow.cpp

+17-12
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ MainWindow::MainWindow(QWidget *parent) :
7575
this, SLOT(blink1SetColorById(QColor,int,QString,int)) );
7676

7777
blink1_enumerate();
78-
blink1dev = blink1_open(); // do initial enumerate and open so refreshBlink1State works FIXME
78+
//blink1dev = blink1_open(); // do initial enumerate and open so refreshBlink1State works FIXME
7979

8080
loadSettings();
8181

@@ -212,8 +212,8 @@ void MainWindow::refreshBlink1State()
212212
}
213213
qDebug() << "--- refreshBlink1State: refreshing:" << refreshCounter++;
214214

215-
blink1_close(blink1dev); // blink1_close checks for null
216-
blink1dev=NULL;
215+
//blink1_close(blink1dev); // blink1_close checks for null
216+
//blink1dev=NULL;
217217
// close all blink1s
218218
for( int i=0; i<blink1devcount; i++) {
219219
blink1_close( blink1devs[i] );
@@ -227,7 +227,9 @@ void MainWindow::refreshBlink1State()
227227
}
228228

229229
qDebug() << " refreshBlink1State: opening blink1Index:" << QString::number(blink1Index,16);
230-
blink1dev = blink1_openById( blink1Index );
230+
//blink1dev = blink1_openById( blink1Index );
231+
int blid = blink1_getCacheIndexById( blink1Index );
232+
blink1dev = blink1devs[ blid ];
231233

232234
qDebug() << " refreshBlink1State: opened";
233235
if( blink1dev ) {
@@ -292,16 +294,19 @@ void MainWindow::blink1SetColorById( QColor color, int millis, QString blink1ser
292294
//if( blink1serialstr=="" ) return;
293295
qDebug() << "*** blink1SetColorById:"<< blink1serialstr<< "color:"<<color << " ms:"<<millis << "blink1Id:"<<blink1Id;
294296
bool ok;
295-
int blink1ser = blink1serialstr.toLong(&ok,16);
296-
if( blink1ser > blink1_max_devices ) { // serial not id
297-
blink1ser = blink1_getCacheIndexBySerial( blink1serialstr.toStdString().c_str() );
298-
if( blink1ser == -1 ) blink1ser = 0; // in case bad serial provided
299-
}
297+
int blid = blink1serialstr.toLong(&ok,16);
298+
299+
blid = blink1_getCacheIndexById( blid );
300300

301-
bool ismaindev = ( blink1serialstr == blink1Id || blink1ser==0 ) ;
302-
qDebug() << "blink1SetColorById: blink1ser:"<<blink1ser<< " ismaindev:"<<ismaindev;
301+
bool ismaindev = ( blink1serialstr == blink1Id || blid==0 ) ;
302+
qDebug() << "blink1SetColorById: blid:"<<blid<< " ismaindev:"<<ismaindev;
303303

304-
blink1_device* bdev = (!ismaindev) ? blink1devs[ blink1ser ] : blink1dev;
304+
if( ismaindev ) {
305+
setColorToBlinkN( color,millis, ledn);
306+
return;
307+
}
308+
blink1_device* bdev = blink1devs[ blid ];
309+
//blink1_device* bdev = (!ismaindev) ? blink1devs[ blink1ser ] : blink1dev;
305310
//blink1_device* bdev = (!ismaindev) ? blink1_openById( blink1ser ) : blink1dev;
306311
if( bdev ) {
307312
qDebug() << "blink1SetColorById: fading";

0 commit comments

Comments
 (0)