Exemple #1
0
        /*
         * private void InitConfig()
         * {
         *  SYSTEM.configPath = MyUtil.FILE.AppFilePath(CONST.CONFIG_FOLDER);
         *  SYSTEM.systemConfigFile = Path.Combine(SYSTEM.configPath, CONST.SYSTEM_CONFIG);
         *
         *  SYSTEM.sc = MyUtil.FILE.RestoreDataFile<SystemConfig>(SYSTEM.systemConfigFile, CONST.SYSTEM_CONFIG_ZIP);
         *  if (Object.ReferenceEquals(SYSTEM.sc, null))
         *  {
         *      SYSTEM.sc = new SystemConfig()
         *      {
         *          robotConfigFile = CONST.DEFAULT_CONFIG.ROBOT_CONFIG_FILE,
         *          blocklyPath = CONST.DEFAULT_CONFIG.BLOCKLY_PATH,
         *          autoCheckVersion = CONST.DEFAULT_CONFIG.AUTO_CHECK_VERSION,
         *          autoCheckFirmware = CONST.DEFAULT_CONFIG.AUTO_CHECK_FIRMWARE,
         *          developerMode = CONST.DEFAULT_CONFIG.DEVEOPER_MODE
         *      };
         *  } else
         *  {
         *      if (SYSTEM.sc.robotConfigFile == null) SYSTEM.sc.robotConfigFile = CONST.DEFAULT_CONFIG.ROBOT_CONFIG_FILE;
         *      if (SYSTEM.sc.blocklyPath == null) SYSTEM.sc.blocklyPath = CONST.DEFAULT_CONFIG.BLOCKLY_PATH;
         *  }
         *
         #region "Version Config"
         *
         *  SYSTEM.versionChecked = false;
         *  if (SYSTEM.sc.autoCheckVersion)
         *  {
         *
         *  }
         *
         *  if (SYSTEM.sc.autoCheckFirmware)
         *  {
         *      Util.CheckFirmware();
         *  }
         *  else
         *  {
         *      SYSTEM.firmwareChecked = false;
         *  }
         *
         #endregion
         *
         *
         #region "Get Robot Config"
         *
         *  if (!File.Exists(SYSTEM.systemConfigFile))
         *  {
         *      MyUtil.FILE.SaveDataFile(SYSTEM.sc, SYSTEM.systemConfigFile, CONST.SYSTEM_CONFIG_ZIP);
         *  }
         *
         *  bool robotConfigReady = false;
         *  string robotConfigFile = Path.Combine(SYSTEM.configPath, SYSTEM.sc.robotConfigFile);
         *  if (File.Exists(robotConfigFile))
         *  {
         *      try
         *      {
         *          SYSTEM.configObject = ConfigObject.FromFile(robotConfigFile);
         *          robotConfigReady = true;
         *      }
         *      catch { }
         *  }
         *
         *  if ((!robotConfigReady) || (Object.ReferenceEquals(SYSTEM.configObject, null)))
         *  {
         *      SYSTEM.configObject = DefaultConfig();
         *  }
         *  CONST.MAX_SERVO = SYSTEM.configObject.max_servo;
         *
         #endregion
         *
         *  if (!File.Exists(Path.Combine(SYSTEM.sc.blocklyPath, CONST.BLOCKLY.CHECK_FILE)))
         *  {
         *      SYSTEM.sc.blocklyPath = "";
         *  }
         *
         *  Util.SaveSystemConfig();
         *
         * }
         *
         * public ConfigObject DefaultConfig()
         * {
         *  int[,] servoPos = new int[20, 2] {
         *                                      {92,95},{48,95},{36,160},
         *                                      {174,95},{220,95},{232,160},
         *                                      {103,184},{97,223},{93,285},{87,343},{96,378},
         *                                      {163,184},{168,223},{173,285},{179,343},{170,378},
         *                                      {133,80},{30, 230},{236,230},{133,180}
         *                                      };
         *
         *  ConfigObject co = new ConfigObject();
         *  co.max_servo = 16;
         *  co.servos = new List<Point>();
         *  for (int i = 0; i < co.max_servo; i++)
         *  {
         *      co.servos.Add(new Point(servoPos[i, 0], servoPos[i, 1]));
         *  }
         *  co.imagePath = "pack://application:,,,/images/alpha1s_300x450.png";
         *  co.appResource = true;
         *  return co;
         * }
         */

        public ImageBrush loadImage(ConfigObject co)
        {
            if (co.imagePath == "")
            {
                return(null);
            }

            /*
             * ImageBrush image = new ImageBrush
             * {
             *  ImageSource = (co.appResource ? new BitmapImage(new Uri(co.imagePath)) : new BitmapImage(new Uri(co.imagePath, UriKind.Relative))),
             *  Stretch = Stretch.Uniform
             * };
             * return image;
             */
            if (co.appResource)
            {
                ImageBrush image = new ImageBrush
                {
                    ImageSource = new BitmapImage(new Uri(co.imagePath)),
                    Stretch     = Stretch.Uniform
                };
                return(image);
            }
            return(co.getImageBrush());
        }
 public void SetConfig(ConfigObject config)
 {
     this.config = config.Clone();
     servos      = null;
     servos      = new List <UcServoMain>();
     gridPanel.Children.Clear();
     LoadImage();
     for (int i = 0; i < config.max_servo; i++)
     {
         AddServo(config.servos[i].X, config.servos[i].Y);
     }
     SetStatus();
 }
