+
+
+ Dream Hacker is program designed to help you have better dreams. Our projects monitors our users heart rate and plays an audio file chosen by the user. Once Dream Hacker detects the user has entered sleep ie. when the beats per minute is below a certain threshold it will play the selected audio.
+
+
+
+ This setup takes data from pulse sensor and time of the day etc, to predict when the person has slept.
+ Then after a while start the audio stimulus.
+
+
+ Checkout docs »
+
+ Read the wiki »
+
+
+
+
+
+
+
+
+ Discuss with us
+ ·
+
Back
-4 hours
-Vivaldi
-Yes
-Stop Reading
-
|
+ DreamHacker
+
+ |
+
#include "../include/CppTimer.h"
|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+
#include <stdlib.h>#include <unistd.h>#include <stdio.h>#include <signal.h>#include <time.h>

Go to the source code of this file.
++Data Structures | |
| class | CppTimer |
+Macros | |
| #define | CLOCKID CLOCK_MONOTONIC |
+Enumerations | |
| enum | cppTimerType_t { PERIODIC +, ONESHOT + } |
| #define CLOCKID CLOCK_MONOTONIC | +
GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
+(C) 2020-2021, Bernd Porr mail@bernporr.me.uk
+This is inspired by the timer_create man page.
+ +Definition at line 19 of file CppTimer.h.
+ +| enum cppTimerType_t | +
Enumeration of CppTimer types
+| Enumerator | |
|---|---|
| PERIODIC | |
| ONESHOT | |
Definition at line 24 of file CppTimer.h.
+|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+

Go to the source code of this file.
++Data Structures | |
| class | CppTimerCallback |
| class | CppTimerCallback::Runnable |
|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+
#include "CppTimer.h"

Go to the source code of this file.
++Data Structures | |
| class | SensorCallback |
| class | SensorTimer |
| class | SenseWindow |
+Macros | |
| #define | BASE 100 |
| #define | SPI_CHAN 0 |
| #define BASE 100 | +
MCP3004/8 SETTINGS
+ +Definition at line 7 of file PulseSensor.h.
+ +| #define SPI_CHAN 0 | +
Definition at line 8 of file PulseSensor.h.
+ +|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+
| CCppTimer | |
| ▼CCppTimerCallback | |
| CRunnable | |
| CJSONCGIADCCallback | |
| ▼CJSONCGIHandler | |
| CGETCallback | |
| CJSONGenerator | |
| CPOSTCallback | |
| CMainWindow | |
| CQMainWindow | |
| Cqt_meta_stringdata_MainWindow_t | |
| CSenseWindow | |
| CSensorCallback | |
| CSENSORfastcgicallback | |
| CSensorTimer |
|
+ DreamHacker
+
+ |
+
#include <CppTimer.h>


+Public Member Functions | |
| CppTimer (const int signo=SIGRTMIN) | |
| virtual void | startns (long nanosecs, cppTimerType_t type=PERIODIC) |
| virtual void | startms (long millisecs, cppTimerType_t type=PERIODIC) |
| virtual void | stop () |
| virtual | ~CppTimer () |
+Protected Member Functions | |
| virtual void | timerEvent ()=0 |
+Static Private Member Functions | |
| static void | handler (int, siginfo_t *si, void *) |
+Private Attributes | |
| timer_t | timerid = 0 |
| struct sigevent | sev |
| struct sigaction | sa |
| struct itimerspec | its |
Timer class which repeatedly fires. It's wrapper around the POSIX per-process timer.
+ +Definition at line 34 of file CppTimer.h.
+| CppTimer::CppTimer | +( | +const int | +signo = SIGRTMIN | ) | ++ |
Creates an instance of the timer and connects the signal handler to the timer. The default signal which is being used is SIGRTMIN but can be changed to other signals if other processes / threads use them.
| signo | The signal used by the timer. |
GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
+(C) 2020-2021, Bernd Porr mail@bernporr.me.uk
+This is inspired by the timer_create man page.
+ +Definition at line 12 of file CppTimer.cpp.
+References CLOCKID, handler(), sa, sev, and timerid.
+
+
|
+ +virtual | +
Destructor disarms the timer, deletes it and disconnect the signal handler.
+ +Definition at line 89 of file CppTimer.cpp.
+References sev, stop(), and timerid.
+
+
|
+ +inlinestaticprivate | +
Definition at line 94 of file CppTimer.h.
+Referenced by CppTimer().
+
+
|
+ +virtual | +
Starts the timer. The timer fires first after the specified time in milliseconds and then at that interval in PERIODIC mode. In ONESHOT mode the timer fires once after the specified time in milliseconds.
| millisecs | Time in milliseconds |
| type | Either PERIODIC or ONESHOT |
Definition at line 55 of file CppTimer.cpp.
+References its, ONESHOT, PERIODIC, and timerid.
+ +Referenced by main().
+
+
|
+ +virtual | +
Starts the timer. The timer fires first after the specified time in nanoseconds and then at that interval in PERIODIC mode. In ONESHOT mode the timer fires once after the specified time in nanoseconds.
| nanosecs | Time in nanoseconds |
| type | Either PERIODIC or ONESHOT |
Definition at line 32 of file CppTimer.cpp.
+
+
|
+ +virtual | +
Stops the timer by disarming it. It can be re-started with start().
+ +Definition at line 78 of file CppTimer.cpp.
+Referenced by SensorTimer::stopNew(), and ~CppTimer().
+
+
|
+ +protectedpure virtual | +
Abstract function which needs to be implemented by the children. This is called every time the timer fires.
+ +Implemented in SensorTimer, and CppTimerCallback.
+ +
+
|
+ +private | +
Definition at line 89 of file CppTimer.h.
+ + + +
+
|
+ +private | +
Definition at line 89 of file CppTimer.h.
+ +Referenced by CppTimer().
+ +
+
|
+ +private | +
Definition at line 89 of file CppTimer.h.
+ +Referenced by CppTimer(), and ~CppTimer().
+ +
+
|
+ +private | +
Definition at line 89 of file CppTimer.h.
+ +Referenced by CppTimer(), startms(), startns(), stop(), and ~CppTimer().
+ +|
+ DreamHacker
+
+ |
+
#include <CppTimerCallback.h>


