Skip to content

Commit

Permalink
ui 변경중
Browse files Browse the repository at this point in the history
  • Loading branch information
coreanq committed Aug 21, 2016
1 parent 1f125bb commit fec9dbf
Show file tree
Hide file tree
Showing 9 changed files with 266 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "C:/Anaconda3/Library/bin/pyrcc5.exe",
"command": "pyrcc5.exe",
"isShellCommand": true,
"args": ["qml.qrc", "-o", "qml_rc.py"],
"showOutput": "always"
Expand Down
4 changes: 4 additions & 0 deletions ReadMe.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
실행전 설치 사항
1. qfirmata 소스를 받아서 빌드 한다.
2. 생성된 라이브러리 파일을 qt가 설치된 곳의 qml 폴더에 위치 시킨다.
3. live coding 을 위해서 qmllivebench 를 사용하는 경우 qmllivebench 내의 설정에서 impport 를 추가해줌
47 changes: 47 additions & 0 deletions arduino/ultra_sonic/ultra_sonic.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#define trigPin 11
#define echoPin 12
#define RedLed 13
#define greenLed 3

void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(RedLed, OUTPUT);
pinMode(greenLed, OUTPUT);
}

void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

// 30 msec time out in sensor spec
float duration = pulseIn(echoPin, HIGH, 30000);
int distance = int(duration * 0.034 / 2);

if (distance < 4) { // This is where the RED LED On/Off happens
digitalWrite(RedLed, HIGH); // When the Red condition is met, the Green LED should turn off
digitalWrite(greenLed, LOW);
}
else {
digitalWrite(RedLed, LOW);
digitalWrite(greenLed, HIGH);
}

Serial.print(distance);
Serial.println(" cm");


// if (distance >= 200 || distance <= 0){
// Serial.println(distance);
// Serial.println(duration);
// }
// else {
// Serial.print(distance);
// Serial.println(" cm");
// }
delay(30);
}
77 changes: 77 additions & 0 deletions arduino/ultra_sonic_firmata/ultra_sonic_firmata.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include <Firmata.h>

#define trigPin 11
#define echoPin 12
#define RedLed 13
#define greenLed 3
#define pingPin 7

void setup() {
Serial.begin (115200);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(RedLed, OUTPUT);
pinMode(greenLed, OUTPUT);
Firmata.setFirmwareVersion(FIRMATA_FIRMWARE_MAJOR_VERSION, FIRMATA_FIRMWARE_MINOR_VERSION);
Firmata.begin(115200);
}

void loop()
{
while (Firmata.available()) {
Firmata.processInput();
}

int distance = computeDistance();

// Serial.print(distance);
// Serial.println(" cm");
Firmata.sendAnalog(pingPin, distance);
}


long computeDistance()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

// 30 msec time out in sensor spec
long duration = pulseIn(echoPin, HIGH, 30000);
int distance = microsecondsToCentimeters(duration);

if (distance < 4) { // This is where the RED LED On/Off happens
digitalWrite(RedLed, HIGH); // When the Red condition is met, the Green LED should turn off
digitalWrite(greenLed, LOW);
}
else {
digitalWrite(RedLed, LOW);
digitalWrite(greenLed, HIGH);
}
// it's timeout(30us) when the distance is 0, so dont need to delay
if ( distance != 0 )
delay(30);

return distance;
}
long microsecondsToInches(long microseconds)
{
// According to Parallax's datasheet for the PING))), there are
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
// second). This gives the distance travelled by the ping, outbound
// and return, so we divide by 2 to get the distance of the obstacle.
// See: [http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf](http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf)
return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
}


3 changes: 3 additions & 0 deletions qml.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
<file>qml/QChartGallery.js</file>
<file>qml/jbQuick/Charts/QChart.js</file>
<file>qml/jbQuick/Charts/QChart.qml</file>
<file>qml/InitWnd.qml</file>
<file>qml/ProcessingWnd.qml</file>
<file>qml/StandbyWnd.qml</file>
</qresource>
</RCC>
7 changes: 7 additions & 0 deletions qml/InitWnd.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3

Rectangle{
color: "black"
}
74 changes: 74 additions & 0 deletions qml/ProcessingWnd.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3
import "firmata"