Exemple #3
0
        private void btnSaveConfig_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.InitialDirectory = UTIL.FILE.GetConfigFilePath();
            saveFileDialog.Filter           = CONST.ROBOT_CONFIG_FILTER;
            saveFileDialog.FileName         = CONST.DEFAULT_ROBOT_CONFIG;
            if (saveFileDialog.ShowDialog() == true)
            {
                string       fileName = saveFileDialog.FileName.Trim();
                ConfigObject co       = ucRobotMaintenance.GetConfigObject();
                UTIL.FILE.SaveDataFile(co, fileName);
            }
        }
Exemple #4
0
        public ImageBrush loadImage(ConfigObject co)
        {
            if (co.imagePath == "")
            {
                return(null);
            }
            ImageBrush image = new ImageBrush
            {
                ImageSource = (co.appResource ? new BitmapImage(new Uri(co.imagePath)) : new BitmapImage(new Uri(co.imagePath, UriKind.Relative))),
                Stretch     = Stretch.Uniform
            };

            return(image);
        }
Exemple #5
0
        private void btnLoadConfig_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = UTIL.FILE.GetConfigFilePath();
            openFileDialog.Filter           = CONST.ROBOT_CONFIG_FILTER;
            if (openFileDialog.ShowDialog() == true)
            {
                string       fileName = openFileDialog.FileName.Trim();
                ConfigObject co       = UTIL.FILE.RestoreDataFile <ConfigObject>(fileName);
                if (!Object.ReferenceEquals(co, null))
                {
                    ucRobotMaintenance.SetConfig(co);
                }
            }
        }
        private void InitServo()
        {
            ConfigObject CONFIG = SYSTEM.configObject;

            gridRobot.Background = loadImage(CONFIG);

            for (byte i = 1; i <= CONFIG.max_servo; i++)
            {
                uc.UcServo us = new uc.UcServo(UBT.GetServo(i));
                us.Width  = 38;
                us.Height = 38;
                us.HorizontalAlignment = HorizontalAlignment.Left;
                us.VerticalAlignment   = VerticalAlignment.Top;
                // us.Margin = new Thickness(servoPos[i, 0], servoPos[i, 1], 0, 0);
                us.Margin = new Thickness(CONFIG.servos[i - 1].X, CONFIG.servos[i - 1].Y, 0, 0);
                us.Show();
                us.MouseDownEventHandler += Servo_MouseDown;
                servo[i] = us;
                gridRobot.Children.Add(us);
            }
        }
Exemple #7
0
        public ConfigObject DefaultConfig()
        {
            int[,] servoPos = new int[20, 2] {
                { 92, 95 }, { 48, 95 }, { 36, 160 },
                { 174, 95 }, { 220, 95 }, { 232, 160 },
                { 103, 184 }, { 97, 223 }, { 93, 285 }, { 87, 343 }, { 96, 378 },
                { 163, 184 }, { 168, 223 }, { 173, 285 }, { 179, 343 }, { 170, 378 },
                { 133, 80 }, { 30, 230 }, { 236, 230 }, { 133, 180 }
            };

            ConfigObject co = new ConfigObject();

            co.max_servo = 20;
            co.servos    = new List <Point>();
            for (int i = 0; i < co.max_servo; i++)
            {
                co.servos.Add(new Point(servoPos[i, 0], servoPos[i, 1]));
            }
            co.imagePath   = "pack://application:,,,/images/alpha1s_300x450.png";
            co.appResource = true;
            return(co);
        }
