Twizy: Dashboard Tuning PluginΒΆ

../../../../_images/dashboard-tuneslider.png

This plugin adds two sliders to adjust neutral and braking recuperation levels to the dashboard.

The sliders listen to driving profile changes and update accordingly.

If not yet logged in, the sliders are disabled.

Install: add the plugin as a hook type to page /dashboard, hook body.pre.

dashboard-tuneslider.htm (hint: right click, save as)

 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
<!--
  Hook plugin for /dashboard:body.pre or :body.post
  - add sliders to adjust recuperation power levels
-->

<style>
#tuneslider {
  margin: 10px 8px 0;
}
.form-inline .form-control.slider-value {
  width: 80px;
}
</style>

<div class="receiver" id="tuneslider" style="display:none">
  <div class="form-group">
    <label class="control-label" for="input-neutral">Neutral recuperation:</label>
    <div class="form-control slider" id="neutral" />
  </div>
  <div class="form-group">
    <label class="control-label" for="input-brake">Brake recuperation:</label>
    <div class="form-control slider" id="brake" />
  </div>
</div>

<script>
(function(){

  // Init sliders:
  $('#neutral').slider({ min:0, max:100, step:1, unit:'%', default:18, value:18, checked:false });
  $('#brake').slider({ min:0, max:100, step:1, unit:'%', default:18, value:18, checked:false });

  // Update sliders on profile changes:
  var profile;
  $('#tuneslider').on('msg:metrics', function(ev, update) {
    if (update["xrt.cfg.profile"] != null) {
      profile = update["xrt.cfg.profile"];
      var neutral = profile[7], brake = profile[8]; // see cfgconv.c tagnames for profile structure
      $('#neutral').slider({ checked: (neutral!=-1), value: (neutral!=-1) ? neutral : null });
      $('#brake').slider({ checked: (brake!=-1), value: (brake!=-1) ? brake : null });
    }
  });

  // Update profile on slider changes:
  $('#tuneslider .slider-value').on('change', function(ev) {
    var neutral = $('#input-neutral').prop('checked') ? $('#input-neutral').val() : -1,
      brake = $('#input-brake').prop('checked') ? $('#input-brake').val() : -1,
      autorecup_minprc = profile[43], autorecup_ref = profile[44];
    var cmd = "xrt cfg recup " + neutral + " " + brake + " " + autorecup_ref + " " + autorecup_minprc;
    loadcmd(cmd, '#loadres');
  });

  // Install into panel:
  $('#main').one('load', function(ev) {
    if (!loggedin) {
      $('#tuneslider .slider').slider({ disabled: true });
    }
    $('#tuneslider').appendTo('#panel-dashboard .panel-body').show();
  });

})();
</script>