@@ -311,6 +311,20 @@ void Logger::updateWaveValue(const QLowEnergyCharacteristic &info, const QByteAr
311
311
if (doStream) {
312
312
udpSocket->writeDatagram (line, QHostAddress::Broadcast, 45454 );
313
313
}
314
+
315
+ // Writes to DataLogger-(datetime in GMT).csv
316
+ if (isFileOpen) {
317
+ QTextStream out (file);
318
+ for (int i = 0 ; i < realValues.length (); ++i) {
319
+ if (i < realValues.length ()) {
320
+ out << QString (" %1," ).arg (QString::number (realValues.value (i)));
321
+ } else {
322
+ out << QString (" %1" ).arg (QString::number (realValues.value (i)));
323
+ }
324
+ }
325
+ out << Qt::endl;
326
+ file->flush ();
327
+ }
314
328
}
315
329
316
330
void Logger::confirmedDescriptorWrite (const QLowEnergyDescriptor &info, const QByteArray &value) {
@@ -322,10 +336,6 @@ void Logger::confirmedDescriptorWrite(const QLowEnergyDescriptor &info, const QB
322
336
}
323
337
}
324
338
325
- void Logger::on_saveToFileButton_clicked () {
326
-
327
- }
328
-
329
339
void Logger::countFrequency () {
330
340
frequencyCheckDone = true ;
331
341
qInfo () << " frequency is " << frequencyCounter;
@@ -350,3 +360,21 @@ void Logger::errorService(QLowEnergyService::ServiceError error) {
350
360
qWarning () << " Service Error: " << error;
351
361
}
352
362
363
+
364
+ void Logger::on_saveToFileButton_toggled (bool checked) {
365
+ if (checked) {
366
+ ui->saveToFileButton ->setText (" Stop Writing" );
367
+ auto fileName = QDir (
368
+ QDir::fromNativeSeparators (QStandardPaths::writableLocation (QStandardPaths::DesktopLocation)) +
369
+ QString (" /DataLogger-%1.csv" ).arg (QDateTime::currentDateTimeUtc ().toString ()));
370
+ file = new QFile (fileName.path ());
371
+ file->open (QIODevice::Append | QIODevice::Text);
372
+ } else {
373
+ ui->saveToFileButton ->setText (" Write to File" );
374
+ file->flush ();
375
+ file->close ();
376
+ }
377
+
378
+ isFileOpen = checked;
379
+ }
380
+
0 commit comments