+Data Structures | |
| class | Runnable |
+Public Member Functions | |
| void | registerEventRunnable (Runnable &h) |
| void | unregisterEventRunnable () |
| void | timerEvent () |
Public Member Functions inherited from CppTimer | |
| CppTimer (const int signo=SIGRTMIN) | |
| virtual void | startns (long nanosecs, cppTimerType_t type=PERIODIC) |
| virtual void | startms (long millisecs, cppTimerType_t type=PERIODIC) |
| virtual void | stop () |
| virtual | ~CppTimer () |
+Private Attributes | |
| Runnable * | cppTimerEventRunnable = NULL |
+Additional Inherited Members |
Definition at line 8 of file CppTimerCallback.h.
+
+
|
+ +inline | +
Definition at line 16 of file CppTimerCallback.h.
+References cppTimerEventRunnable.
+ +
+
|
+ +inlinevirtual | +
Abstract function which needs to be implemented by the children. This is called every time the timer fires.
+ +Implements CppTimer.
+ +Definition at line 24 of file CppTimerCallback.h.
+References cppTimerEventRunnable, and CppTimerCallback::Runnable::run().
+
+
|
+ +inline | +
Definition at line 20 of file CppTimerCallback.h.
+ +References cppTimerEventRunnable.
+ +
+
|
+ +private | +
Definition at line 31 of file CppTimerCallback.h.
+ +Referenced by registerEventRunnable(), timerEvent(), and unregisterEventRunnable().
+ +|
+ DreamHacker
+
+ |
+
#include <CppTimerCallback.h>

+Public Member Functions | |
| virtual void | run ()=0 |
Definition at line 11 of file CppTimerCallback.h.
+
+
|
+ +pure virtual | +
Referenced by CppTimerCallback::timerEvent().
+
|
+ DreamHacker
+
+ |
+


+Public Member Functions | |
| JSONCGIADCCallback (SENSORfastcgicallback *argSENSORfastcgi) | |
| virtual std::string | getJSONString () |
Public Member Functions inherited from JSONCGIHandler::GETCallback | |
| virtual std::string | getContentType () |
+Private Attributes | |
| SENSORfastcgicallback * | sensorfastcgi |
class JSONCGIADCCallback brief FastCGI Callback handles details Callback handler which returns data to the nginx server. Here, simply the current timestamp, sleeping possibility and the beats per minute is transmitted to nginx and the php application.
+ + +
+
|
+ +inline | +
Constructor: argument is the ADC callback handler which keeps the data.
+ +Definition at line 78 of file main.cpp.
+References sensorfastcgi.
+ +
+
|
+ +inlinevirtual | +
Gets the data sends it to the webserver. The callback creates three json entries. One with the timestamp, one with the beats and one with the sleep possibility from the sensor.
+ +Implements JSONCGIHandler::GETCallback.
+ +Definition at line 88 of file main.cpp.
+References JSONCGIHandler::JSONGenerator::add(), SENSORfastcgicallback::beatsPerMinute, JSONCGIHandler::JSONGenerator::getJSON(), sensorfastcgi, SENSORfastcgicallback::sleep, and SENSORfastcgicallback::threshold.
+
+
|
+ +private | +
Pointer to the ADC event handler because it keeps the data in this case.
+ +Definition at line 71 of file main.cpp.
+ +Referenced by getJSONString(), and JSONCGIADCCallback().
+ +|
+ DreamHacker
+
+ |
+
#include <json_fastcgi_web_api.h>

+Data Structures | |
| class | GETCallback |
| class | JSONGenerator |
| class | POSTCallback |
+Public Member Functions | |
| JSONCGIHandler (GETCallback *argGetCallback, POSTCallback *argPostCallback=nullptr, const char socketpath[]="/tmp/fastcgisocket") | |
| ~JSONCGIHandler () | |
+Static Public Member Functions | |
| static std::map< std::string, std::string > | postDecoder (std::string s) |
+Static Private Member Functions | |
| static void | exec (JSONCGIHandler *fastCGIHandler) |
+Private Attributes | |
| FCGX_Request | request |
| int | sock_fd = 0 |
| int | running = 1 |
| std::thread * | mainThread = nullptr |
| GETCallback * | getCallback = nullptr |
| POSTCallback * | postCallback = nullptr |
C++ wrapper around fastCGI which sends and receives JSON in a jQuery friendly format.
+Copyright (C) 2021 Bernd Porr mail@berndporr.me.uk Apache License 2.0
+ +Definition at line 25 of file json_fastcgi_web_api.h.
+
+
|
+ +inline | +
Constructor which opens the connection and starts the main thread. Provide an instance of the callback handler which returns the payload data. argPostCallback is the callback which returns received json packets as a map. The optional socketpath variable can be set to another path for the socket which talks to the webserver.
| argGetCallback | Callback handler for sending JSON |
| argPostCallback | Callback handler for receiving JSON |
| socketpath | Path of the socket which communicates to the webserver |
Definition at line 202 of file json_fastcgi_web_api.h.
+References exec(), getCallback, mainThread, postCallback, request, and sock_fd.
+
+
|
+ +inline | +
Destructor which shuts down the connection to the webserver and it also terminates the thread which is waiting for requests.
+ +Definition at line 229 of file json_fastcgi_web_api.h.
+References mainThread, request, running, and sock_fd.
+ +
+
|
+ +inlinestaticprivate | +
Definition at line 238 of file json_fastcgi_web_api.h.
+References getCallback, JSONCGIHandler::GETCallback::getContentType(), JSONCGIHandler::GETCallback::getJSONString(), postCallback, JSONCGIHandler::POSTCallback::postString(), request, and running.
+ +Referenced by JSONCGIHandler().
+

