Skip to content

Commit

Permalink
Fixed app closing, added command-line arg : config file, added LED ac…
Browse files Browse the repository at this point in the history
…tivation
  • Loading branch information
carlou33 committed Sep 8, 2016
1 parent 0e719d7 commit 5b037cd
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 61 deletions.
6 changes: 5 additions & 1 deletion doc/HOME.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ General informations

This documentation is formatted using the `reStructuredText <http://docutils.sourceforge.net/rst.html>`_ syntax, and is distributed under the Creative Commons BY-SA 4.0 license.

The `RudeConfig™ Open Source C++ Config File Library <http://rudeserver.com/config/>`_ is written and distributed under the `GNU GPL v2 <https://www.gnu.org/licenses/old-licenses/gpl-2.0.html>`_.
The `Open Sound Control (OSC) packet manipulation library <http://www.rossbencina.com/code/oscpack>`_ is written and distributed under the `MIT license <https://opensource.org/licenses/mit-license.phpl>`_, with the following addition :

"Any person wishing to distribute modifications to the Software is requested to send the modifications to `the original developer <mailto:[email protected]>`_ so that they can be incorporated into the canonical version. It is also requested that these non-binding requests be included whenever the above license is reproduced."

The `libaudiotool audio framework <https://github.com/jcelerier/libaudiotool>`_ is distributed under the `GNU GPL v3 <https://www.gnu.org/licenses/gpl-3.0.html>`_.

The application itself is distributed under the `Zlib License <https://opensource.org/licenses/Zlib>`_.
14 changes: 13 additions & 1 deletion doc/SETUP.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,21 @@ The following options are available :
``[files]`` section
~~~~~~~~~~~~~~~~~~~

``export_folder``
``folder``
Files save/load folder (string : path, ending with '/')
Default : /home/pi/songs/

``extension``
Songs files' extension (string : '*.<extension>')
Default : *.song
``[gpio]`` section
~~~~~~~~~~~~~~~~~~

``led``
LED's WiringPi identifier (to use with the ``gpio`` command)
Default : 6

``[osc]`` section
~~~~~~~~~~~~~~~~~

Expand All @@ -63,3 +70,8 @@ The following options are available :
``sender``
Server's OSC sender port (integer)
Default : 9989

Run
---

To start the server, just run ``./be-server``
16 changes: 12 additions & 4 deletions share/musique.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@
# Chercher tous les fichiers .song sur la clef USB
# Les copiers dans /home/ubuntu/songs
######
export DISPLAY=":0"
notify-send "Copying new songs... Please wait."
cp /media/song_usb/*.song /home/ubuntu/songs

#export DISPLAY=":0"
#notify-send "Copying new songs... Please wait."

gpio mode 5 out
gpio write 5 1

cp -n /media/song_usb/*.song /home/ubuntu/songs
sync
umount /media/song_usb
notify-send "Copying done, you can safely remove the USB key"

gpio write 5 0

#notify-send "Copying done, you can safely remove the USB key"
9 changes: 5 additions & 4 deletions src/SerialManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ SerialManager::SerialManager(QObject *parent):
}

void SerialManager::stop() {
finished = true;
this->isRunning = false;
}

void SerialManager::run() {
Expand Down Expand Up @@ -57,13 +57,14 @@ void SerialManager::run() {
int PinPlayTime[8] = {0,0,0,0,0,0,0,0};
int pin = 0;
int hitavg = 0;
bool run = true;

wiringPiSetupSys ();
this->isRunning = true;

//wiringPiSetupSys ();

mcp3004Setup(BASE,SPI_CHAN);

while (run){
while (this->isRunning){

for(pin=0; pin<8; pin++){

Expand Down
2 changes: 1 addition & 1 deletion src/SerialManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public slots:
virtual void run();

private:
bool finished {false}; /*< Status of the reading */
bool isRunning {false}; /*< Status of the reading */
std::shared_ptr<QSerialPort> port; /*< Port to open */
};

Expand Down
100 changes: 64 additions & 36 deletions src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
#include <QDebug>
#include <exception>

