Commit 18d74deb authored by James Goppert's avatar James Goppert

K/R formatting, debugging serialport.

parent 48f4d3ba
......@@ -155,6 +155,7 @@ if(QSERIAL_BUILD_FROM_SOURCE)
${PROJECT_SOURCE_DIR}/thirdParty/qserial/include/QtSerialPort
${PROJECT_SOURCE_DIR}/thirdParty/qserial/src
)
set(QSERIAL_LIBRARIES qserial)
add_custom_command(OUTPUT QSERIAL_BUILD.stamp
COMMAND touch QSERIAL_BUILD.stamp)
endif()
......@@ -216,6 +217,7 @@ endif()
message(STATUS "\t\tQSERIAL\t\t${QSERIAL_FOUND}")
if (QSERIAL_FOUND)
list(APPEND qgroundcontrolIncludes ${QSERIAL_INCLUDE_DIRS})
list(APPEND qgroundcontrolLibs ${QSERIAL_LIBRARIES})
endif()
message(STATUS "\t\tOpenSceneGraph\t${OPENSCENEGRAPH_FOUND}")
......@@ -792,13 +794,13 @@ set (qserialHdrs
thirdParty/qserial/include/QtSerialPort/qserialport_export.h
thirdParty/qserial/include/QtSerialPort/QSerialPort
thirdParty/qserial/include/QtSerialPort/qportsettings.h
thirdParty/qserial/include/QtSerialPort/qserialport.h
thirdParty/qserial/include/QtSerialPort/qserialportnative.h
)
# qserial headers with Q_OBJECT
# r !grep -Rl Q_OBJECT thirdParty/qserial
set (qserialMocSrc
thirdParty/qserial/include/QtSerialPort/qserialport.h
thirdParty/qserial/include/QtSerialPort/qserialportnative.h
)
)
# qserial src
set (qserialSrc
thirdParty/qserial/src/common/qserialport.cpp
......@@ -812,28 +814,32 @@ set(qserialRscSrc
)
# qserial native code
if (WIN32)
list(APPEND qSerialMocSrc
thirdParty/qserial/src/win32/qwincommevtnotifier.h
thirdParty/qserial/src/win32/wincommevtbreaker.h
)
list(APPEND qSerialSrc
thirdParty/qserial/src/win32/qserialportnative_win32.cpp
thirdParty/qserial/src/win32/commdcbhelper.h
thirdParty/qserial/src/win32/commdcbhelper.cpp
thirdParty/qserial/src/win32/qserialportnative_wince.cpp
thirdParty/qserial/src/win32/wincommevtbreaker.cpp
thirdParty/qserial/src/win32/qwincommevtnotifier.cpp
)
elseif(UNIX OR APPLE)
list(APPEND qSerialSrc
#if (WIN32)
#list(APPEND qserialHdrs
#thirdParty/qserial/src/win32/commdcbhelper.h
#)
#list(APPEND qserialMocSrc
#thirdParty/qserial/src/win32/qwincommevtnotifier.h
#thirdParty/qserial/src/win32/wincommevtbreaker.h
#)
#list(APPEND qserialSrc
#thirdParty/qserial/src/win32/qserialportnative_win32.cpp
#thirdParty/qserial/src/win32/commdcbhelper.cpp
#thirdParty/qserial/src/win32/qwincommevtnotifier.cpp
##thirdParty/qserial/src/win32/qserialportnative_wince.cpp
##thirdParty/qserial/src/win32/wincommevtbreaker.cpp
#)
#elseif(UNIX OR APPLE)
list(APPEND qserialHdrs
thirdParty/qserial/src/posix/termioshelper.h
)
list(APPEND qserialSrc
thirdParty/qserial/src/posix/termioshelper.cpp
thirdParty/qserial/src/posix/qserialportnative_posix.cpp
)
else()
message(FATAL_ERROR "unknown OS")
endif()
#else()
#message(FATAL_ERROR "unknown OS")
#endif()
# qserial linking
qt4_wrap_cpp(qserialMoc ${qserialMocSrc})
......
# - Try to find QSERIAL
# Once done, this will define
#
# QSERIAL_FOUND - system has scicoslab
# QSERIAL_INCLUDE_DIRS - the scicoslab include directories
# QSERIAL_LIBRARIES - libraries to link to
include(LibFindMacros)
# Include dir
find_path(QSERIAL_INCLUDE_DIR
NAMES QSerialPort
PATHS
/usr/include/QtSerialPort
/usr/local/include/QtSerialPort
/usr/local/qserialport/include/QtSerialPort
)
# Finally the library itself
find_library(QSERIAL_LIBRARY
NAMES
QtSerialPort
PATHS
/usr/lib
/usr/local/lib
/usr/local/qserialport/lib
)
# Set the include dir variables and the libraries and let libfind_process do the rest.
# NOTE: Singular variables for this library, plural for libraries this this lib depends on.
set(QSERIAL_PROCESS_INCLUDES QSERIAL_INCLUDE_DIR)
set(QSERIAL_PROCESS_LIBS QSERIAL_LIBRARY QSERIAL_LIBRARIES)
libfind_process(QSERIAL)
#!/bin/bash
astyle --style=k/r $(find src -regex ".*\.\(cpp\|cc\|h\|hpp\)")
rm -f $(find . -regex '.*orig$')
git commit
#include "AudioOutput.h"
#ifdef Q_OS_MAC
#include <ApplicationServices/ApplicationServices.h>
#include <ApplicationServices/ApplicationServices.h>
#else
#include <flite.h>
#include <phonon/mediaobject.h>
#include <QTemporaryFile>
#include <flite.h>
#include <phonon/mediaobject.h>
#include <QTemporaryFile>
#endif
#include <QDebug>
......@@ -25,17 +25,16 @@ extern "C" {
};
#endif
AudioOutput::AudioOutput(QString voice, QObject* parent)
: QObject(parent),
voice(NULL),
voiceIndex(0)
AudioOutput::AudioOutput(QString voice, QObject* parent)
: QObject(parent),
voice(NULL),
voiceIndex(0)
{
#if !defined(Q_OS_WIN32) && !defined(Q_OS_MAC)
flite_init();
#endif
switch (voiceIndex)
{
switch (voiceIndex) {
case 0:
selectFemaleVoice();
break;
......@@ -73,20 +72,19 @@ bool AudioOutput::say(QString text, int severity)
#if defined(Q_OS_WIN32)
qDebug() << "Synthesized: " << text << ", NO OUTPUT SUPPORT ON WINDOWS!";
#elif defined(Q_OS_MAC)
// FIXME, copy string, set callback to free the copy
SpeakString((const unsigned char*)text.toAscii().data());
qDebug() << "Synthesized: " << text;
// FIXME, copy string, set callback to free the copy
SpeakString((const unsigned char*)text.toAscii().data());
qDebug() << "Synthesized: " << text;
#else
QTemporaryFile file;
file.setFileTemplate("XXXXXX.wav");
if (file.open())
{
if (file.open()) {
cst_wave* wav = flite_text_to_wave(text.toStdString().c_str(), this->voice);
// file.fileName() returns the unique file name
cst_wave_save(wav, file.fileName().toStdString().c_str(), "riff");
Phonon::MediaObject *music =
Phonon::createPlayer(Phonon::MusicCategory,
Phonon::MediaSource(file.fileName().toStdString().c_str()));
Phonon::createPlayer(Phonon::MusicCategory,
Phonon::MediaSource(file.fileName().toStdString().c_str()));
music->play();
qDebug() << "Synthesized: " << text << ", tmp file:" << file.fileName().toStdString().c_str();
}
......@@ -155,9 +153,9 @@ extern "C" {
l.append(s);
}
printf("\n");
*/
*/
#endif
return l;
return l;
}
#ifdef __cplusplus
}
......
......@@ -87,20 +87,16 @@ Core::Core(int &argc, char* argv[]) : QApplication(argc, argv)
// Show user an upgrade message if QGC got upgraded (see code below, after splash screen)
bool upgraded = false;
QString lastApplicationVersion("");
if (settings.contains("QGC_APPLICATION_VERSION"))
{
if (settings.contains("QGC_APPLICATION_VERSION")) {
QString qgcVersion = settings.value("QGC_APPLICATION_VERSION").toString();
if (qgcVersion != QGC_APPLICATION_VERSION)
{
if (qgcVersion != QGC_APPLICATION_VERSION) {
lastApplicationVersion = qgcVersion;
settings.clear();
// Write current application version
settings.setValue("QGC_APPLICATION_VERSION", QGC_APPLICATION_VERSION);
upgraded = true;
}
}
else
{
} else {
// If application version is not set, clear settings anyway
settings.clear();
// Write current application version
......@@ -172,8 +168,7 @@ Core::Core(int &argc, char* argv[]) : QApplication(argc, argv)
if (upgraded) mainWindow->showInfoMessage(tr("Default Settings Loaded"), tr("QGroundControl has been upgraded from version %1 to version %2. Some of your user preferences have been reset to defaults for safety reasons. Please adjust them where needed.").arg(lastApplicationVersion).arg(QGC_APPLICATION_VERSION));
// Check if link could be connected
if (!udpLink->connect())
{
if (!udpLink->connect()) {
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Critical);
msgBox.setText("Could not connect UDP port. Is an instance of " + qAppName() + "already running?");
......@@ -186,8 +181,7 @@ Core::Core(int &argc, char* argv[]) : QApplication(argc, argv)
QTimer::singleShot(5000, &msgBox, SLOT(reject()));
// Exit application
if (ret == QMessageBox::Yes)
{
if (ret == QMessageBox::Yes) {
//mainWindow->close();
QTimer::singleShot(200, mainWindow, SLOT(close()));
}
......@@ -244,8 +238,7 @@ void Core::startUASManager()
if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release")
pluginsDir.cdUp();
#elif defined(Q_OS_MAC)
if (pluginsDir.dirName() == "MacOS")
{
if (pluginsDir.dirName() == "MacOS") {
pluginsDir.cdUp();
pluginsDir.cdUp();
pluginsDir.cdUp();
......@@ -259,12 +252,10 @@ void Core::startUASManager()
QStringList pluginFileNames;
foreach (QString fileName, pluginsDir.entryList(QDir::Files))
{
foreach (QString fileName, pluginsDir.entryList(QDir::Files)) {
QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
QObject *plugin = loader.instance();
if (plugin)
{
if (plugin) {
//populateMenus(plugin);
pluginFileNames += fileName;
//printf(QString("Loaded plugin from " + fileName + "\n").toStdString().c_str());
......
......@@ -53,25 +53,25 @@ This file is part of the PIXHAWK project
**/
class Core : public QApplication
{
Q_OBJECT
Q_OBJECT
public:
Core(int &argc, char* argv[]);
~Core();
Core(int &argc, char* argv[]);
~Core();
protected:
void startLinkManager();
void startLinkManager();
/**
* @brief Start the robot managing system
*
* The robot manager keeps track of the configured robots.
**/
void startUASManager();
/**
* @brief Start the robot managing system
*
* The robot manager keeps track of the configured robots.
**/
void startUASManager();
private:
MainWindow* mainWindow;
//ViconTarsusProtocol* tarsus;
MainWindow* mainWindow;
//ViconTarsusProtocol* tarsus;
};
#endif /* _CORE_H_ */
......@@ -89,9 +89,9 @@ GAudioOutput* GAudioOutput::instance()
#define QGC_GAUDIOOUTPUT_KEY QString("QGC_AUDIOOUTPUT_")
GAudioOutput::GAudioOutput(QObject* parent) : QObject(parent),
voiceIndex(0),
emergency(false),
muted(false)
voiceIndex(0),
emergency(false),
muted(false)
{
// Load settings
QSettings settings;
......@@ -103,24 +103,20 @@ muted(false)
flite_init();
#endif
#if _MSC_VER2
ISpVoice * pVoice = NULL;
if (FAILED(::CoInitialize(NULL)))
{
qDebug("Creating COM object for audio output failed!");
}
else
{
HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice;);
if( SUCCEEDED( hr ) )
{
hr = pVoice->Speak(L"Hello world", 0, NULL);
pVoice->Release();
pVoice = NULL;
#if _MSC_VER2
ISpVoice * pVoice = NULL;
if (FAILED(::CoInitialize(NULL))) {
qDebug("Creating COM object for audio output failed!");
} else {
HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice;);
if( SUCCEEDED( hr ) ) {
hr = pVoice->Speak(L"Hello world", 0, NULL);
pVoice->Release();
pVoice = NULL;
}
}
}
#endif
// Initialize audio output
m_media = new Phonon::MediaObject(this);
......@@ -131,8 +127,7 @@ muted(false)
emergencyTimer = new QTimer();
connect(emergencyTimer, SIGNAL(timeout()), this, SLOT(beep()));
switch (voiceIndex)
{
switch (voiceIndex) {
case 0:
selectFemaleVoice();
break;
......@@ -145,14 +140,13 @@ muted(false)
GAudioOutput::~GAudioOutput()
{
#ifdef _MSC_VER2
::CoUninitialize();
::CoUninitialize();
#endif
}
void GAudioOutput::mute(bool mute)
{
if (mute != muted)
{
if (mute != muted) {
this->muted = mute;
QSettings settings;
settings.setValue(QGC_GAUDIOOUTPUT_KEY+"muted", this->muted);
......@@ -168,52 +162,47 @@ bool GAudioOutput::isMuted()
bool GAudioOutput::say(QString text, int severity)
{
if (!muted)
{
// TODO Add severity filter
Q_UNUSED(severity);
bool res = false;
if (!emergency)
{
// Speech synthesis is only supported with MSVC compiler
if (!muted) {
// TODO Add severity filter
Q_UNUSED(severity);
bool res = false;
if (!emergency) {
// Speech synthesis is only supported with MSVC compiler
#ifdef _MSC_VER2
SpeechSynthesizer synth = new SpeechSynthesizer();
synth.SelectVoice("Microsoft Anna");
synth.SpeakText(text.toStdString().c_str());
res = true;
SpeechSynthesizer synth = new SpeechSynthesizer();
synth.SelectVoice("Microsoft Anna");
synth.SpeakText(text.toStdString().c_str());
res = true;
#endif
#ifdef Q_OS_LINUX
QTemporaryFile file;
file.setFileTemplate("XXXXXX.wav");
if (file.open())
{
cst_voice* v = register_cmu_us_kal(NULL);
cst_wave* wav = flite_text_to_wave(text.toStdString().c_str(), v);
// file.fileName() returns the unique file name
cst_wave_save(wav, file.fileName().toStdString().c_str(), "riff");
m_media->setCurrentSource(Phonon::MediaSource(file.fileName().toStdString().c_str()));
m_media->play();
res = true;
}
QTemporaryFile file;
file.setFileTemplate("XXXXXX.wav");
if (file.open()) {
cst_voice* v = register_cmu_us_kal(NULL);
cst_wave* wav = flite_text_to_wave(text.toStdString().c_str(), v);
// file.fileName() returns the unique file name
cst_wave_save(wav, file.fileName().toStdString().c_str(), "riff");
m_media->setCurrentSource(Phonon::MediaSource(file.fileName().toStdString().c_str()));
m_media->play();
res = true;
}
#endif
#ifdef Q_OS_MAC
// Slashes necessary to have the right start to the sentence
// copying data prevents SpeakString from reading additional chars
text = "\\" + text;
QStdWString str = text.toStdWString();
unsigned char str2[1024] = {};
memcpy(str2, text.toAscii().data(), str.length());
SpeakString(str2);
res = true;
// Slashes necessary to have the right start to the sentence
// copying data prevents SpeakString from reading additional chars
text = "\\" + text;
QStdWString str = text.toStdWString();
unsigned char str2[1024] = {};
memcpy(str2, text.toAscii().data(), str.length());
SpeakString(str2);
res = true;
#endif
}
return res;
}
else
{
}
return res;
} else {
return false;
}
}
......@@ -223,40 +212,35 @@ bool GAudioOutput::say(QString text, int severity)
*/
bool GAudioOutput::alert(QString text)
{
if (!emergency || !muted)
{
if (!emergency || !muted) {
// Play alert sound
beep();
// Say alert message
say(text, 2);
return true;
}
else
{
} else {
return false;
}
}
void GAudioOutput::notifyPositive()
{
if (!muted)
{
// Use QFile to transform path for all OS
QFile f(QCoreApplication::applicationDirPath()+QString("/audio/double_notify.wav"));
m_media->setCurrentSource(Phonon::MediaSource(f.fileName().toStdString().c_str()));
m_media->play();
}
if (!muted) {
// Use QFile to transform path for all OS
QFile f(QCoreApplication::applicationDirPath()+QString("/audio/double_notify.wav"));
m_media->setCurrentSource(Phonon::MediaSource(f.fileName().toStdString().c_str()));
m_media->play();
}
}
void GAudioOutput::notifyNegative()
{
if (!muted)
{
// Use QFile to transform path for all OS
QFile f(QCoreApplication::applicationDirPath()+QString("/audio/flat_notify.wav"));
m_media->setCurrentSource(Phonon::MediaSource(f.fileName().toStdString().c_str()));
m_media->play();
}
if (!muted) {
// Use QFile to transform path for all OS
QFile f(QCoreApplication::applicationDirPath()+QString("/audio/flat_notify.wav"));
m_media->setCurrentSource(Phonon::MediaSource(f.fileName().toStdString().c_str()));
m_media->play();
}
}
/**
......@@ -268,8 +252,7 @@ void GAudioOutput::notifyNegative()
*/
bool GAudioOutput::startEmergency()
{
if (!emergency)
{
if (!emergency) {
emergency = true;
// Beep immediately and then start timer
if (!muted) beep();
......@@ -287,8 +270,7 @@ bool GAudioOutput::startEmergency()
*/
bool GAudioOutput::stopEmergency()
{
if (emergency)
{
if (emergency) {
emergency = false;
emergencyTimer->stop();
}
......@@ -297,8 +279,7 @@ bool GAudioOutput::stopEmergency()
void GAudioOutput::beep()
{
if (!muted)
{
if (!muted) {
// Use QFile to transform path for all OS
QFile f(QCoreApplication::applicationDirPath()+QString("/audio/alert.wav"));
qDebug() << "FILE:" << f.fileName();
......@@ -339,8 +320,7 @@ QStringList GAudioOutput::listVoices(void)
printf("Voices available: ");
for (v=flite_voice_list; v; v=val_cdr(v))
{
for (v=flite_voice_list; v; v=val_cdr(v)) {
voice = val_voice(val_car(v));
QString s;
s.sprintf("%s",voice->name);
......
......@@ -59,7 +59,7 @@ This file is part of the PIXHAWK project
extern "C" {
cst_voice *REGISTER_VOX(const char *voxdir);
void UNREGISTER_VOX(cst_voice *vox);
cst_voice* register_cmu_us_kal16(const char *voxdir);
cst_voice* register_cmu_us_kal16(const char *voxdir);
}
#endif
......@@ -124,7 +124,7 @@ protected:
bool muted;
private:
GAudioOutput(QObject* parent=NULL);
~GAudioOutput();
~GAudioOutput();
};
#endif // AUDIOOUTPUT_H