+
|
+ +inlinestatic | +
Parses a POST string and returns a std::map with key/value pairs. It also converts back any xx style encoding back to chars using libcurl. Note this is a simple parser and it won't deal with nested JSON structures.
| s | The POST string to be decoded. |
Definition at line 154 of file json_fastcgi_web_api.h.
+
+
|
+ +private | +
Definition at line 288 of file json_fastcgi_web_api.h.
+ +Referenced by exec(), and JSONCGIHandler().
+ +
+
|
+ +private | +
Definition at line 287 of file json_fastcgi_web_api.h.
+ +Referenced by JSONCGIHandler(), and ~JSONCGIHandler().
+ +
+
|
+ +private | +
Definition at line 289 of file json_fastcgi_web_api.h.
+ +Referenced by exec(), and JSONCGIHandler().
+ +
+
|
+ +private | +
Definition at line 284 of file json_fastcgi_web_api.h.
+ +Referenced by exec(), JSONCGIHandler(), and ~JSONCGIHandler().
+ +
+
|
+ +private | +
Definition at line 286 of file json_fastcgi_web_api.h.
+ +Referenced by exec(), and ~JSONCGIHandler().
+ +
+
|
+ +private | +
Definition at line 285 of file json_fastcgi_web_api.h.
+ +Referenced by JSONCGIHandler(), and ~JSONCGIHandler().
+ +|
+ DreamHacker
+
+ |
+
#include <json_fastcgi_web_api.h>


+Public Member Functions | |
| virtual std::string | getJSONString ()=0 |
| virtual std::string | getContentType () |
GET callback handler which needs to be implemented by the main program. This needs to provide the JSON payload as a string either by using the simple JSONGenerator or by an external library.
+ +Definition at line 33 of file json_fastcgi_web_api.h.
+
+
|
+ +inlinevirtual | +
The content type of the payload. That's by default "application/json" but can be overloaded if needed.
Definition at line 47 of file json_fastcgi_web_api.h.
+ +Referenced by JSONCGIHandler::exec().
+
+
|
+ +pure virtual | +
Needs to return the payload data sent to the web browser. Use the JSONGenerator to create the JSON or use an external json generator.
Implemented in JSONCGIADCCallback.
+ +Referenced by JSONCGIHandler::exec().
+
|
+ DreamHacker
+
+ |
+
#include <json_fastcgi_web_api.h>

+Public Member Functions | |
| void | add (std::string key, std::string value) |
| void | add (std::string key, double value) |
| void | add (std::string key, float value) |
| void | add (std::string key, long value) |
| void | add (std::string key, int value) |
| std::string | getJSON () |
+Private Attributes | |
| std::string | json = "{" |
| int | firstEntry = 1 |
Simple helper function to create a key/value json pairs for the callback function.
+ +Definition at line 70 of file json_fastcgi_web_api.h.
+
+
|
+ +inline | +
Adds a JSON entry: double
| key | The JSON key |
| value | The JSON value as a double |
Definition at line 91 of file json_fastcgi_web_api.h.
+References firstEntry, and json.
+ +
+
|
+ +inline | +
Adds a JSON entry: float
| key | The JSON key |
| value | The JSON value as a float |
Definition at line 105 of file json_fastcgi_web_api.h.
+References add().
+
+
|
+ +inline | +
Adds a JSON entry: int
| key | The JSON key |
| value | The JSON value as an int |
Definition at line 128 of file json_fastcgi_web_api.h.
+ +References add().
+
+
|
+ +inline | +
Adds a JSON entry: long int
| key | The JSON key |
| value | The JSON value as a long int |
Definition at line 114 of file json_fastcgi_web_api.h.
+References firstEntry, and json.
+ +
+
|
+ +inline | +
Adds a JSON entry: string
| key | The JSON key |
| value | The JSON value as a string |
Definition at line 77 of file json_fastcgi_web_api.h.
+References firstEntry, and json.
+ +Referenced by add(), and JSONCGIADCCallback::getJSONString().
+
+
|
+ +inline | +
Gets the json string
Definition at line 136 of file json_fastcgi_web_api.h.
+References json.
+ +Referenced by JSONCGIADCCallback::getJSONString().
+
+
|
+ +private | +
Definition at line 140 of file json_fastcgi_web_api.h.
+ +Referenced by add().
+ +
+
|
+ +private | +
Definition at line 139 of file json_fastcgi_web_api.h.
+ + + +|
+ DreamHacker
+
+ |
+
#include <json_fastcgi_web_api.h>

+Public Member Functions | |
| virtual void | postString (std::string postArg)=0 |
Callback handler which needs to be implemented by the main program.
+ +Definition at line 55 of file json_fastcgi_web_api.h.
+
+
|
+ +pure virtual | +
Receives the POST data from the web browser. Use postDecoder() to decode the postArg string.
| postArg | POST data received from jQuery |
Referenced by JSONCGIHandler::exec().
+
|
+ DreamHacker
+
+ |
+
#include <mainwindow.h>


