private void btnAutoFixAngle_Click(object sender, RoutedEventArgs e) { if (activeServo > 0) { byte id = (byte)activeServo; string sFixAngle = txtFixAngle.Text.Trim(); if (sFixAngle == "") { UpdateInfo("Please enter current angle", UTIL.InfoType.error); return; } int iFixAngle; if ((!int.TryParse(sFixAngle, out iFixAngle)) || (iFixAngle < 0) || (iFixAngle > 180)) { UpdateInfo("Invalid angle, should be 0 ~ 180", UTIL.InfoType.error); return; } // first get current adjustment UInt16 adj = UBT.V2_GetAdjAngle(id); if (adj == 0x7F7F) { return; } int adjValue = 0; if ((adj >= 0x0000) && (adj <= 0x0130)) { adjValue = adj; } else if ((adj >= 0xFED0) && (adj <= 0xFFFF)) { adjValue = (adj - 65536); } else { UpdateInfo("Invalid adjustment", UTIL.InfoType.error); return; } // get current angle Byte currAngle = UBT.V2_GetAngle(id); if (currAngle == 0xFF) { return; } int delta = cboDelta.SelectedIndex; // adjValue = 3 * angle int newAdjValue = (currAngle - iFixAngle) * 3 + adjValue; if (newAdjValue < 0) { newAdjValue += 65536 + delta; } SetAdjAngle(newAdjValue); txtAdjPreview.Text = sFixAngle; SetServoAdjAngle(); } }
private void ReadAdjAngle() { UpdateInfo(); UInt16 adj = UBT.V2_GetAdjAngle((byte)activeServo); if (adj != 0x7F7F) { SetAdjAngle((int)adj); } }
public void ReadAdjAngle() { UpdateInfo(); if (activeServo <= 0) { return; } UInt16 adj = UBT.V2_GetAdjAngle((byte)activeServo); if (adj != 0x7F7F) { SetAdjAngle((int)adj); } }