/// <summary> /// Returns the parameter number for the parameter of a given servo, /// given the corresponding parameter number for servo 0. /// </summary> /// <param name="p">e.g. PARAMETER_SERVO0_HOME</param> /// <param name="servo">Channel number.</param> uscParameter specifyServo(uscParameter p, byte servo) { return (uscParameter)((byte)(p) + servo * servoParameterBytes); }
private unsafe ushort getRawParameter(uscParameter parameter) { Range range = Usc.getRange(parameter); ushort value = 0; byte[] array = new byte[range.bytes]; try { controlTransfer(0xC0, (byte)uscRequest.REQUEST_GET_PARAMETER, 0, (ushort)parameter, array); } catch (Exception e) { throw new Exception("There was an error getting parameter " + parameter.ToString() + " from the device.", e); } if (range.bytes == 1) { // read a single byte fixed (byte* pointer = array) { value = *(byte*)pointer; } } else { // read two bytes fixed (byte* pointer = array) { value = *(ushort*)pointer; } } return value; }
private void setRawParameter(uscParameter parameter, ushort value) { Range range = Usc.getRange(parameter); requireArgumentRange(value, range.minimumValue, range.maximumValue, parameter.ToString()); int bytes = range.bytes; setRawParameterNoChecks((ushort)parameter, value, bytes); }
protected static Range getRange(uscParameter parameterId) { if (parameterId == uscParameter.PARAMETER_INITIALIZED) return Range.u8; switch (parameterId) { case uscParameter.PARAMETER_SERVOS_AVAILABLE: return Range.u8; case uscParameter.PARAMETER_SERVO_PERIOD: return Range.u8; case uscParameter.PARAMETER_MINI_MAESTRO_SERVO_PERIOD_L: return Range.u8; case uscParameter.PARAMETER_MINI_MAESTRO_SERVO_PERIOD_HU: return Range.u16; case uscParameter.PARAMETER_SERVO_MULTIPLIER: return Range.u8; case uscParameter.PARAMETER_CHANNEL_MODES_0_3: case uscParameter.PARAMETER_CHANNEL_MODES_4_7: case uscParameter.PARAMETER_CHANNEL_MODES_8_11: case uscParameter.PARAMETER_CHANNEL_MODES_12_15: case uscParameter.PARAMETER_CHANNEL_MODES_16_19: case uscParameter.PARAMETER_CHANNEL_MODES_20_23: case uscParameter.PARAMETER_ENABLE_PULLUPS: return Range.u8; case uscParameter.PARAMETER_SERIAL_MODE: return new Range(1, 0, 3); case uscParameter.PARAMETER_SERIAL_BAUD_DETECT_TYPE: return new Range(1, 0, 1); case uscParameter.PARAMETER_SERIAL_NEVER_SUSPEND: return Range.boolean; case uscParameter.PARAMETER_SERIAL_TIMEOUT: return Range.u16; case uscParameter.PARAMETER_SERIAL_ENABLE_CRC: return Range.boolean; case uscParameter.PARAMETER_SERIAL_DEVICE_NUMBER: return Range.u7; case uscParameter.PARAMETER_SERIAL_FIXED_BAUD_RATE: return Range.u16; case uscParameter.PARAMETER_SERIAL_MINI_SSC_OFFSET: return new Range(1, 0, 254); case uscParameter.PARAMETER_SCRIPT_CRC: return Range.u16; case uscParameter.PARAMETER_SCRIPT_DONE: return Range.boolean; } // must be one of the servo parameters switch ((((byte)parameterId - (byte)uscParameter.PARAMETER_SERVO0_HOME) % 9) + (byte)uscParameter.PARAMETER_SERVO0_HOME) { case (byte)uscParameter.PARAMETER_SERVO0_HOME: case (byte)uscParameter.PARAMETER_SERVO0_NEUTRAL: return new Range(2, 0, 32440); // 32640 - 200 case (byte)uscParameter.PARAMETER_SERVO0_RANGE: return new Range(1, 1, 50); // the upper limit could be adjusted case (byte)uscParameter.PARAMETER_SERVO0_SPEED: case (byte)uscParameter.PARAMETER_SERVO0_MAX: case (byte)uscParameter.PARAMETER_SERVO0_MIN: case (byte)uscParameter.PARAMETER_SERVO0_ACCELERATION: return Range.u8; } throw new ArgumentException("Invalid parameterId " + parameterId.ToString() + ", can not determine the range of this parameter."); }