Ejemplo n.º 1
0
  private void _applySettings(JSONObject js, String pg) throws Exception {

    switch (pg) {
      case (MNEMONIC_GROUP_MOTOR_1):
        TinygDriver.getInstance()
            .machine
            .getMotorByNumber(MNEMONIC_GROUP_MOTOR_1)
            .applyJsonSystemSetting(
                js.getJSONObject(MNEMONIC_GROUP_MOTOR_1), MNEMONIC_GROUP_MOTOR_1);
        setChanged();
        message[0] = "CMD_GET_MOTOR_SETTINGS";
        message[1] = MNEMONIC_GROUP_MOTOR_1;
        notifyObservers(message);
        break;
      case (MNEMONIC_GROUP_MOTOR_2):
        TinygDriver.getInstance()
            .machine
            .getMotorByNumber(MNEMONIC_GROUP_MOTOR_2)
            .applyJsonSystemSetting(
                js.getJSONObject(MNEMONIC_GROUP_MOTOR_2), MNEMONIC_GROUP_MOTOR_2);
        setChanged();
        message[0] = "CMD_GET_MOTOR_SETTINGS";
        message[1] = MNEMONIC_GROUP_MOTOR_2;
        notifyObservers(message);
        break;
      case (MNEMONIC_GROUP_MOTOR_3):
        TinygDriver.getInstance()
            .machine
            .getMotorByNumber(MNEMONIC_GROUP_MOTOR_3)
            .applyJsonSystemSetting(
                js.getJSONObject(MNEMONIC_GROUP_MOTOR_3), MNEMONIC_GROUP_MOTOR_3);
        setChanged();
        message[0] = "CMD_GET_MOTOR_SETTINGS";
        message[1] = MNEMONIC_GROUP_MOTOR_3;
        notifyObservers(message);
        break;

      case (MNEMONIC_GROUP_MOTOR_4):
        TinygDriver.getInstance()
            .machine
            .getMotorByNumber(MNEMONIC_GROUP_MOTOR_4)
            .applyJsonSystemSetting(
                js.getJSONObject(MNEMONIC_GROUP_MOTOR_4), MNEMONIC_GROUP_MOTOR_4);
        setChanged();
        message[0] = "CMD_GET_MOTOR_SETTINGS";
        message[1] = MNEMONIC_GROUP_MOTOR_4;
        notifyObservers(message);
        break;

      case (MNEMONIC_GROUP_AXIS_X):
        TinygDriver.getInstance()
            .machine
            .getAxisByName(MNEMONIC_GROUP_AXIS_X)
            .applyJsonSystemSetting(js.getJSONObject(MNEMONIC_GROUP_AXIS_X), MNEMONIC_GROUP_AXIS_X);
        setChanged();
        message[0] = "CMD_GET_AXIS_SETTINGS";
        message[1] = MNEMONIC_GROUP_AXIS_X;
        notifyObservers(message);
        break;

      case (MNEMONIC_GROUP_AXIS_Y):
        TinygDriver.getInstance()
            .machine
            .getAxisByName(MNEMONIC_GROUP_AXIS_Y)
            .applyJsonSystemSetting(js.getJSONObject(MNEMONIC_GROUP_AXIS_Y), MNEMONIC_GROUP_AXIS_Y);
        setChanged();
        message[0] = "CMD_GET_AXIS_SETTINGS";
        message[1] = MNEMONIC_GROUP_AXIS_Y;
        notifyObservers(message);
        break;

      case (MNEMONIC_GROUP_AXIS_Z):
        TinygDriver.getInstance()
            .machine
            .getAxisByName(MNEMONIC_GROUP_AXIS_Z)
            .applyJsonSystemSetting(js.getJSONObject(MNEMONIC_GROUP_AXIS_Z), MNEMONIC_GROUP_AXIS_Z);
        setChanged();
        message[0] = "CMD_GET_AXIS_SETTINGS";
        message[1] = MNEMONIC_GROUP_AXIS_Z;
        notifyObservers(message);
        break;

      case (MNEMONIC_GROUP_AXIS_A):
        TinygDriver.getInstance()
            .machine
            .getAxisByName(MNEMONIC_GROUP_AXIS_A)
            .applyJsonSystemSetting(js.getJSONObject(MNEMONIC_GROUP_AXIS_A), MNEMONIC_GROUP_AXIS_A);
        setChanged();
        message[0] = "CMD_GET_AXIS_SETTINGS";
        message[1] = MNEMONIC_GROUP_AXIS_A;
        notifyObservers(message);
        break;
      case (MNEMONIC_GROUP_AXIS_B):
        TinygDriver.getInstance()
            .machine
            .getAxisByName(MNEMONIC_GROUP_AXIS_B)
            .applyJsonSystemSetting(js.getJSONObject(MNEMONIC_GROUP_AXIS_B), MNEMONIC_GROUP_AXIS_B);
        setChanged();
        message[0] = "CMD_GET_AXIS_SETTINGS";
        message[1] = MNEMONIC_GROUP_AXIS_B;
        notifyObservers(message);
        break;

      case (MNEMONIC_GROUP_AXIS_C):
        TinygDriver.getInstance()
            .machine
            .getAxisByName(MNEMONIC_GROUP_AXIS_C)
            .applyJsonSystemSetting(js.getJSONObject(MNEMONIC_GROUP_AXIS_C), MNEMONIC_GROUP_AXIS_C);
        setChanged();
        message[0] = "CMD_GET_AXIS_SETTINGS";
        message[1] = MNEMONIC_GROUP_AXIS_C;
        notifyObservers(message);
        break;

      case ("hom"):
        logger.info("HOME");
        break;

      case ("msg"):
        // NOP
        break;

      case (MNEMONIC_GROUP_SYSTEM):
        TinygDriver.getInstance()
            .machine
            .applyJsonSystemSetting(js.getJSONObject(MNEMONIC_GROUP_SYSTEM), MNEMONIC_GROUP_SYSTEM);
        /** UNCOMMENT THIS BELOW WHEN WE HAVE MACHINE SETTINGS THAT NEED TO UPDATE THE GU */
        message[0] = "MACHINE_UPDATE";
        message[1] = null;
        setChanged();
        notifyObservers(message);
        break;
      case (MNEMONIC_GROUP_STATUS_REPORT):
        logger.info("Status Report");
        applySettingMasterGroup(js, MNEMONIC_GROUP_STATUS_REPORT);
        setChanged();
        message[0] = "STATUS_REPORT";
        message[1] = null;
        notifyObservers(message);
        break;
      case (MNEMONIC_GROUP_EMERGENCY_SHUTDOWN):
        Platform.runLater(
            new Runnable() {
              @Override
              public void run() {
                Main.postConsoleMessage("TinyG Alarm " + line);

                MonologFXButton btnYes =
                    MonologFXButtonBuilder.create()
                        .defaultButton(true)
                        .icon("/testmonologfx/dialog_apply.png")
                        .type(MonologFXButton.Type.YES)
                        .build();

                MonologFXButton btnNo =
                    MonologFXButtonBuilder.create()
                        .cancelButton(true)
                        .icon("/testmonologfx/dialog_cancel.png")
                        .type(MonologFXButton.Type.CANCEL)
                        .build();

                MonologFX mono =
                    MonologFXBuilder.create()
                        .titleText("Error Occured")
                        .message(
                            "You have triggered a limit switch.  TinyG is now in DISABLED mode. \n"
                                + "Manually back your machine off of its limit switches.\n  Once done, if you would like to re-enable TinyG click yes.")
                        .button(btnYes)
                        .button(btnNo)
                        .type(MonologFX.Type.ERROR)
                        .build();

                MonologFXButton.Type retval = mono.showDialog();

                switch (retval) {
                  case YES:
                    logger.info("Clicked Yes");

                    try {
                      TinygDriver.getInstance().priorityWrite((byte) 0x18);
                    } catch (Exception ex) {
                      logger.error(ex);
                    }
                    break;
                  case CANCEL:
                    logger.info("Clicked No");
                    Main.postConsoleMessage(
                        "TinyG will remain in diabled mode until you power cycle or click the reset button.");
                    break;
                }
              }
            });

      default:

        // This is for single settings xfr, 1tr etc...
        // This is pretty ugly but it gets the key and the value. For single values.
        responseCommand rc = TinygDriver.getInstance().mneManager.lookupSingleGroup(pg);

        //                  String _parent = String.valueOf(parentGroup.charAt(0));
        String newJs;
        //                  String _key = parentGroup; //I changed this to deal with the fb
        // mnemonic.. not sure if this works all over.
        rc.setSettingValue(String.valueOf(js.get(js.keys().next().toString())));
        logger.info(
            "Single Key Value: Group:"
                + rc.getSettingParent()
                + " key:"
                + rc.getSettingKey()
                + " value:"
                + rc.getSettingValue());
        if (rc.getSettingValue().equals((""))) {
          logger.info(rc.getSettingKey() + " value was null");
        } else {
          this.applySetting(
              rc.buildJsonObject()); // We pass the new json object we created from the string above
        }
    }
  }