aboutsummaryrefslogtreecommitdiff
path: root/vfd-dashboard/src/main/scala/vfd/dashboard/ui/Layout.scala
blob: b3c938746acfd1ef23acf9492c0ec2729a390933 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
package vfd.dashboard.ui

import rx._
import scalatags.JsDom.all._
import vfd.dashboard.Environment
import vfd.dashboard.MavlinkSocket
import vfd.dashboard.ui.instruments._
import org.mavlink.messages._
import vfd.dashboard.rxutil._

class Layout(socket: MavlinkSocket)(implicit env: Environment) {

  private def panel(contents: Frag*) = div(`class` := "d-panel")(contents: _*)

  private def mode(name: String, kind: String, on: Boolean = false) = div(`class` := s"mode $kind ${if (!on) "off"}")(name)

  val modes = div(
    mode("MANUAL", "warning", true),
    mode("STABILIZED", "info", true),
    mode("GUIDED", "success", true),
    mode("AUTO", "success", true))

  val infos = div(
    mode("BAY", "info"),
    mode("RECOVERY", "danger"),
    mode("NOGPS", "warning", true),
    mode("OVERLOAD", "danger", true),
    mode("BATTERY", "danger", false),
    mode("LINK", "danger", true),
    mode("SOCKET", "danger", true),
    div(style := "float: right")(mode("CRITICAL", "danger", true)))

  val map = iframe(
    "frameborder".attr := "0",
    "scrolling".attr := "no",
    "marginheight".attr := "0",
    "marginwidth".attr := "0",
    src := "http://www.openstreetmap.org/export/embed.html?bbox=6.5611016750335684%2C46.51718501017836%2C6.570038795471191%2C46.520577350893525&layer=mapnik")

  val feed = div(style := "width: 100%; color: #ffffff; background-color: #c2c2c2; text-align: center;")(
    p(style := "padding-top: 220px")("video feed"))

  val altimeter = new Altimeter(
    Var(0.0)
  )
  val horizon = new Horizon(socket.message.collect((0.0, 0.0)) {
    case att: Attitude => (att.pitch, att.roll)
  })
  val compass = new Compass(socket.message.collect(0.0) {
    case att: Attitude => att.yaw
  })
  val motor0 = new Generic(0, 50, 100, "%", socket.message.collect(0.0) {
    case s: ServoOutputRaw => 100 * (s.servo1Raw - 1000) / 1000
  })
  val motor1 = new Generic(0, 50, 100, "%", socket.message.collect(0.0) {
    case s: ServoOutputRaw => 100 * (s.servo2Raw - 1000) / 1000
  })
  val motor2 = new Generic(0, 50, 100, "%", socket.message.collect(0.0) {
    case s: ServoOutputRaw => 100 * (s.servo3Raw - 1000) / 1000
  })
  val motor3 = new Generic(0, 50, 100, "%", socket.message.collect(0.0) {
    case s: ServoOutputRaw => 100 * (s.servo4Raw - 1000) / 1000
  })
  val powerDistribution = new Distribution(
    socket.message.collect((0.0, 0.0, 0.0, 0.0)) {
      case s: ServoOutputRaw => (s.servo1Raw, s.servo2Raw, s.servo3Raw, s.servo4Raw)
    }
  )
  val batteryLevel = new Bar(
    Var(0.0)
  )

  val top = header(
    div("Flight Control Panel"),
    div((new Clock).element),
    div("UAV " + socket.remoteSystemId)
  )

  val left = div(
    panel(
      table(`class` := "table-instrument")(
        thead("Communication"),
        tbody(
          tr(
            td("Uplink RSSI"),
            td("89"),
            td("Socket"),
            td("5ms")
          ),
          tr(
            td("Something else"),
            td("unknown"),
            td("Heartbeat"),
            td(i(`class` := "fa fa-heart heartbeat"))
          )
        )
      ),
      table(`class` := "table-instrument")(
        thead("Packets"),
        tbody(
          tr(
            td("OK"),
            Rx{td(socket.stats.packets())},
            td("CRC"),
            Rx{td(socket.stats.crcErrors())},
            td("OFLW"),
            Rx{td(socket.stats.overflows())},
            td("BID"),
            Rx{td(socket.stats.wrongIds())}
          ),
          tr(
            td("Ratio"),
            Rx{
              import socket.stats._
              val sum = packets() + crcErrors() + overflows() + wrongIds() 
              td(1.0 * packets() / sum formatted "%.2f")
              },
            td(),
            td(),
            td(),
            td(),
            td(),
            td()
          )
        )
      )
    ),
    panel(
      table(`class` := "table-instrument")(
        tbody(
          tr(
            td(compass.element),
            td(horizon.element),
            td(altimeter.element),
            td(altimeter.element)
          )
        )
      )
    ),
    panel(
      div(style := "width: 50%; display: inline-block;")(
        table(`class` := "table-instrument")(
          tbody(
            tr(
              td(motor1.element),
              td(),
              td(motor0.element)
            ),
            tr(
              td(),
              td(powerDistribution.element),
              td()
            ),
            tr(
              td(motor2.element),
              td(),
              td(motor3.element)
            )
          )
        )
      ),
      div(style := "width: 50%; display: inline-block;")(
        table(`class` := "table-instrument")(
          thead("Power"),
          tbody(
            tr(
              td("VHIGH"),
              td("12.6V"),
              td("VLOW"),
              td("9V")
            ),
            tr(
              td("Voltage"),
              td("11.2V"),
              td("Remaining"),
              td("80%")
            ),
            tr(
              td("Flight"),
              td("05:00"),
              td("Endurance"),
              td("12:00")
            )
          )
        ),
        table(`class` := "table-instrument")(
          thead("Navigation"),
          tbody(
            tr(
              td("Satellites"),
              td("5"),
              td("Precision"),
              td("10cm")
            ),
            tr(
              td("LON"),
              td(""),
              td("LAT"),
              td("")
            ),
            tr(
              td("GSpeed"),
              td("3 m/s"),
              td(),
              td()
            ),
            tr(
              td("Travelled"),
              td("5000m"),
              td("Home"),
              td("1200m")
            )
          )
        )
      )
    )
  )

  val element = div(`class` := "d-container d-column")(
    div(`class` := "d-above")(
      top
    ),
    div(`class` := "d-above d-container d-row")(
      panel(modes),
      panel(infos)
    ),
    div(`class` := "d-container d-row")(
      div(`class` := "d-container d-left")(
        left
      ),
      div(`class` := "d-container d-column d-middle")(
        panel(feed),
        panel(map)
      ),
      div(`class` := "d-container d-right")()
    )
  ).render

}