+Public Member Functions | |
| MainWindow (QWidget *parent=0) | |
| void | timerEvent (QTimerEvent *) |
| void | addRealtimeSample (double v) |
| void | callPlot () |
+Private Slots | |
| void | titleDoubleClick (QMouseEvent *event) |
| void | axisLabelDoubleClick (QCPAxis *axis, QCPAxis::SelectablePart part) |
| void | legendDoubleClick (QCPLegend *legend, QCPAbstractLegendItem *item) |
| void | selectionChanged () |
| void | mousePress () |
| void | mouseWheel () |
| void | addRandomGraph () |
| void | addRealtimeGraph () |
| void | removeSelectedGraph () |
| void | removeAllGraphs () |
| void | contextMenuRequest (QPoint pos) |
| void | moveLegend () |
| void | graphClicked (QCPAbstractPlottable *plottable, int dataIndex) |
+Private Attributes | |
| QWidget * | centralWidget |
| QVBoxLayout * | verticalLayout |
| QFrame * | frame_2 |
| QVBoxLayout * | verticalLayout_3 |
| QCustomPlot * | customPlot |
| QFrame * | frame |
| QVBoxLayout * | verticalLayout_2 |
| QLabel * | label |
| QMenuBar * | menuBar |
| QStatusBar * | statusBar |
| QSharedPointer< QCPDataContainer< QCPGraphData > > | animdata |
| const int | nRealtimePoints = 500 |
| const double | dt = 0.02 |
| double | t = 0 |
Definition at line 19 of file mainwindow.h.
+
+
|
+ +explicit | +
Definition at line 16 of file mainwindow.cpp.
+References addRealtimeGraph(), axisLabelDoubleClick(), centralWidget, contextMenuRequest(), customPlot, frame, frame_2, graphClicked(), instructionsTxt, label, legendDoubleClick(), mousePress(), mouseWheel(), selectionChanged(), statusBar, titleDoubleClick(), titleTxt, verticalLayout, verticalLayout_2, and verticalLayout_3.
+
+
|
+ +privateslot | +
Definition at line 254 of file mainwindow.cpp.
+References customPlot.
+ +Referenced by contextMenuRequest().
+
+
|
+ +privateslot | +
Definition at line 219 of file mainwindow.cpp.
+References animdata, customPlot, dt, and nRealtimePoints.
+ +Referenced by MainWindow().
+
| void MainWindow::addRealtimeSample | +( | +double | +v | ) | ++ |
Definition at line 236 of file mainwindow.cpp.
+References animdata.
+ +Referenced by timerEvent(), and SenseWindow::timerEvent().
+
+
|
+ +privateslot | +
Definition at line 123 of file mainwindow.cpp.
+References customPlot.
+ +Referenced by MainWindow().
+
| void MainWindow::callPlot | +( | +) | ++ |
Definition at line 119 of file mainwindow.cpp.
+ +References customPlot.
+ +Referenced by SenseWindow::timerEvent().
+
+
|
+ +privateslot | +
Definition at line 294 of file mainwindow.cpp.
+References addRandomGraph(), customPlot, moveLegend(), removeAllGraphs(), and removeSelectedGraph().
+ +Referenced by MainWindow().
+

+
|
+ +privateslot | +
Definition at line 330 of file mainwindow.cpp.
+References statusBar.
+ +Referenced by MainWindow().
+
+
|
+ +privateslot | +
Definition at line 137 of file mainwindow.cpp.
+References customPlot.
+ +Referenced by MainWindow().
+
+
|
+ +privateslot | +
Definition at line 195 of file mainwindow.cpp.
+References customPlot.
+ +Referenced by MainWindow().
+
+
|
+ +privateslot | +
Definition at line 207 of file mainwindow.cpp.
+References customPlot.
+ +Referenced by MainWindow().
+
+
|
+ +privateslot | +
Definition at line 317 of file mainwindow.cpp.
+References customPlot.
+ +Referenced by contextMenuRequest().
+
+
|
+ +privateslot | +
Definition at line 289 of file mainwindow.cpp.
+ +References customPlot.
+ +Referenced by contextMenuRequest().
+
+
|
+ +privateslot | +
Definition at line 281 of file mainwindow.cpp.
+References customPlot.
+ +Referenced by contextMenuRequest().
+
+
|
+ +privateslot | +
Definition at line 153 of file mainwindow.cpp.
+References customPlot.
+ +Referenced by MainWindow().
+
| void MainWindow::timerEvent | +( | +QTimerEvent * | +) | ++ |
Definition at line 245 of file mainwindow.cpp.
+References addRealtimeSample(), customPlot, dt, and t.
+
+
|
+ +privateslot | +
Definition at line 105 of file mainwindow.cpp.
+References customPlot.
+ +Referenced by MainWindow().
+
+
|
+ +private | +
Definition at line 56 of file mainwindow.h.
+ +Referenced by addRealtimeGraph(), and addRealtimeSample().
+ +
+
|
+ +private | +
Definition at line 46 of file mainwindow.h.
+ +Referenced by MainWindow().
+ +
+
|
+ +private | +
Definition at line 50 of file mainwindow.h.
+ +Referenced by addRandomGraph(), addRealtimeGraph(), axisLabelDoubleClick(), callPlot(), contextMenuRequest(), legendDoubleClick(), MainWindow(), mousePress(), mouseWheel(), moveLegend(), removeAllGraphs(), removeSelectedGraph(), selectionChanged(), timerEvent(), and titleDoubleClick().
+ +
+
|
+ +private | +
Definition at line 58 of file mainwindow.h.
+ +Referenced by addRealtimeGraph(), and timerEvent().
+ +
+
|
+ +private | +
Definition at line 51 of file mainwindow.h.
+ +Referenced by MainWindow().
+ +
+
|
+ +private | +
Definition at line 48 of file mainwindow.h.
+ +Referenced by MainWindow().
+ +
+
|
+ +private | +
Definition at line 53 of file mainwindow.h.
+ +Referenced by MainWindow().
+ +
+
|
+ +private | +
Definition at line 54 of file mainwindow.h.
+ +
+
|
+ +private | +
Definition at line 57 of file mainwindow.h.
+ +Referenced by addRealtimeGraph().
+ +
+
|
+ +private | +
Definition at line 55 of file mainwindow.h.
+ +Referenced by graphClicked(), and MainWindow().
+ +
+
|
+ +private | +
Definition at line 59 of file mainwindow.h.
+ +Referenced by timerEvent().
+ +
+
|
+ +private | +
Definition at line 47 of file mainwindow.h.
+ +Referenced by MainWindow().
+ +
+
|
+ +private | +
Definition at line 52 of file mainwindow.h.
+ +Referenced by MainWindow().
+ +
+
|
+ +private | +
Definition at line 49 of file mainwindow.h.
+ +Referenced by MainWindow().
+ +|
+ DreamHacker
+
+ |
+


|
+ DreamHacker
+
+ |
+


