public MainVM() { // getting current version Assembly assembly = Assembly.GetExecutingAssembly(); FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location); _config = new DeviceConfig(); _configExchanger = new DeviceConfigExchangerVM(); _configExchanger.Received += ConfigReceived; _configExchanger.Sent += ConfigSent; PinsVM = new PinsVM(Config); PinsVM.ConfigChanged += PinConfigChanged; _joystick = new Joystick(Config); AxesVM = new AxesVM(_joystick, Config); ButtonsVM = new ButtonsVM(_joystick, Config); ButtonsVM.ConfigChanged += ButtonsVM_ConfigChanged; AxesToButtonsVM = new AxesToButtonsVM(_joystick, Config); AxesToButtonsVM.ConfigChanged += AxesToButtonsVM_ConfigChanged; ShiftRegistersVM = new ShiftRegistersVM(_joystick, Config); ShiftRegistersVM.ConfigChanged += ShiftRegistersVM_ConfigChanged; LedVM = new LedVM(_joystick, Config); LedVM.ConfigChanged += LedVM_ConfigChanged; FirmwareUpdaterVM = new FirmwareUpdaterVM(); GetDeviceConfig = new DelegateCommand(() => { _configExchanger.GetConfigRequest(); WriteLog("Requesting config..", false); }); SendDeviceConfig = new DelegateCommand(() => { _configExchanger.SendConfig(Config); WriteLog("Writting config..", false); }); ResetAllPins = new DelegateCommand(() => PinsVM.ResetPins()); SaveConfig = new DelegateCommand(() => SaveConfigToFile()); LoadConfig = new DelegateCommand(() => ReadConfigFromFile()); SetDefault = new DelegateCommand(() => LoadDefaultConfig()); LoadDefaultConfig(); Hid.Start(Config.Vid); Hid.DeviceAdded += DeviceAddedEventHandler; Hid.DeviceRemoved += DeviceRemovedEventHandler; Hid.DeviceListUpdated += Hid_DeviceListUpdated; // Try to connect to device if (HidDevices.Count > 0) { SelectedDeviceIndex = 0; } WriteLog("Program started", true); }
private void PinConfigChanged() { ButtonsVM.Update(Config); AxesVM.Update(Config); AxesToButtonsVM.Update(Config); ShiftRegistersVM.Update(Config); LedVM.Update(Config); }