summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosef Holzmayr <holzmayr@rsi-elektrotechnik.de>2011-12-26 14:34:23 +0100
committerJuergen Beisert <jbe@pengutronix.de>2012-07-17 16:52:51 +0200
commit66440015f11d1e3a64247d07bfb34ebf6dd96429 (patch)
tree6fde026d00da0c292f10e5c010131dffa211b506
parentda07c17a6d0aa07096b3745e37ffd1a39b134bd2 (diff)
downloadOSELAS.BSP-Pengutronix-Mini6410-66440015f11d1e3a64247d07bfb34ebf6dd96429.tar.gz
OSELAS.BSP-Pengutronix-Mini6410-66440015f11d1e3a64247d07bfb34ebf6dd96429.tar.xz
QML demo: add buzzer to QML Demo
-rw-r--r--Changelog4
-rw-r--r--local_src/qml-demo-master/qml-demo.pro10
-rw-r--r--local_src/qml-demo-master/qml/Button.qml42
-rw-r--r--local_src/qml-demo-master/qml/main.qml18
-rw-r--r--local_src/qml-demo-master/src/buzzer.cpp78
-rw-r--r--local_src/qml-demo-master/src/buzzer.h46
-rw-r--r--local_src/qml-demo-master/src/main.cpp4
7 files changed, 197 insertions, 5 deletions
diff --git a/Changelog b/Changelog
index 38f2767..36cce62 100644
--- a/Changelog
+++ b/Changelog
@@ -1,3 +1,7 @@
+2011-12-26 Josef Holzmayr <holzmayr@rsi-elektrotechnik.de>
+
+ * QML demo: add buzzer to QML Demo
+
2011-11-24 Josef Holzmayr <holzmayr@rsi-elektrotechnik.de>
* QML demo: add QML demo from the Mini2440 project
diff --git a/local_src/qml-demo-master/qml-demo.pro b/local_src/qml-demo-master/qml-demo.pro
index 87b13a2..2ffb799 100644
--- a/local_src/qml-demo-master/qml-demo.pro
+++ b/local_src/qml-demo-master/qml-demo.pro
@@ -2,14 +2,16 @@ CONFIG += qt
TARGET = qml-demo
-SOURCES = src/main.cpp
+SOURCES = src/main.cpp \
+ src/buzzer.cpp
FORMS =
-HEADERS =
+HEADERS = \
+ src/buzzer.h
QT += declarative
MOC_DIR = moc
OTHER_FILES += \
- qml/main.qml
-
+ qml/main.qml \
+ qml/Button.qml
diff --git a/local_src/qml-demo-master/qml/Button.qml b/local_src/qml-demo-master/qml/Button.qml
new file mode 100644
index 0000000..5072eba
--- /dev/null
+++ b/local_src/qml-demo-master/qml/Button.qml
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2011 Josef Holzmayr, holzmayr@rsi-elektrotechnik.de
+ *
+ * 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 2
+ * 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.
+ */
+
+import QtQuick 1.0
+
+Rectangle {
+ id: btnMain
+ width: 50
+ height: 50
+
+ property alias text: btnText.text
+
+ signal clicked
+
+ Text {
+ id: btnText
+ x: 13
+ y: 18
+ text: qsTr("text")
+ verticalAlignment: Text.AlignVCenter
+ horizontalAlignment: Text.AlignHCenter
+ anchors.verticalCenter: parent.verticalCenter
+ anchors.horizontalCenter: parent.horizontalCenter
+ font.pixelSize: 12
+ }
+
+ MouseArea {
+ id: btnMAclicked
+ anchors.fill: parent
+ onClicked: btnMain.clicked()
+ }
+}
diff --git a/local_src/qml-demo-master/qml/main.qml b/local_src/qml-demo-master/qml/main.qml
index c2c7e62..f5b5bfd 100644
--- a/local_src/qml-demo-master/qml/main.qml
+++ b/local_src/qml-demo-master/qml/main.qml
@@ -12,6 +12,7 @@
*/
import QtQuick 1.0
+import Mini2440 1.0
Rectangle {
id: page
@@ -24,6 +25,20 @@ Rectangle {
property int borderoffset: 10
property int boxoffset: (boxsize - markersize) / 2
+ Buzzer {
+ id: buzzer
+ }
+
+ Button {
+ id: buzzerButton
+ text: qsTr("Beep!")
+ x: (page.width / 2) - (buzzerButton.width / 2)
+ y: page.height - (buzzerButton.height + borderoffset)
+ height: 50
+ width: 50
+ onClicked: buzzer.beep()
+ }
+
Rectangle {
id: rectTL
width: boxsize
@@ -99,7 +114,7 @@ Rectangle {
}
Text {
- id: text1
+ id: textTouchMarker
text: qsTr("Touch the black squares to move the red marker.")
anchors.right: parent.right
anchors.rightMargin: borderoffset
@@ -115,6 +130,7 @@ Rectangle {
font.underline: true
font.pixelSize: 12
}
+
states: [
State {
name: "TL"
diff --git a/local_src/qml-demo-master/src/buzzer.cpp b/local_src/qml-demo-master/src/buzzer.cpp
new file mode 100644
index 0000000..ac4074f
--- /dev/null
+++ b/local_src/qml-demo-master/src/buzzer.cpp
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2011 Josef Holzmayr <holzmayr@rsi-elektrotechnik.de>
+ *
+ * This code is derived from the 'evtest' sources:
+ * Copyright (c) 1999-2000 Vojtech Pavlik
+ * Copyright (c) 2009 Red Hat, Inc
+ * Copyright (c) 2011 Juergen Beisert <kernel@pengutronix.de>
+ *
+ * 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 2 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.
+ *
+ * Purpose:
+ * This is a small demo how to create kernel input subsystem related events
+ * and to ring the bell device. Regular way would be to echo an alert into the
+ * current TTY device. But for some embedded devices there is no TTY, because it
+ * runs only a graphical application.
+ */
+
+#include "buzzer.h"
+
+#define _XOPEN_SOURCE 500 /* for usleep() */
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <linux/version.h>
+#include <linux/input.h>
+
+#define BEEP_DEVICE "/dev/input/beeper"
+
+Buzzer::Buzzer(QObject *parent) :
+ QObject(parent)
+{
+
+}
+
+void
+Buzzer::beep()
+{
+ ssize_t s;
+ struct input_event ev;
+
+ int fd;
+
+ fd = open(BEEP_DEVICE, O_WRONLY);
+ if (fd != -1) {
+ /* ev.time = ??; TODO */
+ ev.type = EV_SND;
+ ev.code = SND_BELL;
+ ev.value = 1; /* enable (ring) the bell */
+
+ s = write(fd, &ev, sizeof(ev));
+ if (s == -1) {
+ return;
+ }
+
+ usleep(100 * 1000); /* 100 ms */
+
+ ev.value = 0; /* stop bell from ringing */
+
+ s = write(fd, &ev, sizeof(ev));
+ if (s == -1) {
+ return;
+ }
+ }
+}
diff --git a/local_src/qml-demo-master/src/buzzer.h b/local_src/qml-demo-master/src/buzzer.h
new file mode 100644
index 0000000..6931530
--- /dev/null
+++ b/local_src/qml-demo-master/src/buzzer.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2011 Josef Holzmayr <holzmayr@rsi-elektrotechnik.de>
+ *
+ * This code is derived from the 'evtest' sources:
+ * Copyright (c) 1999-2000 Vojtech Pavlik
+ * Copyright (c) 2009 Red Hat, Inc
+ * Copyright (c) 2011 Juergen Beisert <kernel@pengutronix.de>
+ *
+ * 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 2 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.
+ *
+ * Purpose:
+ * This is a small demo how to create kernel input subsystem related events
+ * and to ring the bell device. Regular way would be to echo an alert into the
+ * current TTY device. But for some embedded devices there is no TTY, because it
+ * runs only a graphical application.
+ */
+
+#ifndef BUZZER_H
+#define BUZZER_H
+
+#include <QObject>
+
+class Buzzer : public QObject
+{
+ Q_OBJECT
+ Q_REVISION(1)
+
+public:
+ explicit Buzzer(QObject *parent = 0);
+
+ Q_INVOKABLE void beep();
+
+public slots:
+
+protected:
+};
+
+#endif // BUZZER_H
diff --git a/local_src/qml-demo-master/src/main.cpp b/local_src/qml-demo-master/src/main.cpp
index 8036f8b..ecda7bf 100644
--- a/local_src/qml-demo-master/src/main.cpp
+++ b/local_src/qml-demo-master/src/main.cpp
@@ -13,8 +13,11 @@
#include <QtGui/QApplication>
#include <QDeclarativeView>
+#include <QDeclarativeComponent>
#include <QWSServer>
+#include "buzzer.h"
+
int main(int argc, char **argv)
{
@@ -25,6 +28,7 @@ int main(int argc, char **argv)
QWSServer::setCursorVisible( false );
#endif
+ qmlRegisterType<Buzzer>("Mini2440", 1, 0, "Buzzer");
QDeclarativeView *qdv = new QDeclarativeView;
qdv->setSource(QUrl::fromLocalFile("/usr/lib/qml-demo/main.qml"));
qdv->setResizeMode(QDeclarativeView::SizeRootObjectToView);