+Public Member Functions | |
| virtual void | hasSample (int beats, bool mayBeSleep, int bpmThreshold) |
+Data Fields | |
| int | beatsPerMinute |
| bool | sleep |
| int | threshold |
| long | t |
class SENSORfastcgicallback brief Callback class when beats data arrive details Handler which receives the data here just saves the most recent sample with timestamp. Obviously, the data would be forwarde to frontend for showing to user.
+ + +
+
|
+ +inlinevirtual | +
brief Callback with the fresh pulse data. details This function is called whenever a new pulse data is arrived. It updates the local variables, which in turn forwarded to frontend. param beats int – Beats per minute, real data from sensor mayBeSleep boolean – Sleep defining variable, true if person is asleep. return void
+ +Implements SensorCallback.
+ +Definition at line 48 of file main.cpp.
+References beatsPerMinute, sleep, t, and threshold.
+ +| int SENSORfastcgicallback::beatsPerMinute | +
Definition at line 32 of file main.cpp.
+ +Referenced by JSONCGIADCCallback::getJSONString(), and hasSample().
+ +| bool SENSORfastcgicallback::sleep | +
Definition at line 33 of file main.cpp.
+ +Referenced by JSONCGIADCCallback::getJSONString(), and hasSample().
+ +| long SENSORfastcgicallback::t | +
Definition at line 35 of file main.cpp.
+ +Referenced by hasSample().
+ +| int SENSORfastcgicallback::threshold | +
Definition at line 34 of file main.cpp.
+ +Referenced by JSONCGIADCCallback::getJSONString(), and hasSample().
+ +|
+ DreamHacker
+
+ |
+
#include <PulseSensor.h>


+Public Member Functions | |
| SenseWindow () | |
| void | timerEvent (QTimerEvent *) |
Public Member Functions inherited from MainWindow | |
| MainWindow (QWidget *parent=0) | |
| void | timerEvent (QTimerEvent *) |
| void | addRealtimeSample (double v) |
| void | callPlot () |
+Private Attributes | |
| int | Signal |
Definition at line 531 of file PulseSensor.h.
+
+
|
+ +inline | +
Definition at line 535 of file PulseSensor.h.
+ +
+
|
+ +inline | +
Definition at line 537 of file PulseSensor.h.
+References MainWindow::addRealtimeSample(), BASE, MainWindow::callPlot(), and Signal.
+
+
|
+ +private | +
Definition at line 533 of file PulseSensor.h.
+ +Referenced by timerEvent().
+ +|
+ DreamHacker
+
+ |
+
#include <PulseSensor.h>


+Public Member Functions | |
| virtual void | hasSample (int beats, bool mayBeSleep, int bpmThreshold)=0 |
class SensorCallback brief Callback class for sensor data details Callback for new samples which needs to be implemented by the main program. The function hasSample needs to be overloaded in the main program.
+ +Definition at line 18 of file PulseSensor.h.
+
+
|
+ +pure virtual | +
Called after a sample has arrived.
+ +Implemented in SENSORfastcgicallback.
+ +Referenced by SensorTimer::timerEvent().
+
|
+ DreamHacker
+
+ |
+
#include <PulseSensor.h>


+Public Member Functions | |
| SensorTimer (int, bool, bool) | |
| void | setCallback (SensorCallback *cb) |
| void | timerEvent () |
| void | initPulseSensorVariables (void) |
| void | getPulse (void) |
| bool | analyzeBeatsForSleep (int bpm) |
| void | initializeVariablesForSleep (void) |
| void | audioprocess () |
| pid_t | play_audio (char *audio_name) |
| void | kill_the_pid (pid_t x) |
| void | beatsPerMinuteSimulation () |
| void | setPeriodOfSimulatedWave (int) |
| void | setSurelySleptTime (int) |
| void | setNigtTimeToNow () |
| void | stopNew () |
Public Member Functions inherited from CppTimer | |
| CppTimer (const int signo=SIGRTMIN) | |
| virtual void | startns (long nanosecs, cppTimerType_t type=PERIODIC) |
| virtual void | startms (long millisecs, cppTimerType_t type=PERIODIC) |
| virtual void | stop () |
| virtual | ~CppTimer () |
+Data Fields | |
| time_t | start_of_simulation |
+Private Attributes | |
| SensorCallback * | sensorCallback = nullptr |
| unsigned int | eventCounter |
| unsigned int | thisTime |
| unsigned int | lastTime |
| unsigned int | elapsedTime |
| int | firstTime |
| int | secondTime |
| int | duration |
| int | timeOutStart |
| int | dataRequestStart |
| int | m |
| int | Signal |
| unsigned int | sampleCounter |
| int | threshSetting |
| int | lastBeatTime |
| int | thresh = 550 |
| int | P = 512 |
| int | T = 512 |
| int | firstBeat = 1 |
| int | secondBeat = 0 |
| int | QS = 0 |
| int | rate [10] |
| int | BPM = 0 |
| int | IBI = 600 |
| int | Pulse = 0 |
| int | amp = 100 |
| int | call_time_period = 2000 |
| time_t | nightTime |
| time_t | wakeTime |
| int | bpmThreshold = 77 |
| bool | maybeSleep = 0 |
| time_t | surelySleptTime = 2 |
| bool | sleep |
| time_t | startOfProspectiveSleep |
| int | countdown = 0 |
| bool | is_audio_playing = 0 |
| bool | play_audio_locally = 1 |
| pid_t | audio_pid |
| char | audio_name [500] |
| bool | is_simulation = 0 |
| bool | simulation_started = 0 |
| time_t | period_of_simulation = 60*1 |
+Additional Inherited Members |
SensorTimer is inherited from CppTimer which itself is a wrapper around timer present in time.h SensorTimer declares variables and functions to take readings from the hardware. Analyze the beats per minute to determine sleep and plays an audio in such a case.
+ +Definition at line 31 of file PulseSensor.h.
+| SensorTimer::SensorTimer | +( | +int | +l_bpmThreshold, | +
| + | + | bool | +l_simulation, | +
| + | + | bool | +l_local_audio | +
| + | ) | ++ |
Constructor function takes three arguments: bpm threshold: this sets the bpmThreshold variable is_simulation: this sets the is_simulation variable local_audio: this sets the play_audio_locally variable The function also intializes variables necessary for measurement of pulse and variables need to analyze bpm for sleep.
+ +Definition at line 226 of file PulseSensor.h.
+References audio_name, bpmThreshold, initializeVariablesForSleep(), initPulseSensorVariables(), is_simulation, and play_audio_locally.
+
| bool SensorTimer::analyzeBeatsForSleep | +( | +int | +bpm | ) | ++ |
Function to analyze sleep based on beats per minute. if BPM is below a certain threshold mayBeSleep should be on if mayBeSleep is on for a while then return 1;
+ +Definition at line 499 of file PulseSensor.h.
+References bpmThreshold, countdown, maybeSleep, nightTime, startOfProspectiveSleep, surelySleptTime, and wakeTime.
+ +Referenced by timerEvent().
+
| void SensorTimer::audioprocess | +( | +) | ++ |
This function monitors the sleep variable and decides if an audio must be played. It also keeps track of the pids of the processes created to play the audio.
+ +Definition at line 261 of file PulseSensor.h.
+References audio_name, audio_pid, is_audio_playing, kill_the_pid(), play_audio(), play_audio_locally, and sleep.
+ +Referenced by timerEvent().
+