//#define CONFIG_FILE "~/.config/Boites Electriques/config.txt"
#define COMPANY_NAME "Rock & Chanson"
#define APP_NAME "Boites Electriques"
#include <wiringPi.h>

#define DEFAULT_EXTENSION "*.song" /*< Song files extension */
#define DEFAULT_FOLDER "/home/pi/songs/" /*< Files save/load folder*/
Expand All @@ -26,14 +24,39 @@
#define DEFAULT_PAN 0
#define DEFAULT_ACTIVATION false

Server::Server(int& argc, char *argv[]):
QCoreApplication(argc, argv){
#define DEFAULT_LED 6 /*< wiringPi LED's GPIO identifier */

void Server::ledSetup(){
wiringPiSetupSys();
//pinMode(LED_VALUE, OUTPUT);

QString c = QStringLiteral("gpio mode %1 out").arg(options->value("gpio/led").toInt());
std::system(c.toStdString().c_str());
}

void Server::ledOn(){
//digitalWrite(LED_VALUE, HIGH);

QString c = QStringLiteral("gpio write %1 1").arg(options->value("gpio/led").toInt());
std::system(c.toStdString().c_str());
}

void Server::ledOff(){
//digitalWrite(LED_VALUE, LOW);

QString c = QStringLiteral("gpio write %1 0").arg(options->value("gpio/led").toInt());
std::system(c.toStdString().c_str());
}

Server::Server(QSettings* opt):
options(opt){

options = new QSettings(QSettings::IniFormat, QSettings::UserScope,
COMPANY_NAME, APP_NAME);
initConf(options);
qDebug() << options->fileName();

ledSetup();
ledOn();

player = new PlayThread(options);

options->beginGroup("osc");
Expand Down Expand Up @@ -116,8 +139,9 @@ Server::Server(int& argc, char *argv[]):
}

Server::~Server() {
qDebug() << "Quitting server...";
qDebug() << "Stopping server...";
stop();

player->stop();
qDebug() << "PlayThread stopping...";
if(!player->wait(5000)) {
Expand All @@ -138,11 +162,12 @@ Server::~Server() {

qDebug() << "Deleting pointers...";
delete player;
delete options;

qDebug() << "Proper quitting OK";
ledOff();
delete options;

QCoreApplication::quit();
qDebug() << "Stopping CoreApp...";
QCoreApplication::exit(0);
}

int Server::getTempo() const {
Expand All @@ -154,32 +179,35 @@ unsigned int Server::getThreshold() const {
}

bool Server::initConf(QSettings *c) {
QFile f(c->fileName());

if(!f.exists()){
c->beginGroup("default");
c->setValue("threshold", DEFAULT_THRESHOLD);
c->setValue("master", DEFAULT_MASTER_VOLUME);
c->setValue("volume", DEFAULT_VOLUME);
c->setValue("pan", DEFAULT_PAN);
c->setValue("activation", DEFAULT_ACTIVATION);
c->endGroup();

c->beginGroup("files");
c->setValue("folder", DEFAULT_FOLDER);
c->setValue("extension", DEFAULT_EXTENSION);
c->endGroup();

c->beginGroup("osc");
c->setValue("ip", DEFAULT_IP);
c->setValue("sender", DEFAULT_SENDER);
c->setValue("receiver", DEFAULT_RECEIVER);
c->endGroup();

return false;
} else
return true;

QList<struct Settings> default_settings;

default_settings.append(Settings("default/threshold", DEFAULT_THRESHOLD));
default_settings.append(Settings("default/master", DEFAULT_MASTER_VOLUME));
default_settings.append(Settings("default/volume", DEFAULT_VOLUME));
default_settings.append(Settings("default/pan", DEFAULT_PAN));
default_settings.append(Settings("default/activation", DEFAULT_ACTIVATION));

default_settings.append(Settings("files/folder", DEFAULT_FOLDER));
default_settings.append(Settings("files/extension", DEFAULT_EXTENSION));

default_settings.append(Settings("gpio/led", DEFAULT_LED));

default_settings.append(Settings("osc/ip", DEFAULT_IP));
default_settings.append(Settings("osc/sender", DEFAULT_SENDER));
default_settings.append(Settings("osc/receiver", DEFAULT_RECEIVER));

QList<struct Settings>::const_iterator it;
for(it = default_settings.constBegin(); it < default_settings.constEnd(); it++){
if(!c->contains(it->key))
c->setValue(it->key, it->value.toString());
}

QStringList lst = c->allKeys();
for(QStringList::const_iterator k = lst.constBegin(); k<lst.constEnd(); k++)
qDebug() << *k << " : " << c->value(*k).toString();

return false;
}

void Server::sendReady(bool isReady) {
Expand Down
37 changes: 26 additions & 11 deletions src/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,22 @@ class SaveManager;
#define EXPORT_FOLDER "/home/pi/songs/" /*< Files save/load folder*/
#define FILES_EXTENSION "*.song" /*< Song files extension */

struct Settings {
QString key;
QVariant value;

Settings(QString k, QVariant v){
key = k;
value = v;
}
};

/**
* @brief Main class
*
* Handles the events and dispatch the corresponding actions
*/
class Server : public QCoreApplication {
class Server : public /*QCoreApplication*/ QObject {
Q_OBJECT
Q_PROPERTY(int tempo READ getTempo WRITE setTempo)

Expand Down Expand Up @@ -55,6 +65,19 @@ class Server : public QCoreApplication {
OscReceiver* receiver; /*< Receiving interface with OSC protocol */
OscSender* sender; /*< Sending interface with OSC protocol */

/**
* @brief Setup WiringPi interface
*/
void ledSetup();
/**
* @brief Activate the configured LED
*/
void ledOn();
/**
* @brief Deactivate the configured LED
*/
void ledOff();

/***************************
* TRANSMISSIONS TO CLIENT *
***************************/
Expand Down Expand Up @@ -221,10 +244,9 @@ class Server : public QCoreApplication {
public:
/**
* @brief Constructor of the Server class
* @param argc Number of arguments
* @param argv Arguments array
* @param opt Configuration data
*/
explicit Server(int& argc, char* argv[]);
explicit Server(QSettings* opt);
~Server();

/**
Expand Down Expand Up @@ -262,13 +284,6 @@ class Server : public QCoreApplication {
void resetThreshold();

public slots:

/**
* @brief Stop properly the application
* @param sig Exit signal
*/
// static void quit(int sig);

/**
* @brief Reset the values to default
*/
Expand Down
2 changes: 1 addition & 1 deletion src/be-server.pro
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ HEADERS += \
INCLUDEPATH += $$PWD/../../libaudiotool/src/libwatermark
DEPENDPATH += $$PWD/../../libaudiotool/src/libwatermark

LIBS+= -lgomp -lsndfile
LIBS+= -lgomp -lsndfile -lwiringpi
#LIBS+= -lportaudiocpp -lportaudio
LIBS+= -lrtaudio
LIBS+= -lasound
Expand Down
28 changes: 26 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#include <QDebug>
#include <csignal>

#define COMPANY_NAME "Rock & Chanson"
#define APP_NAME "Boites Electriques"

struct QuitStruct{
QuitStruct(){
std::signal(SIGINT, &QuitStruct::exitApp );
Expand All @@ -21,6 +24,27 @@ struct QuitStruct{

int main(int argc, char *argv[]) {
QuitStruct qs;
Server s(argc, argv);
return s.exec();
QCoreApplication app(argc, argv);

QCommandLineParser p;
p.setApplicationDescription("Boites Electriques - Server");
p.addHelpOption();
QCommandLineOption configFile(QStringList()<<"c"<<"config",
QCoreApplication::translate("config", "Set config file path to <directory>"),
QCoreApplication::translate("config", "directory"));
p.addOption(configFile);
p.process(app);

QSettings* opt;
if(p.isSet(configFile)){
qDebug() << "Cust : " << p.value(configFile);
opt = new QSettings(p.value(configFile), QSettings::IniFormat);
} else {
opt = new QSettings(QSettings::IniFormat, QSettings::UserScope,
COMPANY_NAME, APP_NAME);
}

Server s(opt);

return app.exec();
}

0 comments on commit 5b037cd

Please sign in to comment.