Permalink
Browse files

Adding virtualBrosDevice, for info check wiki

  • Loading branch information...
1 parent 53a7c8a commit 7a1133481e600070b3b34a77c9c1ed1d5f77017d cpscotti committed Mar 6, 2011
@@ -300,4 +300,7 @@ void DevicesManager::SetupAbstractDevices()
PushN8SimpleReportsGenerator * reportGenerator = new PushN8SimpleReportsGenerator();
configuredDevices->push_back(reportGenerator);
+
+ VirtualBrosDevice * virtualBros = new VirtualBrosDevice();
+ configuredDevices->push_back(virtualBros);
}
@@ -63,6 +63,8 @@
#include "pushn8airtimedetector.h"
#include "pushn8simplereportsgenerator.h"
+#include "virtualbrosdevice.h"
+
//#include "pushn8unprogdev.h"
#include "pushn8simulationdevice.h"
@@ -0,0 +1,94 @@
+#include "virtualbrosdevice.h"
+
+VirtualBrosDevice::VirtualBrosDevice(QObject *parent) :
+ PushBurtonGenericDevice(parent)
+{
+ applause = 0;
+
+
+ QString applausePath;
+
+#ifdef Q_OS_SYMBIAN
+ //This is a tricky part but all we need here is to retrieve the path to where we deployed the sound file.
+ //read more at:
+ //http://wiki.forum.nokia.com/index.php/Get_private_path_in_Qt#Converting_path_from_Qt_format_to_Symbian_format
+ QString privatePathQt(QApplication::applicationDirPath() );
+ QString privatePathSymbian(QDir::toNativeSeparators(privatePathQt));
+
+ applausePath = privatePathSymbian + "\\applause.mp3";
+#else
+ applausePath = "/applause.mp3";
+#endif
+
+ //This loads the file and leaves it in a "ready to play" state.
+ //Note also that "createPlayer" is the simplest way to playing one sound using Phonon
+ //and it basically "takes ownership" of the sound sink and that sort of thing so if we
+ //wanted more sounds playing concurrently we would need to use the less minimalistic calls to phonon.
+ applause = Phonon::createPlayer(Phonon::MusicCategory, Phonon::MediaSource(applausePath));
+}
+
+VirtualBrosDevice::~VirtualBrosDevice()
+{
+
+ if(applause) {
+ applause->stop();
+ applause->deleteLater();
+ }
+}
+
+QString VirtualBrosDevice::get_description()
+{
+ //Just giving it a name for sake of id
+ return "VirtualBros";
+}
+
+bool VirtualBrosDevice::is_online()
+{
+ //if pointer is valid, it's good to go
+ return (applause);
+}
+
+//This function is called by PushDevicesHolder before calling "subscribesTo" to all other devices
+//obviously, if this returns false, PushDevicesHolder will skip that check.
+bool VirtualBrosDevice::subscribesToAny()
+{
+ return true;
+}
+
+
+//This is an important bit. The code here checks if the device passed as a parameter is actually a
+//PushN8AirTimeDetector. Obviously, for all other devices it'll return false.
+bool VirtualBrosDevice::subscribesTo(PushBurtonGenericDevice* deviceType)
+{
+ if(typeid(*deviceType) == typeid(PushN8AirTimeDetector)){
+ return true;
+ } else {
+ return false;
+ }
+}
+
+void VirtualBrosDevice::incoming_reading(NPushLogTick * tick)
+{
+ //Checking if input tick is a AirTimeTick
+ if(typeid(*tick) == typeid(NPushAirTimeTick)) {
+ NPushAirTimeTick * airTimeTick = (NPushAirTimeTick *)tick;
+
+ //The AirTimeTick provides all known data from the "current"
+ //jump/airtime. For example, it'll tell you if the rider just
+ //landed a jump through the bool "landed"
+ if(airTimeTick->landed) {
+ applause->seek(0);
+ applause->play();
+ }
+
+ //The airTimeTick also brings airTimeTick->msecsOnAir which
+ //tells you for how long the rider is in the air
+ //Basically, when a rider does a jump, this slot will receive
+ //lots of ticks with msecsOnAir increasing until the rider hits
+ //the ground. Then it'll receive a tick with
+ //airTimeTick->landed == true
+ //and with msecsOnAir holding the final measure of how long
+ //the air time was.
+
+ }
+}
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2011 Nokia Corporation
+ *
+ * This file is part of the Push Snowboarding Project, More info at:
+ * www.pushsnowboading.com
+ *
+ * Author: Clovis Scotti <scotti@ieee.org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef VIRTUALBROSDEVICE_H
+#define VIRTUALBROSDEVICE_H
+
+#include <Phonon/Phonon>
+#include <QString>
+#include <typeinfo> //needed by the subscribe mechanism
+
+#include <QApplication>
+
+#include "pushburtongenericdevice.h"
+
+#include "npushairtimetick.h" //data structure that will "bring" the air time data
+#include "pushn8airtimedetector.h" //device who we'll subscribe to
+
+class VirtualBrosDevice : public PushBurtonGenericDevice
+{
+ Q_OBJECT
+public:
+ explicit VirtualBrosDevice(QObject *parent = 0); //Was created automatically
+
+ //We'll need the good'ol destructor to keep things clean
+ ~VirtualBrosDevice();
+
+ //The following two functions are Pure Virtual functions on PushBurtonGenericDevice
+ //you have to implement them - there's no implementation on the baseclass
+ //(Watch the =0 at the end of their declarations there!!)
+ QString get_description();
+ bool is_online();
+
+ //Our device subscribes to other devices so we need to reimplement these 2 functions
+ //accordingly. One can argue that subscribesToAny wouldn't be necessary but it SURE
+ //prevents doing a huge amount of unnecessary checks.
+ bool subscribesToAny();//returns true..
+
+ //This function will return true when the given device is a AirTimeDetector
+ bool subscribesTo(PushBurtonGenericDevice* deviceType);
+
+
+signals:
+
+public slots:
+ //last but not least, we need to reimplement the slot that will receive all the incoming data,
+ //"judge" it and stream sounds accordingly
+ void incoming_reading(NPushLogTick *);
+
+private:
+ //pointer that will hold the sound ready to be "played"
+ Phonon::MediaObject *applause;
+
+};
+
+#endif // VIRTUALBROSDEVICE_H

0 comments on commit 7a11334

Please sign in to comment.