| void SensorTimer::beatsPerMinuteSimulation | +( | +) | ++ |
Simulates bpm values as a triangular wave.
+ +Definition at line 335 of file PulseSensor.h.
+References BPM, period_of_simulation, simulation_started, and start_of_simulation.
+ +Referenced by timerEvent().
+
| void SensorTimer::getPulse | +( | +void | +) | ++ |
This function gets the Signal from the DAC and calculates bpm and othe parameters from the Signal.
+This function is taken from the hardware vendor's github repo.
+ +Definition at line 391 of file PulseSensor.h.
+References amp, BASE, BPM, duration, elapsedTime, firstBeat, IBI, lastBeatTime, lastTime, P, Pulse, QS, rate, sampleCounter, secondBeat, Signal, T, thisTime, thresh, and threshSetting.
+ +Referenced by timerEvent().
+
| void SensorTimer::initializeVariablesForSleep | +( | +void | +) | ++ |
This function initializes the variables for sleep detection.
+ +Definition at line 479 of file PulseSensor.h.
+References is_simulation, nightTime, and wakeTime.
+ +Referenced by SensorTimer().
+
| void SensorTimer::initPulseSensorVariables | +( | +void | +) | ++ |
This function intializes variables necessary to read the data, and get the beats per minute.
+This function is taken from the hardware vendor's github repo.
+ +Definition at line 361 of file PulseSensor.h.
+References amp, BASE, BPM, call_time_period, firstBeat, IBI, lastBeatTime, lastTime, P, Pulse, QS, rate, sampleCounter, secondBeat, SPI_CHAN, T, thresh, threshSetting, and timeOutStart.
+ +Referenced by SensorTimer().
+
| void SensorTimer::kill_the_pid | +( | +pid_t | +x | ) | ++ |
Kills the pid of given to it as parameter
+ +Definition at line 304 of file PulseSensor.h.
+Referenced by audioprocess().
+
| pid_t SensorTimer::play_audio | +( | +char * | +audio_name | ) | ++ |
This function is used inside the audioprocess It takes in the audio name as argument and forks the program to run the audio returns pid of the process which runs audio to the parent process
+ +Definition at line 292 of file PulseSensor.h.
+References audio_name, and is_audio_playing.
+ +Referenced by audioprocess().
+
| void SensorTimer::setCallback | +( | +SensorCallback * | +cb | ) | ++ |
Sets the callback which is called whenever there is a sample
+ +Definition at line 314 of file PulseSensor.h.
+References sensorCallback.
+ +Referenced by main().
+
| void SensorTimer::setNigtTimeToNow | +( | +) | ++ |
sets the night time to the current time. Useful in testing.
+ +Definition at line 247 of file PulseSensor.h.
+ +References nightTime, and wakeTime.
+ +Referenced by main().
+
| void SensorTimer::setPeriodOfSimulatedWave | +( | +int | +period | ) | ++ |
sets the time period of the triangular wave of bpm simulation
+ +Definition at line 251 of file PulseSensor.h.
+ +References period_of_simulation.
+ +| void SensorTimer::setSurelySleptTime | +( | +int | +t | ) | ++ |
sets the surelySleptTime variable
+ +Definition at line 244 of file PulseSensor.h.
+ +References surelySleptTime.
+ +Referenced by main().
+
| void SensorTimer::stopNew | +( | +) | ++ |
This function is a wrapper around stop() function of the stop() function of the CppTimer This function also kills any audio pid if it is present.
+ +Definition at line 255 of file PulseSensor.h.
+References audio_pid, and CppTimer::stop().
+ +Referenced by main().
+

