Skip to content

Commit 611b0fa

Browse files
committed
blink1control: multi-blink1 via API server working really well, maybe just maybe
1 parent d9eb4a7 commit 611b0fa

File tree

6 files changed

+63
-25
lines changed

6 files changed

+63
-25
lines changed

.gitignore

+11-1
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,23 @@ pip-log.txt
161161
# Mac crap
162162
.DS_Store
163163

164-
# tod stuff
164+
#### tod stuff
165+
165166
# emacs
166167
*~
168+
167169
# c build results
168170
*.o
169171
*.so
172+
170173
# java build results
171174
*.class
175+
176+
# misc
172177
*.pro
173178
*.sav
179+
*.pro.user*
180+
*.a
181+
*.def
182+
*.dll
183+
*.exp

qt/blink1control/httpserver.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ void HttpServer::startRead(){
149149
mw->setColorToBlinkN( c,time*1000,ledn);
150150
}
151151
else {
152-
mw->blink1SetColorById( c, time*1000, id, ledn );
152+
//mw->blink1SetColorById( c, time*1000, id, ledn );
153+
emit blink1SetColorById( c, time*1000, id, ledn );
153154
}
154155
}
155156
} else {

qt/blink1control/httpserver.h

+6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ public slots:
3434
void acceptConnection();
3535
void startRead();
3636
void discardClient();
37+
38+
signals:
39+
void blink1SetColorById( QColor color, int millis, QString blink1serial, int ledn );
40+
41+
42+
3743
private:
3844
MainWindow *mw;
3945
QString host;

qt/blink1control/mainwindow.cpp

+43-21
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ void qt_set_sequence_auto_mnemonic(bool);
2929
extern void qt_mac_set_dock_menu(QMenu *);
3030
#endif
3131

32+
static QMutex blink1mutex;
33+
static blink1_device* blink1devs[16];
34+
static int blink1devcount;
35+
3236
#include "patternsReadOnly.h"
3337

3438
enum {
@@ -65,8 +69,10 @@ MainWindow::MainWindow(QWidget *parent) :
6569
mode = NONE;
6670
duplicateCounter=0;
6771

68-
httpserver=new HttpServer();
72+
httpserver = new HttpServer();
6973
httpserver->setController(this);
74+
connect( httpserver, SIGNAL(blink1SetColorById(QColor,int,QString,int)),
75+
this, SLOT(blink1SetColorById(QColor,int,QString,int)) );
7076

7177
blink1_enumerate();
7278
blink1dev = blink1_open(); // do initial enumerate and open so refreshBlink1State works FIXME
@@ -205,14 +211,22 @@ void MainWindow::refreshBlink1State()
205211
blink1_disableDegamma();
206212
}
207213
qDebug() << "--- refreshBlink1State: refreshing:" << refreshCounter++;
208-
//blink1mutex.lock();
209-
214+
210215
blink1_close(blink1dev); // blink1_close checks for null
211216
blink1dev=NULL;
217+
// close all blink1s
218+
for( int i=0; i<blink1devcount; i++) {
219+
blink1_close( blink1devs[i] );
220+
}
221+
222+
blink1devcount = blink1_enumerate();
223+
// open up all blink1s
224+
for( int i=0; i<blink1devcount; i++ ) {
225+
blink1devs[i] = blink1_openById( i );
226+
qDebug() << " refreshBlink1State: opened blink1 #" << i <<":"<<blink1devs[i];
227+
}
212228

213229
qDebug() << " refreshBlink1State: opening blink1Index:" << QString::number(blink1Index,16);
214-
blink1_enumerate();
215-
//qDebug() << "refreshBlink1State: enumerated";
216230
blink1dev = blink1_openById( blink1Index );
217231

218232
qDebug() << " refreshBlink1State: opened";
@@ -229,7 +243,6 @@ void MainWindow::refreshBlink1State()
229243
blink1Id = "none";
230244
}
231245

232-
//blink1mutex.unlock();
233246
qDebug() << "--- refreshBlink1State: done refreshing";
234247