Rectangle{
id: main
anchors.fill: parent
PortSelector {
id: port
anchors.top: main.top
height:40
width: main.width
Rectangle {
visible: false
anchors.fill: parent
color: "black"
opacity: 0.5
}

Component.onCompleted: {

}
onDataReceived: {
dataUpdate(rawValue)
}



}
QChartGallery{
id: gallery
anchors.left: main.left
anchors.top: port.bottom
width: main.width
height: main.height - port.height

Rectangle{
visible: false
anchors.fill: parent
color: "green"
opacity: 0.5
}
}
Timer {
id: timer
interval: 100
running: false
repeat: true
onTriggered: {
var d = new Date()
gallery.chart_line_data.ChartLineData["labels"].shift()
gallery.chart_line_data.ChartLineData["labels"].push(d.getSeconds() + "." + d.getMilliseconds() )
gallery.chart_line_data.ChartLineData["datasets"][0]["data"].shift()
gallery.chart_line_data.ChartLineData["datasets"][0]["data"].push(Math.floor(Math.random() * 400 +1 ).toString())
gallery.chart_line_data.ChartLineData["datasets"][1]["data"].shift()
gallery.chart_line_data.ChartLineData["datasets"][1]["data"].push(Math.floor(Math.random() * 400 +1 ).toString())
gallery.chart_line.repaint()

}
}
function dataUpdate(rawValue){
var d = new Date()
gallery.chart_line_data.ChartLineData["labels"].shift()
gallery.chart_line_data.ChartLineData["labels"].push(d.getSeconds() + "." + d.getMilliseconds() )
gallery.chart_line_data.ChartLineData["datasets"][0]["data"].shift()
gallery.chart_line_data.ChartLineData["datasets"][0]["data"].push(rawValue.toString())
// gallery.chart_line_data.ChartLineData["datasets"][1]["data"].shift()
// gallery.chart_line_data.ChartLineData["datasets"][1]["data"].push(Math.floor(Math.random() * 400 +1 ).toString())
gallery.chart_line.repaint()

}
}

8 changes: 8 additions & 0 deletions qml/StandbyWnd.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3
Rectangle{
color: "red"
anchors.fill: parent
}

117 changes: 45 additions & 72 deletions qml/main.qml
Original file line number Diff line number Diff line change
@@ -1,88 +1,61 @@
import QtQuick 2.5
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.2
import "firmata"
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3
import QtQuick.Extras 1.4

ApplicationWindow{
Rectangle{
id: main
visible: true
width: 640
height: 480
title: qsTr("Hello World")
PortSelector {
id: port
anchors.top: main.top
height:40
width: main.width
Rectangle {
visible: false
anchors.fill: parent
color: "black"
opacity: 0.5
}
anchors.fill: parent

Component.onCompleted: {
color: "blue"

ListModel {
id: viewModel
ListElement {
qmlName: "InitWnd.qml"
}
onDataReceived: {
dataUpdate(rawValue)
ListElement {
qmlName: "ProcessingWnd.qml"
}



}
QChartGallery{
id: gallery
anchors.left: main.left
anchors.top: port.bottom
width: main.width
height: main.height - port.height

Rectangle{
visible: false
anchors.fill: parent
color: "green"
opacity: 0.5
ListElement {
qmlName: "StandbyWnd.qml"
}
}
Timer {
id: timer
interval: 100
running: false
repeat: true
onTriggered: {
var d = new Date()
gallery.chart_line_data.ChartLineData["labels"].shift()
gallery.chart_line_data.ChartLineData["labels"].push(d.getSeconds() + "." + d.getMilliseconds() )
gallery.chart_line_data.ChartLineData["datasets"][0]["data"].shift()
gallery.chart_line_data.ChartLineData["datasets"][0]["data"].push(Math.floor(Math.random() * 400 +1 ).toString())
gallery.chart_line_data.ChartLineData["datasets"][1]["data"].shift()
gallery.chart_line_data.ChartLineData["datasets"][1]["data"].push(Math.floor(Math.random() * 400 +1 ).toString())
gallery.chart_line.repaint()
Component {
id: delegate
Loader {
id: wnd
source: qmlName
width: parent.width / 10 * 8
height: parent.height / 10 * 8
z: wnd.PathView.isCurrentItem ? 0 : -1
opacity: wnd.PathView.isCurrentItem ? 1: 0.5
scale: wnd.PathView.isCurrentItem ? 1: 0.5

}
}
function dataUpdate(rawValue){
var d = new Date()
gallery.chart_line_data.ChartLineData["labels"].shift()
gallery.chart_line_data.ChartLineData["labels"].push(d.getSeconds() + "." + d.getMilliseconds() )
gallery.chart_line_data.ChartLineData["datasets"][0]["data"].shift()
gallery.chart_line_data.ChartLineData["datasets"][0]["data"].push(rawValue.toString())
// gallery.chart_line_data.ChartLineData["datasets"][1]["data"].shift()
// gallery.chart_line_data.ChartLineData["datasets"][1]["data"].push(Math.floor(Math.random() * 400 +1 ).toString())
gallery.chart_line.repaint()
// Rectangle{
// anchors.left: parent.left
// width: 580
// height: 180
// color: "yellow"
// opacity: 0.5
// z: 100

// }

PathView {
id: pathView
anchors.fill: parent
model: viewModel
delegate: delegate
path: Path {
startX: parent.width /2
startY: parent.height /2
PathQuad { x: parent.width / 2; y: -parent.height * 0.1; controlX: parent.width * 1.1 ; controlY: parent.height/2 }
PathQuad { x: parent.width / 2; y: parent.height /2; controlX: -parent.width * 0.1; controlY: parent.height/2 }
}
}
}


// footer: TabBar {
// id: tabBar
// currentIndex: swipeView.currentIndex
// TabButton {
// text: qsTr("First")
// }
// TabButton {
// text: qsTr("Second")
// }
// }

0 comments on commit fec9dbf

Please sign in to comment.