+
|
+ +virtual | +
This is a function in the parent class which is overidden here. Everything mentioned in the function is fired periodically after a certain interval.
+ +Implements CppTimer.
+ +Definition at line 319 of file PulseSensor.h.
+References analyzeBeatsForSleep(), audioprocess(), beatsPerMinuteSimulation(), BPM, bpmThreshold, countdown, getPulse(), SensorCallback::hasSample(), is_audio_playing, is_simulation, maybeSleep, sensorCallback, and sleep.
+
+
|
+ +private | +
Definition at line 50 of file PulseSensor.h.
+ +Referenced by getPulse(), and initPulseSensorVariables().
+ +
+
|
+ +private | +
string which stores the name of the audio file which should be played.
+ +Definition at line 121 of file PulseSensor.h.
+ +Referenced by audioprocess(), play_audio(), and SensorTimer().
+ +
+
|
+ +private | +
pid_t tracks the pid of the process which plays the audio. It needs to be tracked so that it can be killed at an appropriate moment. Also, it helps the program to avoid creating multiple pids.
+ +Definition at line 116 of file PulseSensor.h.
+ +Referenced by audioprocess(), and stopNew().
+ +
+
|
+ +private | +
Definition at line 47 of file PulseSensor.h.
+ +Referenced by beatsPerMinuteSimulation(), getPulse(), initPulseSensorVariables(), and timerEvent().
+ +
+
|
+ +private | +
int variable which stores the threshold on beats per minute
+ +Definition at line 70 of file PulseSensor.h.
+ +Referenced by analyzeBeatsForSleep(), SensorTimer(), and timerEvent().
+ +
+
|
+ +private | +
Definition at line 51 of file PulseSensor.h.
+ +Referenced by initPulseSensorVariables().
+ +
+
|
+ +private | +
Definition at line 97 of file PulseSensor.h.
+ +Referenced by analyzeBeatsForSleep(), and timerEvent().
+ +
+
|
+ +private | +
Definition at line 36 of file PulseSensor.h.
+ +
+
|
+ +private | +
Definition at line 35 of file PulseSensor.h.
+ +Referenced by getPulse().
+ +
+
|
+ +private | +
Definition at line 34 of file PulseSensor.h.
+ +Referenced by getPulse().
+ +
+
|
+ +private | +
Definition at line 34 of file PulseSensor.h.
+ +
+
|
+ +private | +
Definition at line 43 of file PulseSensor.h.
+ +Referenced by getPulse(), and initPulseSensorVariables().
+ +
+
|
+ +private | +
Definition at line 35 of file PulseSensor.h.
+ +
+
|
+ +private | +
Definition at line 48 of file PulseSensor.h.
+ +Referenced by getPulse(), and initPulseSensorVariables().
+ +
+
|
+ +private | +
bool which if 1 means the audio is playin and if zero means the audio is not playing. This is useful for functions which play audio as they must know if audio is playing or not.
+ +Definition at line 104 of file PulseSensor.h.
+ +Referenced by audioprocess(), play_audio(), and timerEvent().
+ +
+
|
+ +private | +
bool which if 1, will lead to production of simulated values of beats per minute (BPM).
+ +Definition at line 126 of file PulseSensor.h.
+ +Referenced by initializeVariablesForSleep(), SensorTimer(), and timerEvent().
+ +
+
|
+ +private | +
Definition at line 39 of file PulseSensor.h.
+ +Referenced by getPulse(), and initPulseSensorVariables().
+ +
+
|
+ +private | +
Definition at line 34 of file PulseSensor.h.
+ +Referenced by getPulse(), and initPulseSensorVariables().
+ +
+
|
+ +private | +
Definition at line 36 of file PulseSensor.h.
+ +
+
|
+ +private | +
bool variable which if is one the person is in maybesleep state. If it remains in this state for a while then the person gets into sleep state in a while maybeSleep is a superset of the sleep state. In other words, maybeSleep is a necessary condition for sleep.
+ +Definition at line 78 of file PulseSensor.h.
+ +Referenced by analyzeBeatsForSleep(), and timerEvent().
+ +
+
|
+ +private | +
time_t variable stores when the night will start on the current day
+ +Definition at line 59 of file PulseSensor.h.
+ +Referenced by analyzeBeatsForSleep(), initializeVariablesForSleep(), and setNigtTimeToNow().
+ +
+
|
+ +private | +
Definition at line 41 of file PulseSensor.h.
+ +Referenced by getPulse(), and initPulseSensorVariables().
+ +
+
|
+ +private | +
The simulation produces a triagular wave of bpm. This is the time period of the waveform
+ +Definition at line 136 of file PulseSensor.h.
+ +Referenced by beatsPerMinuteSimulation(), and setPeriodOfSimulatedWave().
+ +
+
|
+ +private | +
bool which if > 0 means that the audio will be played by the program itself and not a remote server.
+ +Definition at line 110 of file PulseSensor.h.
+ +Referenced by audioprocess(), and SensorTimer().
+ +
+
|
+ +private | +
Definition at line 49 of file PulseSensor.h.
+ +Referenced by getPulse(), and initPulseSensorVariables().
+ +
+
|
+ +private | +
Definition at line 45 of file PulseSensor.h.
+ +Referenced by getPulse(), and initPulseSensorVariables().
+ +
+
|
+ +private | +
Definition at line 46 of file PulseSensor.h.
+ +Referenced by getPulse(), and initPulseSensorVariables().
+ +
+
|
+ +private | +
Definition at line 38 of file PulseSensor.h.
+ +Referenced by getPulse(), and initPulseSensorVariables().
+ +
+
|
+ +private | +
Definition at line 44 of file PulseSensor.h.
+ +Referenced by getPulse(), and initPulseSensorVariables().
+ +
+
|
+ +private | +
Definition at line 35 of file PulseSensor.h.
+ +
+
|
+ +private | +
Definition at line 33 of file PulseSensor.h.
+ +Referenced by setCallback(), and timerEvent().
+ +
+
|
+ +private | +
Definition at line 37 of file PulseSensor.h.
+ +Referenced by getPulse().
+ +
+
|
+ +private | +
bool which is set to 1 if the simulation has started.
+ +Definition at line 131 of file PulseSensor.h.
+ +Referenced by beatsPerMinuteSimulation().
+ +
+
|
+ +private | +
This variable is set to one by [todo] to one if the person is sleep. This is read by various other functions to take appropriate actions.
+ +Definition at line 90 of file PulseSensor.h.
+ +Referenced by audioprocess(), and timerEvent().
+ +| time_t SensorTimer::start_of_simulation | +
Definition at line 201 of file PulseSensor.h.
+ +Referenced by beatsPerMinuteSimulation().
+ +
+
|
+ +private | +
time_t variable which stores the unix time of a person getting in the maybeSleep state
+ +Definition at line 95 of file PulseSensor.h.
+ +Referenced by analyzeBeatsForSleep().
+ +
+
|
+ +private | +
time_t variable which contains the time the program waits for the person to be in maybesleep state before he is put into sleep state as well.
+ +Definition at line 84 of file PulseSensor.h.
+ +Referenced by analyzeBeatsForSleep(), and setSurelySleptTime().
+ +
+
|
+ +private | +
Definition at line 42 of file PulseSensor.h.
+ +Referenced by getPulse(), and initPulseSensorVariables().
+ +
+
|
+ +private | +
Definition at line 34 of file PulseSensor.h.
+ +Referenced by getPulse().
+ +
+
|
+ +private | +
Definition at line 40 of file PulseSensor.h.
+ +Referenced by getPulse(), and initPulseSensorVariables().
+ +
+
|
+ +private | +
Definition at line 39 of file PulseSensor.h.
+ +Referenced by getPulse(), and initPulseSensorVariables().
+ +
+
|
+ +private | +
Definition at line 36 of file PulseSensor.h.
+ +Referenced by initPulseSensorVariables().
+ +
+
|
+ +private | +
time_t which is set as nightTime plus 8 hours. Not the actual wake up time of the person it can be taken as the morning time.
+ +Definition at line 65 of file PulseSensor.h.
+ +Referenced by analyzeBeatsForSleep(), initializeVariablesForSleep(), and setNigtTimeToNow().
+ +|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+
| File in drmhk_autogen | Includes file in drmhk_autogen/6YEA5652QU |
|---|---|
| mocs_compilation.cpp | moc_mainwindow.cpp |
|
+ DreamHacker
+
+ |
+
| File in drmhk_autogen/6YEA5652QU | Includes file in include |
|---|---|
| moc_mainwindow.cpp | mainwindow.h |
|
+ DreamHacker
+
+ |
+
| File in main | Includes file in include |
|---|---|
| main.cpp | CppTimer.h |
| main.cpp | json_fastcgi_web_api.h |
| main.cpp | mainwindow.h |
| main.cpp | PulseSensor.h |
|
+ DreamHacker
+
+ |
+
| File in src | Includes file in include |
|---|---|
| CppTimer.cpp | CppTimer.h |
| mainwindowdemo.cpp | mainwindow.h |
|
+ DreamHacker
+
+ |
+