Exemple #8
0
        private void InitConfig()
        {
            SystemConfig sc = UTIL.FILE.RestoreConfig <SystemConfig>(CONST.CONFIG_FILE, false);

            if (Object.ReferenceEquals(sc, null))
            {
                sc = new SystemConfig()
                {
                    robotConfig = CONST.DEFAULT_ROBOT_CONFIG
                };
            }

            if (!File.Exists(UTIL.FILE.GetConfigFileFullName(CONST.CONFIG_FILE)))
            {
                UTIL.FILE.SaveConfig(sc, CONST.CONFIG_FILE, false);
            }

            bool   configReady = false;
            string fullName    = UTIL.FILE.GetConfigFileFullName(sc.robotConfig);

            if (File.Exists(fullName))
            {
                try
                {
                    SYSTEM.configObject = ConfigObject.FromFile(fullName);
                    configReady         = true;
                    SYSTEM.robotConfig  = sc.robotConfig;
                }
                catch { }
            }

            if ((!configReady) || (Object.ReferenceEquals(SYSTEM.configObject, null)))
            {
                SYSTEM.robotConfig  = "";
                SYSTEM.configObject = DefaultConfig();
            }
            CONST.MAX_SERVO = SYSTEM.configObject.max_servo;
        }
Exemple #9
0
        private void InitConfig()
        {
            SYSTEM.configPath       = MyUtil.FILE.AppFilePath(CONST.CONFIG_FOLDER);
            SYSTEM.systemConfigFile = Path.Combine(SYSTEM.configPath, CONST.SYSTEM_CONFIG);

            SYSTEM.sc = MyUtil.FILE.RestoreDataFile <SystemConfig>(SYSTEM.systemConfigFile, CONST.SYSTEM_CONFIG_ZIP);
            if (Object.ReferenceEquals(SYSTEM.sc, null))
            {
                SYSTEM.sc = new SystemConfig()
                {
                    robotConfigFile      = CONST.DEFAULT_CONFIG.ROBOT_CONFIG_FILE,
                    blocklyPath          = MyUtil.FILE.AppFilePath(CONST.DEFAULT_CONFIG.BLOCKLY_PATH),
                    autoCheckVersion     = CONST.DEFAULT_CONFIG.AUTO_CHECK_VERSION,
                    autoCheckFirmware    = CONST.DEFAULT_CONFIG.AUTO_CHECK_FIRMWARE,
                    waitRebootSec        = CONST.DEFAULT_CONFIG.WAIT_REBOOT_SEC,
                    disableBatteryUpdate = CONST.DEFAULT_CONFIG.DISABLE_BATTERY_UPDATE,
                    disableMpuUpdate     = CONST.DEFAULT_CONFIG.DISABLE_MPU_UPDATE,
                    developerMode        = CONST.DEFAULT_CONFIG.DEVEOPER_MODE
                };
            }
            else
            {
                if (SYSTEM.sc.robotConfigFile == null)
                {
                    SYSTEM.sc.robotConfigFile = CONST.DEFAULT_CONFIG.ROBOT_CONFIG_FILE;
                }
                if (String.IsNullOrWhiteSpace(SYSTEM.sc.blocklyPath))
                {
                    SYSTEM.sc.blocklyPath = MyUtil.FILE.AppFilePath(CONST.DEFAULT_CONFIG.BLOCKLY_PATH);
                }
            }

            // fill default for invalid value, to handle for reading from old config files
            if ((SYSTEM.sc.waitRebootSec == 0) || (SYSTEM.sc.waitRebootSec > 99))
            {
                SYSTEM.sc.waitRebootSec = CONST.DEFAULT_CONFIG.WAIT_REBOOT_SEC;
            }

            // Check blockly path

            if (!Util.IsBlocklyPath(SYSTEM.sc.blocklyPath))
            {
                if (!Util.IsBlocklyPath(MyUtil.FILE.AppFilePath(CONST.DEFAULT_CONFIG.BLOCKLY_PATH)))
                {
                    SYSTEM.sc.blocklyPath = MyUtil.FILE.AppFilePath(CONST.DEFAULT_CONFIG.BLOCKLY_PATH);
                }
            }

            #region "Version Config"

            if (SYSTEM.sc.autoCheckFirmware)
            {
                Util.CheckFirmware();
            }
            else
            {
                SYSTEM.firmwareChecked = false;
            }

            #endregion


            #region "Get Robot Config"

            if (!File.Exists(SYSTEM.systemConfigFile))
            {
                MyUtil.FILE.SaveDataFile(SYSTEM.sc, SYSTEM.systemConfigFile, CONST.SYSTEM_CONFIG_ZIP);
            }

            bool   robotConfigReady = false;
            string robotConfigFile  = Path.Combine(SYSTEM.configPath, SYSTEM.sc.robotConfigFile);
            if (File.Exists(robotConfigFile))
            {
                try
                {
                    SYSTEM.configObject = ConfigObject.FromFile(robotConfigFile);
                    robotConfigReady    = true;
                }
                catch { }
            }

            if ((!robotConfigReady) || (Object.ReferenceEquals(SYSTEM.configObject, null)))
            {
                SYSTEM.configObject = DefaultConfig();
            }
            CONST.MAX_SERVO = SYSTEM.configObject.max_servo;

            #endregion

            if (!File.Exists(Path.Combine(SYSTEM.sc.blocklyPath, CONST.BLOCKLY.CHECK_FILE)))
            {
                SYSTEM.sc.blocklyPath = "";
            }

            Util.SaveSystemConfig();
        }
