mirror of
https://github.com/CopterExpress/clover.git
synced 2026-05-26 11:43:25 +00:00
rc: use web for statustext notifications
This commit is contained in:
@@ -9,6 +9,5 @@ target 'cleverrc' do
|
||||
|
||||
# Pods for cleverrc
|
||||
pod 'SwiftSocket', '~> 2.0'
|
||||
pod 'NotificationBannerSwift'
|
||||
|
||||
end
|
||||
|
||||
@@ -62,15 +62,7 @@ class ViewController: UIViewController, WKScriptMessageHandler {
|
||||
} else if (message.name == "notification") {
|
||||
// Got notification message
|
||||
print(message)
|
||||
let m = message.body as! NSDictionary;
|
||||
let level = m["severity"] as! Int
|
||||
if level == 4 {
|
||||
let banner = NotificationBanner(title: m["text"] as! String, style: .warning)
|
||||
banner.show()
|
||||
} else {
|
||||
let banner = NotificationBanner(title: m["text"] as! String, style: .danger)
|
||||
banner.show()
|
||||
}
|
||||
tapticNotify()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
<div class="stick-pointer"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="notifications"></div>
|
||||
<script src="main.js" type="text/javascript"></script>
|
||||
<script src="telemetry.js" type="text/javascript"></script>
|
||||
</body>
|
||||
|
||||
@@ -8,7 +8,7 @@ html, body {
|
||||
}
|
||||
|
||||
* {
|
||||
user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.stick {
|
||||
@@ -76,7 +76,8 @@ body.armed .telemetry .mode {
|
||||
|
||||
body.low-battery .battery {
|
||||
color: #ff554b;
|
||||
animation: scale 0.3s 1 ease-in-out}
|
||||
animation: scale 0.3s 1 ease-in-out
|
||||
}
|
||||
|
||||
.logo {
|
||||
position: absolute;
|
||||
@@ -93,3 +94,32 @@ body.low-battery .battery {
|
||||
user-select: none;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.notifications {
|
||||
pointer-events: none;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.notifications.hidden {
|
||||
transform: translateY(-100%);
|
||||
}
|
||||
|
||||
.notifications.anim {
|
||||
transition: transform 0.2s ease;
|
||||
}
|
||||
|
||||
.notifications .item {
|
||||
font-size: 4mm;
|
||||
-webkit-text-size-adjust: none;
|
||||
background: #fca83a;
|
||||
padding: 3mm;
|
||||
padding-bottom: 1.5mm;
|
||||
}
|
||||
|
||||
.notifications .item:last-child {
|
||||
padding-bottom: 3mm;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
var url = 'ws://192.168.11.1:9090';
|
||||
var modeEl = document.querySelector('.telemetry .mode');
|
||||
var batteryEl = document.querySelector('.battery');
|
||||
var notificationsEl = document.querySelector('.notifications');
|
||||
|
||||
var ros = new ROSLIB.Ros({ url: url });
|
||||
|
||||
@@ -60,6 +61,30 @@ new ROSLIB.Topic({
|
||||
}
|
||||
});
|
||||
|
||||
var notificationHideTimer;
|
||||
|
||||
function notify(text, severity) {
|
||||
var item = document.createElement('div');
|
||||
item.innerHTML = text;
|
||||
item.classList.add('item');
|
||||
notificationsEl.prepend(item);
|
||||
var itemHeight = item.offsetHeight;
|
||||
notificationsEl.classList.remove('anim');
|
||||
notificationsEl.style.transform = 'translateY(' + -itemHeight + 'px)';
|
||||
setTimeout(function() {
|
||||
notificationsEl.classList.add('anim');
|
||||
notificationsEl.style.transform = 'translateY(0)';
|
||||
}, 0);
|
||||
clearTimeout(notificationHideTimer);
|
||||
notificationHideTimer = setTimeout(function() {
|
||||
notificationsEl.style.transform = '';
|
||||
notificationsEl.classList.add('hidden');
|
||||
setTimeout(function() {
|
||||
notificationsEl.innerHTML = '';
|
||||
}, 210);
|
||||
}, 4000);
|
||||
}
|
||||
|
||||
new ROSLIB.Topic({
|
||||
ros: ros,
|
||||
name: '/mavros/statustext/recv',
|
||||
@@ -73,6 +98,7 @@ new ROSLIB.Topic({
|
||||
console.log('Filtered out message ' + message.text);
|
||||
return;
|
||||
}
|
||||
notify(message.text, message.severity);
|
||||
callNativeApp('notification', message);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user