+Files | |
| file | moc_mainwindow.cpp [code] |
|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+

+Files | |
| file | CppTimer.cpp [code] |
| file | mainwindowdemo.cpp [code] |
|
+ DreamHacker
+
+ |
+

+Directories | |
| directory | 6YEA5652QU |
+Files | |
| file | moc_predefs.h [code] |
| file | mocs_compilation.cpp [code] |
|
+ DreamHacker
+
+ |
+
+Files | |
| file | CppTimer.cpp [code] |
| file | CppTimer.h [code] |
| file | CppTimerCallback.h [code] |
| file | json_fastcgi_web_api.h [code] |
| file | mainwindow.cpp [code] |
| file | mainwindow.h [code] |
| file | mainwindowdemo.cpp [code] |
| file | PulseSensor.h [code] |
|
+ DreamHacker
+
+ |
+
+Files | |
| file | CppTimer.h [code] |
| file | CppTimerCallback.h [code] |
| file | json_fastcgi_web_api.h [code] |
| file | mainwindow.cpp [code] |
| file | mainwindow.h [code] |
| file | PulseSensor.h [code] |
|
+ DreamHacker
+
+ |
+
| ▼ drmhk_autogen | |
| ▼ 6YEA5652QU | |
| moc_mainwindow.cpp | |
| moc_predefs.h | |
| mocs_compilation.cpp | |
| ▼ include | |
| CppTimer.h | |
| CppTimerCallback.h | |
| json_fastcgi_web_api.h | |
| mainwindow.cpp | |
| mainwindow.h | |
| PulseSensor.h | |
| ▼ main | |
| main.cpp | |
| ▼ src | |
| CppTimer.cpp | |
| mainwindowdemo.cpp |
|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+
This page explains how to interpret the graphs that are generated by doxygen.
+Consider the following example:
This will result in the following graph:
+
The boxes in the above graph have the following meaning:
+The arrows have the following meaning:
+|
+ DreamHacker
+
+ |
+
|
+ DreamHacker
+
+ |
+
+
Dream Hacker is program designed to help you have better dreams. Our projects monitors our users heart rate and plays an audio file chosen by the user. Once Dream Hacker detects the user has entered sleep ie. when the beats per minute is below a certain threshold it will play the selected audio.
+Website interface enables user to select the music they want to play while they are sleeping. They can also see their different information using web Interface. The information will include bpm (beats per minute), the threshold and when the user has slept.
+If you have any questions about DreamHacker or want to share some information with us, please go to one of the following places:
+ +Before you file an issue, make sure you have read the known issues.
+[-] Next Software Release (v2.0) - ML of sleep detection using Python and ML algo
Hardware
Software
my_file.mp3 present in the audio/ directory then write audio/my_file.mp3. Make sure that the file has just one line../drmhk -s 1 -t 70../drmhkSee CONTRIBUTING for more information.
+Distributed under the GPL-3.0 License. See LICENSE for more information.
Team 39 in Real Time Embedded Programming
+👤 Amber Dehariya (2594660d)
+👤 Michael Hiluf (2529225h)
+👤 Praveen (2620969t)
+👤 Shreyansh Singh (2611417s)
+|
+ DreamHacker
+
+ |
+
+
+ |
+
+ |
+
+ |
+
+ |
+
+ |
+
+ |
+
+ |
+
+ |
+
+ |
|
+ DreamHacker
+
+ |
+
#include <stdint.h>#include <unistd.h>#include <stdio.h>#include <stdlib.h>#include <sys/signal.h>#include <sys/stat.h>#include <sys/socket.h>#include <iostream>#include <fcgio.h>#include <thread>#include <string>#include <map>#include <curl/curl.h>

Go to the source code of this file.
++Data Structures | |
| class | JSONCGIHandler |
| class | JSONCGIHandler::GETCallback |
| class | JSONCGIHandler::POSTCallback |
| class | JSONCGIHandler::JSONGenerator |