Exemple #10
0
        private void InitConfig()
        {
            SYSTEM.configPath       = MyUtil.FILE.AppFilePath(CONST.CONFIG_FOLDER);
            SYSTEM.systemConfigFile = Path.Combine(SYSTEM.configPath, CONST.SYSTEM_CONFIG);

            SYSTEM.sc = MyUtil.FILE.RestoreDataFile <SystemConfig>(SYSTEM.systemConfigFile, CONST.SYSTEM_CONFIG_ZIP);
            if (Object.ReferenceEquals(SYSTEM.sc, null))
            {
                SYSTEM.sc = new SystemConfig()
                {
                    robotConfigFile      = CONST.DEFAULT_CONFIG.ROBOT_CONFIG_FILE,
                    blocklyPath          = CONST.DEFAULT_CONFIG.BLOCKLY_PATH,
                    autoCheckVersion     = CONST.DEFAULT_CONFIG.AUTO_CHECK_VERSION,
                    autoCheckFirmware    = CONST.DEFAULT_CONFIG.AUTO_CHECK_FIRMWARE,
                    disableBatteryUpdate = CONST.DEFAULT_CONFIG.DISABLE_BATTERY_UPDATE,
                    disableMpuUpdate     = CONST.DEFAULT_CONFIG.DISABLE_MPU_UPDATE,
                    developerMode        = CONST.DEFAULT_CONFIG.DEVEOPER_MODE
                };
            }
            else
            {
                if (SYSTEM.sc.robotConfigFile == null)
                {
                    SYSTEM.sc.robotConfigFile = CONST.DEFAULT_CONFIG.ROBOT_CONFIG_FILE;
                }
                if (SYSTEM.sc.blocklyPath == null)
                {
                    SYSTEM.sc.blocklyPath = CONST.DEFAULT_CONFIG.BLOCKLY_PATH;
                }
            }

            #region "Version Config"

            SYSTEM.versionChecked = false;
            if (SYSTEM.sc.autoCheckVersion)
            {
            }

            if (SYSTEM.sc.autoCheckFirmware)
            {
                Util.CheckFirmware();
            }
            else
            {
                SYSTEM.firmwareChecked = false;
            }

            #endregion


            #region "Get Robot Config"

            if (!File.Exists(SYSTEM.systemConfigFile))
            {
                MyUtil.FILE.SaveDataFile(SYSTEM.sc, SYSTEM.systemConfigFile, CONST.SYSTEM_CONFIG_ZIP);
            }

            bool   robotConfigReady = false;
            string robotConfigFile  = Path.Combine(SYSTEM.configPath, SYSTEM.sc.robotConfigFile);
            if (File.Exists(robotConfigFile))
            {
                try
                {
                    SYSTEM.configObject = ConfigObject.FromFile(robotConfigFile);
                    robotConfigReady    = true;
                }
                catch { }
            }

            if ((!robotConfigReady) || (Object.ReferenceEquals(SYSTEM.configObject, null)))
            {
                SYSTEM.configObject = DefaultConfig();
            }
            CONST.MAX_SERVO = SYSTEM.configObject.max_servo;

            #endregion

            if (!File.Exists(Path.Combine(SYSTEM.sc.blocklyPath, CONST.BLOCKLY.CHECK_FILE)))
            {
                SYSTEM.sc.blocklyPath = "";
            }

            Util.SaveSystemConfig();
        }