235248
blinkStatusAction->setText(blinkStatus);
@@ -277,23 +290,32 @@ void MainWindow::blink1Blink( QString blink1serialstr, QString colorstr, int mil
277290
void MainWindow::blink1SetColorById( QColor color, int millis, QString blink1serialstr, int ledn )
278291
{
279292
//if( blink1serialstr=="" ) return;
280-
qDebug() << "\n*** blink1SetColorById:"<< blink1serialstr<< "color:"<<color << " ms:"<<millis << "blink1Id:"<<blink1Id;
293+
qDebug() << "*** blink1SetColorById:"<< blink1serialstr<< "color:"<<color << " ms:"<<millis << "blink1Id:"<<blink1Id;
281294
bool ok;
282295
int blink1ser = blink1serialstr.toLong(&ok,16);
283-
bool maindev = ( blink1serialstr == blink1Id || blink1ser==0 ) ;
284-
qDebug() << "blink1SetColorById: blink1ser:"<<blink1ser<< " maindev:"<<maindev;
285-
//blink1mutex.lock();
286-
blink1_device* bdev = (!maindev) ? blink1_openById( blink1ser ) : blink1dev;
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+
}
300+
301+
bool ismaindev = ( blink1serialstr == blink1Id || blink1ser==0 ) ;
302+
qDebug() << "blink1SetColorById: blink1ser:"<<blink1ser<< " ismaindev:"<<ismaindev;
303+
304+
blink1_device* bdev = (!ismaindev) ? blink1devs[ blink1ser ] : blink1dev;
305+
//blink1_device* bdev = (!ismaindev) ? blink1_openById( blink1ser ) : blink1dev;
287306
if( bdev ) {
288307
qDebug() << "blink1SetColorById: fading";
289308
blink1_fadeToRGBN(bdev, millis, color.red(),color.green(),color.blue(), ledn);
290309
}
291-
if( !maindev ) {
292-
qDebug() << "blink1SetColorById: closing not main device";
293-
blink1_close(bdev);
310+
else {
311+
qDebug() << "blink1SetColorById: null bdev";
312+
}
313+
if( !ismaindev ) {
314+
//qDebug() << "blink1SetColorById: closing not main device";
315+
//blink1_close(bdev);
294316
}
295-
//blink1mutex.unlock();
296-
//QThread::sleep(10);
317+
318+
//QThread::msleep(10); // no
297319
qDebug() << "*** blink1SetColorById: done";
298320
}
299321

@@ -406,7 +428,7 @@ void MainWindow::updateInputs()
406428
emailsIterator->next();
407429
QString mailname=emailsIterator->key();
408430
//qDebug() << "updateInputs: "<< mailname;
409-
addToLog(mailname);
431+
addToLog("email: "+mailname);
410432
if(emails.value(mailname)->getFreqCounter()==0){
411433
emails.value(mailname)->checkMail();
412434
}
@@ -421,7 +443,7 @@ void MainWindow::updateInputs()
421443
hardwaresIterator->next();
422444
QString name=hardwaresIterator->key();
423445
//qDebug() << "updateInputs: " << name;
424-
addToLog(name);
446+
addToLog("hardware:"+name);
425447
if(hardwareMonitors.value(name)->getFreqCounter()==0){
426448
hardwareMonitors.value(name)->checkMonitor();
427449
}
@@ -470,10 +492,10 @@ void MainWindow::checkIfttt(QString txt)
470492
QString evname = ev["name"].toString();
471493
QString evsource = ev["source"].toString();
472494
qint64 evdate = evdatestr.toLongLong();
473-
qDebug() << "evname:"<<evname<<" evdate:"<< evdate << " lastIftttDate:"<<lastIftttDate;
495+
qDebug() << "evname:"<<evname<<"evdate:"<< evdate << "recent:"<<recentIftttDate << "last:"<<lastIftttDate;
474496

475497
// is this event newer since last time we checked?
476-
if( evdate > lastIftttDate ) {
498+
if( evdate > lastIftttDate && evdate != recentIftttDate ) {
477499
recentIftttDate = evdate;
478500
addRecentEvent(evdate, evname+" - "+evsource, "IFTTT");
479501
}
@@ -678,7 +700,7 @@ void MainWindow::loadSettings()
678700
QString sIftttKey = settings.value("iftttKey", "").toString();
679701
QRegExp re("^[a-f0-9]+$");
680702
qDebug() << "loadSettings: " << sIftttKey << re.exactMatch(sIftttKey.toLower());
681-
addToLog(sIftttKey);
703+
addToLog("iftttKey:"+sIftttKey);
682704

683705
if(sIftttKey=="" || sIftttKey=="none" || !re.exactMatch(sIftttKey.toLower())){
684706
sIftttKey="";

qt/blink1control/mainwindow.h

-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,6 @@ public slots:
303303
QTimer* blink1timer;
304304
blink1_device* blink1dev;
305305
//bool blink1Refreshing;
306-
//QMutex blink1mutex;
307306
int refreshCounter;
308307

309308
uint8_t mode;

qt/blink1control/qml/qml/PreferencesWindow.qml

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Window {
105105
Label { text: "serverPort:" }
106106
TextField { id: serverPortText; text: mw.serverPort }
107107

108-
Label { Layout.columnSpan:2; text: "(changes require restart)" }
108+
Label { Layout.columnSpan:2; text: "(requires restart)" }
109109
}
110110
} // api server groupbox
111111

0 commit comments

Comments
 (0)