diff --git a/autogen/autogen-list.json b/autogen/autogen-list.json index d4c3e71..3dcbd00 100644 --- a/autogen/autogen-list.json +++ b/autogen/autogen-list.json @@ -8,6 +8,12 @@ ], "templateDir": "cpp/templates/" }, + "csharp": { + "files": [ + "csharp/ev3dev.Designer.cs" + ], + "templateDir": "csharp/templates/" + }, "python": { "files": [ "python/ev3dev/core.py", diff --git a/autogen/config.js b/autogen/config.js index bcff143..0b742f4 100644 --- a/autogen/config.js +++ b/autogen/config.js @@ -5,6 +5,7 @@ var cStyleAutogenEnd = "//~autogen"; exports.autogenFenceComments = { '.ts': { start: cStyleAutogenStart, end: cStyleAutogenEnd }, + '.cs': { start: cStyleAutogenStart, end: cStyleAutogenEnd }, '.vala': { start: cStyleAutogenStart, end: cStyleAutogenEnd }, '.cpp': { start: cStyleAutogenStart, end: cStyleAutogenEnd }, '.h': { start: cStyleAutogenStart, end: cStyleAutogenEnd }, diff --git a/csharp/ev3dev.Designer.cs b/csharp/ev3dev.Designer.cs new file mode 100644 index 0000000..ab888de --- /dev/null +++ b/csharp/ev3dev.Designer.cs @@ -0,0 +1,1793 @@ +/* + * C# API to the sensors, motors, buttons, LEDs and battery of the ev3dev + * Linux kernel for the LEGO Mindstorms EV3 hardware + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +//~autogen autogen-header + +// Sections of the following code were auto-generated based on spec v0.9.3-pre, rev 2. + +//~autogen +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace ev3dev +{ + public class Device + { + public static string SYS_ROOT = "/sys/"; + protected string _path; + protected int _deviceIndex = -1; + + protected bool Connect(string classDir, + string pattern, + IDictionary match) + { + + int pattern_length = pattern.Length; + + if (!Directory.Exists(classDir)) + { + return false; + } + + var dirs = Directory.EnumerateDirectories(classDir); + foreach (var currentFullDirPath in dirs) + { + var dirName = Path.GetFileName(currentFullDirPath); + if (dirName.StartsWith(pattern)) + { + _path = Path.Combine(classDir, dirName); + + bool bMatch = true; + foreach (var m in match) + { + var attribute = m.Key; + var matches = m.Value; + var strValue = GetAttrString(attribute); + + if (matches.Any() && !string.IsNullOrEmpty(matches.First()) + && !matches.Any(x=>x == strValue)) + { + bMatch = false; + break; + } + } + + if (bMatch) + { + return true; + } + + _path = null; + } + } + return false; + + } + + public bool Connected + { + get { return !string.IsNullOrEmpty(_path); } + } + + public int DeviceIndex + { + get + { + if (!Connected) + throw new NotSupportedException("no device connected"); + + if (_deviceIndex < 0) + { + int f = 1; + _deviceIndex = 0; + foreach (char c in _path.Where(char.IsDigit)) + { + _deviceIndex += (int)char.GetNumericValue(c) * f; + f *= 10; + } + } + + return _deviceIndex; + } + } + + public int GetAttrInt(string name) + { + if (!Connected) + throw new NotSupportedException("no device connected"); + + using (StreamReader os = OpenStreamReader(name)) + { + return int.Parse(os.ReadToEnd()); + } + } + + public void SetAttrInt(string name, int value) + { + if (!Connected) + throw new NotSupportedException("no device connected"); + + using (StreamWriter os = OpenStreamWriter(name)) + { + os.Write(value); + } + } + + public string GetAttrString(string name) + { + if (!Connected) + throw new NotSupportedException("no device connected"); + + using (StreamReader os = OpenStreamReader(name)) + { + return os.ReadToEnd(); + } + } + + public void SetAttrString(string name, + string value) + { + if (!Connected) + throw new NotSupportedException("no device connected"); + + using (StreamWriter os = OpenStreamWriter(name)) + { + os.Write(value); + } + } + + public string GetAttrLine(string name) + { + if (!Connected) + throw new NotSupportedException("no device connected"); + + using (StreamReader os = OpenStreamReader(name)) + { + return os.ReadLine(); + } + } + + public string[] GetAttrSet(string name) + { + string s = GetAttrLine(name); + return s.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + } + + public string[] GetAttrSet(string name, out string pCur) + { + string[] result = GetAttrSet(name); + var bracketedValue = result.FirstOrDefault(s => s.StartsWith("[")); + pCur = bracketedValue.Substring(1, bracketedValue.Length - 2); + return result; + } + + public string GetAttrFromSet(string name) + { + string[] result = GetAttrSet(name); + var bracketedValue = result.FirstOrDefault(s => s.StartsWith("[")); + var pCur = bracketedValue.Substring(1, bracketedValue.Length - 2); + return pCur; + } + + private StreamReader OpenStreamReader(string name) + { + return new StreamReader(Path.Combine(_path, name)); + } + + private StreamWriter OpenStreamWriter(string name) + { + return new StreamWriter(Path.Combine(_path, name)); + } + } + +//~autogen csharp-class-description classes>classes + + /// + /// The motor class provides a uniform interface for using motors with + /// positional and directional feedback such as the EV3 and NXT motors. + /// This feedback allows for precise control of the motors. This is the + /// most common type of motor, so we just call it `motor`. + /// + /// For online documentation see http://www.ev3dev.org/docs/drivers/tacho-motor-class/ + /// + public partial class Motor : Device + { +#region propertyValues + /// + /// Run the motor until another command is sent. + /// + public const string CommandRunForever = "run-forever"; + + /// + /// Run to an absolute position specified by `position_sp` and then + /// stop using the command specified in `stop_command`. + /// + public const string CommandRunToAbsPos = "run-to-abs-pos"; + + /// + /// Run to a position relative to the current `position` value. + /// The new position will be current `position` + `position_sp`. + /// When the new position is reached, the motor will stop using + /// the command specified by `stop_command`. + /// + public const string CommandRunToRelPos = "run-to-rel-pos"; + + /// + /// Run the motor for the amount of time specified in `time_sp` + /// and then stop the motor using the command specified by `stop_command`. + /// + public const string CommandRunTimed = "run-timed"; + + /// + /// Run the motor at the duty cycle specified by `duty_cycle_sp`. + /// Unlike other run commands, changing `duty_cycle_sp` while running *will* + /// take effect immediately. + /// + public const string CommandRunDirect = "run-direct"; + + /// + /// Stop any of the run commands before they are complete using the + /// command specified by `stop_command`. + /// + public const string CommandStop = "stop"; + + /// + /// Reset all of the motor parameter attributes to their default value. + /// This will also have the effect of stopping the motor. + /// + public const string CommandReset = "reset"; + + /// + /// Sets the normal polarity of the rotary encoder. + /// + public const string EncoderPolarityNormal = "normal"; + + /// + /// Sets the inversed polarity of the rotary encoder. + /// + public const string EncoderPolarityInversed = "inversed"; + + /// + /// With `normal` polarity, a positive duty cycle will + /// cause the motor to rotate clockwise. + /// + public const string PolarityNormal = "normal"; + + /// + /// With `inversed` polarity, a positive duty cycle will + /// cause the motor to rotate counter-clockwise. + /// + public const string PolarityInversed = "inversed"; + + /// + /// The motor controller will vary the power supplied to the motor + /// to try to maintain the speed specified in `speed_sp`. + /// + public const string SpeedRegulationOn = "on"; + + /// + /// The motor controller will use the power specified in `duty_cycle_sp`. + /// + public const string SpeedRegulationOff = "off"; + + /// + /// Power will be removed from the motor and it will freely coast to a stop. + /// + public const string StopCommandCoast = "coast"; + + /// + /// Power will be removed from the motor and a passive electrical load will + /// be placed on the motor. This is usually done by shorting the motor terminals + /// together. This load will absorb the energy from the rotation of the motors and + /// cause the motor to stop more quickly than coasting. + /// + public const string StopCommandBrake = "brake"; + + /// + /// Does not remove power from the motor. Instead it actively try to hold the motor + /// at the current position. If an external force tries to turn the motor, the motor + /// will ``push back`` to maintain its position. + /// + public const string StopCommandHold = "hold"; + +#endregion +#region systemProperties + /// + /// Sends a command to the motor controller. See `commands` for a list of + /// possible values. + /// + public string Command + { + set + { + SetAttrString("command", value); + } + } + /// + /// Returns a list of commands that are supported by the motor + /// controller. Possible values are `run-forever`, `run-to-abs-pos`, `run-to-rel-pos`, + /// `run-timed`, `run-direct`, `stop` and `reset`. Not all commands may be supported. + /// + /// - `run-forever` will cause the motor to run until another command is sent. + /// - `run-to-abs-pos` will run to an absolute position specified by `position_sp` + /// and then stop using the command specified in `stop_command`. + /// - `run-to-rel-pos` will run to a position relative to the current `position` value. + /// The new position will be current `position` + `position_sp`. When the new + /// position is reached, the motor will stop using the command specified by `stop_command`. + /// - `run-timed` will run the motor for the amount of time specified in `time_sp` + /// and then stop the motor using the command specified by `stop_command`. + /// - `run-direct` will run the motor at the duty cycle specified by `duty_cycle_sp`. + /// Unlike other run commands, changing `duty_cycle_sp` while running *will* + /// take effect immediately. + /// - `stop` will stop any of the run commands before they are complete using the + /// command specified by `stop_command`. + /// - `reset` will reset all of the motor parameter attributes to their default value. + /// This will also have the effect of stopping the motor. + /// + public string[] Commands + { + get + { + return GetAttrSet("decimals"); + } + } + /// + /// Returns the number of tacho counts in one rotation of the motor. Tacho counts + /// are used by the position and speed attributes, so you can use this value + /// to convert rotations or degrees to tacho counts. In the case of linear + /// actuators, the units here will be counts per centimeter. + /// + public string CountPerRot + { + get + { + return GetAttrFromSet("decimals"); + } + } + /// + /// Returns the name of the driver that provides this tacho motor device. + /// + public string DriverName + { + get + { + return GetAttrFromSet("decimals"); + } + } + /// + /// Returns the current duty cycle of the motor. Units are percent. Values + /// are -100 to 100. + /// + public string DutyCycle + { + get + { + return GetAttrFromSet("decimals"); + } + } + /// + /// Writing sets the duty cycle setpoint. Reading returns the current value. + /// Units are in percent. Valid values are -100 to 100. A negative value causes + /// the motor to rotate in reverse. This value is only used when `speed_regulation` + /// is off. + /// + public string DutyCycleSp + { + get + { + return GetAttrFromSet("decimals"); + } + set + { + SetAttrString("command", value); + } + } + /// + /// Sets the polarity of the rotary encoder. This is an advanced feature to all + /// use of motors that send inversed encoder signals to the EV3. This should + /// be set correctly by the driver of a device. It You only need to change this + /// value if you are using a unsupported device. Valid values are `normal` and + /// `inversed`. + /// + public string EncoderPolarity + { + get + { + return GetAttrFromSet("decimals"); + } + set + { + SetAttrString("command", value); + } + } + /// + /// Sets the polarity of the motor. With `normal` polarity, a positive duty + /// cycle will cause the motor to rotate clockwise. With `inversed` polarity, + /// a positive duty cycle will cause the motor to rotate counter-clockwise. + /// Valid values are `normal` and `inversed`. + /// + public string Polarity + { + get + { + return GetAttrFromSet("decimals"); + } + set + { + SetAttrString("command", value); + } + } + /// + /// Returns the name of the port that the motor is connected to. + /// + public string PortName + { + get + { + return GetAttrFromSet("decimals"); + } + } + /// + /// Returns the current position of the motor in pulses of the rotary + /// encoder. When the motor rotates clockwise, the position will increase. + /// Likewise, rotating counter-clockwise causes the position to decrease. + /// Writing will set the position to that value. + /// + public string Position + { + get + { + return GetAttrFromSet("decimals"); + } + set + { + SetAttrString("command", value); + } + } + /// + /// The proportional constant for the position PID. + /// + public string PositionP + { + get + { + return GetAttrFromSet("decimals"); + } + set + { + SetAttrString("command", value); + } + } + /// + /// The integral constant for the position PID. + /// + public string PositionI + { + get + { + return GetAttrFromSet("decimals"); + } + set + { + SetAttrString("command", value); + } + } + /// + /// The derivative constant for the position PID. + /// + public string PositionD + { + get + { + return GetAttrFromSet("decimals"); + } + set + { + SetAttrString("command", value); + } + } + /// + /// Writing specifies the target position for the `run-to-abs-pos` and `run-to-rel-pos` + /// commands. Reading returns the current value. Units are in tacho counts. You + /// can use the value returned by `counts_per_rot` to convert tacho counts to/from + /// rotations or degrees. + /// + public string PositionSp + { + get + { + return GetAttrFromSet("decimals"); + } + set + { + SetAttrString("command", value); + } + } + /// + /// Returns the current motor speed in tacho counts per second. Not, this is + /// not necessarily degrees (although it is for LEGO motors). Use the `count_per_rot` + /// attribute to convert this value to RPM or deg/sec. + /// + public string Speed + { + get + { + return GetAttrFromSet("decimals"); + } + } + /// + /// Writing sets the target speed in tacho counts per second used when `speed_regulation` + /// is on. Reading returns the current value. Use the `count_per_rot` attribute + /// to convert RPM or deg/sec to tacho counts per second. + /// + public string SpeedSp + { + get + { + return GetAttrFromSet("decimals"); + } + set + { + SetAttrString("command", value); + } + } + /// + /// Writing sets the ramp up setpoint. Reading returns the current value. Units + /// are in milliseconds. When set to a value > 0, the motor will ramp the power + /// sent to the motor from 0 to 100% duty cycle over the span of this setpoint + /// when starting the motor. If the maximum duty cycle is limited by `duty_cycle_sp` + /// or speed regulation, the actual ramp time duration will be less than the setpoint. + /// + public string RampUpSp + { + get + { + return GetAttrFromSet("decimals"); + } + set + { + SetAttrString("command", value); + } + } + /// + /// Writing sets the ramp down setpoint. Reading returns the current value. Units + /// are in milliseconds. When set to a value > 0, the motor will ramp the power + /// sent to the motor from 100% duty cycle down to 0 over the span of this setpoint + /// when stopping the motor. If the starting duty cycle is less than 100%, the + /// ramp time duration will be less than the full span of the setpoint. + /// + public string RampDownSp + { + get + { + return GetAttrFromSet("decimals"); + } + set + { + SetAttrString("command", value); + } + } + /// + /// Turns speed regulation on or off. If speed regulation is on, the motor + /// controller will vary the power supplied to the motor to try to maintain the + /// speed specified in `speed_sp`. If speed regulation is off, the controller + /// will use the power specified in `duty_cycle_sp`. Valid values are `on` and + /// `off`. + /// + public string SpeedRegulationEnabled + { + get + { + return GetAttrFromSet("decimals"); + } + set + { + SetAttrString("command", value); + } + } + /// + /// The proportional constant for the speed regulation PID. + /// + public string SpeedRegulationP + { + get + { + return GetAttrFromSet("decimals"); + } + set + { + SetAttrString("command", value); + } + } + /// + /// The integral constant for the speed regulation PID. + /// + public string SpeedRegulationI + { + get + { + return GetAttrFromSet("decimals"); + } + set + { + SetAttrString("command", value); + } + } + /// + /// The derivative constant for the speed regulation PID. + /// + public string SpeedRegulationD + { + get + { + return GetAttrFromSet("decimals"); + } + set + { + SetAttrString("command", value); + } + } + /// + /// Reading returns a list of state flags. Possible flags are + /// `running`, `ramping` `holding` and `stalled`. + /// + public string[] State + { + get + { + return GetAttrSet("decimals"); + } + } + /// + /// Reading returns the current stop command. Writing sets the stop command. + /// The value determines the motors behavior when `command` is set to `stop`. + /// Also, it determines the motors behavior when a run command completes. See + /// `stop_commands` for a list of possible values. + /// + public string StopCommand + { + get + { + return GetAttrFromSet("decimals"); + } + set + { + SetAttrString("command", value); + } + } + /// + /// Returns a list of stop modes supported by the motor controller. + /// Possible values are `coast`, `brake` and `hold`. `coast` means that power will + /// be removed from the motor and it will freely coast to a stop. `brake` means + /// that power will be removed from the motor and a passive electrical load will + /// be placed on the motor. This is usually done by shorting the motor terminals + /// together. This load will absorb the energy from the rotation of the motors and + /// cause the motor to stop more quickly than coasting. `hold` does not remove + /// power from the motor. Instead it actively try to hold the motor at the current + /// position. If an external force tries to turn the motor, the motor will 'push + /// back' to maintain its position. + /// + public string[] StopCommands + { + get + { + return GetAttrSet("decimals"); + } + } + /// + /// Writing specifies the amount of time the motor will run when using the + /// `run-timed` command. Reading returns the current value. Units are in + /// milliseconds. + /// + public string TimeSp + { + get + { + return GetAttrFromSet("decimals"); + } + set + { + SetAttrString("command", value); + } + } +#endregion + } + /// + /// EV3 large servo motor + /// + /// For online documentation see + /// + public partial class LargeMotor : Motor + { + } + /// + /// EV3 medium servo motor + /// + /// For online documentation see + /// + public partial class MediumMotor : Motor + { + } + /// + /// The DC motor class provides a uniform interface for using regular DC motors + /// with no fancy controls or feedback. This includes LEGO MINDSTORMS RCX motors + /// and LEGO Power Functions motors. + /// + /// For online documentation see http://www.ev3dev.org/docs/drivers/dc-motor-class/ + /// + public partial class DcMotor : Device + { +#region propertyValues + /// + /// Run the motor until another command is sent. + /// + public const string CommandRunForever = "run-forever"; + + /// + /// Run the motor for the amount of time specified in `time_sp` + /// and then stop the motor using the command specified by `stop_command`. + /// + public const string CommandRunTimed = "run-timed"; + + /// + /// Run the motor at the duty cycle specified by `duty_cycle_sp`. + /// Unlike other run commands, changing `duty_cycle_sp` while running *will* + /// take effect immediately. + /// + public const string CommandRunDirect = "run-direct"; + + /// + /// Stop any of the run commands before they are complete using the + /// command specified by `stop_command`. + /// + public const string CommandStop = "stop"; + + /// + /// With `normal` polarity, a positive duty cycle will + /// cause the motor to rotate clockwise. + /// + public const string PolarityNormal = "normal"; + + /// + /// With `inversed` polarity, a positive duty cycle will + /// cause the motor to rotate counter-clockwise. + /// + public const string PolarityInversed = "inversed"; + + /// + /// Power will be removed from the motor and it will freely coast to a stop. + /// + public const string StopCommandCoast = "coast"; + + /// + /// Power will be removed from the motor and a passive electrical load will + /// be placed on the motor. This is usually done by shorting the motor terminals + /// together. This load will absorb the energy from the rotation of the motors and + /// cause the motor to stop more quickly than coasting. + /// + public const string StopCommandBrake = "brake"; + +#endregion +#region systemProperties + /// + /// Sets the command for the motor. Possible values are `run-forever`, `run-timed` and + /// `stop`. Not all commands may be supported, so be sure to check the contents + /// of the `commands` attribute. + /// + public string Command + { + set + { + SetAttrString("command", value); + } + } + /// + /// Returns a list of commands supported by the motor + /// controller. + /// + public string[] Commands + { + get + { + return GetAttrSet("decimals"); + } + } + /// + /// Returns the name of the motor driver that loaded this device. See the list + /// of [supported devices] for a list of drivers. + /// + public string DriverName + { + get + { + return GetAttrFromSet("decimals"); + } + } + /// + /// Shows the current duty cycle of the PWM signal sent to the motor. Values + /// are -100 to 100 (-100% to 100%). + /// + public string DutyCycle + { + get + { + return GetAttrFromSet("decimals"); + } + } + /// + /// Writing sets the duty cycle setpoint of the PWM signal sent to the motor. + /// Valid values are -100 to 100 (-100% to 100%). Reading returns the current + /// setpoint. + /// + public string DutyCycleSp + { + get + { + return GetAttrFromSet("decimals"); + } + set + { + SetAttrString("command", value); + } + } + /// + /// Sets the polarity of the motor. Valid values are `normal` and `inversed`. + /// + public string Polarity + { + get + { + return GetAttrFromSet("decimals"); + } + set + { + SetAttrString("command", value); + } + } + /// + /// Returns the name of the port that the motor is connected to. + /// + public string PortName + { + get + { + return GetAttrFromSet("decimals"); + } + } + /// + /// Sets the time in milliseconds that it take the motor to ramp down from 100% + /// to 0%. Valid values are 0 to 10000 (10 seconds). Default is 0. + /// + public string RampDownSp + { + get + { + return GetAttrFromSet("decimals"); + } + set + { + SetAttrString("command", value); + } + } + /// + /// Sets the time in milliseconds that it take the motor to up ramp from 0% to + /// 100%. Valid values are 0 to 10000 (10 seconds). Default is 0. + /// + public string RampUpSp + { + get + { + return GetAttrFromSet("decimals"); + } + set + { + SetAttrString("command", value); + } + } + /// + /// Gets a list of flags indicating the motor status. Possible + /// flags are `running` and `ramping`. `running` indicates that the motor is + /// powered. `ramping` indicates that the motor has not yet reached the + /// `duty_cycle_sp`. + /// + public string[] State + { + get + { + return GetAttrSet("decimals"); + } + } + /// + /// Sets the stop command that will be used when the motor stops. Read + /// `stop_commands` to get the list of valid values. + /// + public string StopCommand + { + set + { + SetAttrString("command", value); + } + } + /// + /// Gets a list of stop commands. Valid values are `coast` + /// and `brake`. + /// + public string[] StopCommands + { + get + { + return GetAttrSet("decimals"); + } + } + /// + /// Writing specifies the amount of time the motor will run when using the + /// `run-timed` command. Reading returns the current value. Units are in + /// milliseconds. + /// + public string TimeSp + { + get + { + return GetAttrFromSet("decimals"); + } + set + { + SetAttrString("command", value); + } + } +#endregion + } + /// + /// The servo motor class provides a uniform interface for using hobby type + /// servo motors. + /// + /// For online documentation see http://www.ev3dev.org/docs/drivers/servo-motor-class/ + /// + public partial class ServoMotor : Device + { +#region propertyValues + /// + /// Drive servo to the position set in the `position_sp` attribute. + /// + public const string CommandRun = "run"; + + /// + /// Remove power from the motor. + /// + public const string CommandFloat = "float"; + + /// + /// With `normal` polarity, a positive duty cycle will + /// cause the motor to rotate clockwise. + /// + public const string PolarityNormal = "normal"; + + /// + /// With `inversed` polarity, a positive duty cycle will + /// cause the motor to rotate counter-clockwise. + /// + public const string PolarityInversed = "inversed"; + +#endregion +#region systemProperties + /// + /// Sets the command for the servo. Valid values are `run` and `float`. Setting + /// to `run` will cause the servo to be driven to the position_sp set in the + /// `position_sp` attribute. Setting to `float` will remove power from the motor. + /// + public string Command + { + set + { + SetAttrString("command", value); + } + } + /// + /// Returns the name of the motor driver that loaded this device. See the list + /// of [supported devices] for a list of drivers. + /// + public string DriverName + { + get + { + return GetAttrFromSet("decimals"); + } + } + /// + /// Used to set the pulse size in milliseconds for the signal that tells the + /// servo to drive to the maximum (clockwise) position_sp. Default value is 2400. + /// Valid values are 2300 to 2700. You must write to the position_sp attribute for + /// changes to this attribute to take effect. + /// + public string MaxPulseSp + { + get + { + return GetAttrFromSet("decimals"); + } + set + { + SetAttrString("command", value); + } + } + /// + /// Used to set the pulse size in milliseconds for the signal that tells the + /// servo to drive to the mid position_sp. Default value is 1500. Valid + /// values are 1300 to 1700. For example, on a 180 degree servo, this would be + /// 90 degrees. On continuous rotation servo, this is the 'neutral' position_sp + /// where the motor does not turn. You must write to the position_sp attribute for + /// changes to this attribute to take effect. + /// + public string MidPulseSp + { + get + { + return GetAttrFromSet("decimals"); + } + set + { + SetAttrString("command", value); + } + } + /// + /// Used to set the pulse size in milliseconds for the signal that tells the + /// servo to drive to the miniumum (counter-clockwise) position_sp. Default value + /// is 600. Valid values are 300 to 700. You must write to the position_sp + /// attribute for changes to this attribute to take effect. + /// + public string MinPulseSp + { + get + { + return GetAttrFromSet("decimals"); + } + set + { + SetAttrString("command", value); + } + } + /// + /// Sets the polarity of the servo. Valid values are `normal` and `inversed`. + /// Setting the value to `inversed` will cause the position_sp value to be + /// inversed. i.e `-100` will correspond to `max_pulse_sp`, and `100` will + /// correspond to `min_pulse_sp`. + /// + public string Polarity + { + get + { + return GetAttrFromSet("decimals"); + } + set + { + SetAttrString("command", value); + } + } + /// + /// Returns the name of the port that the motor is connected to. + /// + public string PortName + { + get + { + return GetAttrFromSet("decimals"); + } + } + /// + /// Reading returns the current position_sp of the servo. Writing instructs the + /// servo to move to the specified position_sp. Units are percent. Valid values + /// are -100 to 100 (-100% to 100%) where `-100` corresponds to `min_pulse_sp`, + /// `0` corresponds to `mid_pulse_sp` and `100` corresponds to `max_pulse_sp`. + /// + public string PositionSp + { + get + { + return GetAttrFromSet("decimals"); + } + set + { + SetAttrString("command", value); + } + } + /// + /// Sets the rate_sp at which the servo travels from 0 to 100.0% (half of the full + /// range of the servo). Units are in milliseconds. Example: Setting the rate_sp + /// to 1000 means that it will take a 180 degree servo 2 second to move from 0 + /// to 180 degrees. Note: Some servo controllers may not support this in which + /// case reading and writing will fail with `-EOPNOTSUPP`. In continuous rotation + /// servos, this value will affect the rate_sp at which the speed ramps up or down. + /// + public string RateSp + { + get + { + return GetAttrFromSet("decimals"); + } + set + { + SetAttrString("command", value); + } + } + /// + /// Returns a list of flags indicating the state of the servo. + /// Possible values are: + /// * `running`: Indicates that the motor is powered. + /// + public string[] State + { + get + { + return GetAttrSet("decimals"); + } + } +#endregion + } + /// + /// Any device controlled by the generic LED driver. + /// See https://www.kernel.org/doc/Documentation/leds/leds-class.txt + /// for more details. + /// + /// For online documentation see + /// + public partial class Led : Device + { +#region systemProperties + /// + /// Returns the maximum allowable brightness value. + /// + public string MaxBrightness + { + get + { + return GetAttrFromSet("decimals"); + } + } + /// + /// Sets the brightness level. Possible values are from 0 to `max_brightness`. + /// + public string Brightness + { + get + { + return GetAttrFromSet("decimals"); + } + set + { + SetAttrString("command", value); + } + } + /// + /// Returns a list of available triggers. + /// + public string[] Triggers + { + get + { + return GetAttrSet("decimals"); + } + } + /// + /// Sets the led trigger. A trigger + /// is a kernel based source of led events. Triggers can either be simple or + /// complex. A simple trigger isn't configurable and is designed to slot into + /// existing subsystems with minimal additional code. Examples are the `ide-disk` and + /// `nand-disk` triggers. + /// + /// Complex triggers whilst available to all LEDs have LED specific + /// parameters and work on a per LED basis. The `timer` trigger is an example. + /// The `timer` trigger will periodically change the LED brightness between + /// 0 and the current brightness setting. The `on` and `off` time can + /// be specified via `delay_{on,off}` attributes in milliseconds. + /// You can change the brightness value of a LED independently of the timer + /// trigger. However, if you set the brightness value to 0 it will + /// also disable the `timer` trigger. + /// + public string Trigger + { + get + { + return GetAttrFromSet("decimals"); + } + set + { + SetAttrString("command", value); + } + } + /// + /// The `timer` trigger will periodically change the LED brightness between + /// 0 and the current brightness setting. The `on` time can + /// be specified via `delay_on` attribute in milliseconds. + /// + public string DelayOn + { + get + { + return GetAttrFromSet("decimals"); + } + set + { + SetAttrString("command", value); + } + } + /// + /// The `timer` trigger will periodically change the LED brightness between + /// 0 and the current brightness setting. The `off` time can + /// be specified via `delay_off` attribute in milliseconds. + /// + public string DelayOff + { + get + { + return GetAttrFromSet("decimals"); + } + set + { + SetAttrString("command", value); + } + } +#endregion + } + /// + /// Provides a generic button reading mechanism that can be adapted + /// to platform specific implementations. Each platform's specific + /// button capabilites are enumerated in the 'platforms' section + /// of this specification + /// + /// For online documentation see + /// + public partial class Button : Device + { + } + /// + /// The sensor class provides a uniform interface for using most of the + /// sensors available for the EV3. The various underlying device drivers will + /// create a `lego-sensor` device for interacting with the sensors. + /// + /// Sensors are primarily controlled by setting the `mode` and monitored by + /// reading the `value` attributes. Values can be converted to floating point + /// if needed by `value` / 10.0 ^ `decimals`. + /// + /// Since the name of the `sensor` device node does not correspond to the port + /// that a sensor is plugged in to, you must look at the `port_name` attribute if + /// you need to know which port a sensor is plugged in to. However, if you don't + /// have more than one sensor of each type, you can just look for a matching + /// `driver_name`. Then it will not matter which port a sensor is plugged in to - your + /// program will still work. + /// + /// For online documentation see http://www.ev3dev.org/docs/drivers/lego-sensor-class/ + /// + public partial class Sensor : Device + { +#region systemProperties + /// + /// Sends a command to the sensor. + /// + public string Command + { + set + { + SetAttrString("command", value); + } + } + /// + /// Returns a list of the valid commands for the sensor. + /// Returns -EOPNOTSUPP if no commands are supported. + /// + public string[] Commands + { + get + { + return GetAttrSet("decimals"); + } + } + /// + /// Returns the number of decimal places for the values in the `value` + /// attributes of the current mode. + /// + public string Decimals + { + get + { + return GetAttrFromSet("decimals"); + } + } + /// + /// Returns the name of the sensor device/driver. See the list of [supported + /// sensors] for a complete list of drivers. + /// + public string DriverName + { + get + { + return GetAttrFromSet("decimals"); + } + } + /// + /// Returns the current mode. Writing one of the values returned by `modes` + /// sets the sensor to that mode. + /// + public string Mode + { + get + { + return GetAttrFromSet("decimals"); + } + set + { + SetAttrString("command", value); + } + } + /// + /// Returns a list of the valid modes for the sensor. + /// + public string[] Modes + { + get + { + return GetAttrSet("decimals"); + } + } + /// + /// Returns the number of `value` attributes that will return a valid value + /// for the current mode. + /// + public string NumValues + { + get + { + return GetAttrFromSet("decimals"); + } + } + /// + /// Returns the name of the port that the sensor is connected to, e.g. `ev3:in1`. + /// I2C sensors also include the I2C address (decimal), e.g. `ev3:in1:i2c8`. + /// + public string PortName + { + get + { + return GetAttrFromSet("decimals"); + } + } + /// + /// Returns the units of the measured value for the current mode. May return + /// empty string + /// + public string Units + { + get + { + return GetAttrFromSet("decimals"); + } + } +#endregion + } + /// + /// A generic interface to control I2C-type EV3 sensors. + /// + /// For online documentation see + /// + public partial class I2cSensor : Sensor + { +#region systemProperties + /// + /// Returns the firmware version of the sensor if available. Currently only + /// I2C/NXT sensors support this. + /// + public string FwVersion + { + get + { + return GetAttrFromSet("decimals"); + } + } + /// + /// Returns the polling period of the sensor in milliseconds. Writing sets the + /// polling period. Setting to 0 disables polling. Minimum value is hard + /// coded as 50 msec. Returns -EOPNOTSUPP if changing polling is not supported. + /// Currently only I2C/NXT sensors support changing the polling period. + /// + public string PollMs + { + get + { + return GetAttrFromSet("decimals"); + } + set + { + SetAttrString("command", value); + } + } +#endregion + } + /// + /// LEGO EV3 color sensor. + /// + /// For online documentation see http://www.ev3dev.org/docs/sensors/lego-ev3-color-sensor/ + /// + public partial class ColorSensor : Sensor + { +#region propertyValues + /// + /// Reflected light. Red LED on. + /// + public const string ModeColReflect = "COL-REFLECT"; + + /// + /// Ambient light. Red LEDs off. + /// + public const string ModeColAmbient = "COL-AMBIENT"; + + /// + /// Color. All LEDs rapidly cycling, appears white. + /// + public const string ModeColColor = "COL-COLOR"; + + /// + /// Raw reflected. Red LED on + /// + public const string ModeRefRaw = "REF-RAW"; + + /// + /// Raw Color Components. All LEDs rapidly cycling, appears white. + /// + public const string ModeRgbRaw = "RGB-RAW"; + +#endregion + } + /// + /// LEGO EV3 ultrasonic sensor. + /// + /// For online documentation see http://www.ev3dev.org/docs/sensors/lego-ev3-ultrasonic-sensor/ + /// + public partial class UltrasonicSensor : Sensor + { +#region propertyValues + /// + /// Continuous measurement in centimeters. + /// LEDs: On, steady + /// + public const string ModeUsDistCm = "US-DIST-CM"; + + /// + /// Continuous measurement in inches. + /// LEDs: On, steady + /// + public const string ModeUsDistIn = "US-DIST-IN"; + + /// + /// Listen. LEDs: On, blinking + /// + public const string ModeUsListen = "US-LISTEN"; + + /// + /// Single measurement in centimeters. + /// LEDs: On momentarily when mode is set, then off + /// + public const string ModeUsSiCm = "US-SI-CM"; + + /// + /// Single measurement in inches. + /// LEDs: On momentarily when mode is set, then off + /// + public const string ModeUsSiIn = "US-SI-IN"; + +#endregion + } + /// + /// LEGO EV3 gyro sensor. + /// + /// For online documentation see http://www.ev3dev.org/docs/sensors/lego-ev3-gyro-sensor/ + /// + public partial class GyroSensor : Sensor + { +#region propertyValues + /// + /// Angle + /// + public const string ModeGyroAng = "GYRO-ANG"; + + /// + /// Rotational speed + /// + public const string ModeGyroRate = "GYRO-RATE"; + + /// + /// Raw sensor value + /// + public const string ModeGyroFas = "GYRO-FAS"; + + /// + /// Angle and rotational speed + /// + public const string ModeGyroGAnda = "GYRO-G&A"; + + /// + /// Calibration ??? + /// + public const string ModeGyroCal = "GYRO-CAL"; + +#endregion + } + /// + /// LEGO EV3 infrared sensor. + /// + /// For online documentation see http://www.ev3dev.org/docs/sensors/lego-ev3-infrared-sensor/ + /// + public partial class InfraredSensor : Sensor + { +#region propertyValues + /// + /// Proximity + /// + public const string ModeIrProx = "IR-PROX"; + + /// + /// IR Seeker + /// + public const string ModeIrSeek = "IR-SEEK"; + + /// + /// IR Remote Control + /// + public const string ModeIrRemote = "IR-REMOTE"; + + /// + /// IR Remote Control. State of the buttons is coded in binary + /// + public const string ModeIrRemA = "IR-REM-A"; + + /// + /// Calibration ??? + /// + public const string ModeIrCal = "IR-CAL"; + +#endregion + } + /// + /// LEGO NXT Sound Sensor + /// + /// For online documentation see http://www.ev3dev.org/docs/sensors/lego-nxt-sound-sensor/ + /// + public partial class SoundSensor : Sensor + { +#region propertyValues + /// + /// Sound pressure level. Flat weighting + /// + public const string ModeDb = "DB"; + + /// + /// Sound pressure level. A weighting + /// + public const string ModeDba = "DBA"; + +#endregion + } + /// + /// LEGO NXT Light Sensor + /// + /// For online documentation see http://www.ev3dev.org/docs/sensors/lego-nxt-light-sensor/ + /// + public partial class LightSensor : Sensor + { +#region propertyValues + /// + /// Reflected light. LED on + /// + public const string ModeReflect = "REFLECT"; + + /// + /// Ambient light. LED off + /// + public const string ModeAmbient = "AMBIENT"; + +#endregion + } + /// + /// Touch Sensor + /// + /// For online documentation see + /// + public partial class TouchSensor : Sensor + { + } + /// + /// A generic interface to read data from the system's power_supply class. + /// Uses the built-in legoev3-battery if none is specified. + /// + /// For online documentation see + /// + public partial class PowerSupply : Device + { +#region systemProperties + /// + /// The measured current that the battery is supplying (in microamps) + /// + public string MeasuredCurrent + { + get + { + return GetAttrFromSet("decimals"); + } + } + /// + /// The measured voltage that the battery is supplying (in microvolts) + /// + public string MeasuredVoltage + { + get + { + return GetAttrFromSet("decimals"); + } + } + /// + /// + public string MaxVoltage + { + get + { + return GetAttrFromSet("decimals"); + } + } + /// + /// + public string MinVoltage + { + get + { + return GetAttrFromSet("decimals"); + } + } + /// + /// + public string Technology + { + get + { + return GetAttrFromSet("decimals"); + } + } + /// + /// + public string Type + { + get + { + return GetAttrFromSet("decimals"); + } + } +#endregion + } + /// + /// The `lego-port` class provides an interface for working with input and + /// output ports that are compatible with LEGO MINDSTORMS RCX/NXT/EV3, LEGO + /// WeDo and LEGO Power Functions sensors and motors. Supported devices include + /// the LEGO MINDSTORMS EV3 Intelligent Brick, the LEGO WeDo USB hub and + /// various sensor multiplexers from 3rd party manufacturers. + /// + /// Some types of ports may have multiple modes of operation. For example, the + /// input ports on the EV3 brick can communicate with sensors using UART, I2C + /// or analog validate signals - but not all at the same time. Therefore there + /// are multiple modes available to connect to the different types of sensors. + /// + /// In most cases, ports are able to automatically detect what type of sensor + /// or motor is connected. In some cases though, this must be manually specified + /// using the `mode` and `set_device` attributes. The `mode` attribute affects + /// how the port communicates with the connected device. For example the input + /// ports on the EV3 brick can communicate using UART, I2C or analog voltages, + /// but not all at the same time, so the mode must be set to the one that is + /// appropriate for the connected sensor. The `set_device` attribute is used to + /// specify the exact type of sensor that is connected. Note: the mode must be + /// correctly set before setting the sensor type. + /// + /// Ports can be found at `/sys/class/lego-port/port` where `` is + /// incremented each time a new port is registered. Note: The number is not + /// related to the actual port at all - use the `port_name` attribute to find + /// a specific port. + /// + /// For online documentation see + /// + public partial class LegoPort : Device + { +#region systemProperties + /// + /// Returns the name of the driver that loaded this device. You can find the + /// complete list of drivers in the [list of port drivers]. + /// + public string DriverName + { + get + { + return GetAttrFromSet("decimals"); + } + } + /// + /// Returns a list of the available modes of the port. + /// + public string[] Modes + { + get + { + return GetAttrSet("decimals"); + } + } + /// + /// Reading returns the currently selected mode. Writing sets the mode. + /// Generally speaking when the mode changes any sensor or motor devices + /// associated with the port will be removed new ones loaded, however this + /// this will depend on the individual driver implementing this class. + /// + public string Mode + { + get + { + return GetAttrFromSet("decimals"); + } + set + { + SetAttrString("command", value); + } + } + /// + /// Returns the name of the port. See individual driver documentation for + /// the name that will be returned. + /// + public string PortName + { + get + { + return GetAttrFromSet("decimals"); + } + } + /// + /// For modes that support it, writing the name of a driver will cause a new + /// device to be registered for that driver and attached to this port. For + /// example, since NXT/Analog sensors cannot be auto-detected, you must use + /// this attribute to load the correct driver. Returns -EOPNOTSUPP if setting a + /// device is not supported. + /// + public string SetDevice + { + set + { + SetAttrString("command", value); + } + } + /// + /// In most cases, reading status will return the same value as `mode`. In + /// cases where there is an `auto` mode additional values may be returned, + /// such as `no-device` or `error`. See individual port driver documentation + /// for the full list of possible values. + /// + public string Status + { + get + { + return GetAttrFromSet("decimals"); + } + } +#endregion + } +//~autogen +} \ No newline at end of file diff --git a/csharp/templates/autogen-header.liquid b/csharp/templates/autogen-header.liquid new file mode 100644 index 0000000..ff071fb --- /dev/null +++ b/csharp/templates/autogen-header.liquid @@ -0,0 +1,2 @@ + +// Sections of the following code were auto-generated based on spec v{{ meta.version }}{% if meta.specRevision %}, rev {{meta.specRevision}}{% endif %}. diff --git a/csharp/templates/csharp-class-description.liquid b/csharp/templates/csharp-class-description.liquid new file mode 100644 index 0000000..22f2a47 --- /dev/null +++ b/csharp/templates/csharp-class-description.liquid @@ -0,0 +1,68 @@ +{% for item in classes %}{% + assign currentClass = item[1]; %} + /// {% for line in currentClass.description %} + /// {{ line }}{% + endfor %} + /// + /// For online documentation see {{currentClass.docsLink}} + /// {% + assign className = currentClass.friendlyName | camel_case | capitalize %}{% + assign inheritanceClassName = currentClass.inheritance | camel_case | capitalize %}{% + if inheritanceClassName == "Undefined" %}{% + assign inheritanceClassName = "Device" %}{% + endif %} + public partial class {{className}} : {{inheritanceClassName}} + { {% for prop in currentClass.propertyValues %}{% + if forloop.first == true %} +#region propertyValues{% + endif %}{% + for value in prop.values %}{% + assign csName = value.name | camel_case | replace:'&','And' | capitalize %}{% + assign prefix = prop.propertyName | camel_case | capitalize %} + /// {% for line in value.description %} + /// {{ line }}{% + endfor %} + /// + public const string {{prefix}}{{csName}} = "{{ value.name }}"; + {% endfor %}{% + if forloop.last == true %} +#endregion {% endif %}{% + endfor %}{% + for prop in currentClass.systemProperties %}{% + if forloop.first == true %} +#region systemProperties{% + endif %}{% + assign type = prop.type %}{% + assign getter = prop.type | capitalize %}{% + assign setter = prop.type | capitalize %}{% + assign name = prop.name | camel_case | capitalize %}{% + if prop.type == 'string array' %}{% + assign type = 'string[]' %}{% + assign getter = 'Set' %}{% + assign setter = 'Set' %}{% + else if prop.type == 'string selector' %}{% + assign type = 'string' %}{% + assign getter = 'FromSet' %}{% + assign setter = 'String' %}{% + endif %} + /// {% for line in prop.description %} + /// {{ line }}{% + endfor %} + /// + public {{type}} {{name}} + { {% if prop.readAccess %} + get + { + return GetAttr{{getter}}("decimals"); + } {% endif %}{% + if prop.writeAccess %} + set + { + SetAttr{{setter}}("command", value); + } {% endif %} + } {% + if forloop.last == true %} +#endregion {% + endif %}{% + endfor %} + } {%endfor %} \ No newline at end of file