void server_ForceBack(float f) { if (Math.Abs(f * 255 - preDamp) > 30) { DeviceDataManager.Damp d = new DeviceDataManager.Damp(); d.value = (int)(-f * 127 + 128); InfoControl.device.SetDamp(d); } preDamp = (int)(f * 255); }
void device_GetSportStatus(DeviceDataManager.SportStatus sportStatus) { if (LearningMode) { double[] input = { (double)DataCount / TrainingCount, (double)sportStatus.Speed / 20, (double)sportStatus.HeartRate / byte.MaxValue, (double)preLoad / byte.MaxValue }; double[] output = { (double)Shift / byte.MaxValue }; Console.WriteLine(sportStatus.load); Console.WriteLine(Shift); preLoad = Shift; inputList[DataCount] = input; outputList[DataCount] = output; DataCount++; if (DataCount == TrainingCount) { LearningMode = false; DataCount = 0; for (int i = 0; i < 5000; i++) { double error = bp.RunEpoch(inputList, outputList); listBox1.Invoke(new Action(() => { listBox1.Items.Add(error); })); } MessageBox.Show("Learning Over"); timer1.Start(); } } else { double[] input = { (double)DataCount / TrainingCount, (double)sportStatus.Speed / byte.MaxValue, /*(double)sportStatus.HeartRate*/ (double)60 / byte.MaxValue, (double)preLoad / byte.MaxValue }; double output = an.Compute(input)[0]; listBox2.Invoke(new Action(() => { listBox2.Items.Add(((int)(output * 255)).ToString()); })); BuzzWin.DeviceDataManager.Damp d = new DeviceDataManager.Damp(); d.value = (int)(output * 255); device.SetDamp(d); DataCount++; } }
void device_GetGameControl(DeviceDataManager.GameControl gameControl) { BuzzWin.DeviceDataManager.Damp d = new DeviceDataManager.Damp(); if (gameControl.Btn2) { if (Shift < 255) { Shift += 1; d.value = Shift; device.SetDamp(d); } } if (gameControl.Btn1) { if (Shift > 0) { Shift -= 1; d.value = Shift; device.SetDamp(d); } } }
void device_GetSportStatus(DeviceDataManager.SportStatus sportStatus) { if (LearningMode) { double[] input = { (double)DataCount / TrainingCount, (double)sportStatus.Speed / 20, (double)sportStatus.HeartRate / byte.MaxValue, (double)preLoad / byte.MaxValue }; double[] output = { (double)Shift / byte.MaxValue }; Console.WriteLine(sportStatus.load); Console.WriteLine(Shift); preLoad = Shift; inputList[DataCount] = input; outputList[DataCount] = output; loadData.Add(new LoadInfo(Shift, DataCount)); //loadData.Add(new LoadInfo(DataCount * 10 + 10, DataCount * 5 + 5)); //this.Dispatcher.Invoke(new Action(() => //{ // loadData.Add(new LoadInfo(2, 5)); // chartLoad.ItemsSource = loadData; // chartLoad.Refresh(); //})); this.Dispatcher.Invoke(new Action(() => { updateChartInfo(loadData); })); DataCount++; if (DataCount == TrainingCount) { LearningMode = false; DataCount = 0; for (int i = 0; i < 5000; i++) { double error = bp.RunEpoch(inputList, outputList); //listBox1.Invoke(new Action(() => //{ // listBox1.Items.Add(error); //})); Console.WriteLine(error); } MessageBox.Show("Learning Over"); } } else { double[] input = { (double)DataCount / TrainingCount, (double)sportStatus.Speed / byte.MaxValue, /*(double)sportStatus.HeartRate*/ (double)60 / byte.MaxValue, (double)preLoad / byte.MaxValue }; double output = an.Compute(input)[0]; //listBox2.Invoke(new Action(() => // { // listBox2.Items.Add(((int)(output * 255)).ToString()); // })); BuzzWin.DeviceDataManager.Damp d = new DeviceDataManager.Damp(); d.value = (int)(output * 255); loadData.Add(new LoadInfo(d.value, DataCount)); while (loadData.Count > MAX_COUNT) { loadData.RemoveAt(0); } this.Dispatcher.Invoke(new Action(() => { updateChartInfo(loadData); })); InfoControl.device.SetDamp(d); DataCount++; } }