<commit_before>
$(function () {
  window.Mavelous = window.Mavelous || {};

  Mavelous.FlightModeModel = Backbone.Model.extend({
    defaults: function () {
      return {
        armed: false,
        arming: false,
        disarming: false,
        modestring: 'None'
      };
    },
    initialize: function () {
      var mavlinkSrc = this.get('mavlinkSrc');
      this.heartbeat = mavlinkSrc.subscribe('HEARTBEAT',
                            this.onHeartbeat , this);
      this.on('change:armed', this.onChangeArmed, this);
    },
    onHeartbeat: function () {
      var modestring = mavutil.heartbeat.modestring(this.heartbeat);
      var armed = mavutil.heartbeat.armed(this.heartbeat);
      this.set({ armed: armed, modestring: modestring });
    },
    onChangeArmed: function () {
      if (this.get('armed')) {
        if (this.get('arming')) {
          this.set('arming', false);
           /* No more override, use the radio controller's values. */
          this.post({ch3: 0, ch4: 0});
        }
      } else {
        if (this.get('disarming')) {
          this.set('disarming', false);
           /* No more override, use the radio controller's values. */
          this.post({ch3: 0, ch4: 0});
        }
      }
    },
    requestArm: function () {
      console.log('requested to arm');
      // Send RC override:
      // rc 3 1000, rc 4 2000
      this.post({
        'ch3': 1000,
        'ch4': 2000
      });
      this.set('arming', true);
    },

    requestDisarm: function () {
      console.log('requested to disarm');
      this.post({
        'ch3': 1000,
        'ch4': 1000
      });
      this.set('disarming', true);
    },
    post: function (override) {
      $.ajax({ type: 'POST',
               url: '/rcoverride',
               data: JSON.stringify(override) });
    }
  });
<commit_msg>flightmode.js: reimplement arming and disarming in terms of arm/disarm command_long<commit_after>
$(function () {
  window.Mavelous = window.Mavelous || {};

  Mavelous.FlightModeModel = Backbone.Model.extend({
    defaults: function () {
      return {
        armed: false,
        arming: false,
        disarming: false,
        modestring: 'None'
      };
    },
    initialize: function () {
      var mavlinkSrc = this.get('mavlinkSrc');
      this.heartbeat = mavlinkSrc.subscribe('HEARTBEAT',
                            this.onHeartbeat , this);
      this.on('change:armed', this.onChangeArmed, this);
    },
    onHeartbeat: function () {
      var modestring = mavutil.heartbeat.modestring(this.heartbeat);
      var armed = mavutil.heartbeat.armed(this.heartbeat);
      this.set({ armed: armed, modestring: modestring });
    },
    onChangeArmed: function () {
      if (this.get('armed')) {
        if (this.get('arming')) {
          this.set('arming', false);
        }
      } else {
        if (this.get('disarming')) {
          this.set('disarming', false);
        }
      }
    },
    requestArm: function () {
      console.log('requested to arm');
      this.postArmRequest();
      this.set('arming', true);
    },

    requestDisarm: function () {
      console.log('requested to disarm');
      this.postDisarmRequest();
      this.set('disarming', true);
    },
    postArmRequest: function () {
      $.ajax({ type: 'POST',
               url: '/command_long',
               data: JSON.stringify({
                  command: 'COMPONENT_ARM_DISARM',
                  component: 'SYSTEM_CONTROL',
                  setting: 'ARM',
               })});
    },
    postDisarmRequest: function () {
      $.ajax({ type: 'POST',
               url: '/command_long',
               data: JSON.stringify({
                  command: 'COMPONENT_ARM_DISARM',
                  component: 'SYSTEM_CONTROL',
                  setting: 'DISARM',
               })});
    }
  });

{'fraction_non_alphanumeric': 0.1474041220975737, 'fraction_numerical': 0.009913905557004957, 'mean_word_length': 1.8979591836734695, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7308258', 'n_tokens_mistral': 1196, 'n_tokens_neox': 1133, 'n_words': 232}