Initial comit
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import QtQuick 2.0
|
||||
import QtSensors 5.0
|
||||
|
||||
Item {
|
||||
property int azimuth: 0
|
||||
property real calibration: 0.0
|
||||
property bool running: false
|
||||
property bool enabled: true//settings.getSettings("compassSetting",false)
|
||||
|
||||
Timer {
|
||||
id: waittimer
|
||||
running: false
|
||||
repeat: false
|
||||
interval: 750
|
||||
onTriggered: {
|
||||
if (!aCompass.running) {
|
||||
aCompass.enabled = false
|
||||
aMagnetometer.enabled = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: waittimer.running = true//if (!running) {enabled = false;aMagnetometer.enabled = true}
|
||||
|
||||
onEnabledChanged: {
|
||||
console.log("*** COMPASS: "+enabled)
|
||||
if (!enabled) running = false
|
||||
}
|
||||
|
||||
Compass {
|
||||
active: enabled && Qt.application.active
|
||||
dataRate: 5
|
||||
|
||||
onReadingChanged: {
|
||||
running = true
|
||||
if (enabled) {
|
||||
azimuth = reading.azimuth
|
||||
calibration = reading.calibrationLevel
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
import QtQuick 2.0
|
||||
import Sailfish.Silica 1.0
|
||||
|
||||
Item {
|
||||
id: compassCapsule
|
||||
width: parent.height
|
||||
height: width
|
||||
|
||||
property real direction: normalize360(- __ringRotation) // In degrees, 0-359
|
||||
property int azimuth: 0 // In degrees, set (bind) from outside, the compass needle follows this
|
||||
property int anchor: 0
|
||||
property bool changingDirection: false // Is the direction (ring rotation) changing right now?
|
||||
property alias anchorArrow: anchorArrow.opacity
|
||||
property real __previousAngle: 0
|
||||
property real __ringRotation: 0
|
||||
|
||||
function normalize360(angle) {
|
||||
var semiNormalized = angle % 360
|
||||
return semiNormalized >= 0 ? semiNormalized : semiNormalized + 360
|
||||
}
|
||||
|
||||
Image {
|
||||
id: basePicture
|
||||
source: showCompasNumbers ? "../images/compass_ring_base_black.png" : "../images/compass_ring_base_white.png"
|
||||
opacity: showCompasNumbers ? 0.7 : 0.5
|
||||
//visible: !aGps.enabled
|
||||
width: parent.width
|
||||
height: parent.height
|
||||
fillMode: Image.PreserveAspectFit
|
||||
anchors.centerIn: parent
|
||||
}
|
||||
Image {
|
||||
id: numberRing
|
||||
source: "../images/compass_ring_360_day.png"
|
||||
// opacity:
|
||||
visible: showCompasNumbers
|
||||
width: parent.width
|
||||
height: parent.height
|
||||
fillMode: Image.PreserveAspectFit
|
||||
anchors.centerIn: parent
|
||||
}
|
||||
Image {
|
||||
source: "../images/compass_needle_day_N_red.png"
|
||||
anchors.centerIn: parent
|
||||
width: parent.width*0.80
|
||||
height: parent.height*0.80
|
||||
fillMode: Image.PreserveAspectFit
|
||||
visible: true
|
||||
opacity: 0.7
|
||||
rotation: - compassCapsule.azimuth
|
||||
Behavior on rotation { RotationAnimation { duration: 250; direction: RotationAnimation.Shortest } }
|
||||
Behavior on opacity {
|
||||
FadeAnimator {}
|
||||
}
|
||||
}
|
||||
|
||||
Image {
|
||||
id: anchorArrow
|
||||
source: "../images/compass_needle_day_N_green.png"
|
||||
anchors.centerIn: parent
|
||||
width: parent.width*0.80
|
||||
height: parent.height*0.80
|
||||
fillMode: Image.PreserveAspectFit
|
||||
opacity: 0.8
|
||||
rotation: - compassCapsule.azimuth + compassCapsule.anchor //compassCapsule.azimuth > compassCapsule.anchor ? compassCapsule.anchor - compassCapsule.azimuth : compassCapsule.azimuth - compassCapsule.anchor
|
||||
Behavior on rotation { RotationAnimation { duration: 200; direction: RotationAnimation.Shortest } }
|
||||
Behavior on opacity {
|
||||
FadeAnimator {duration: 200}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import QtQuick 2.0
|
||||
import Sailfish.Silica 1.0
|
||||
|
||||
GlassItem {
|
||||
property int active: 0 // 0 = empty; 1 = active; 2 = inactive
|
||||
property bool ghost: false
|
||||
property bool glowing: false
|
||||
id: dot
|
||||
width: Theme.paddingLarge * 2
|
||||
height: width
|
||||
radius: dots == 1 ? 0.6 : 0 // 0 ? 0.2 : 0
|
||||
falloffRadius: dots == 1 ? 0.65 : 3 // 0 ? 0.25 : 2
|
||||
color: Theme.highlightColor
|
||||
opacity: 0.1
|
||||
Timer {
|
||||
property bool up
|
||||
id: glowingTimer
|
||||
running: glowing
|
||||
repeat: true
|
||||
interval: 30
|
||||
onTriggered: {
|
||||
if (opacity == 1){
|
||||
up = false
|
||||
} else if (opacity < 0.5) {
|
||||
up = true
|
||||
}
|
||||
if (up)
|
||||
opacity += 0.05
|
||||
else
|
||||
opacity -= 0.05
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
import QtQuick 2.0
|
||||
import QtPositioning 5.2
|
||||
//import QtLocation 5.0
|
||||
|
||||
Item {
|
||||
property real currentLatitude: 0.0
|
||||
property real currentLongitude: 0.0
|
||||
property real currentAltitude: 0.0
|
||||
property int distance: 0
|
||||
property int direction: 0
|
||||
property string positionBearing: ""
|
||||
property bool active: inact == 0 ? true : false
|
||||
property int inact: 2
|
||||
property bool enabled: false
|
||||
|
||||
onEnabledChanged: {
|
||||
if (!enabled) inact = 2; else waittimer.running = true
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: waittimer
|
||||
running: inact == 0 ? false : true
|
||||
repeat: true
|
||||
interval: 3000
|
||||
onTriggered: {
|
||||
inact = inact + 1
|
||||
}
|
||||
}
|
||||
|
||||
PositionSource {
|
||||
id: src
|
||||
active: enabled ? true : false
|
||||
preferredPositioningMethods: PositionSource.AllPositioningMethods
|
||||
|
||||
onPositionChanged: {
|
||||
var coord = src.position.coordinate;
|
||||
currentLongitude = coord.longitude
|
||||
currentLatitude = coord.latitude
|
||||
currentAltitude = coord.altitude
|
||||
if (anchorLatitude == 500 && anchorLongitude == 500) {
|
||||
anchorLatitude = currentLatitude
|
||||
anchorLongitude = currentLongitude
|
||||
}
|
||||
|
||||
distance = getdistance(currentLatitude,currentLongitude,anchorLatitude,anchorLongitude)
|
||||
direction = positionbearing(currentLatitude,currentLongitude,anchorLatitude,anchorLongitude)
|
||||
|
||||
//console.log(anchorLatitude + " - " + anchorLongitude)
|
||||
|
||||
if (inact > 2) {
|
||||
waittimer.running = false
|
||||
inact = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function radians(n) {
|
||||
return n * (Math.PI / 180);
|
||||
}
|
||||
|
||||
function degrees(n) {
|
||||
return n * (180 / Math.PI);
|
||||
}
|
||||
|
||||
function getdistance(lat1,lon1,lat2,lon2){
|
||||
var R = 6371; // km
|
||||
var dLat = radians(lat2-lat1) //(lat2-lat1) * Math.PI / 180;
|
||||
var dLon = radians(lon2-lon1) //(lon2-lon1) * Math.PI / 180;
|
||||
lat1 = radians(lat1) //lat1 * Math.PI / 180;
|
||||
lat2 = radians(lat2) //lat2 * Math.PI / 180;
|
||||
|
||||
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
|
||||
Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);
|
||||
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
|
||||
var d = (R * c) * 1000;
|
||||
|
||||
return d
|
||||
|
||||
}
|
||||
|
||||
function positionbearing(lat1,lon1,lat2,lon2){
|
||||
var startLat = radians(lat1);
|
||||
var startLong = radians(lon1);
|
||||
var endLat = radians(lat2);
|
||||
var endLong = radians(lon2);
|
||||
var dLong = endLong - startLong;
|
||||
var dPhi = Math.log(Math.tan(endLat/2.0+Math.PI/4.0)/Math.tan(startLat/2.0+Math.PI/4.0));
|
||||
|
||||
if (Math.abs(dLong) > Math.PI){
|
||||
if (dLong > 0.0)
|
||||
dLong = -(2.0 * Math.PI - dLong);
|
||||
else
|
||||
dLong = (2.0 * Math.PI + dLong);
|
||||
}
|
||||
|
||||
var brng = degrees(Math.atan2(dLong,dPhi))
|
||||
return brng
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
import QtQuick 2.0
|
||||
import QtSensors 5.0
|
||||
|
||||
Item {
|
||||
property bool running: false
|
||||
property bool enabled: false//settings.getSettings("magnetometerSetting",true)
|
||||
property int azimuth: 0
|
||||
property real calibration: 0.0
|
||||
property variant data: [0,0,0,0,0]
|
||||
|
||||
onEnabledChanged: {
|
||||
console.log("*** MAGNETOMETER: "+enabled)
|
||||
if (!enabled) running = false
|
||||
}
|
||||
|
||||
Accelerometer
|
||||
{
|
||||
id: accel
|
||||
dataRate: 6
|
||||
active: enabled && Qt.application.active
|
||||
}
|
||||
|
||||
Magnetometer {
|
||||
id: mag
|
||||
dataRate: 6
|
||||
returnGeoValues: true // not sure
|
||||
active: enabled && Qt.application.active
|
||||
|
||||
onReadingChanged: {
|
||||
running = true
|
||||
var accelVec = [accel.reading.x, accel.reading.y, accel.reading.z]
|
||||
var magEast = crossProduct([mag.reading.x, mag.reading.y, mag.reading.z], accelVec)
|
||||
var magNorth = crossProduct(accelVec, magEast)
|
||||
|
||||
magEast = normVec(magEast)
|
||||
magNorth = normVec(magNorth)
|
||||
|
||||
var deviceHeading = [0., 1., -1.] //This is for portrait orientation on android
|
||||
var dotWithEast = dotProduct(deviceHeading, magEast)
|
||||
var dotWithNorth = dotProduct(deviceHeading, magNorth)
|
||||
var bearingRad = Math.atan2(dotWithEast, dotWithNorth)
|
||||
var t = ((bearingRad * 180 / Math.PI) - 360) %360
|
||||
var bearingDeg = 360 - Math.abs(t)
|
||||
calibration = mag.reading.calibrationLevel
|
||||
azimuth = normalize360(bearingDeg)
|
||||
}
|
||||
|
||||
function normalize360(angle) {
|
||||
var semiNormalized = angle % 360
|
||||
return semiNormalized >= 0 ? semiNormalized : semiNormalized + 360
|
||||
}
|
||||
|
||||
function normalizeAngle(angle)
|
||||
{
|
||||
var newAngle = angle;
|
||||
if (newAngle <= -180) newAngle = newAngle + 360;
|
||||
if (newAngle > 180) newAngle = newAngle - 360;
|
||||
return newAngle;
|
||||
}
|
||||
|
||||
function crossProduct(a, b) {
|
||||
if (a.length != 3 || b.length != 3) {
|
||||
return;
|
||||
}
|
||||
|
||||
return [a[1]*b[2] - a[2]*b[1],
|
||||
a[2]*b[0] - a[0]*b[2],
|
||||
a[0]*b[1] - a[1]*b[0]];
|
||||
}
|
||||
|
||||
function normVec(a) {
|
||||
var compSq = 0.
|
||||
for(var i=0;i<a.length;i++)
|
||||
compSq += Math.pow(a[i], 2)
|
||||
var mag = Math.pow(compSq, 0.5)
|
||||
if(mag == 0.) return
|
||||
var out = []
|
||||
for(var i=0;i<a.length;i++)
|
||||
out.push(a[i]/mag)
|
||||
return out
|
||||
}
|
||||
|
||||
function dotProduct(a, b)
|
||||
{
|
||||
if (a.length != b.length) return;
|
||||
var comp = 0.
|
||||
for(var i=0;i<a.length;i++)
|
||||
comp += a[i] * b[i]
|
||||
return comp
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import QtQuick 2.0
|
||||
import Nemo.DBus 2.0
|
||||
|
||||
Item {
|
||||
property bool enabled: keepScreenOn && Qt.application.active ? true : false
|
||||
function request(){
|
||||
var method = "req_display" + (enabled ? "" : "_cancel") + "_blanking_pause";
|
||||
console.log('screen blank:', enabled, method);
|
||||
dbif.call(method, [])
|
||||
}
|
||||
|
||||
onEnabledChanged: {
|
||||
request();
|
||||
}
|
||||
|
||||
DBusInterface {
|
||||
id: dbif
|
||||
|
||||
service: "com.nokia.mce"
|
||||
path: "/com/nokia/mce/request"
|
||||
iface: "com.nokia.mce.request"
|
||||
|
||||
bus: DBusInterface.SystemBus
|
||||
}
|
||||
Timer { //request seems to time out after a while:
|
||||
running: parent.enabled
|
||||
interval: 15000 //minimum setting for blank display is 15s
|
||||
repeat: true
|
||||
onTriggered: {
|
||||
if(parent.enabled) {
|
||||
parent.request()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component.onDestruction: {
|
||||
if(enabled){
|
||||
enabled=false
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import QtQuick 2.0
|
||||
import QtQuick.LocalStorage 2.0
|
||||
import "../js/settings.js" as Settings
|
||||
|
||||
Item {
|
||||
|
||||
function delAnchor(name) {
|
||||
Settings.delAnchor(name)
|
||||
}
|
||||
|
||||
function getAnchors() {
|
||||
Settings.getAnchors(dbAnchors)
|
||||
}
|
||||
|
||||
function setAnchor(name, description, icon, latitude, longitude) {
|
||||
Settings.setAnchor(name, description, icon, latitude, longitude)
|
||||
}
|
||||
|
||||
function setSettings(slati,slongi,icon,name,description) {
|
||||
|
||||
Settings.setValue("anchorLatitude",slati)
|
||||
Settings.setValue("anchorLongitude",slongi)
|
||||
Settings.setValue("anchorIcon",icon)
|
||||
Settings.setValue("anchorName",name)
|
||||
Settings.setValue("anchorDescription",description)
|
||||
}
|
||||
|
||||
function getQanchor() {
|
||||
anchorIcon = Settings.getValue("anchorIcon")
|
||||
anchorName = Settings.getValue("anchorName")
|
||||
anchorDescription = Settings.getValue("anchorDescription")
|
||||
anchorLatitude = Settings.getValue("anchorLatitude")
|
||||
anchorLongitude = Settings.getValue("anchorLongitude")
|
||||
}
|
||||
|
||||
function getSettings(setting,def) {
|
||||
return Settings.getValue(setting,def)
|
||||
|
||||
}
|
||||
function setSetting(setting,value) {
|
||||
Settings.setValue(setting,value)
|
||||
}
|
||||
|
||||
function setSettingSetting(compass,magnet,radius,numbers,screenon) {
|
||||
// Settings.setValue("compassSetting",compass)
|
||||
// Settings.setValue("magnetometerSetting",magnet)
|
||||
Settings.setValue("keepScreenOn",screenon)
|
||||
Settings.setValue("anchorRadius",radius)
|
||||
Settings.setValue("numbers",numbers)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user