aboutsummaryrefslogtreecommitdiff
path: root/src/haptic.cpp
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-07-30 16:01:03 -0500
committerCharles Kerr <charles.kerr@canonical.com>2014-07-30 16:01:03 -0500
commit559d185dd7d51e56fbd8246970ef520d3edd18ae (patch)
treed9a4dca12256877c7a74a7361b84826e4dbd9871 /src/haptic.cpp
parentd6b290fda978379fb07285aaddfeb31686735667 (diff)
downloadayatana-indicator-datetime-559d185dd7d51e56fbd8246970ef520d3edd18ae.tar.gz
ayatana-indicator-datetime-559d185dd7d51e56fbd8246970ef520d3edd18ae.tar.bz2
ayatana-indicator-datetime-559d185dd7d51e56fbd8246970ef520d3edd18ae.zip
initial draft of haptic feedback when alarms play
Diffstat (limited to 'src/haptic.cpp')
-rw-r--r--src/haptic.cpp92
1 files changed, 92 insertions, 0 deletions
diff --git a/src/haptic.cpp b/src/haptic.cpp
new file mode 100644
index 0000000..c5a20df
--- /dev/null
+++ b/src/haptic.cpp
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2014 Canonical Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY, 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/>.
+ *
+ * Authors:
+ * Charles Kerr <charles.kerr@canonical.com>
+ */
+
+#include <notifications/haptic.h>
+
+#include <ubuntu/application/sensors/haptic.h>
+
+#include <glib.h>
+
+namespace unity {
+namespace indicator {
+namespace notifications {
+
+/***
+****
+***/
+
+class Haptic::Impl
+{
+public:
+
+ Impl(const Mode& mode):
+ m_mode(mode),
+ m_sensor(ua_sensors_haptic_new())
+ {
+ if (m_sensor == nullptr)
+ g_warning ("Haptic device unavailable");
+ else
+ m_tag = g_timeout_add_seconds (1, on_timeout, this);
+ }
+
+ ~Impl()
+ {
+ if (m_tag)
+ g_source_remove(m_tag);
+ }
+
+private:
+
+ static gboolean on_timeout (gpointer gself)
+ {
+ static_cast<Impl*>(gself)->vibrate_now();
+ return G_SOURCE_CONTINUE;
+ }
+
+ void vibrate_now()
+ {
+ const uint32_t msec = 1500;
+ ua_sensors_haptic_vibrate_once (m_sensor, msec);
+ }
+
+ const Mode m_mode;
+ UASensorsHaptic * m_sensor = nullptr;
+ guint m_tag = 0;
+};
+
+/***
+****
+***/
+
+Haptic::Haptic(const Mode& mode):
+ impl(new Impl (mode))
+{
+}
+
+Haptic::~Haptic()
+{
+}
+
+/***
+****
+***/
+
+} // namespace datetime
+} // namespace indicator
+} // namespace unity