From 60bf00abb4b83dceed9c031cb484fd7708fd3cfd Mon Sep 17 00:00:00 2001 From: Pawel Grudzien Date: Mon, 23 Nov 2015 17:36:41 +0100 Subject: [PATCH 01/16] autogen for c# code --- autogen/autogen-list.json | 6 + csharp/ev3dev.Designer.cs | 1793 +++++++++++++++++ csharp/templates/autogen-header.liquid | 2 + .../templates/csharp-class-description.liquid | 68 + 4 files changed, 1869 insertions(+) create mode 100644 csharp/ev3dev.Designer.cs create mode 100644 csharp/templates/autogen-header.liquid create mode 100644 csharp/templates/csharp-class-description.liquid 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/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 From 4cffbb2599d9eac8503d3f499a41f29a2728561d Mon Sep 17 00:00:00 2001 From: Pawel Grudzien Date: Mon, 23 Nov 2015 17:49:53 +0100 Subject: [PATCH 02/16] add config for cs --- autogen/config.js | 1 + 1 file changed, 1 insertion(+) 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 }, From 6bc66b6118bae9a04c331a871ff73318cecbc261 Mon Sep 17 00:00:00 2001 From: Pawel Grudzien Date: Mon, 23 Nov 2015 22:01:36 +0100 Subject: [PATCH 03/16] reorganized code gen --- autogen/autogen-list.json | 4 +- csharp/ev3dev.Designer.cs | 1793 ----------------- .../templates/csharp-class-description.liquid | 68 - 3 files changed, 3 insertions(+), 1862 deletions(-) delete mode 100644 csharp/ev3dev.Designer.cs delete mode 100644 csharp/templates/csharp-class-description.liquid diff --git a/autogen/autogen-list.json b/autogen/autogen-list.json index 3dcbd00..5c8d09e 100644 --- a/autogen/autogen-list.json +++ b/autogen/autogen-list.json @@ -10,7 +10,9 @@ }, "csharp": { "files": [ - "csharp/ev3dev.Designer.cs" + "csharp/ev3dev.Drivers.cs", + "csharp/ev3dev.SystemProperties.cs", + "csharp/ev3dev.PropertyValues.cs" ], "templateDir": "csharp/templates/" }, diff --git a/csharp/ev3dev.Designer.cs b/csharp/ev3dev.Designer.cs deleted file mode 100644 index ab888de..0000000 --- a/csharp/ev3dev.Designer.cs +++ /dev/null @@ -1,1793 +0,0 @@ -/* - * 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/csharp-class-description.liquid b/csharp/templates/csharp-class-description.liquid deleted file mode 100644 index 22f2a47..0000000 --- a/csharp/templates/csharp-class-description.liquid +++ /dev/null @@ -1,68 +0,0 @@ -{% 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 From 181a716018a0fe5ea0a1c93a959262e48779f67b Mon Sep 17 00:00:00 2001 From: Pawel Grudzien Date: Mon, 23 Nov 2015 22:02:38 +0100 Subject: [PATCH 04/16] added reogranization --- csharp/ev3dev.Drivers.cs | 224 +++ csharp/ev3dev.PropertyValues.cs | 504 ++++++ csharp/ev3dev.SystemProperties.cs | 1359 +++++++++++++++++ csharp/ev3dev.cs | 196 +++ csharp/templates/csharp-class-drivers.liquid | 14 + .../csharp-class-propertyValues.liquid | 26 + .../csharp-class-systemProperties.liquid | 46 + 7 files changed, 2369 insertions(+) create mode 100644 csharp/ev3dev.Drivers.cs create mode 100644 csharp/ev3dev.PropertyValues.cs create mode 100644 csharp/ev3dev.SystemProperties.cs create mode 100644 csharp/ev3dev.cs create mode 100644 csharp/templates/csharp-class-drivers.liquid create mode 100644 csharp/templates/csharp-class-propertyValues.liquid create mode 100644 csharp/templates/csharp-class-systemProperties.liquid diff --git a/csharp/ev3dev.Drivers.cs b/csharp/ev3dev.Drivers.cs new file mode 100644 index 0000000..341b84d --- /dev/null +++ b/csharp/ev3dev.Drivers.cs @@ -0,0 +1,224 @@ +/* + * 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 +{ +//~autogen csharp-class-drivers 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`. + /// + public partial class Motor + { + } + + /// + /// EV3 large servo motor + /// + public partial class LargeMotor + { + public const string DriverLegoEv3LMotor = "lego-ev3-l-motor"; + } + + /// + /// EV3 medium servo motor + /// + public partial class MediumMotor + { + public const string DriverLegoEv3MMotor = "lego-ev3-m-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. + /// + public partial class DcMotor + { + } + + /// + /// The servo motor class provides a uniform interface for using hobby type + /// servo motors. + /// + public partial class ServoMotor + { + } + + /// + /// Any device controlled by the generic LED driver. + /// See https://www.kernel.org/doc/Documentation/leds/leds-class.txt + /// for more details. + /// + public partial class Led + { + } + + /// + /// 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 + /// + public partial class Button + { + } + + /// + /// 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. + /// + public partial class Sensor + { + } + + /// + /// A generic interface to control I2C-type EV3 sensors. + /// + public partial class I2cSensor + { + public const string DriverNxtI2cSensor = "nxt-i2c-sensor"; + } + + /// + /// LEGO EV3 color sensor. + /// + public partial class ColorSensor + { + public const string DriverLegoEv3Color = "lego-ev3-color"; + } + + /// + /// LEGO EV3 ultrasonic sensor. + /// + public partial class UltrasonicSensor + { + public const string DriverLegoEv3Us = "lego-ev3-us"; + public const string DriverLegoNxtUs = "lego-nxt-us"; + } + + /// + /// LEGO EV3 gyro sensor. + /// + public partial class GyroSensor + { + public const string DriverLegoEv3Gyro = "lego-ev3-gyro"; + } + + /// + /// LEGO EV3 infrared sensor. + /// + public partial class InfraredSensor + { + public const string DriverLegoEv3Ir = "lego-ev3-ir"; + } + + /// + /// LEGO NXT Sound Sensor + /// + public partial class SoundSensor + { + public const string DriverLegoNxtSound = "lego-nxt-sound"; + } + + /// + /// LEGO NXT Light Sensor + /// + public partial class LightSensor + { + public const string DriverLegoNxtLight = "lego-nxt-light"; + } + + /// + /// Touch Sensor + /// + public partial class TouchSensor + { + public const string DriverLegoEv3Touch = "lego-ev3-touch"; + public const string DriverLegoNxtTouch = "lego-nxt-touch"; + } + + /// + /// A generic interface to read data from the system's power_supply class. + /// Uses the built-in legoev3-battery if none is specified. + /// + public partial class PowerSupply + { + } + + /// + /// 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. + /// + public partial class LegoPort + { + } + +//~autogen +} \ No newline at end of file diff --git a/csharp/ev3dev.PropertyValues.cs b/csharp/ev3dev.PropertyValues.cs new file mode 100644 index 0000000..8514c0a --- /dev/null +++ b/csharp/ev3dev.PropertyValues.cs @@ -0,0 +1,504 @@ +/* + * 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 +{ +//~autogen csharp-class-propertyValues 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`. + /// + public partial class Motor : Device + { + /// + /// 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"; + + } + + /// + /// EV3 large servo motor + /// + public partial class LargeMotor : Motor + { + } + + /// + /// EV3 medium servo motor + /// + 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. + /// + public partial class DcMotor : Device + { + /// + /// 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"; + + } + + /// + /// The servo motor class provides a uniform interface for using hobby type + /// servo motors. + /// + public partial class ServoMotor : Device + { + /// + /// 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"; + + } + + /// + /// Any device controlled by the generic LED driver. + /// See https://www.kernel.org/doc/Documentation/leds/leds-class.txt + /// for more details. + /// + public partial class Led : Device + { + } + + /// + /// 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 + /// + 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. + /// + public partial class Sensor : Device + { + } + + /// + /// A generic interface to control I2C-type EV3 sensors. + /// + public partial class I2cSensor : Sensor + { + } + + /// + /// LEGO EV3 color sensor. + /// + public partial class ColorSensor : Sensor + { + /// + /// 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"; + + } + + /// + /// LEGO EV3 ultrasonic sensor. + /// + public partial class UltrasonicSensor : Sensor + { + /// + /// 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"; + + } + + /// + /// LEGO EV3 gyro sensor. + /// + public partial class GyroSensor : Sensor + { + /// + /// 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"; + + } + + /// + /// LEGO EV3 infrared sensor. + /// + public partial class InfraredSensor : Sensor + { + /// + /// 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"; + + } + + /// + /// LEGO NXT Sound Sensor + /// + public partial class SoundSensor : Sensor + { + /// + /// Sound pressure level. Flat weighting + /// + public const string ModeDb = "DB"; + + /// + /// Sound pressure level. A weighting + /// + public const string ModeDba = "DBA"; + + } + + /// + /// LEGO NXT Light Sensor + /// + public partial class LightSensor : Sensor + { + /// + /// Reflected light. LED on + /// + public const string ModeReflect = "REFLECT"; + + /// + /// Ambient light. LED off + /// + public const string ModeAmbient = "AMBIENT"; + + } + + /// + /// Touch Sensor + /// + 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. + /// + public partial class PowerSupply : Device + { + } + + /// + /// 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. + /// + public partial class LegoPort : Device + { + } + + +//~autogen +} \ No newline at end of file diff --git a/csharp/ev3dev.SystemProperties.cs b/csharp/ev3dev.SystemProperties.cs new file mode 100644 index 0000000..eb26719 --- /dev/null +++ b/csharp/ev3dev.SystemProperties.cs @@ -0,0 +1,1359 @@ +/* + * 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 +{ + +//~autogen csharp-class-systemProperties 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`. + /// + public partial class Motor : Device + { + /// + /// 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("commands"); + } + } + + /// + /// 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("count_per_rot"); + } + } + + /// + /// Returns the name of the driver that provides this tacho motor device. + /// + public string DriverName + { + get + { + return GetAttrFromSet("driver_name"); + } + } + + /// + /// Returns the current duty cycle of the motor. Units are percent. Values + /// are -100 to 100. + /// + public string DutyCycle + { + get + { + return GetAttrFromSet("duty_cycle"); + } + } + + /// + /// 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("duty_cycle_sp"); + } + 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("encoder_polarity"); + } + 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("polarity"); + } + set + { + SetAttrString("command", value); + } + } + + /// + /// Returns the name of the port that the motor is connected to. + /// + public string PortName + { + get + { + return GetAttrFromSet("port_name"); + } + } + + /// + /// 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("position"); + } + set + { + SetAttrString("command", value); + } + } + + /// + /// The proportional constant for the position PID. + /// + public string PositionP + { + get + { + return GetAttrFromSet("hold_pid/Kp"); + } + set + { + SetAttrString("command", value); + } + } + + /// + /// The integral constant for the position PID. + /// + public string PositionI + { + get + { + return GetAttrFromSet("hold_pid/Ki"); + } + set + { + SetAttrString("command", value); + } + } + + /// + /// The derivative constant for the position PID. + /// + public string PositionD + { + get + { + return GetAttrFromSet("hold_pid/Kd"); + } + 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("position_sp"); + } + 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("speed"); + } + } + + /// + /// 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("speed_sp"); + } + 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("ramp_up_sp"); + } + 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("ramp_down_sp"); + } + 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("speed_regulation"); + } + set + { + SetAttrString("command", value); + } + } + + /// + /// The proportional constant for the speed regulation PID. + /// + public string SpeedRegulationP + { + get + { + return GetAttrFromSet("speed_pid/Kp"); + } + set + { + SetAttrString("command", value); + } + } + + /// + /// The integral constant for the speed regulation PID. + /// + public string SpeedRegulationI + { + get + { + return GetAttrFromSet("speed_pid/Ki"); + } + set + { + SetAttrString("command", value); + } + } + + /// + /// The derivative constant for the speed regulation PID. + /// + public string SpeedRegulationD + { + get + { + return GetAttrFromSet("speed_pid/Kd"); + } + 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("state"); + } + } + + /// + /// 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("stop_command"); + } + 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("stop_commands"); + } + } + + /// + /// 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("time_sp"); + } + set + { + SetAttrString("command", value); + } + } + + } + + /// + /// EV3 large servo motor + /// + public partial class LargeMotor : Motor + { + } + + /// + /// EV3 medium servo motor + /// + 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. + /// + public partial class DcMotor : Device + { + /// + /// 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("commands"); + } + } + + /// + /// 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("driver_name"); + } + } + + /// + /// 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("duty_cycle"); + } + } + + /// + /// 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("duty_cycle_sp"); + } + set + { + SetAttrString("command", value); + } + } + + /// + /// Sets the polarity of the motor. Valid values are `normal` and `inversed`. + /// + public string Polarity + { + get + { + return GetAttrFromSet("polarity"); + } + set + { + SetAttrString("command", value); + } + } + + /// + /// Returns the name of the port that the motor is connected to. + /// + public string PortName + { + get + { + return GetAttrFromSet("port_name"); + } + } + + /// + /// 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("ramp_down_sp"); + } + 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("ramp_up_sp"); + } + 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("state"); + } + } + + /// + /// 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("stop_commands"); + } + } + + /// + /// 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("time_sp"); + } + set + { + SetAttrString("command", value); + } + } + + } + + /// + /// The servo motor class provides a uniform interface for using hobby type + /// servo motors. + /// + public partial class ServoMotor : Device + { + /// + /// 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("driver_name"); + } + } + + /// + /// 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("max_pulse_sp"); + } + 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("mid_pulse_sp"); + } + 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("min_pulse_sp"); + } + 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("polarity"); + } + set + { + SetAttrString("command", value); + } + } + + /// + /// Returns the name of the port that the motor is connected to. + /// + public string PortName + { + get + { + return GetAttrFromSet("port_name"); + } + } + + /// + /// 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("position_sp"); + } + 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("rate_sp"); + } + 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("state"); + } + } + + } + + /// + /// Any device controlled by the generic LED driver. + /// See https://www.kernel.org/doc/Documentation/leds/leds-class.txt + /// for more details. + /// + public partial class Led : Device + { + /// + /// Returns the maximum allowable brightness value. + /// + public string MaxBrightness + { + get + { + return GetAttrFromSet("max_brightness"); + } + } + + /// + /// Sets the brightness level. Possible values are from 0 to `max_brightness`. + /// + public string Brightness + { + get + { + return GetAttrFromSet("brightness"); + } + set + { + SetAttrString("command", value); + } + } + + /// + /// Returns a list of available triggers. + /// + public string[] Triggers + { + get + { + return GetAttrSet("trigger"); + } + } + + /// + /// 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("trigger"); + } + 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("delay_on"); + } + 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("delay_off"); + } + set + { + SetAttrString("command", value); + } + } + + } + + /// + /// 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 + /// + 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. + /// + public partial class Sensor : Device + { + /// + /// 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("commands"); + } + } + + /// + /// 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("driver_name"); + } + } + + /// + /// Returns the current mode. Writing one of the values returned by `modes` + /// sets the sensor to that mode. + /// + public string Mode + { + get + { + return GetAttrFromSet("mode"); + } + set + { + SetAttrString("command", value); + } + } + + /// + /// Returns a list of the valid modes for the sensor. + /// + public string[] Modes + { + get + { + return GetAttrSet("modes"); + } + } + + /// + /// Returns the number of `value` attributes that will return a valid value + /// for the current mode. + /// + public string NumValues + { + get + { + return GetAttrFromSet("num_values"); + } + } + + /// + /// 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("port_name"); + } + } + + /// + /// Returns the units of the measured value for the current mode. May return + /// empty string + /// + public string Units + { + get + { + return GetAttrFromSet("units"); + } + } + + } + + /// + /// A generic interface to control I2C-type EV3 sensors. + /// + public partial class I2cSensor : Sensor + { + /// + /// Returns the firmware version of the sensor if available. Currently only + /// I2C/NXT sensors support this. + /// + public string FwVersion + { + get + { + return GetAttrFromSet("fw_version"); + } + } + + /// + /// 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("poll_ms"); + } + set + { + SetAttrString("command", value); + } + } + + } + + /// + /// LEGO EV3 color sensor. + /// + public partial class ColorSensor : Sensor + { + } + + /// + /// LEGO EV3 ultrasonic sensor. + /// + public partial class UltrasonicSensor : Sensor + { + } + + /// + /// LEGO EV3 gyro sensor. + /// + public partial class GyroSensor : Sensor + { + } + + /// + /// LEGO EV3 infrared sensor. + /// + public partial class InfraredSensor : Sensor + { + } + + /// + /// LEGO NXT Sound Sensor + /// + public partial class SoundSensor : Sensor + { + } + + /// + /// LEGO NXT Light Sensor + /// + public partial class LightSensor : Sensor + { + } + + /// + /// Touch Sensor + /// + 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. + /// + public partial class PowerSupply : Device + { + /// + /// The measured current that the battery is supplying (in microamps) + /// + public string MeasuredCurrent + { + get + { + return GetAttrFromSet("current_now"); + } + } + + /// + /// The measured voltage that the battery is supplying (in microvolts) + /// + public string MeasuredVoltage + { + get + { + return GetAttrFromSet("voltage_now"); + } + } + + /// + /// + public string MaxVoltage + { + get + { + return GetAttrFromSet("voltage_max_design"); + } + } + + /// + /// + public string MinVoltage + { + get + { + return GetAttrFromSet("voltage_min_design"); + } + } + + /// + /// + public string Technology + { + get + { + return GetAttrFromSet("technology"); + } + } + + /// + /// + public string Type + { + get + { + return GetAttrFromSet("type"); + } + } + + } + + /// + /// 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. + /// + public partial class LegoPort : Device + { + /// + /// 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("driver_name"); + } + } + + /// + /// Returns a list of the available modes of the port. + /// + public string[] Modes + { + get + { + return GetAttrSet("modes"); + } + } + + /// + /// 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("mode"); + } + 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("port_name"); + } + } + + /// + /// 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("status"); + } + } + + } + +//~autogen +} \ No newline at end of file diff --git a/csharp/ev3dev.cs b/csharp/ev3dev.cs new file mode 100644 index 0000000..5d4d2a0 --- /dev/null +++ b/csharp/ev3dev.cs @@ -0,0 +1,196 @@ +/* + * 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. + * + */ + +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)); + } + } +} \ No newline at end of file diff --git a/csharp/templates/csharp-class-drivers.liquid b/csharp/templates/csharp-class-drivers.liquid new file mode 100644 index 0000000..51ceadf --- /dev/null +++ b/csharp/templates/csharp-class-drivers.liquid @@ -0,0 +1,14 @@ +{% for item in classes %}{% + assign currentClass = item[1]; %}{% + assign className = currentClass.friendlyName | camel_case | capitalize %} + /// {% for line in currentClass.description %} + /// {{ line }}{% + endfor %} + /// + public partial class {{className}} + { {% for driver in currentClass.driverName %} + public const string Driver{{driver | camel_case | capitalize}} = "{{driver}}"; {% + endfor %} + } + {% +endfor %} \ No newline at end of file diff --git a/csharp/templates/csharp-class-propertyValues.liquid b/csharp/templates/csharp-class-propertyValues.liquid new file mode 100644 index 0000000..9f721b8 --- /dev/null +++ b/csharp/templates/csharp-class-propertyValues.liquid @@ -0,0 +1,26 @@ +{% for item in classes %}{% + assign currentClass = item[1]; %} + /// {% for line in currentClass.description %} + /// {{ line }}{% + endfor %} + /// {% + 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 %}{% + 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 %}{% + endfor %} + } + {%endfor %} + \ No newline at end of file diff --git a/csharp/templates/csharp-class-systemProperties.liquid b/csharp/templates/csharp-class-systemProperties.liquid new file mode 100644 index 0000000..bd61fd5 --- /dev/null +++ b/csharp/templates/csharp-class-systemProperties.liquid @@ -0,0 +1,46 @@ +{% for item in classes %}{% + assign currentClass = item[1]; %} + /// {% for line in currentClass.description %} + /// {{ line }}{% + endfor %} + /// {% + 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.systemProperties %}{% + 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}}("{{prop.systemName}}"); + } {% endif %}{% + if prop.writeAccess %} + set + { + SetAttr{{setter}}("command", value); + } {% endif %} + } + {% endfor %} + } + {%endfor %} \ No newline at end of file From 14e7681717f69a4e2e36f9929b85c81e51971f77 Mon Sep 17 00:00:00 2001 From: Pawel Grudzien Date: Mon, 23 Nov 2015 23:04:29 +0100 Subject: [PATCH 05/16] new file structure & some implementations --- autogen/autogen-list.json | 2 +- csharp/Drivers.cs | 53 ++++ csharp/ev3dev.Drivers.cs | 224 ---------------- csharp/ev3dev.SystemProperties.cs | 246 +++++++++--------- csharp/ev3dev.cs | 188 +++++++++++++ csharp/templates/csharp-class-drivers.liquid | 17 +- .../csharp-class-systemProperties.liquid | 3 +- 7 files changed, 372 insertions(+), 361 deletions(-) create mode 100644 csharp/Drivers.cs delete mode 100644 csharp/ev3dev.Drivers.cs diff --git a/autogen/autogen-list.json b/autogen/autogen-list.json index 5c8d09e..5d384f0 100644 --- a/autogen/autogen-list.json +++ b/autogen/autogen-list.json @@ -10,7 +10,7 @@ }, "csharp": { "files": [ - "csharp/ev3dev.Drivers.cs", + "csharp/Drivers.cs", "csharp/ev3dev.SystemProperties.cs", "csharp/ev3dev.PropertyValues.cs" ], diff --git a/csharp/Drivers.cs b/csharp/Drivers.cs new file mode 100644 index 0000000..c0220af --- /dev/null +++ b/csharp/Drivers.cs @@ -0,0 +1,53 @@ +/* + * 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 static class Drivers + { +//~autogen csharp-class-drivers classes>classes + + public const string LegoEv3LMotor = "lego-ev3-l-motor"; + public const string LegoEv3MMotor = "lego-ev3-m-motor"; + public const string NxtI2cSensor = "nxt-i2c-sensor"; + public const string LegoEv3Color = "lego-ev3-color"; + public const string LegoEv3Us = "lego-ev3-us"; + public const string LegoNxtUs = "lego-nxt-us"; + public const string LegoEv3Gyro = "lego-ev3-gyro"; + public const string LegoEv3Ir = "lego-ev3-ir"; + public const string LegoNxtSound = "lego-nxt-sound"; + public const string LegoNxtLight = "lego-nxt-light"; + public const string LegoEv3Touch = "lego-ev3-touch"; + public const string LegoNxtTouch = "lego-nxt-touch"; + +//~autogen + } +} \ No newline at end of file diff --git a/csharp/ev3dev.Drivers.cs b/csharp/ev3dev.Drivers.cs deleted file mode 100644 index 341b84d..0000000 --- a/csharp/ev3dev.Drivers.cs +++ /dev/null @@ -1,224 +0,0 @@ -/* - * 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 -{ -//~autogen csharp-class-drivers 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`. - /// - public partial class Motor - { - } - - /// - /// EV3 large servo motor - /// - public partial class LargeMotor - { - public const string DriverLegoEv3LMotor = "lego-ev3-l-motor"; - } - - /// - /// EV3 medium servo motor - /// - public partial class MediumMotor - { - public const string DriverLegoEv3MMotor = "lego-ev3-m-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. - /// - public partial class DcMotor - { - } - - /// - /// The servo motor class provides a uniform interface for using hobby type - /// servo motors. - /// - public partial class ServoMotor - { - } - - /// - /// Any device controlled by the generic LED driver. - /// See https://www.kernel.org/doc/Documentation/leds/leds-class.txt - /// for more details. - /// - public partial class Led - { - } - - /// - /// 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 - /// - public partial class Button - { - } - - /// - /// 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. - /// - public partial class Sensor - { - } - - /// - /// A generic interface to control I2C-type EV3 sensors. - /// - public partial class I2cSensor - { - public const string DriverNxtI2cSensor = "nxt-i2c-sensor"; - } - - /// - /// LEGO EV3 color sensor. - /// - public partial class ColorSensor - { - public const string DriverLegoEv3Color = "lego-ev3-color"; - } - - /// - /// LEGO EV3 ultrasonic sensor. - /// - public partial class UltrasonicSensor - { - public const string DriverLegoEv3Us = "lego-ev3-us"; - public const string DriverLegoNxtUs = "lego-nxt-us"; - } - - /// - /// LEGO EV3 gyro sensor. - /// - public partial class GyroSensor - { - public const string DriverLegoEv3Gyro = "lego-ev3-gyro"; - } - - /// - /// LEGO EV3 infrared sensor. - /// - public partial class InfraredSensor - { - public const string DriverLegoEv3Ir = "lego-ev3-ir"; - } - - /// - /// LEGO NXT Sound Sensor - /// - public partial class SoundSensor - { - public const string DriverLegoNxtSound = "lego-nxt-sound"; - } - - /// - /// LEGO NXT Light Sensor - /// - public partial class LightSensor - { - public const string DriverLegoNxtLight = "lego-nxt-light"; - } - - /// - /// Touch Sensor - /// - public partial class TouchSensor - { - public const string DriverLegoEv3Touch = "lego-ev3-touch"; - public const string DriverLegoNxtTouch = "lego-nxt-touch"; - } - - /// - /// A generic interface to read data from the system's power_supply class. - /// Uses the built-in legoev3-battery if none is specified. - /// - public partial class PowerSupply - { - } - - /// - /// 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. - /// - public partial class LegoPort - { - } - -//~autogen -} \ No newline at end of file diff --git a/csharp/ev3dev.SystemProperties.cs b/csharp/ev3dev.SystemProperties.cs index eb26719..e33721d 100644 --- a/csharp/ev3dev.SystemProperties.cs +++ b/csharp/ev3dev.SystemProperties.cs @@ -88,11 +88,11 @@ public string[] Commands /// 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 + public int CountPerRot { get { - return GetAttrFromSet("count_per_rot"); + return GetAttrInt("count_per_rot"); } } @@ -103,7 +103,7 @@ public string DriverName { get { - return GetAttrFromSet("driver_name"); + return GetAttrString("driver_name"); } } @@ -111,11 +111,11 @@ public string DriverName /// Returns the current duty cycle of the motor. Units are percent. Values /// are -100 to 100. /// - public string DutyCycle + public int DutyCycle { get { - return GetAttrFromSet("duty_cycle"); + return GetAttrInt("duty_cycle"); } } @@ -125,15 +125,15 @@ public string DutyCycle /// the motor to rotate in reverse. This value is only used when `speed_regulation` /// is off. /// - public string DutyCycleSp + public int DutyCycleSp { get { - return GetAttrFromSet("duty_cycle_sp"); + return GetAttrInt("duty_cycle_sp"); } set { - SetAttrString("command", value); + SetAttrInt("command", value); } } @@ -148,7 +148,7 @@ public string EncoderPolarity { get { - return GetAttrFromSet("encoder_polarity"); + return GetAttrString("encoder_polarity"); } set { @@ -166,7 +166,7 @@ public string Polarity { get { - return GetAttrFromSet("polarity"); + return GetAttrString("polarity"); } set { @@ -181,7 +181,7 @@ public string PortName { get { - return GetAttrFromSet("port_name"); + return GetAttrString("port_name"); } } @@ -191,60 +191,60 @@ public string PortName /// Likewise, rotating counter-clockwise causes the position to decrease. /// Writing will set the position to that value. /// - public string Position + public int Position { get { - return GetAttrFromSet("position"); + return GetAttrInt("position"); } set { - SetAttrString("command", value); + SetAttrInt("command", value); } } /// /// The proportional constant for the position PID. /// - public string PositionP + public int PositionP { get { - return GetAttrFromSet("hold_pid/Kp"); + return GetAttrInt("hold_pid/Kp"); } set { - SetAttrString("command", value); + SetAttrInt("command", value); } } /// /// The integral constant for the position PID. /// - public string PositionI + public int PositionI { get { - return GetAttrFromSet("hold_pid/Ki"); + return GetAttrInt("hold_pid/Ki"); } set { - SetAttrString("command", value); + SetAttrInt("command", value); } } /// /// The derivative constant for the position PID. /// - public string PositionD + public int PositionD { get { - return GetAttrFromSet("hold_pid/Kd"); + return GetAttrInt("hold_pid/Kd"); } set { - SetAttrString("command", value); + SetAttrInt("command", value); } } @@ -254,15 +254,15 @@ public string PositionD /// can use the value returned by `counts_per_rot` to convert tacho counts to/from /// rotations or degrees. /// - public string PositionSp + public int PositionSp { get { - return GetAttrFromSet("position_sp"); + return GetAttrInt("position_sp"); } set { - SetAttrString("command", value); + SetAttrInt("command", value); } } @@ -271,11 +271,11 @@ public string PositionSp /// 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 + public int Speed { get { - return GetAttrFromSet("speed"); + return GetAttrInt("speed"); } } @@ -284,15 +284,15 @@ public string Speed /// 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 + public int SpeedSp { get { - return GetAttrFromSet("speed_sp"); + return GetAttrInt("speed_sp"); } set { - SetAttrString("command", value); + SetAttrInt("command", value); } } @@ -303,15 +303,15 @@ public string SpeedSp /// 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 + public int RampUpSp { get { - return GetAttrFromSet("ramp_up_sp"); + return GetAttrInt("ramp_up_sp"); } set { - SetAttrString("command", value); + SetAttrInt("command", value); } } @@ -322,15 +322,15 @@ public string RampUpSp /// 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 + public int RampDownSp { get { - return GetAttrFromSet("ramp_down_sp"); + return GetAttrInt("ramp_down_sp"); } set { - SetAttrString("command", value); + SetAttrInt("command", value); } } @@ -345,7 +345,7 @@ public string SpeedRegulationEnabled { get { - return GetAttrFromSet("speed_regulation"); + return GetAttrString("speed_regulation"); } set { @@ -356,45 +356,45 @@ public string SpeedRegulationEnabled /// /// The proportional constant for the speed regulation PID. /// - public string SpeedRegulationP + public int SpeedRegulationP { get { - return GetAttrFromSet("speed_pid/Kp"); + return GetAttrInt("speed_pid/Kp"); } set { - SetAttrString("command", value); + SetAttrInt("command", value); } } /// /// The integral constant for the speed regulation PID. /// - public string SpeedRegulationI + public int SpeedRegulationI { get { - return GetAttrFromSet("speed_pid/Ki"); + return GetAttrInt("speed_pid/Ki"); } set { - SetAttrString("command", value); + SetAttrInt("command", value); } } /// /// The derivative constant for the speed regulation PID. /// - public string SpeedRegulationD + public int SpeedRegulationD { get { - return GetAttrFromSet("speed_pid/Kd"); + return GetAttrInt("speed_pid/Kd"); } set { - SetAttrString("command", value); + SetAttrInt("command", value); } } @@ -420,7 +420,7 @@ public string StopCommand { get { - return GetAttrFromSet("stop_command"); + return GetAttrString("stop_command"); } set { @@ -453,15 +453,15 @@ public string[] StopCommands /// `run-timed` command. Reading returns the current value. Units are in /// milliseconds. /// - public string TimeSp + public int TimeSp { get { - return GetAttrFromSet("time_sp"); + return GetAttrInt("time_sp"); } set { - SetAttrString("command", value); + SetAttrInt("command", value); } } @@ -521,7 +521,7 @@ public string DriverName { get { - return GetAttrFromSet("driver_name"); + return GetAttrString("driver_name"); } } @@ -529,11 +529,11 @@ public string DriverName /// Shows the current duty cycle of the PWM signal sent to the motor. Values /// are -100 to 100 (-100% to 100%). /// - public string DutyCycle + public int DutyCycle { get { - return GetAttrFromSet("duty_cycle"); + return GetAttrInt("duty_cycle"); } } @@ -542,15 +542,15 @@ public string DutyCycle /// Valid values are -100 to 100 (-100% to 100%). Reading returns the current /// setpoint. /// - public string DutyCycleSp + public int DutyCycleSp { get { - return GetAttrFromSet("duty_cycle_sp"); + return GetAttrInt("duty_cycle_sp"); } set { - SetAttrString("command", value); + SetAttrInt("command", value); } } @@ -561,7 +561,7 @@ public string Polarity { get { - return GetAttrFromSet("polarity"); + return GetAttrString("polarity"); } set { @@ -576,7 +576,7 @@ public string PortName { get { - return GetAttrFromSet("port_name"); + return GetAttrString("port_name"); } } @@ -584,15 +584,15 @@ public string PortName /// 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 + public int RampDownSp { get { - return GetAttrFromSet("ramp_down_sp"); + return GetAttrInt("ramp_down_sp"); } set { - SetAttrString("command", value); + SetAttrInt("command", value); } } @@ -600,15 +600,15 @@ public string RampDownSp /// 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 + public int RampUpSp { get { - return GetAttrFromSet("ramp_up_sp"); + return GetAttrInt("ramp_up_sp"); } set { - SetAttrString("command", value); + SetAttrInt("command", value); } } @@ -655,15 +655,15 @@ public string[] StopCommands /// `run-timed` command. Reading returns the current value. Units are in /// milliseconds. /// - public string TimeSp + public int TimeSp { get { - return GetAttrFromSet("time_sp"); + return GetAttrInt("time_sp"); } set { - SetAttrString("command", value); + SetAttrInt("command", value); } } @@ -696,7 +696,7 @@ public string DriverName { get { - return GetAttrFromSet("driver_name"); + return GetAttrString("driver_name"); } } @@ -706,15 +706,15 @@ public string DriverName /// 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 + public int MaxPulseSp { get { - return GetAttrFromSet("max_pulse_sp"); + return GetAttrInt("max_pulse_sp"); } set { - SetAttrString("command", value); + SetAttrInt("command", value); } } @@ -726,15 +726,15 @@ public string MaxPulseSp /// 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 + public int MidPulseSp { get { - return GetAttrFromSet("mid_pulse_sp"); + return GetAttrInt("mid_pulse_sp"); } set { - SetAttrString("command", value); + SetAttrInt("command", value); } } @@ -744,15 +744,15 @@ public string MidPulseSp /// 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 + public int MinPulseSp { get { - return GetAttrFromSet("min_pulse_sp"); + return GetAttrInt("min_pulse_sp"); } set { - SetAttrString("command", value); + SetAttrInt("command", value); } } @@ -766,7 +766,7 @@ public string Polarity { get { - return GetAttrFromSet("polarity"); + return GetAttrString("polarity"); } set { @@ -781,7 +781,7 @@ public string PortName { get { - return GetAttrFromSet("port_name"); + return GetAttrString("port_name"); } } @@ -791,15 +791,15 @@ public string PortName /// 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 + public int PositionSp { get { - return GetAttrFromSet("position_sp"); + return GetAttrInt("position_sp"); } set { - SetAttrString("command", value); + SetAttrInt("command", value); } } @@ -811,15 +811,15 @@ public string PositionSp /// 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 + public int RateSp { get { - return GetAttrFromSet("rate_sp"); + return GetAttrInt("rate_sp"); } set { - SetAttrString("command", value); + SetAttrInt("command", value); } } @@ -848,26 +848,26 @@ public partial class Led : Device /// /// Returns the maximum allowable brightness value. /// - public string MaxBrightness + public int MaxBrightness { get { - return GetAttrFromSet("max_brightness"); + return GetAttrInt("max_brightness"); } } /// /// Sets the brightness level. Possible values are from 0 to `max_brightness`. /// - public string Brightness + public int Brightness { get { - return GetAttrFromSet("brightness"); + return GetAttrInt("brightness"); } set { - SetAttrString("command", value); + SetAttrInt("command", value); } } @@ -915,15 +915,15 @@ public string Trigger /// 0 and the current brightness setting. The `on` time can /// be specified via `delay_on` attribute in milliseconds. /// - public string DelayOn + public int DelayOn { get { - return GetAttrFromSet("delay_on"); + return GetAttrInt("delay_on"); } set { - SetAttrString("command", value); + SetAttrInt("command", value); } } @@ -932,15 +932,15 @@ public string DelayOn /// 0 and the current brightness setting. The `off` time can /// be specified via `delay_off` attribute in milliseconds. /// - public string DelayOff + public int DelayOff { get { - return GetAttrFromSet("delay_off"); + return GetAttrInt("delay_off"); } set { - SetAttrString("command", value); + SetAttrInt("command", value); } } @@ -1001,11 +1001,11 @@ public string[] Commands /// Returns the number of decimal places for the values in the `value` /// attributes of the current mode. /// - public string Decimals + public int Decimals { get { - return GetAttrFromSet("decimals"); + return GetAttrInt("decimals"); } } @@ -1017,7 +1017,7 @@ public string DriverName { get { - return GetAttrFromSet("driver_name"); + return GetAttrString("driver_name"); } } @@ -1029,7 +1029,7 @@ public string Mode { get { - return GetAttrFromSet("mode"); + return GetAttrString("mode"); } set { @@ -1052,11 +1052,11 @@ public string[] Modes /// Returns the number of `value` attributes that will return a valid value /// for the current mode. /// - public string NumValues + public int NumValues { get { - return GetAttrFromSet("num_values"); + return GetAttrInt("num_values"); } } @@ -1068,7 +1068,7 @@ public string PortName { get { - return GetAttrFromSet("port_name"); + return GetAttrString("port_name"); } } @@ -1080,7 +1080,7 @@ public string Units { get { - return GetAttrFromSet("units"); + return GetAttrString("units"); } } @@ -1099,7 +1099,7 @@ public string FwVersion { get { - return GetAttrFromSet("fw_version"); + return GetAttrString("fw_version"); } } @@ -1109,15 +1109,15 @@ public string FwVersion /// 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 + public int PollMs { get { - return GetAttrFromSet("poll_ms"); + return GetAttrInt("poll_ms"); } set { - SetAttrString("command", value); + SetAttrInt("command", value); } } @@ -1181,42 +1181,42 @@ public partial class PowerSupply : Device /// /// The measured current that the battery is supplying (in microamps) /// - public string MeasuredCurrent + public int MeasuredCurrent { get { - return GetAttrFromSet("current_now"); + return GetAttrInt("current_now"); } } /// /// The measured voltage that the battery is supplying (in microvolts) /// - public string MeasuredVoltage + public int MeasuredVoltage { get { - return GetAttrFromSet("voltage_now"); + return GetAttrInt("voltage_now"); } } /// /// - public string MaxVoltage + public int MaxVoltage { get { - return GetAttrFromSet("voltage_max_design"); + return GetAttrInt("voltage_max_design"); } } /// /// - public string MinVoltage + public int MinVoltage { get { - return GetAttrFromSet("voltage_min_design"); + return GetAttrInt("voltage_min_design"); } } @@ -1226,7 +1226,7 @@ public string Technology { get { - return GetAttrFromSet("technology"); + return GetAttrString("technology"); } } @@ -1236,7 +1236,7 @@ public string Type { get { - return GetAttrFromSet("type"); + return GetAttrString("type"); } } @@ -1279,7 +1279,7 @@ public string DriverName { get { - return GetAttrFromSet("driver_name"); + return GetAttrString("driver_name"); } } @@ -1304,7 +1304,7 @@ public string Mode { get { - return GetAttrFromSet("mode"); + return GetAttrString("mode"); } set { @@ -1320,7 +1320,7 @@ public string PortName { get { - return GetAttrFromSet("port_name"); + return GetAttrString("port_name"); } } @@ -1349,7 +1349,7 @@ public string Status { get { - return GetAttrFromSet("status"); + return GetAttrString("status"); } } diff --git a/csharp/ev3dev.cs b/csharp/ev3dev.cs index 5d4d2a0..1fc0e54 100644 --- a/csharp/ev3dev.cs +++ b/csharp/ev3dev.cs @@ -193,4 +193,192 @@ private StreamWriter OpenStreamWriter(string name) return new StreamWriter(Path.Combine(_path, name)); } } + + public partial class Motor + { + public Motor(string port) + { + Connect(new Dictionary + { + { "port_name", new[] { port } + } + }); + } + + public Motor(string port, string motorType) + { + Connect(new Dictionary + { + { "port_name", new[] { port } }, + { "driver_name", new[] { motorType } } + }); + } + + protected bool Connect(IDictionary match) + { + string classDir = Path.Combine(SYS_ROOT, "class", "tacho-motor"); + string pattern = "motor"; + + return Connect(classDir, pattern, match); + } + } + + public partial class LargeMotor + { + + } + + public partial class MediumMotor + { + + } + + + public partial class DcMotor + { + } + + public partial class ServoMotor + { + } + + public partial class Led + { + } + + public partial class Button + { + } + + public partial class Sensor + { + public Sensor(string port) + { + Connect(new Dictionary + { + { "port_name", new[] { port } + } + }); + } + + protected bool Connect(IDictionary match) + { + string classDir = Path.Combine(SYS_ROOT, "class", "lego-sensor"); + string pattern = "sensor"; + + return Connect(classDir, pattern, match); + } + + public Sensor(string port, string[] driverNames) + { + Connect(new Dictionary + { + { "port_name", new[] { port } }, + { "driver_name", driverNames } + }); + } + + + /// + /// Returns the value or values measured by the sensor. Check `num_values` to + /// see how many values there are. Values with index >= num_values will return + /// an error. The values are fixed point numbers, so check `decimals` to see + /// if you need to divide to get the actual value. + /// + public int GetInt(int index = 0) + { + if (index >= NumValues) + throw new ArgumentOutOfRangeException(); + + return GetAttrInt("value" + index); + } + + /// + /// The value converted to float using `decimals`. + /// + public double GetFloat(int index = 0) + { + return GetInt(index) * Math.Pow(10, -Decimals); + } + + /// + /// Human-readable name of the connected sensor. + /// + public string TypeName + { + get + { + var type = DriverName; + if (string.IsNullOrEmpty(type)) + { + return ""; + } + + var lookupTable = new Dictionary{ + { Drivers.LegoEv3Touch, "EV3 touch" }, + { Drivers.LegoEv3Color, "EV3 color" }, + { Drivers.LegoEv3Us, "EV3 ultrasonic" }, + { Drivers.LegoEv3Gyro, "EV3 gyro" }, + { Drivers.LegoEv3Ir, "EV3 infrared" }, + { Drivers.LegoNxtTouch, "NXT touch" }, + { Drivers.LegoNxtLight, "NXT light" }, + { Drivers.LegoNxtSound, "NXT sound" }, + { Drivers.LegoNxtUs, "NXT ultrasonic" }, + { Drivers.NxtI2cSensor, "I2C sensor" }, + }; + + string value; + if (lookupTable.TryGetValue(type, out value)) + return value; + + return type; + } + } + } + + public partial class I2cSensor + { + } + + public partial class ColorSensor + { + + } + + public partial class UltrasonicSensor + { + + } + + public partial class GyroSensor + { + + } + + public partial class InfraredSensor + { + + } + + public partial class SoundSensor + { + + } + + public partial class LightSensor + { + + } + + public partial class TouchSensor + { + } + + public partial class PowerSupply + { + } + + public partial class LegoPort + { + } } \ No newline at end of file diff --git a/csharp/templates/csharp-class-drivers.liquid b/csharp/templates/csharp-class-drivers.liquid index 51ceadf..9d87fcb 100644 --- a/csharp/templates/csharp-class-drivers.liquid +++ b/csharp/templates/csharp-class-drivers.liquid @@ -1,14 +1,7 @@ {% for item in classes %}{% assign currentClass = item[1]; %}{% - assign className = currentClass.friendlyName | camel_case | capitalize %} - /// {% for line in currentClass.description %} - /// {{ line }}{% - endfor %} - /// - public partial class {{className}} - { {% for driver in currentClass.driverName %} - public const string Driver{{driver | camel_case | capitalize}} = "{{driver}}"; {% - endfor %} - } - {% -endfor %} \ No newline at end of file + assign className = currentClass.friendlyName | camel_case | capitalize %}{% + for driver in currentClass.driverName %} + public const string {{driver | camel_case | capitalize}} = "{{driver}}"; {% + endfor %}{% +endfor %} diff --git a/csharp/templates/csharp-class-systemProperties.liquid b/csharp/templates/csharp-class-systemProperties.liquid index bd61fd5..9d47fe6 100644 --- a/csharp/templates/csharp-class-systemProperties.liquid +++ b/csharp/templates/csharp-class-systemProperties.liquid @@ -20,7 +20,8 @@ assign type = 'string[]' %}{% assign getter = 'Set' %}{% assign setter = 'Set' %}{% - else if prop.type == 'string selector' %}{% + endif %}{% + if prop.type == 'string selector' %}{% assign type = 'string' %}{% assign getter = 'FromSet' %}{% assign setter = 'String' %}{% From 0eb35b4cbd215c36a57d0a0b79bc8ad1fa9fc1a4 Mon Sep 17 00:00:00 2001 From: Pawel Grudzien Date: Sun, 29 Nov 2015 17:37:05 +0100 Subject: [PATCH 06/16] added constructors; added motor commands --- autogen/autogen-list.json | 1 + csharp/ev3dev.MotorCommands.cs | 67 ++++++ csharp/ev3dev.cs | 219 ++++++++++++------ csharp/templates/csharp-motor-commands.liquid | 15 ++ 4 files changed, 229 insertions(+), 73 deletions(-) create mode 100644 csharp/ev3dev.MotorCommands.cs create mode 100644 csharp/templates/csharp-motor-commands.liquid diff --git a/autogen/autogen-list.json b/autogen/autogen-list.json index 5d384f0..25b70d3 100644 --- a/autogen/autogen-list.json +++ b/autogen/autogen-list.json @@ -11,6 +11,7 @@ "csharp": { "files": [ "csharp/Drivers.cs", + "csharp/ev3dev.MotorCommands.cs", "csharp/ev3dev.SystemProperties.cs", "csharp/ev3dev.PropertyValues.cs" ], diff --git a/csharp/ev3dev.MotorCommands.cs b/csharp/ev3dev.MotorCommands.cs new file mode 100644 index 0000000..6706abe --- /dev/null +++ b/csharp/ev3dev.MotorCommands.cs @@ -0,0 +1,67 @@ +/* + * 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 + +namespace ev3dev +{ + + public partial class Motor + { +//~autogen csharp-motor-commands classes.motor>currentClass + + // Run the motor until another command is sent. + public void RunForever() { Command = "run-forever"; } + + // Run to an absolute position specified by `position_sp` and then + // stop using the command specified in `stop_command`. + public void RunToAbsPos() { Command = "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 void RunToRelPos() { Command = "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 void RunTimed() { Command = "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 void RunDirect() { Command = "run-direct"; } + + // Stop any of the run commands before they are complete using the + // command specified by `stop_command`. + public void Stop() { Command = "stop"; } + + // Reset all of the motor parameter attributes to their default value. + // This will also have the effect of stopping the motor. + public void Reset() { Command = "reset"; } + + +//~autogen + } +} diff --git a/csharp/ev3dev.cs b/csharp/ev3dev.cs index 1fc0e54..06cff8c 100644 --- a/csharp/ev3dev.cs +++ b/csharp/ev3dev.cs @@ -17,7 +17,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ - + using System; using System.Collections.Generic; using System.IO; @@ -25,6 +25,22 @@ namespace ev3dev { + public static class Inputs + { + const string INPUT_1 = "in1"; //!< Sensor port 1 + const string INPUT_2 = "in2"; //!< Sensor port 2 + const string INPUT_3 = "in3"; //!< Sensor port 3 + const string INPUT_4 = "in4"; //!< Sensor port 4 + } + + public static class Outputs + { + const string OUTPUT_A = "outA"; //!< Motor port A + const string OUTPUT_B = "outB"; //!< Motor port B + const string OUTPUT_C = "outC"; //!< Motor port C + const string OUTPUT_D = "outD"; //!< Motor port D + } + public class Device { public static string SYS_ROOT = "/sys/"; @@ -58,8 +74,8 @@ protected bool Connect(string classDir, var matches = m.Value; var strValue = GetAttrString(attribute); - if (matches.Any() && !string.IsNullOrEmpty(matches.First()) - && !matches.Any(x=>x == strValue)) + if (matches.Any() && !string.IsNullOrEmpty(matches.First()) + && !matches.Any(x => x == strValue)) { bMatch = false; break; @@ -174,7 +190,7 @@ public string[] GetAttrSet(string name, out string pCur) pCur = bracketedValue.Substring(1, bracketedValue.Length - 2); return result; } - + public string GetAttrFromSet(string name) { string[] result = GetAttrSet(name); @@ -196,16 +212,16 @@ private StreamWriter OpenStreamWriter(string name) public partial class Motor { - public Motor(string port) - { - Connect(new Dictionary - { - { "port_name", new[] { port } - } - }); - } - - public Motor(string port, string motorType) + //protected Motor(string port) + //{ + // Connect(new Dictionary + // { + // { "port_name", new[] { port } + // } + // }); + //} + + protected Motor(string port, string motorType) { Connect(new Dictionary { @@ -222,34 +238,42 @@ protected bool Connect(IDictionary match) return Connect(classDir, pattern, match); } } - + public partial class LargeMotor - { - - } - + { + public LargeMotor(string port) + : base(port, "lego-ev3-l-motor") + { + + } + } + public partial class MediumMotor - { - - } - - + { + public MediumMotor(string port) + : base(port, "lego-ev3-m-motor") + { + + } + } + + public partial class DcMotor - { - } - + { + } + public partial class ServoMotor - { - } - + { + } + public partial class Led - { - } - + { + } + public partial class Button - { - } - + { + } + public partial class Sensor { public Sensor(string port) @@ -277,8 +301,8 @@ public Sensor(string port, string[] driverNames) { "driver_name", driverNames } }); } - - + + /// /// Returns the value or values measured by the sensor. Check `num_values` to /// see how many values there are. Values with index >= num_values will return @@ -334,51 +358,100 @@ public string TypeName return type; } } - } - + } + public partial class I2cSensor - { + { + public I2cSensor() + : base(string.Empty) + { + throw new NotSupportedException(); + } } - + public partial class ColorSensor - { - - } - + { + public ColorSensor() + : base(string.Empty) + { + throw new NotSupportedException(); + } + } + public partial class UltrasonicSensor - { - - } - + { + public UltrasonicSensor() + : base(string.Empty) + { + throw new NotSupportedException(); + } + } + public partial class GyroSensor - { - - } - + { + public GyroSensor() + : base(string.Empty) + { + throw new NotSupportedException(); + } + } + public partial class InfraredSensor - { - - } - + { + public InfraredSensor() + : base(string.Empty) + { + throw new NotSupportedException(); + } + } + public partial class SoundSensor - { - - } - + { + public SoundSensor() + : base(string.Empty) + { + throw new NotSupportedException(); + } + } + public partial class LightSensor - { - - } - + { + public LightSensor() + : base(string.Empty) + { + throw new NotSupportedException(); + } + } + public partial class TouchSensor { - } - + public TouchSensor() + : base(string.Empty) + { + throw new NotSupportedException(); + } + } + public partial class PowerSupply - { - } - + { + public PowerSupply(string name) + { + string strClassDir = Path.Combine(SYS_ROOT, "class", "power_supply"); + + if (string.IsNullOrEmpty(name)) + name = "legoev3-battery"; + + Connect(strClassDir, + name, + new Dictionary()); + } + } + public partial class LegoPort - { - } + { + public LegoPort() + { + throw new NotSupportedException(); + } + } } \ No newline at end of file diff --git a/csharp/templates/csharp-motor-commands.liquid b/csharp/templates/csharp-motor-commands.liquid new file mode 100644 index 0000000..2e561f7 --- /dev/null +++ b/csharp/templates/csharp-motor-commands.liquid @@ -0,0 +1,15 @@ +{% for prop in currentClass.propertyValues %}{% + if prop.propertyName == 'Command' %}{% + assign className = currentClass.friendlyName | camel_case | capitalize %}{% + for value in prop.values %}{% + assign commandName = value.name | camel_case | capitalize %}{% + if commandName == 'float' %}{% + assign commandName = 'float_' %}{% + endif %}{% + for line in value.description %} + // {{ line }}{% + endfor%} + public void {{ commandName }}() { Command = "{{ value.name }}"; } +{% endfor %}{% + endif %}{% +endfor %} From 9de1c441b07ad132b37e76e93ceba2b21cae64a0 Mon Sep 17 00:00:00 2001 From: Pawel Grudzien Date: Sun, 29 Nov 2015 20:26:40 +0100 Subject: [PATCH 07/16] handle undeifned with camel_case --- autogen/config.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/autogen/config.js b/autogen/config.js index 57695b2..d6f7f00 100644 --- a/autogen/config.js +++ b/autogen/config.js @@ -24,7 +24,9 @@ exports.extraLiquidFilters = { }); } - if(typeof input == 'string') + if(!input) + return "undefined"; + else if(typeof input == 'string') return camelCaseSingle(input); else return input.map(camelCaseSingle); From 05e59706cea0e548dc0ed037d9b8f9e73be8bc44 Mon Sep 17 00:00:00 2001 From: Pawel Grudzien Date: Sun, 29 Nov 2015 20:27:17 +0100 Subject: [PATCH 08/16] motor commands c# style comments --- csharp/ev3dev.MotorCommands.cs | 46 ++++++++++++------- csharp/templates/csharp-motor-commands.liquid | 6 ++- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/csharp/ev3dev.MotorCommands.cs b/csharp/ev3dev.MotorCommands.cs index 6706abe..836a0ed 100644 --- a/csharp/ev3dev.MotorCommands.cs +++ b/csharp/ev3dev.MotorCommands.cs @@ -31,34 +31,48 @@ public partial class Motor { //~autogen csharp-motor-commands classes.motor>currentClass - // Run the motor until another command is sent. + /// + /// Run the motor until another command is sent. + /// public void RunForever() { Command = "run-forever"; } - // Run to an absolute position specified by `position_sp` and then - // stop using the command specified in `stop_command`. + /// + /// Run to an absolute position specified by `position_sp` and then + /// stop using the command specified in `stop_command`. + /// public void RunToAbsPos() { Command = "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`. + /// + /// 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 void RunToRelPos() { Command = "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`. + /// + /// 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 void RunTimed() { Command = "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. + /// + /// 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 void RunDirect() { Command = "run-direct"; } - // Stop any of the run commands before they are complete using the - // command specified by `stop_command`. + /// + /// Stop any of the run commands before they are complete using the + /// command specified by `stop_command`. + /// public void Stop() { Command = "stop"; } - // Reset all of the motor parameter attributes to their default value. - // This will also have the effect of stopping the motor. + /// + /// Reset all of the motor parameter attributes to their default value. + /// This will also have the effect of stopping the motor. + /// public void Reset() { Command = "reset"; } diff --git a/csharp/templates/csharp-motor-commands.liquid b/csharp/templates/csharp-motor-commands.liquid index 2e561f7..f54bb43 100644 --- a/csharp/templates/csharp-motor-commands.liquid +++ b/csharp/templates/csharp-motor-commands.liquid @@ -5,10 +5,12 @@ assign commandName = value.name | camel_case | capitalize %}{% if commandName == 'float' %}{% assign commandName = 'float_' %}{% - endif %}{% + endif %} + /// {% for line in value.description %} - // {{ line }}{% + /// {{ line }}{% endfor%} + /// public void {{ commandName }}() { Command = "{{ value.name }}"; } {% endfor %}{% endif %}{% From 3126f34195f5a8cd8b5f0c622d56dbabc982ecd5 Mon Sep 17 00:00:00 2001 From: Pawel Grudzien Date: Sun, 29 Nov 2015 20:27:52 +0100 Subject: [PATCH 09/16] set attr fix --- csharp/ev3dev.SystemProperties.cs | 74 +++++++++---------- .../csharp-class-systemProperties.liquid | 2 +- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/csharp/ev3dev.SystemProperties.cs b/csharp/ev3dev.SystemProperties.cs index e33721d..985e032 100644 --- a/csharp/ev3dev.SystemProperties.cs +++ b/csharp/ev3dev.SystemProperties.cs @@ -133,7 +133,7 @@ public int DutyCycleSp } set { - SetAttrInt("command", value); + SetAttrInt("duty_cycle_sp", value); } } @@ -152,7 +152,7 @@ public string EncoderPolarity } set { - SetAttrString("command", value); + SetAttrString("encoder_polarity", value); } } @@ -170,7 +170,7 @@ public string Polarity } set { - SetAttrString("command", value); + SetAttrString("polarity", value); } } @@ -199,7 +199,7 @@ public int Position } set { - SetAttrInt("command", value); + SetAttrInt("position", value); } } @@ -214,7 +214,7 @@ public int PositionP } set { - SetAttrInt("command", value); + SetAttrInt("hold_pid/Kp", value); } } @@ -229,7 +229,7 @@ public int PositionI } set { - SetAttrInt("command", value); + SetAttrInt("hold_pid/Ki", value); } } @@ -244,7 +244,7 @@ public int PositionD } set { - SetAttrInt("command", value); + SetAttrInt("hold_pid/Kd", value); } } @@ -262,7 +262,7 @@ public int PositionSp } set { - SetAttrInt("command", value); + SetAttrInt("position_sp", value); } } @@ -292,7 +292,7 @@ public int SpeedSp } set { - SetAttrInt("command", value); + SetAttrInt("speed_sp", value); } } @@ -311,7 +311,7 @@ public int RampUpSp } set { - SetAttrInt("command", value); + SetAttrInt("ramp_up_sp", value); } } @@ -330,7 +330,7 @@ public int RampDownSp } set { - SetAttrInt("command", value); + SetAttrInt("ramp_down_sp", value); } } @@ -349,7 +349,7 @@ public string SpeedRegulationEnabled } set { - SetAttrString("command", value); + SetAttrString("speed_regulation", value); } } @@ -364,7 +364,7 @@ public int SpeedRegulationP } set { - SetAttrInt("command", value); + SetAttrInt("speed_pid/Kp", value); } } @@ -379,7 +379,7 @@ public int SpeedRegulationI } set { - SetAttrInt("command", value); + SetAttrInt("speed_pid/Ki", value); } } @@ -394,7 +394,7 @@ public int SpeedRegulationD } set { - SetAttrInt("command", value); + SetAttrInt("speed_pid/Kd", value); } } @@ -424,7 +424,7 @@ public string StopCommand } set { - SetAttrString("command", value); + SetAttrString("stop_command", value); } } @@ -461,7 +461,7 @@ public int TimeSp } set { - SetAttrInt("command", value); + SetAttrInt("time_sp", value); } } @@ -550,7 +550,7 @@ public int DutyCycleSp } set { - SetAttrInt("command", value); + SetAttrInt("duty_cycle_sp", value); } } @@ -565,7 +565,7 @@ public string Polarity } set { - SetAttrString("command", value); + SetAttrString("polarity", value); } } @@ -592,7 +592,7 @@ public int RampDownSp } set { - SetAttrInt("command", value); + SetAttrInt("ramp_down_sp", value); } } @@ -608,7 +608,7 @@ public int RampUpSp } set { - SetAttrInt("command", value); + SetAttrInt("ramp_up_sp", value); } } @@ -634,7 +634,7 @@ public string StopCommand { set { - SetAttrString("command", value); + SetAttrString("stop_command", value); } } @@ -663,7 +663,7 @@ public int TimeSp } set { - SetAttrInt("command", value); + SetAttrInt("time_sp", value); } } @@ -714,7 +714,7 @@ public int MaxPulseSp } set { - SetAttrInt("command", value); + SetAttrInt("max_pulse_sp", value); } } @@ -734,7 +734,7 @@ public int MidPulseSp } set { - SetAttrInt("command", value); + SetAttrInt("mid_pulse_sp", value); } } @@ -752,7 +752,7 @@ public int MinPulseSp } set { - SetAttrInt("command", value); + SetAttrInt("min_pulse_sp", value); } } @@ -770,7 +770,7 @@ public string Polarity } set { - SetAttrString("command", value); + SetAttrString("polarity", value); } } @@ -799,7 +799,7 @@ public int PositionSp } set { - SetAttrInt("command", value); + SetAttrInt("position_sp", value); } } @@ -819,7 +819,7 @@ public int RateSp } set { - SetAttrInt("command", value); + SetAttrInt("rate_sp", value); } } @@ -867,7 +867,7 @@ public int Brightness } set { - SetAttrInt("command", value); + SetAttrInt("brightness", value); } } @@ -906,7 +906,7 @@ public string Trigger } set { - SetAttrString("command", value); + SetAttrString("trigger", value); } } @@ -923,7 +923,7 @@ public int DelayOn } set { - SetAttrInt("command", value); + SetAttrInt("delay_on", value); } } @@ -940,7 +940,7 @@ public int DelayOff } set { - SetAttrInt("command", value); + SetAttrInt("delay_off", value); } } @@ -1033,7 +1033,7 @@ public string Mode } set { - SetAttrString("command", value); + SetAttrString("mode", value); } } @@ -1117,7 +1117,7 @@ public int PollMs } set { - SetAttrInt("command", value); + SetAttrInt("poll_ms", value); } } @@ -1308,7 +1308,7 @@ public string Mode } set { - SetAttrString("command", value); + SetAttrString("mode", value); } } @@ -1335,7 +1335,7 @@ public string SetDevice { set { - SetAttrString("command", value); + SetAttrString("set_device", value); } } diff --git a/csharp/templates/csharp-class-systemProperties.liquid b/csharp/templates/csharp-class-systemProperties.liquid index 9d47fe6..d28f5bc 100644 --- a/csharp/templates/csharp-class-systemProperties.liquid +++ b/csharp/templates/csharp-class-systemProperties.liquid @@ -39,7 +39,7 @@ if prop.writeAccess %} set { - SetAttr{{setter}}("command", value); + SetAttr{{setter}}("{{prop.systemName}}", value); } {% endif %} } {% endfor %} From 9440a109dfffc0b3c1f1ce6256120fa8ef90c5e2 Mon Sep 17 00:00:00 2001 From: Pawel Grudzien Date: Sun, 29 Nov 2015 20:29:04 +0100 Subject: [PATCH 10/16] .net exceptions utilized; fix input/output access mod --- csharp/ev3dev.cs | 60 ++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/csharp/ev3dev.cs b/csharp/ev3dev.cs index 06cff8c..b7e4d4a 100644 --- a/csharp/ev3dev.cs +++ b/csharp/ev3dev.cs @@ -27,18 +27,18 @@ namespace ev3dev { public static class Inputs { - const string INPUT_1 = "in1"; //!< Sensor port 1 - const string INPUT_2 = "in2"; //!< Sensor port 2 - const string INPUT_3 = "in3"; //!< Sensor port 3 - const string INPUT_4 = "in4"; //!< Sensor port 4 + public const string INPUT_1 = "in1"; //!< Sensor port 1 + public const string INPUT_2 = "in2"; //!< Sensor port 2 + public const string INPUT_3 = "in3"; //!< Sensor port 3 + public const string INPUT_4 = "in4"; //!< Sensor port 4 } public static class Outputs { - const string OUTPUT_A = "outA"; //!< Motor port A - const string OUTPUT_B = "outB"; //!< Motor port B - const string OUTPUT_C = "outC"; //!< Motor port C - const string OUTPUT_D = "outD"; //!< Motor port D + public const string OUTPUT_A = "outA"; //!< Motor port A + public const string OUTPUT_B = "outB"; //!< Motor port B + public const string OUTPUT_C = "outC"; //!< Motor port C + public const string OUTPUT_D = "outD"; //!< Motor port D } public class Device @@ -103,8 +103,7 @@ public int DeviceIndex { get { - if (!Connected) - throw new NotSupportedException("no device connected"); + AssertConnected(); if (_deviceIndex < 0) { @@ -123,8 +122,7 @@ public int DeviceIndex public int GetAttrInt(string name) { - if (!Connected) - throw new NotSupportedException("no device connected"); + AssertConnected(); using (StreamReader os = OpenStreamReader(name)) { @@ -134,8 +132,7 @@ public int GetAttrInt(string name) public void SetAttrInt(string name, int value) { - if (!Connected) - throw new NotSupportedException("no device connected"); + AssertConnected(); using (StreamWriter os = OpenStreamWriter(name)) { @@ -145,20 +142,18 @@ public void SetAttrInt(string name, int value) public string GetAttrString(string name) { - if (!Connected) - throw new NotSupportedException("no device connected"); + AssertConnected(); using (StreamReader os = OpenStreamReader(name)) { - return os.ReadToEnd(); + return os.ReadToEnd().TrimEnd(); } } public void SetAttrString(string name, string value) { - if (!Connected) - throw new NotSupportedException("no device connected"); + AssertConnected(); using (StreamWriter os = OpenStreamWriter(name)) { @@ -168,8 +163,7 @@ public void SetAttrString(string name, public string GetAttrLine(string name) { - if (!Connected) - throw new NotSupportedException("no device connected"); + AssertConnected(); using (StreamReader os = OpenStreamReader(name)) { @@ -208,6 +202,12 @@ private StreamWriter OpenStreamWriter(string name) { return new StreamWriter(Path.Combine(_path, name)); } + + private void AssertConnected() + { + if (!Connected) + throw new InvalidOperationException("no device connected"); + } } public partial class Motor @@ -365,7 +365,7 @@ public partial class I2cSensor public I2cSensor() : base(string.Empty) { - throw new NotSupportedException(); + throw new NotImplementedException(); } } @@ -374,7 +374,7 @@ public partial class ColorSensor public ColorSensor() : base(string.Empty) { - throw new NotSupportedException(); + throw new NotImplementedException(); } } @@ -383,7 +383,7 @@ public partial class UltrasonicSensor public UltrasonicSensor() : base(string.Empty) { - throw new NotSupportedException(); + throw new NotImplementedException(); } } @@ -392,7 +392,7 @@ public partial class GyroSensor public GyroSensor() : base(string.Empty) { - throw new NotSupportedException(); + throw new NotImplementedException(); } } @@ -401,7 +401,7 @@ public partial class InfraredSensor public InfraredSensor() : base(string.Empty) { - throw new NotSupportedException(); + throw new NotImplementedException(); } } @@ -410,7 +410,7 @@ public partial class SoundSensor public SoundSensor() : base(string.Empty) { - throw new NotSupportedException(); + throw new NotImplementedException(); } } @@ -419,7 +419,7 @@ public partial class LightSensor public LightSensor() : base(string.Empty) { - throw new NotSupportedException(); + throw new NotImplementedException(); } } @@ -428,7 +428,7 @@ public partial class TouchSensor public TouchSensor() : base(string.Empty) { - throw new NotSupportedException(); + throw new NotImplementedException(); } } @@ -451,7 +451,7 @@ public partial class LegoPort { public LegoPort() { - throw new NotSupportedException(); + throw new NotImplementedException(); } } } \ No newline at end of file From b8c75c54330a712d88458ce40222c45dd9b2be30 Mon Sep 17 00:00:00 2001 From: Pawel Grudzien Date: Sun, 29 Nov 2015 20:32:12 +0100 Subject: [PATCH 11/16] throw not implemented where needed --- csharp/ev3dev.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/csharp/ev3dev.cs b/csharp/ev3dev.cs index b7e4d4a..e66197d 100644 --- a/csharp/ev3dev.cs +++ b/csharp/ev3dev.cs @@ -257,21 +257,36 @@ public MediumMotor(string port) } } - public partial class DcMotor { + public DcMotor() + { + throw new NotImplementedException(); + } } public partial class ServoMotor { + public ServoMotor() + { + throw new NotImplementedException(); + } } public partial class Led { + public Led() + { + throw new NotImplementedException(); + } } public partial class Button { + public Button() + { + throw new NotImplementedException(); + } } public partial class Sensor From e056abd5841b7034d2363b4b492b62a9706a680f Mon Sep 17 00:00:00 2001 From: Pawel Grudzien Date: Sat, 12 Dec 2015 16:40:11 +0100 Subject: [PATCH 12/16] moved code to projects, added demo projects --- .gitignore | 1 + autogen/autogen-list.json | 9 +-- csharp/.gitignore | 3 + csharp/NuGet.Config | 8 +++ csharp/README.md | 5 ++ csharp/global.json | 6 ++ csharp/src/IrRemoteDemo/DriveService.cs | 70 ++++++++++++++++++ csharp/src/IrRemoteDemo/DriveState.cs | 71 +++++++++++++++++++ csharp/src/IrRemoteDemo/Program.cs | 43 +++++++++++ .../IrRemoteDemo/Properties/AssemblyInfo.cs | 19 +++++ csharp/src/IrRemoteDemo/project.json | 23 ++++++ csharp/src/SensorDemo/Program.cs | 38 ++++++++++ .../src/SensorDemo/Properties/AssemblyInfo.cs | 23 ++++++ csharp/src/SensorDemo/project.json | 23 ++++++ csharp/src/ShootDemo/Program.cs | 41 +++++++++++ .../src/ShootDemo/Properties/AssemblyInfo.cs | 23 ++++++ csharp/src/ShootDemo/project.json | 23 ++++++ csharp/{ => src/ev3dev}/Drivers.cs | 0 csharp/src/ev3dev/Properties/AssemblyInfo.cs | 23 ++++++ .../src/ev3dev/ev3dev.InfraredSensorModes.cs | 67 +++++++++++++++++ .../{ => src/ev3dev}/ev3dev.MotorCommands.cs | 0 .../{ => src/ev3dev}/ev3dev.PropertyValues.cs | 0 .../ev3dev}/ev3dev.SystemProperties.cs | 0 csharp/{ => src/ev3dev}/ev3dev.cs | 6 +- csharp/src/ev3dev/project.json | 12 ++++ .../csharp-infraredsensor-modes.liquid | 18 +++++ 26 files changed, 548 insertions(+), 7 deletions(-) create mode 100644 csharp/.gitignore create mode 100644 csharp/NuGet.Config create mode 100644 csharp/README.md create mode 100644 csharp/global.json create mode 100644 csharp/src/IrRemoteDemo/DriveService.cs create mode 100644 csharp/src/IrRemoteDemo/DriveState.cs create mode 100644 csharp/src/IrRemoteDemo/Program.cs create mode 100644 csharp/src/IrRemoteDemo/Properties/AssemblyInfo.cs create mode 100644 csharp/src/IrRemoteDemo/project.json create mode 100644 csharp/src/SensorDemo/Program.cs create mode 100644 csharp/src/SensorDemo/Properties/AssemblyInfo.cs create mode 100644 csharp/src/SensorDemo/project.json create mode 100644 csharp/src/ShootDemo/Program.cs create mode 100644 csharp/src/ShootDemo/Properties/AssemblyInfo.cs create mode 100644 csharp/src/ShootDemo/project.json rename csharp/{ => src/ev3dev}/Drivers.cs (100%) create mode 100644 csharp/src/ev3dev/Properties/AssemblyInfo.cs create mode 100644 csharp/src/ev3dev/ev3dev.InfraredSensorModes.cs rename csharp/{ => src/ev3dev}/ev3dev.MotorCommands.cs (100%) rename csharp/{ => src/ev3dev}/ev3dev.PropertyValues.cs (100%) rename csharp/{ => src/ev3dev}/ev3dev.SystemProperties.cs (100%) rename csharp/{ => src/ev3dev}/ev3dev.cs (99%) create mode 100644 csharp/src/ev3dev/project.json create mode 100644 csharp/templates/csharp-infraredsensor-modes.liquid diff --git a/.gitignore b/.gitignore index ad865f3..00354db 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.vscode/ *.o cpp/bin/* cpp/lib/* diff --git a/autogen/autogen-list.json b/autogen/autogen-list.json index 441389d..c74aa7d 100644 --- a/autogen/autogen-list.json +++ b/autogen/autogen-list.json @@ -10,10 +10,11 @@ }, "csharp": { "files": [ - "csharp/Drivers.cs", - "csharp/ev3dev.MotorCommands.cs", - "csharp/ev3dev.SystemProperties.cs", - "csharp/ev3dev.PropertyValues.cs" + "csharp/src/ev3dev/Drivers.cs", + "csharp/src/ev3dev/ev3dev.MotorCommands.cs", + "csharp/src/ev3dev/ev3dev.InfraredSensorModes.cs", + "csharp/src/ev3dev/ev3dev.SystemProperties.cs", + "csharp/src/ev3dev/ev3dev.PropertyValues.cs" ], "templateDir": "csharp/templates/" }, diff --git a/csharp/.gitignore b/csharp/.gitignore new file mode 100644 index 0000000..65f3e6b --- /dev/null +++ b/csharp/.gitignore @@ -0,0 +1,3 @@ +bin/ +*.user +*.lock.json diff --git a/csharp/NuGet.Config b/csharp/NuGet.Config new file mode 100644 index 0000000..95143bd --- /dev/null +++ b/csharp/NuGet.Config @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/csharp/README.md b/csharp/README.md new file mode 100644 index 0000000..65965e1 --- /dev/null +++ b/csharp/README.md @@ -0,0 +1,5 @@ +# Getting started + +See [this blog post](http://bleedingnedge.com/2015/11/08/asp-net-5-on-lego-mindstorms-ev3-using-ev3dev/) for instructions how install DNX, run .NET applications and compile C# code for Lego Mindstorms EV3. + +The `ev3dev` project is SDK implementation. Check also demo projects for exemplary usage. \ No newline at end of file diff --git a/csharp/global.json b/csharp/global.json new file mode 100644 index 0000000..0c71551 --- /dev/null +++ b/csharp/global.json @@ -0,0 +1,6 @@ +{ + "projects": [ "src", "test" ], + "sdk": { + "version": "1.0.0-beta8" + } +} diff --git a/csharp/src/IrRemoteDemo/DriveService.cs b/csharp/src/IrRemoteDemo/DriveService.cs new file mode 100644 index 0000000..5b4b2d9 --- /dev/null +++ b/csharp/src/IrRemoteDemo/DriveService.cs @@ -0,0 +1,70 @@ +using System; +using ev3dev; + +namespace IrRemote +{ + internal class DriveService + { + private readonly Motor rightMotor; + private readonly Motor leftMotor; + public DriveState DriveState { get; private set; } + + public DriveService(string rightMotorPort, string leftMotorPort) + { + this.DriveState = new DriveState(0); + this.rightMotor = new LargeMotor(rightMotorPort); + this.leftMotor = new LargeMotor(leftMotorPort); + + if (!rightMotor.Connected) + this.rightMotor = new MediumMotor(rightMotorPort); + + if (!leftMotor.Connected) + this.leftMotor = new MediumMotor(leftMotorPort); + + if (rightMotor.Connected) + rightMotor.StopCommand = Motor.StopCommandCoast; + if (leftMotor.Connected) + leftMotor.StopCommand = Motor.StopCommandCoast; + } + + internal void Drive(DriveState driveState) + { + if (driveState.LeftMotor != DriveState.LeftMotor) + { + Apply(leftMotor, driveState.LeftMotor); + } + + if (driveState.RightMotor != DriveState.RightMotor) + { + Apply(rightMotor, driveState.RightMotor); + } + + DriveState = driveState; + } + + private static void Apply(Motor motor, MotorDrive drive) + { + if (!motor.Connected) + return; + if (drive == MotorDrive.Stop) + { + motor.Stop(); + return; + } + + if (drive == MotorDrive.Forward) + { + motor.DutyCycleSp = 100; + motor.RunForever(); + return; + } + + if (drive == MotorDrive.Backward) + { + motor.DutyCycleSp = -100; + motor.RunForever(); + return; + } + } + } +} \ No newline at end of file diff --git a/csharp/src/IrRemoteDemo/DriveState.cs b/csharp/src/IrRemoteDemo/DriveState.cs new file mode 100644 index 0000000..12301cf --- /dev/null +++ b/csharp/src/IrRemoteDemo/DriveState.cs @@ -0,0 +1,71 @@ +namespace IrRemote +{ + internal class DriveState + { + public DriveState(int remoteState) + { + switch (remoteState) + { + case 0:// none + RightMotor = MotorDrive.Stop; + LeftMotor = MotorDrive.Stop; + break; + case 1:// red up + RightMotor = MotorDrive.Stop; + LeftMotor = MotorDrive.Forward; + break; + case 2:// red down + RightMotor = MotorDrive.Stop; + LeftMotor = MotorDrive.Backward; + break; + case 3:// blue up + RightMotor = MotorDrive.Forward; + LeftMotor = MotorDrive.Stop; + break; + case 4:// blue down + RightMotor = MotorDrive.Backward; + LeftMotor = MotorDrive.Stop; + break; + case 5:// red up and blue up + RightMotor = MotorDrive.Forward; + LeftMotor = MotorDrive.Forward; + break; + case 6:// red up and blue down + RightMotor = MotorDrive.Backward; + LeftMotor = MotorDrive.Forward; + break; + case 7:// red down and blue up + RightMotor = MotorDrive.Forward; + LeftMotor = MotorDrive.Backward; + break; + case 8:// red down and blue down + RightMotor = MotorDrive.Stop; + LeftMotor = MotorDrive.Stop; + break; + case 9:// beacon + RightMotor = MotorDrive.Stop; + LeftMotor = MotorDrive.Stop; + break; + case 10:// red up and red down + RightMotor = MotorDrive.Stop; + LeftMotor = MotorDrive.Stop; + break; + case 11:// blue up and blue down + RightMotor = MotorDrive.Stop; + LeftMotor = MotorDrive.Stop; + break; + break; + } + } + + public MotorDrive LeftMotor { get; private set; } + public MotorDrive RightMotor { get; private set; } + } + + enum MotorDrive + { + Stop, + Forward, + Backward + } +} diff --git a/csharp/src/IrRemoteDemo/Program.cs b/csharp/src/IrRemoteDemo/Program.cs new file mode 100644 index 0000000..98eaa70 --- /dev/null +++ b/csharp/src/IrRemoteDemo/Program.cs @@ -0,0 +1,43 @@ +using System; +using System.Threading; +using ev3dev; + +namespace IrRemote +{ + public class Program + { + public static void Main(string[] args) + { + InfraredSensor s = new InfraredSensor(Inputs.INPUT_4); + + var driveService1 = new DriveService(Outputs.OUTPUT_A, Outputs.OUTPUT_D); + var driveService2 = new DriveService(Outputs.OUTPUT_B, Outputs.OUTPUT_C); + + s.SetIrRemote(); + + while (true) + { + Console.WriteLine("Sensor value: " + s.GetInt()); + + Thread.Sleep(100); + if (Console.KeyAvailable) + { + var key = Console.ReadKey(); + if (key.Key == ConsoleKey.Escape) + break; + } + + int value0 = s.GetInt(0); + + DriveState driveState1 = new DriveState(value0); + driveService1.Drive(driveState1); + + int value1 = s.GetInt(1); + + DriveState driveState2 = new DriveState(value1); + driveService2.Drive(driveState2); + + } + } + } +} diff --git a/csharp/src/IrRemoteDemo/Properties/AssemblyInfo.cs b/csharp/src/IrRemoteDemo/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..b957653 --- /dev/null +++ b/csharp/src/IrRemoteDemo/Properties/AssemblyInfo.cs @@ -0,0 +1,19 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("IrRemoteDemo")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("IrRemoteDemo")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] diff --git a/csharp/src/IrRemoteDemo/project.json b/csharp/src/IrRemoteDemo/project.json new file mode 100644 index 0000000..412fe04 --- /dev/null +++ b/csharp/src/IrRemoteDemo/project.json @@ -0,0 +1,23 @@ +{ + "version": "1.0.0-*", + "description": "IrRemote Console Application", + "authors": [ "pgrudzien12" ], + "tags": [ "" ], + "projectUrl": "", + "licenseUrl": "", + + "dependencies": { + }, + + "commands": { + "IrRemoteDemo": "IrRemoteDemo" + }, + + "frameworks": { + "dnx451": { + "dependencies": { + "ev3dev": "1.0.0-*" + } + } + } +} diff --git a/csharp/src/SensorDemo/Program.cs b/csharp/src/SensorDemo/Program.cs new file mode 100644 index 0000000..80b29a7 --- /dev/null +++ b/csharp/src/SensorDemo/Program.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using ev3dev; + +namespace SensorDemo +{ + /// + /// + /// + public class Program + { + public void Main(string[] args) + { + Device.SYS_ROOT = "c:/temp/ev3-sensors"; + Console.WriteLine("Reading sensor data"); + Sensor s = new Sensor(string.Empty); + + if (s.Modes.Any()) + Console.WriteLine("Avaliable sensor modes: " + s.Modes.Aggregate((x, y) => x + " " + y)); + + while (true) + { + Console.WriteLine("Sensor value: " + s.GetInt()); + + Thread.Sleep(2000); + if (Console.KeyAvailable) + { + var key = Console.ReadKey(); + if (key.Key == ConsoleKey.Escape) + break; + } + } + } + } +} diff --git a/csharp/src/SensorDemo/Properties/AssemblyInfo.cs b/csharp/src/SensorDemo/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..36fa013 --- /dev/null +++ b/csharp/src/SensorDemo/Properties/AssemblyInfo.cs @@ -0,0 +1,23 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("SensorDemo")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("SensorDemo")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("28c860e3-536b-4fd6-a6d0-2f8b6335502f")] diff --git a/csharp/src/SensorDemo/project.json b/csharp/src/SensorDemo/project.json new file mode 100644 index 0000000..be02d26 --- /dev/null +++ b/csharp/src/SensorDemo/project.json @@ -0,0 +1,23 @@ +{ + "version": "1.0.0-*", + "description": "SensorDemo Console Application", + "authors": [ "pgrudzien12" ], + "tags": [ "" ], + "projectUrl": "", + "licenseUrl": "", + + "dependencies": { + }, + + "commands": { + "SensorDemo": "SensorDemo" + }, + + "frameworks": { + "dnx451": { + "dependencies": { + "ev3dev": "1.0.0-*" + } + } + } +} diff --git a/csharp/src/ShootDemo/Program.cs b/csharp/src/ShootDemo/Program.cs new file mode 100644 index 0000000..54a924d --- /dev/null +++ b/csharp/src/ShootDemo/Program.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using ev3dev; + +namespace ShootDemo +{ + public class Program + { + public static void Main(string[] args) + { + //Device.SYS_ROOT = "c:/temp/ev3-sensors"; + Motor m = new LargeMotor(Outputs.OUTPUT_D); + + var sw = Stopwatch.StartNew(); + Console.WriteLine("started"); + m.Reset(); + Console.WriteLine("RunTimed " + sw.ElapsedMilliseconds); + + m.DutyCycleSp = 100; + m.TimeSp = 1000; + m.RunTimed(); + Console.WriteLine("RunTimed 1 done " + sw.ElapsedMilliseconds); + Thread.Sleep(1000); + Console.WriteLine("Timer 1 1000 done " + sw.ElapsedMilliseconds); + + m.DutyCycleSp = -100; + m.TimeSp = 1000; + m.RunTimed(); + Console.WriteLine("RunTimed 2 done " + sw.ElapsedMilliseconds); + Thread.Sleep(1000); + Console.WriteLine("Timer 2 1000 done " + sw.ElapsedMilliseconds); + + m.StopCommand = "coast"; + m.Stop(); + } + } +} diff --git a/csharp/src/ShootDemo/Properties/AssemblyInfo.cs b/csharp/src/ShootDemo/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..18a6d45 --- /dev/null +++ b/csharp/src/ShootDemo/Properties/AssemblyInfo.cs @@ -0,0 +1,23 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ShootDemo")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ShootDemo")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("88b7f426-da95-440f-a46f-baa35b8d702c")] diff --git a/csharp/src/ShootDemo/project.json b/csharp/src/ShootDemo/project.json new file mode 100644 index 0000000..b837366 --- /dev/null +++ b/csharp/src/ShootDemo/project.json @@ -0,0 +1,23 @@ +{ + "version": "1.0.0-*", + "description": "ShootDemo Console Application", + "authors": [ "pgrudzien12" ], + "tags": [ "" ], + "projectUrl": "", + "licenseUrl": "", + + "dependencies": { + }, + + "commands": { + "ShootDemo": "ShootDemo" + }, + + "frameworks": { + "dnx451": { + "dependencies": { + "ev3dev": "1.0.0-*" + } + } + } +} diff --git a/csharp/Drivers.cs b/csharp/src/ev3dev/Drivers.cs similarity index 100% rename from csharp/Drivers.cs rename to csharp/src/ev3dev/Drivers.cs diff --git a/csharp/src/ev3dev/Properties/AssemblyInfo.cs b/csharp/src/ev3dev/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..aee866f --- /dev/null +++ b/csharp/src/ev3dev/Properties/AssemblyInfo.cs @@ -0,0 +1,23 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ev3dev")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ev3dev")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("4c85bdd4-fe74-4b50-bb1e-934258910e59")] diff --git a/csharp/src/ev3dev/ev3dev.InfraredSensorModes.cs b/csharp/src/ev3dev/ev3dev.InfraredSensorModes.cs new file mode 100644 index 0000000..0f7faf8 --- /dev/null +++ b/csharp/src/ev3dev/ev3dev.InfraredSensorModes.cs @@ -0,0 +1,67 @@ +/* + * 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 + +namespace ev3dev +{ + + public partial class InfraredSensor + { +//~autogen csharp-infraredsensor-modes classes.infraredSensor>currentClass + + /// + /// Proximity + /// + public void SetIrProx() { Mode = "IR-PROX"; } + public bool IsIrProx() { return Mode == "IR-PROX"; } + + /// + /// IR Seeker + /// + public void SetIrSeek() { Mode = "IR-SEEK"; } + public bool IsIrSeek() { return Mode == "IR-SEEK"; } + + /// + /// IR Remote Control + /// + public void SetIrRemote() { Mode = "IR-REMOTE"; } + public bool IsIrRemote() { return Mode == "IR-REMOTE"; } + + /// + /// IR Remote Control. State of the buttons is coded in binary + /// + public void SetIrRemA() { Mode = "IR-REM-A"; } + public bool IsIrRemA() { return Mode == "IR-REM-A"; } + + /// + /// Calibration ??? + /// + public void SetIrCal() { Mode = "IR-CAL"; } + public bool IsIrCal() { return Mode == "IR-CAL"; } + + +//~autogen + } +} \ No newline at end of file diff --git a/csharp/ev3dev.MotorCommands.cs b/csharp/src/ev3dev/ev3dev.MotorCommands.cs similarity index 100% rename from csharp/ev3dev.MotorCommands.cs rename to csharp/src/ev3dev/ev3dev.MotorCommands.cs diff --git a/csharp/ev3dev.PropertyValues.cs b/csharp/src/ev3dev/ev3dev.PropertyValues.cs similarity index 100% rename from csharp/ev3dev.PropertyValues.cs rename to csharp/src/ev3dev/ev3dev.PropertyValues.cs diff --git a/csharp/ev3dev.SystemProperties.cs b/csharp/src/ev3dev/ev3dev.SystemProperties.cs similarity index 100% rename from csharp/ev3dev.SystemProperties.cs rename to csharp/src/ev3dev/ev3dev.SystemProperties.cs diff --git a/csharp/ev3dev.cs b/csharp/src/ev3dev/ev3dev.cs similarity index 99% rename from csharp/ev3dev.cs rename to csharp/src/ev3dev/ev3dev.cs index e66197d..93adee1 100644 --- a/csharp/ev3dev.cs +++ b/csharp/src/ev3dev/ev3dev.cs @@ -413,10 +413,10 @@ public GyroSensor() public partial class InfraredSensor { - public InfraredSensor() - : base(string.Empty) + public InfraredSensor(string port) + : base(port, new[] { Drivers.LegoEv3Ir }) { - throw new NotImplementedException(); + } } diff --git a/csharp/src/ev3dev/project.json b/csharp/src/ev3dev/project.json new file mode 100644 index 0000000..7d04daa --- /dev/null +++ b/csharp/src/ev3dev/project.json @@ -0,0 +1,12 @@ +{ + "version": "1.0.0-*", + "description": "ev3dev Class Library", + "authors": [ "pgrudzien12" ], + "tags": [ "" ], + "projectUrl": "", + "licenseUrl": "", + + "frameworks": { + "dnx451": { } + } +} diff --git a/csharp/templates/csharp-infraredsensor-modes.liquid b/csharp/templates/csharp-infraredsensor-modes.liquid new file mode 100644 index 0000000..1c19fb3 --- /dev/null +++ b/csharp/templates/csharp-infraredsensor-modes.liquid @@ -0,0 +1,18 @@ +{% for prop in currentClass.propertyValues %}{% + if prop.propertyName == 'Mode' %}{% + assign className = currentClass.friendlyName | camel_case | capitalize %}{% + for value in prop.values %}{% + assign modeName = value.name | camel_case | capitalize %}{% + if modeName == 'float' %}{% + assign modeName = 'float_' %}{% + endif %} + /// {% + for line in value.description %} + /// {{ line }}{% + endfor%} + /// + public void Set{{ modeName }}() { Mode = "{{ value.name }}"; } + public bool Is{{ modeName }}() { return Mode == "{{ value.name }}"; } +{% endfor %}{% + endif %}{% +endfor %} From dc146c672c2e9701be3408f8fa05a7dc2b3b280d Mon Sep 17 00:00:00 2001 From: Pawel Grudzien Date: Sat, 12 Dec 2015 17:02:55 +0100 Subject: [PATCH 13/16] added README.md files for projects and added info on global README on supported lang --- README.md | 1 + csharp/src/IrRemoteDemo/DriveState.cs | 1 - csharp/src/IrRemoteDemo/README.md | 13 +++++++++++++ csharp/src/SensorDemo/Program.cs | 1 - csharp/src/SensorDemo/README.md | 3 +++ csharp/src/ShootDemo/README.md | 3 +++ csharp/src/ev3dev/README.md | 3 +++ 7 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 csharp/src/IrRemoteDemo/README.md create mode 100644 csharp/src/SensorDemo/README.md create mode 100644 csharp/src/ShootDemo/README.md create mode 100644 csharp/src/ev3dev/README.md diff --git a/README.md b/README.md index f61129e..457c248 100644 --- a/README.md +++ b/README.md @@ -8,5 +8,6 @@ We currently have libraries for the following languages here: - Lua - Node.JS - Python +- .NET (C#) Each binding complies with our universal language binding specification, which also serves as high-level documentation for our wrappers. diff --git a/csharp/src/IrRemoteDemo/DriveState.cs b/csharp/src/IrRemoteDemo/DriveState.cs index 12301cf..434df41 100644 --- a/csharp/src/IrRemoteDemo/DriveState.cs +++ b/csharp/src/IrRemoteDemo/DriveState.cs @@ -54,7 +54,6 @@ public DriveState(int remoteState) RightMotor = MotorDrive.Stop; LeftMotor = MotorDrive.Stop; break; - break; } } diff --git a/csharp/src/IrRemoteDemo/README.md b/csharp/src/IrRemoteDemo/README.md new file mode 100644 index 0000000..61a1ae7 --- /dev/null +++ b/csharp/src/IrRemoteDemo/README.md @@ -0,0 +1,13 @@ +#IrRemoteDemo + +This simple demo acts as replacement for default EV3 remote control. + +Supports only standard EV3 Large and Medium Motors. + +Motors have to be connected as so: +- Channel 1: + * Output A + * Output D +- Channel 2: + * Output B + * Output C \ No newline at end of file diff --git a/csharp/src/SensorDemo/Program.cs b/csharp/src/SensorDemo/Program.cs index 80b29a7..361478d 100644 --- a/csharp/src/SensorDemo/Program.cs +++ b/csharp/src/SensorDemo/Program.cs @@ -14,7 +14,6 @@ public class Program { public void Main(string[] args) { - Device.SYS_ROOT = "c:/temp/ev3-sensors"; Console.WriteLine("Reading sensor data"); Sensor s = new Sensor(string.Empty); diff --git a/csharp/src/SensorDemo/README.md b/csharp/src/SensorDemo/README.md new file mode 100644 index 0000000..74caad6 --- /dev/null +++ b/csharp/src/SensorDemo/README.md @@ -0,0 +1,3 @@ +#SensorDemo + +This simple demo outputs value of first found sensor. \ No newline at end of file diff --git a/csharp/src/ShootDemo/README.md b/csharp/src/ShootDemo/README.md new file mode 100644 index 0000000..74caad6 --- /dev/null +++ b/csharp/src/ShootDemo/README.md @@ -0,0 +1,3 @@ +#SensorDemo + +This simple demo outputs value of first found sensor. \ No newline at end of file diff --git a/csharp/src/ev3dev/README.md b/csharp/src/ev3dev/README.md new file mode 100644 index 0000000..bf2b9a4 --- /dev/null +++ b/csharp/src/ev3dev/README.md @@ -0,0 +1,3 @@ +#ev3dev .NET SDK + +This project has code for .NET ev3dev SDK. \ No newline at end of file From 68c9eb329e3f2dc8d1f62fd7ee32a69ac1405d7f Mon Sep 17 00:00:00 2001 From: Pawel Grudzien Date: Sat, 12 Dec 2015 17:20:15 +0100 Subject: [PATCH 14/16] support for simple sensors --- csharp/src/ev3dev/ev3dev.cs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/csharp/src/ev3dev/ev3dev.cs b/csharp/src/ev3dev/ev3dev.cs index 93adee1..a5c9636 100644 --- a/csharp/src/ev3dev/ev3dev.cs +++ b/csharp/src/ev3dev/ev3dev.cs @@ -377,17 +377,21 @@ public string TypeName public partial class I2cSensor { - public I2cSensor() - : base(string.Empty) + public I2cSensor(string port) + : base(port, new[] { Drivers.NxtI2cSensor }) { - throw new NotImplementedException(); } } public partial class ColorSensor { - public ColorSensor() - : base(string.Empty) + public ColorSensor(string port) + : base(port, new[] { Drivers.LegoEv3Color }) + { + } + + public ColorSensor(string port, string address) + : base(port, new[] { Drivers.LegoEv3Color }) { throw new NotImplementedException(); } @@ -396,18 +400,16 @@ public ColorSensor() public partial class UltrasonicSensor { public UltrasonicSensor() - : base(string.Empty) + : base(port, new [] { Drivers.LegoEv3Us, Drivers.LegoNxtUs }) { - throw new NotImplementedException(); } } public partial class GyroSensor { public GyroSensor() - : base(string.Empty) + : base(port, new[] { Drivers.LegoEv3Gyro }) { - throw new NotImplementedException(); } } @@ -432,18 +434,16 @@ public SoundSensor() public partial class LightSensor { public LightSensor() - : base(string.Empty) + : base(port, new[] { Drivers.LegoNxtLight }) { - throw new NotImplementedException(); } } public partial class TouchSensor { - public TouchSensor() - : base(string.Empty) + public TouchSensor(string port) + : base(port, new [] { Drivers.LegoEv3Touch, Drivers.LegoNxtTouch }) { - throw new NotImplementedException(); } } From 0c84408ff840b5cbf4e53d2d866d97498364a764 Mon Sep 17 00:00:00 2001 From: Pawel Grudzien Date: Sat, 12 Dec 2015 17:28:37 +0100 Subject: [PATCH 15/16] added licence header --- csharp/README.md | 10 +++++++++- csharp/src/IrRemoteDemo/DriveService.cs | 21 ++++++++++++++++++++- csharp/src/IrRemoteDemo/DriveState.cs | 20 +++++++++++++++++++- csharp/src/IrRemoteDemo/Program.cs | 20 +++++++++++++++++++- csharp/src/SensorDemo/Program.cs | 20 +++++++++++++++++++- csharp/src/ShootDemo/Program.cs | 20 +++++++++++++++++++- 6 files changed, 105 insertions(+), 6 deletions(-) diff --git a/csharp/README.md b/csharp/README.md index 65965e1..b563b6c 100644 --- a/csharp/README.md +++ b/csharp/README.md @@ -2,4 +2,12 @@ See [this blog post](http://bleedingnedge.com/2015/11/08/asp-net-5-on-lego-mindstorms-ev3-using-ev3dev/) for instructions how install DNX, run .NET applications and compile C# code for Lego Mindstorms EV3. -The `ev3dev` project is SDK implementation. Check also demo projects for exemplary usage. \ No newline at end of file +The `ev3dev` project is SDK implementation. Check also demo projects for exemplary usage. + +# Usage + +0. Install DNX with above instructions +1. Clone this project +2. Compile code with `dnu publish --no-source` +3. Copy `/bin/output` folder with your scp client to Lego brick +4. Run your project using DNX (usually indirectly through compiler generated command) \ No newline at end of file diff --git a/csharp/src/IrRemoteDemo/DriveService.cs b/csharp/src/IrRemoteDemo/DriveService.cs index 5b4b2d9..63ccd7f 100644 --- a/csharp/src/IrRemoteDemo/DriveService.cs +++ b/csharp/src/IrRemoteDemo/DriveService.cs @@ -1,4 +1,23 @@ -using System; +/* + * + * 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. + * + */ + + +using System; using ev3dev; namespace IrRemote diff --git a/csharp/src/IrRemoteDemo/DriveState.cs b/csharp/src/IrRemoteDemo/DriveState.cs index 434df41..a6bc4d1 100644 --- a/csharp/src/IrRemoteDemo/DriveState.cs +++ b/csharp/src/IrRemoteDemo/DriveState.cs @@ -1,4 +1,22 @@ -namespace IrRemote +/* + * + * 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. + * + */ + +namespace IrRemote { internal class DriveState { diff --git a/csharp/src/IrRemoteDemo/Program.cs b/csharp/src/IrRemoteDemo/Program.cs index 98eaa70..7e963a2 100644 --- a/csharp/src/IrRemoteDemo/Program.cs +++ b/csharp/src/IrRemoteDemo/Program.cs @@ -1,4 +1,22 @@ -using System; +/* + * + * 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. + * + */ + +using System; using System.Threading; using ev3dev; diff --git a/csharp/src/SensorDemo/Program.cs b/csharp/src/SensorDemo/Program.cs index 361478d..53177f7 100644 --- a/csharp/src/SensorDemo/Program.cs +++ b/csharp/src/SensorDemo/Program.cs @@ -1,4 +1,22 @@ -using System; +/* + * + * 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. + * + */ + +using System; using System.Collections.Generic; using System.Linq; using System.Threading; diff --git a/csharp/src/ShootDemo/Program.cs b/csharp/src/ShootDemo/Program.cs index 54a924d..6c53ff1 100644 --- a/csharp/src/ShootDemo/Program.cs +++ b/csharp/src/ShootDemo/Program.cs @@ -1,4 +1,22 @@ -using System; +/* + * + * 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. + * + */ + +using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; From e0b5250a781e440b113f056b9278413804dcf017 Mon Sep 17 00:00:00 2001 From: Pawel Grudzien Date: Mon, 21 Dec 2015 19:34:21 +0100 Subject: [PATCH 16/16] replaced scharp code with submodule --- .gitmodules | 3 + csharp | 1 + csharp/.gitignore | 3 - csharp/NuGet.Config | 8 - csharp/README.md | 13 - csharp/global.json | 6 - csharp/src/IrRemoteDemo/DriveService.cs | 89 -- csharp/src/IrRemoteDemo/DriveState.cs | 88 -- csharp/src/IrRemoteDemo/Program.cs | 61 - .../IrRemoteDemo/Properties/AssemblyInfo.cs | 19 - csharp/src/IrRemoteDemo/README.md | 13 - csharp/src/IrRemoteDemo/project.json | 23 - csharp/src/SensorDemo/Program.cs | 55 - .../src/SensorDemo/Properties/AssemblyInfo.cs | 23 - csharp/src/SensorDemo/README.md | 3 - csharp/src/SensorDemo/project.json | 23 - csharp/src/ShootDemo/Program.cs | 59 - .../src/ShootDemo/Properties/AssemblyInfo.cs | 23 - csharp/src/ShootDemo/README.md | 3 - csharp/src/ShootDemo/project.json | 23 - csharp/src/ev3dev/Drivers.cs | 53 - csharp/src/ev3dev/Properties/AssemblyInfo.cs | 23 - csharp/src/ev3dev/README.md | 3 - .../src/ev3dev/ev3dev.InfraredSensorModes.cs | 67 - csharp/src/ev3dev/ev3dev.MotorCommands.cs | 81 - csharp/src/ev3dev/ev3dev.PropertyValues.cs | 504 ------ csharp/src/ev3dev/ev3dev.SystemProperties.cs | 1359 ----------------- csharp/src/ev3dev/ev3dev.cs | 472 ------ csharp/src/ev3dev/project.json | 12 - csharp/templates/autogen-header.liquid | 2 - csharp/templates/csharp-class-drivers.liquid | 7 - .../csharp-class-propertyValues.liquid | 26 - .../csharp-class-systemProperties.liquid | 47 - .../csharp-infraredsensor-modes.liquid | 18 - csharp/templates/csharp-motor-commands.liquid | 17 - 35 files changed, 4 insertions(+), 3226 deletions(-) create mode 160000 csharp delete mode 100644 csharp/.gitignore delete mode 100644 csharp/NuGet.Config delete mode 100644 csharp/README.md delete mode 100644 csharp/global.json delete mode 100644 csharp/src/IrRemoteDemo/DriveService.cs delete mode 100644 csharp/src/IrRemoteDemo/DriveState.cs delete mode 100644 csharp/src/IrRemoteDemo/Program.cs delete mode 100644 csharp/src/IrRemoteDemo/Properties/AssemblyInfo.cs delete mode 100644 csharp/src/IrRemoteDemo/README.md delete mode 100644 csharp/src/IrRemoteDemo/project.json delete mode 100644 csharp/src/SensorDemo/Program.cs delete mode 100644 csharp/src/SensorDemo/Properties/AssemblyInfo.cs delete mode 100644 csharp/src/SensorDemo/README.md delete mode 100644 csharp/src/SensorDemo/project.json delete mode 100644 csharp/src/ShootDemo/Program.cs delete mode 100644 csharp/src/ShootDemo/Properties/AssemblyInfo.cs delete mode 100644 csharp/src/ShootDemo/README.md delete mode 100644 csharp/src/ShootDemo/project.json delete mode 100644 csharp/src/ev3dev/Drivers.cs delete mode 100644 csharp/src/ev3dev/Properties/AssemblyInfo.cs delete mode 100644 csharp/src/ev3dev/README.md delete mode 100644 csharp/src/ev3dev/ev3dev.InfraredSensorModes.cs delete mode 100644 csharp/src/ev3dev/ev3dev.MotorCommands.cs delete mode 100644 csharp/src/ev3dev/ev3dev.PropertyValues.cs delete mode 100644 csharp/src/ev3dev/ev3dev.SystemProperties.cs delete mode 100644 csharp/src/ev3dev/ev3dev.cs delete mode 100644 csharp/src/ev3dev/project.json delete mode 100644 csharp/templates/autogen-header.liquid delete mode 100644 csharp/templates/csharp-class-drivers.liquid delete mode 100644 csharp/templates/csharp-class-propertyValues.liquid delete mode 100644 csharp/templates/csharp-class-systemProperties.liquid delete mode 100644 csharp/templates/csharp-infraredsensor-modes.liquid delete mode 100644 csharp/templates/csharp-motor-commands.liquid diff --git a/.gitmodules b/.gitmodules index b8d0c54..21e006b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -5,3 +5,6 @@ path = python url = https://github.com/rhempel/ev3dev-lang-python branch = master +[submodule "csharp"] + path = csharp + url = https://github.com/pgrudzien12/ev3dev-lang-csharp diff --git a/csharp b/csharp new file mode 160000 index 0000000..f89c68d --- /dev/null +++ b/csharp @@ -0,0 +1 @@ +Subproject commit f89c68d63c0a943c08c88966b9ef7d4c519e294c diff --git a/csharp/.gitignore b/csharp/.gitignore deleted file mode 100644 index 65f3e6b..0000000 --- a/csharp/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -bin/ -*.user -*.lock.json diff --git a/csharp/NuGet.Config b/csharp/NuGet.Config deleted file mode 100644 index 95143bd..0000000 --- a/csharp/NuGet.Config +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/csharp/README.md b/csharp/README.md deleted file mode 100644 index b563b6c..0000000 --- a/csharp/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# Getting started - -See [this blog post](http://bleedingnedge.com/2015/11/08/asp-net-5-on-lego-mindstorms-ev3-using-ev3dev/) for instructions how install DNX, run .NET applications and compile C# code for Lego Mindstorms EV3. - -The `ev3dev` project is SDK implementation. Check also demo projects for exemplary usage. - -# Usage - -0. Install DNX with above instructions -1. Clone this project -2. Compile code with `dnu publish --no-source` -3. Copy `/bin/output` folder with your scp client to Lego brick -4. Run your project using DNX (usually indirectly through compiler generated command) \ No newline at end of file diff --git a/csharp/global.json b/csharp/global.json deleted file mode 100644 index 0c71551..0000000 --- a/csharp/global.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "projects": [ "src", "test" ], - "sdk": { - "version": "1.0.0-beta8" - } -} diff --git a/csharp/src/IrRemoteDemo/DriveService.cs b/csharp/src/IrRemoteDemo/DriveService.cs deleted file mode 100644 index 63ccd7f..0000000 --- a/csharp/src/IrRemoteDemo/DriveService.cs +++ /dev/null @@ -1,89 +0,0 @@ -/* - * - * 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. - * - */ - - -using System; -using ev3dev; - -namespace IrRemote -{ - internal class DriveService - { - private readonly Motor rightMotor; - private readonly Motor leftMotor; - public DriveState DriveState { get; private set; } - - public DriveService(string rightMotorPort, string leftMotorPort) - { - this.DriveState = new DriveState(0); - this.rightMotor = new LargeMotor(rightMotorPort); - this.leftMotor = new LargeMotor(leftMotorPort); - - if (!rightMotor.Connected) - this.rightMotor = new MediumMotor(rightMotorPort); - - if (!leftMotor.Connected) - this.leftMotor = new MediumMotor(leftMotorPort); - - if (rightMotor.Connected) - rightMotor.StopCommand = Motor.StopCommandCoast; - if (leftMotor.Connected) - leftMotor.StopCommand = Motor.StopCommandCoast; - } - - internal void Drive(DriveState driveState) - { - if (driveState.LeftMotor != DriveState.LeftMotor) - { - Apply(leftMotor, driveState.LeftMotor); - } - - if (driveState.RightMotor != DriveState.RightMotor) - { - Apply(rightMotor, driveState.RightMotor); - } - - DriveState = driveState; - } - - private static void Apply(Motor motor, MotorDrive drive) - { - if (!motor.Connected) - return; - if (drive == MotorDrive.Stop) - { - motor.Stop(); - return; - } - - if (drive == MotorDrive.Forward) - { - motor.DutyCycleSp = 100; - motor.RunForever(); - return; - } - - if (drive == MotorDrive.Backward) - { - motor.DutyCycleSp = -100; - motor.RunForever(); - return; - } - } - } -} \ No newline at end of file diff --git a/csharp/src/IrRemoteDemo/DriveState.cs b/csharp/src/IrRemoteDemo/DriveState.cs deleted file mode 100644 index a6bc4d1..0000000 --- a/csharp/src/IrRemoteDemo/DriveState.cs +++ /dev/null @@ -1,88 +0,0 @@ -/* - * - * 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. - * - */ - -namespace IrRemote -{ - internal class DriveState - { - public DriveState(int remoteState) - { - switch (remoteState) - { - case 0:// none - RightMotor = MotorDrive.Stop; - LeftMotor = MotorDrive.Stop; - break; - case 1:// red up - RightMotor = MotorDrive.Stop; - LeftMotor = MotorDrive.Forward; - break; - case 2:// red down - RightMotor = MotorDrive.Stop; - LeftMotor = MotorDrive.Backward; - break; - case 3:// blue up - RightMotor = MotorDrive.Forward; - LeftMotor = MotorDrive.Stop; - break; - case 4:// blue down - RightMotor = MotorDrive.Backward; - LeftMotor = MotorDrive.Stop; - break; - case 5:// red up and blue up - RightMotor = MotorDrive.Forward; - LeftMotor = MotorDrive.Forward; - break; - case 6:// red up and blue down - RightMotor = MotorDrive.Backward; - LeftMotor = MotorDrive.Forward; - break; - case 7:// red down and blue up - RightMotor = MotorDrive.Forward; - LeftMotor = MotorDrive.Backward; - break; - case 8:// red down and blue down - RightMotor = MotorDrive.Stop; - LeftMotor = MotorDrive.Stop; - break; - case 9:// beacon - RightMotor = MotorDrive.Stop; - LeftMotor = MotorDrive.Stop; - break; - case 10:// red up and red down - RightMotor = MotorDrive.Stop; - LeftMotor = MotorDrive.Stop; - break; - case 11:// blue up and blue down - RightMotor = MotorDrive.Stop; - LeftMotor = MotorDrive.Stop; - break; - } - } - - public MotorDrive LeftMotor { get; private set; } - public MotorDrive RightMotor { get; private set; } - } - - enum MotorDrive - { - Stop, - Forward, - Backward - } -} diff --git a/csharp/src/IrRemoteDemo/Program.cs b/csharp/src/IrRemoteDemo/Program.cs deleted file mode 100644 index 7e963a2..0000000 --- a/csharp/src/IrRemoteDemo/Program.cs +++ /dev/null @@ -1,61 +0,0 @@ -/* - * - * 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. - * - */ - -using System; -using System.Threading; -using ev3dev; - -namespace IrRemote -{ - public class Program - { - public static void Main(string[] args) - { - InfraredSensor s = new InfraredSensor(Inputs.INPUT_4); - - var driveService1 = new DriveService(Outputs.OUTPUT_A, Outputs.OUTPUT_D); - var driveService2 = new DriveService(Outputs.OUTPUT_B, Outputs.OUTPUT_C); - - s.SetIrRemote(); - - while (true) - { - Console.WriteLine("Sensor value: " + s.GetInt()); - - Thread.Sleep(100); - if (Console.KeyAvailable) - { - var key = Console.ReadKey(); - if (key.Key == ConsoleKey.Escape) - break; - } - - int value0 = s.GetInt(0); - - DriveState driveState1 = new DriveState(value0); - driveService1.Drive(driveState1); - - int value1 = s.GetInt(1); - - DriveState driveState2 = new DriveState(value1); - driveService2.Drive(driveState2); - - } - } - } -} diff --git a/csharp/src/IrRemoteDemo/Properties/AssemblyInfo.cs b/csharp/src/IrRemoteDemo/Properties/AssemblyInfo.cs deleted file mode 100644 index b957653..0000000 --- a/csharp/src/IrRemoteDemo/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("IrRemoteDemo")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("IrRemoteDemo")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] diff --git a/csharp/src/IrRemoteDemo/README.md b/csharp/src/IrRemoteDemo/README.md deleted file mode 100644 index 61a1ae7..0000000 --- a/csharp/src/IrRemoteDemo/README.md +++ /dev/null @@ -1,13 +0,0 @@ -#IrRemoteDemo - -This simple demo acts as replacement for default EV3 remote control. - -Supports only standard EV3 Large and Medium Motors. - -Motors have to be connected as so: -- Channel 1: - * Output A - * Output D -- Channel 2: - * Output B - * Output C \ No newline at end of file diff --git a/csharp/src/IrRemoteDemo/project.json b/csharp/src/IrRemoteDemo/project.json deleted file mode 100644 index 412fe04..0000000 --- a/csharp/src/IrRemoteDemo/project.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "version": "1.0.0-*", - "description": "IrRemote Console Application", - "authors": [ "pgrudzien12" ], - "tags": [ "" ], - "projectUrl": "", - "licenseUrl": "", - - "dependencies": { - }, - - "commands": { - "IrRemoteDemo": "IrRemoteDemo" - }, - - "frameworks": { - "dnx451": { - "dependencies": { - "ev3dev": "1.0.0-*" - } - } - } -} diff --git a/csharp/src/SensorDemo/Program.cs b/csharp/src/SensorDemo/Program.cs deleted file mode 100644 index 53177f7..0000000 --- a/csharp/src/SensorDemo/Program.cs +++ /dev/null @@ -1,55 +0,0 @@ -/* - * - * 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. - * - */ - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using ev3dev; - -namespace SensorDemo -{ - /// - /// - /// - public class Program - { - public void Main(string[] args) - { - Console.WriteLine("Reading sensor data"); - Sensor s = new Sensor(string.Empty); - - if (s.Modes.Any()) - Console.WriteLine("Avaliable sensor modes: " + s.Modes.Aggregate((x, y) => x + " " + y)); - - while (true) - { - Console.WriteLine("Sensor value: " + s.GetInt()); - - Thread.Sleep(2000); - if (Console.KeyAvailable) - { - var key = Console.ReadKey(); - if (key.Key == ConsoleKey.Escape) - break; - } - } - } - } -} diff --git a/csharp/src/SensorDemo/Properties/AssemblyInfo.cs b/csharp/src/SensorDemo/Properties/AssemblyInfo.cs deleted file mode 100644 index 36fa013..0000000 --- a/csharp/src/SensorDemo/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("SensorDemo")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("SensorDemo")] -[assembly: AssemblyCopyright("Copyright © 2015")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("28c860e3-536b-4fd6-a6d0-2f8b6335502f")] diff --git a/csharp/src/SensorDemo/README.md b/csharp/src/SensorDemo/README.md deleted file mode 100644 index 74caad6..0000000 --- a/csharp/src/SensorDemo/README.md +++ /dev/null @@ -1,3 +0,0 @@ -#SensorDemo - -This simple demo outputs value of first found sensor. \ No newline at end of file diff --git a/csharp/src/SensorDemo/project.json b/csharp/src/SensorDemo/project.json deleted file mode 100644 index be02d26..0000000 --- a/csharp/src/SensorDemo/project.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "version": "1.0.0-*", - "description": "SensorDemo Console Application", - "authors": [ "pgrudzien12" ], - "tags": [ "" ], - "projectUrl": "", - "licenseUrl": "", - - "dependencies": { - }, - - "commands": { - "SensorDemo": "SensorDemo" - }, - - "frameworks": { - "dnx451": { - "dependencies": { - "ev3dev": "1.0.0-*" - } - } - } -} diff --git a/csharp/src/ShootDemo/Program.cs b/csharp/src/ShootDemo/Program.cs deleted file mode 100644 index 6c53ff1..0000000 --- a/csharp/src/ShootDemo/Program.cs +++ /dev/null @@ -1,59 +0,0 @@ -/* - * - * 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. - * - */ - -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using ev3dev; - -namespace ShootDemo -{ - public class Program - { - public static void Main(string[] args) - { - //Device.SYS_ROOT = "c:/temp/ev3-sensors"; - Motor m = new LargeMotor(Outputs.OUTPUT_D); - - var sw = Stopwatch.StartNew(); - Console.WriteLine("started"); - m.Reset(); - Console.WriteLine("RunTimed " + sw.ElapsedMilliseconds); - - m.DutyCycleSp = 100; - m.TimeSp = 1000; - m.RunTimed(); - Console.WriteLine("RunTimed 1 done " + sw.ElapsedMilliseconds); - Thread.Sleep(1000); - Console.WriteLine("Timer 1 1000 done " + sw.ElapsedMilliseconds); - - m.DutyCycleSp = -100; - m.TimeSp = 1000; - m.RunTimed(); - Console.WriteLine("RunTimed 2 done " + sw.ElapsedMilliseconds); - Thread.Sleep(1000); - Console.WriteLine("Timer 2 1000 done " + sw.ElapsedMilliseconds); - - m.StopCommand = "coast"; - m.Stop(); - } - } -} diff --git a/csharp/src/ShootDemo/Properties/AssemblyInfo.cs b/csharp/src/ShootDemo/Properties/AssemblyInfo.cs deleted file mode 100644 index 18a6d45..0000000 --- a/csharp/src/ShootDemo/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("ShootDemo")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("ShootDemo")] -[assembly: AssemblyCopyright("Copyright © 2015")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("88b7f426-da95-440f-a46f-baa35b8d702c")] diff --git a/csharp/src/ShootDemo/README.md b/csharp/src/ShootDemo/README.md deleted file mode 100644 index 74caad6..0000000 --- a/csharp/src/ShootDemo/README.md +++ /dev/null @@ -1,3 +0,0 @@ -#SensorDemo - -This simple demo outputs value of first found sensor. \ No newline at end of file diff --git a/csharp/src/ShootDemo/project.json b/csharp/src/ShootDemo/project.json deleted file mode 100644 index b837366..0000000 --- a/csharp/src/ShootDemo/project.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "version": "1.0.0-*", - "description": "ShootDemo Console Application", - "authors": [ "pgrudzien12" ], - "tags": [ "" ], - "projectUrl": "", - "licenseUrl": "", - - "dependencies": { - }, - - "commands": { - "ShootDemo": "ShootDemo" - }, - - "frameworks": { - "dnx451": { - "dependencies": { - "ev3dev": "1.0.0-*" - } - } - } -} diff --git a/csharp/src/ev3dev/Drivers.cs b/csharp/src/ev3dev/Drivers.cs deleted file mode 100644 index c0220af..0000000 --- a/csharp/src/ev3dev/Drivers.cs +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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 static class Drivers - { -//~autogen csharp-class-drivers classes>classes - - public const string LegoEv3LMotor = "lego-ev3-l-motor"; - public const string LegoEv3MMotor = "lego-ev3-m-motor"; - public const string NxtI2cSensor = "nxt-i2c-sensor"; - public const string LegoEv3Color = "lego-ev3-color"; - public const string LegoEv3Us = "lego-ev3-us"; - public const string LegoNxtUs = "lego-nxt-us"; - public const string LegoEv3Gyro = "lego-ev3-gyro"; - public const string LegoEv3Ir = "lego-ev3-ir"; - public const string LegoNxtSound = "lego-nxt-sound"; - public const string LegoNxtLight = "lego-nxt-light"; - public const string LegoEv3Touch = "lego-ev3-touch"; - public const string LegoNxtTouch = "lego-nxt-touch"; - -//~autogen - } -} \ No newline at end of file diff --git a/csharp/src/ev3dev/Properties/AssemblyInfo.cs b/csharp/src/ev3dev/Properties/AssemblyInfo.cs deleted file mode 100644 index aee866f..0000000 --- a/csharp/src/ev3dev/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("ev3dev")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("ev3dev")] -[assembly: AssemblyCopyright("Copyright © 2015")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("4c85bdd4-fe74-4b50-bb1e-934258910e59")] diff --git a/csharp/src/ev3dev/README.md b/csharp/src/ev3dev/README.md deleted file mode 100644 index bf2b9a4..0000000 --- a/csharp/src/ev3dev/README.md +++ /dev/null @@ -1,3 +0,0 @@ -#ev3dev .NET SDK - -This project has code for .NET ev3dev SDK. \ No newline at end of file diff --git a/csharp/src/ev3dev/ev3dev.InfraredSensorModes.cs b/csharp/src/ev3dev/ev3dev.InfraredSensorModes.cs deleted file mode 100644 index 0f7faf8..0000000 --- a/csharp/src/ev3dev/ev3dev.InfraredSensorModes.cs +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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 - -namespace ev3dev -{ - - public partial class InfraredSensor - { -//~autogen csharp-infraredsensor-modes classes.infraredSensor>currentClass - - /// - /// Proximity - /// - public void SetIrProx() { Mode = "IR-PROX"; } - public bool IsIrProx() { return Mode == "IR-PROX"; } - - /// - /// IR Seeker - /// - public void SetIrSeek() { Mode = "IR-SEEK"; } - public bool IsIrSeek() { return Mode == "IR-SEEK"; } - - /// - /// IR Remote Control - /// - public void SetIrRemote() { Mode = "IR-REMOTE"; } - public bool IsIrRemote() { return Mode == "IR-REMOTE"; } - - /// - /// IR Remote Control. State of the buttons is coded in binary - /// - public void SetIrRemA() { Mode = "IR-REM-A"; } - public bool IsIrRemA() { return Mode == "IR-REM-A"; } - - /// - /// Calibration ??? - /// - public void SetIrCal() { Mode = "IR-CAL"; } - public bool IsIrCal() { return Mode == "IR-CAL"; } - - -//~autogen - } -} \ No newline at end of file diff --git a/csharp/src/ev3dev/ev3dev.MotorCommands.cs b/csharp/src/ev3dev/ev3dev.MotorCommands.cs deleted file mode 100644 index 836a0ed..0000000 --- a/csharp/src/ev3dev/ev3dev.MotorCommands.cs +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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 - -namespace ev3dev -{ - - public partial class Motor - { -//~autogen csharp-motor-commands classes.motor>currentClass - - /// - /// Run the motor until another command is sent. - /// - public void RunForever() { Command = "run-forever"; } - - /// - /// Run to an absolute position specified by `position_sp` and then - /// stop using the command specified in `stop_command`. - /// - public void RunToAbsPos() { Command = "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 void RunToRelPos() { Command = "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 void RunTimed() { Command = "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 void RunDirect() { Command = "run-direct"; } - - /// - /// Stop any of the run commands before they are complete using the - /// command specified by `stop_command`. - /// - public void Stop() { Command = "stop"; } - - /// - /// Reset all of the motor parameter attributes to their default value. - /// This will also have the effect of stopping the motor. - /// - public void Reset() { Command = "reset"; } - - -//~autogen - } -} diff --git a/csharp/src/ev3dev/ev3dev.PropertyValues.cs b/csharp/src/ev3dev/ev3dev.PropertyValues.cs deleted file mode 100644 index 8514c0a..0000000 --- a/csharp/src/ev3dev/ev3dev.PropertyValues.cs +++ /dev/null @@ -1,504 +0,0 @@ -/* - * 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 -{ -//~autogen csharp-class-propertyValues 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`. - /// - public partial class Motor : Device - { - /// - /// 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"; - - } - - /// - /// EV3 large servo motor - /// - public partial class LargeMotor : Motor - { - } - - /// - /// EV3 medium servo motor - /// - 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. - /// - public partial class DcMotor : Device - { - /// - /// 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"; - - } - - /// - /// The servo motor class provides a uniform interface for using hobby type - /// servo motors. - /// - public partial class ServoMotor : Device - { - /// - /// 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"; - - } - - /// - /// Any device controlled by the generic LED driver. - /// See https://www.kernel.org/doc/Documentation/leds/leds-class.txt - /// for more details. - /// - public partial class Led : Device - { - } - - /// - /// 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 - /// - 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. - /// - public partial class Sensor : Device - { - } - - /// - /// A generic interface to control I2C-type EV3 sensors. - /// - public partial class I2cSensor : Sensor - { - } - - /// - /// LEGO EV3 color sensor. - /// - public partial class ColorSensor : Sensor - { - /// - /// 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"; - - } - - /// - /// LEGO EV3 ultrasonic sensor. - /// - public partial class UltrasonicSensor : Sensor - { - /// - /// 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"; - - } - - /// - /// LEGO EV3 gyro sensor. - /// - public partial class GyroSensor : Sensor - { - /// - /// 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"; - - } - - /// - /// LEGO EV3 infrared sensor. - /// - public partial class InfraredSensor : Sensor - { - /// - /// 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"; - - } - - /// - /// LEGO NXT Sound Sensor - /// - public partial class SoundSensor : Sensor - { - /// - /// Sound pressure level. Flat weighting - /// - public const string ModeDb = "DB"; - - /// - /// Sound pressure level. A weighting - /// - public const string ModeDba = "DBA"; - - } - - /// - /// LEGO NXT Light Sensor - /// - public partial class LightSensor : Sensor - { - /// - /// Reflected light. LED on - /// - public const string ModeReflect = "REFLECT"; - - /// - /// Ambient light. LED off - /// - public const string ModeAmbient = "AMBIENT"; - - } - - /// - /// Touch Sensor - /// - 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. - /// - public partial class PowerSupply : Device - { - } - - /// - /// 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. - /// - public partial class LegoPort : Device - { - } - - -//~autogen -} \ No newline at end of file diff --git a/csharp/src/ev3dev/ev3dev.SystemProperties.cs b/csharp/src/ev3dev/ev3dev.SystemProperties.cs deleted file mode 100644 index 985e032..0000000 --- a/csharp/src/ev3dev/ev3dev.SystemProperties.cs +++ /dev/null @@ -1,1359 +0,0 @@ -/* - * 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 -{ - -//~autogen csharp-class-systemProperties 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`. - /// - public partial class Motor : Device - { - /// - /// 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("commands"); - } - } - - /// - /// 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 int CountPerRot - { - get - { - return GetAttrInt("count_per_rot"); - } - } - - /// - /// Returns the name of the driver that provides this tacho motor device. - /// - public string DriverName - { - get - { - return GetAttrString("driver_name"); - } - } - - /// - /// Returns the current duty cycle of the motor. Units are percent. Values - /// are -100 to 100. - /// - public int DutyCycle - { - get - { - return GetAttrInt("duty_cycle"); - } - } - - /// - /// 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 int DutyCycleSp - { - get - { - return GetAttrInt("duty_cycle_sp"); - } - set - { - SetAttrInt("duty_cycle_sp", 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 GetAttrString("encoder_polarity"); - } - set - { - SetAttrString("encoder_polarity", 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 GetAttrString("polarity"); - } - set - { - SetAttrString("polarity", value); - } - } - - /// - /// Returns the name of the port that the motor is connected to. - /// - public string PortName - { - get - { - return GetAttrString("port_name"); - } - } - - /// - /// 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 int Position - { - get - { - return GetAttrInt("position"); - } - set - { - SetAttrInt("position", value); - } - } - - /// - /// The proportional constant for the position PID. - /// - public int PositionP - { - get - { - return GetAttrInt("hold_pid/Kp"); - } - set - { - SetAttrInt("hold_pid/Kp", value); - } - } - - /// - /// The integral constant for the position PID. - /// - public int PositionI - { - get - { - return GetAttrInt("hold_pid/Ki"); - } - set - { - SetAttrInt("hold_pid/Ki", value); - } - } - - /// - /// The derivative constant for the position PID. - /// - public int PositionD - { - get - { - return GetAttrInt("hold_pid/Kd"); - } - set - { - SetAttrInt("hold_pid/Kd", 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 int PositionSp - { - get - { - return GetAttrInt("position_sp"); - } - set - { - SetAttrInt("position_sp", 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 int Speed - { - get - { - return GetAttrInt("speed"); - } - } - - /// - /// 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 int SpeedSp - { - get - { - return GetAttrInt("speed_sp"); - } - set - { - SetAttrInt("speed_sp", 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 int RampUpSp - { - get - { - return GetAttrInt("ramp_up_sp"); - } - set - { - SetAttrInt("ramp_up_sp", 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 int RampDownSp - { - get - { - return GetAttrInt("ramp_down_sp"); - } - set - { - SetAttrInt("ramp_down_sp", 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 GetAttrString("speed_regulation"); - } - set - { - SetAttrString("speed_regulation", value); - } - } - - /// - /// The proportional constant for the speed regulation PID. - /// - public int SpeedRegulationP - { - get - { - return GetAttrInt("speed_pid/Kp"); - } - set - { - SetAttrInt("speed_pid/Kp", value); - } - } - - /// - /// The integral constant for the speed regulation PID. - /// - public int SpeedRegulationI - { - get - { - return GetAttrInt("speed_pid/Ki"); - } - set - { - SetAttrInt("speed_pid/Ki", value); - } - } - - /// - /// The derivative constant for the speed regulation PID. - /// - public int SpeedRegulationD - { - get - { - return GetAttrInt("speed_pid/Kd"); - } - set - { - SetAttrInt("speed_pid/Kd", value); - } - } - - /// - /// Reading returns a list of state flags. Possible flags are - /// `running`, `ramping` `holding` and `stalled`. - /// - public string[] State - { - get - { - return GetAttrSet("state"); - } - } - - /// - /// 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 GetAttrString("stop_command"); - } - set - { - SetAttrString("stop_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("stop_commands"); - } - } - - /// - /// 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 int TimeSp - { - get - { - return GetAttrInt("time_sp"); - } - set - { - SetAttrInt("time_sp", value); - } - } - - } - - /// - /// EV3 large servo motor - /// - public partial class LargeMotor : Motor - { - } - - /// - /// EV3 medium servo motor - /// - 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. - /// - public partial class DcMotor : Device - { - /// - /// 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("commands"); - } - } - - /// - /// 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 GetAttrString("driver_name"); - } - } - - /// - /// Shows the current duty cycle of the PWM signal sent to the motor. Values - /// are -100 to 100 (-100% to 100%). - /// - public int DutyCycle - { - get - { - return GetAttrInt("duty_cycle"); - } - } - - /// - /// 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 int DutyCycleSp - { - get - { - return GetAttrInt("duty_cycle_sp"); - } - set - { - SetAttrInt("duty_cycle_sp", value); - } - } - - /// - /// Sets the polarity of the motor. Valid values are `normal` and `inversed`. - /// - public string Polarity - { - get - { - return GetAttrString("polarity"); - } - set - { - SetAttrString("polarity", value); - } - } - - /// - /// Returns the name of the port that the motor is connected to. - /// - public string PortName - { - get - { - return GetAttrString("port_name"); - } - } - - /// - /// 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 int RampDownSp - { - get - { - return GetAttrInt("ramp_down_sp"); - } - set - { - SetAttrInt("ramp_down_sp", 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 int RampUpSp - { - get - { - return GetAttrInt("ramp_up_sp"); - } - set - { - SetAttrInt("ramp_up_sp", 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("state"); - } - } - - /// - /// 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("stop_command", value); - } - } - - /// - /// Gets a list of stop commands. Valid values are `coast` - /// and `brake`. - /// - public string[] StopCommands - { - get - { - return GetAttrSet("stop_commands"); - } - } - - /// - /// 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 int TimeSp - { - get - { - return GetAttrInt("time_sp"); - } - set - { - SetAttrInt("time_sp", value); - } - } - - } - - /// - /// The servo motor class provides a uniform interface for using hobby type - /// servo motors. - /// - public partial class ServoMotor : Device - { - /// - /// 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 GetAttrString("driver_name"); - } - } - - /// - /// 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 int MaxPulseSp - { - get - { - return GetAttrInt("max_pulse_sp"); - } - set - { - SetAttrInt("max_pulse_sp", 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 int MidPulseSp - { - get - { - return GetAttrInt("mid_pulse_sp"); - } - set - { - SetAttrInt("mid_pulse_sp", 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 int MinPulseSp - { - get - { - return GetAttrInt("min_pulse_sp"); - } - set - { - SetAttrInt("min_pulse_sp", 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 GetAttrString("polarity"); - } - set - { - SetAttrString("polarity", value); - } - } - - /// - /// Returns the name of the port that the motor is connected to. - /// - public string PortName - { - get - { - return GetAttrString("port_name"); - } - } - - /// - /// 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 int PositionSp - { - get - { - return GetAttrInt("position_sp"); - } - set - { - SetAttrInt("position_sp", 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 int RateSp - { - get - { - return GetAttrInt("rate_sp"); - } - set - { - SetAttrInt("rate_sp", 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("state"); - } - } - - } - - /// - /// Any device controlled by the generic LED driver. - /// See https://www.kernel.org/doc/Documentation/leds/leds-class.txt - /// for more details. - /// - public partial class Led : Device - { - /// - /// Returns the maximum allowable brightness value. - /// - public int MaxBrightness - { - get - { - return GetAttrInt("max_brightness"); - } - } - - /// - /// Sets the brightness level. Possible values are from 0 to `max_brightness`. - /// - public int Brightness - { - get - { - return GetAttrInt("brightness"); - } - set - { - SetAttrInt("brightness", value); - } - } - - /// - /// Returns a list of available triggers. - /// - public string[] Triggers - { - get - { - return GetAttrSet("trigger"); - } - } - - /// - /// 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("trigger"); - } - set - { - SetAttrString("trigger", 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 int DelayOn - { - get - { - return GetAttrInt("delay_on"); - } - set - { - SetAttrInt("delay_on", 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 int DelayOff - { - get - { - return GetAttrInt("delay_off"); - } - set - { - SetAttrInt("delay_off", value); - } - } - - } - - /// - /// 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 - /// - 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. - /// - public partial class Sensor : Device - { - /// - /// 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("commands"); - } - } - - /// - /// Returns the number of decimal places for the values in the `value` - /// attributes of the current mode. - /// - public int Decimals - { - get - { - return GetAttrInt("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 GetAttrString("driver_name"); - } - } - - /// - /// Returns the current mode. Writing one of the values returned by `modes` - /// sets the sensor to that mode. - /// - public string Mode - { - get - { - return GetAttrString("mode"); - } - set - { - SetAttrString("mode", value); - } - } - - /// - /// Returns a list of the valid modes for the sensor. - /// - public string[] Modes - { - get - { - return GetAttrSet("modes"); - } - } - - /// - /// Returns the number of `value` attributes that will return a valid value - /// for the current mode. - /// - public int NumValues - { - get - { - return GetAttrInt("num_values"); - } - } - - /// - /// 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 GetAttrString("port_name"); - } - } - - /// - /// Returns the units of the measured value for the current mode. May return - /// empty string - /// - public string Units - { - get - { - return GetAttrString("units"); - } - } - - } - - /// - /// A generic interface to control I2C-type EV3 sensors. - /// - public partial class I2cSensor : Sensor - { - /// - /// Returns the firmware version of the sensor if available. Currently only - /// I2C/NXT sensors support this. - /// - public string FwVersion - { - get - { - return GetAttrString("fw_version"); - } - } - - /// - /// 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 int PollMs - { - get - { - return GetAttrInt("poll_ms"); - } - set - { - SetAttrInt("poll_ms", value); - } - } - - } - - /// - /// LEGO EV3 color sensor. - /// - public partial class ColorSensor : Sensor - { - } - - /// - /// LEGO EV3 ultrasonic sensor. - /// - public partial class UltrasonicSensor : Sensor - { - } - - /// - /// LEGO EV3 gyro sensor. - /// - public partial class GyroSensor : Sensor - { - } - - /// - /// LEGO EV3 infrared sensor. - /// - public partial class InfraredSensor : Sensor - { - } - - /// - /// LEGO NXT Sound Sensor - /// - public partial class SoundSensor : Sensor - { - } - - /// - /// LEGO NXT Light Sensor - /// - public partial class LightSensor : Sensor - { - } - - /// - /// Touch Sensor - /// - 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. - /// - public partial class PowerSupply : Device - { - /// - /// The measured current that the battery is supplying (in microamps) - /// - public int MeasuredCurrent - { - get - { - return GetAttrInt("current_now"); - } - } - - /// - /// The measured voltage that the battery is supplying (in microvolts) - /// - public int MeasuredVoltage - { - get - { - return GetAttrInt("voltage_now"); - } - } - - /// - /// - public int MaxVoltage - { - get - { - return GetAttrInt("voltage_max_design"); - } - } - - /// - /// - public int MinVoltage - { - get - { - return GetAttrInt("voltage_min_design"); - } - } - - /// - /// - public string Technology - { - get - { - return GetAttrString("technology"); - } - } - - /// - /// - public string Type - { - get - { - return GetAttrString("type"); - } - } - - } - - /// - /// 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. - /// - public partial class LegoPort : Device - { - /// - /// 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 GetAttrString("driver_name"); - } - } - - /// - /// Returns a list of the available modes of the port. - /// - public string[] Modes - { - get - { - return GetAttrSet("modes"); - } - } - - /// - /// 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 GetAttrString("mode"); - } - set - { - SetAttrString("mode", value); - } - } - - /// - /// Returns the name of the port. See individual driver documentation for - /// the name that will be returned. - /// - public string PortName - { - get - { - return GetAttrString("port_name"); - } - } - - /// - /// 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("set_device", 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 GetAttrString("status"); - } - } - - } - -//~autogen -} \ No newline at end of file diff --git a/csharp/src/ev3dev/ev3dev.cs b/csharp/src/ev3dev/ev3dev.cs deleted file mode 100644 index a5c9636..0000000 --- a/csharp/src/ev3dev/ev3dev.cs +++ /dev/null @@ -1,472 +0,0 @@ -/* - * 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. - * - */ - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; - -namespace ev3dev -{ - public static class Inputs - { - public const string INPUT_1 = "in1"; //!< Sensor port 1 - public const string INPUT_2 = "in2"; //!< Sensor port 2 - public const string INPUT_3 = "in3"; //!< Sensor port 3 - public const string INPUT_4 = "in4"; //!< Sensor port 4 - } - - public static class Outputs - { - public const string OUTPUT_A = "outA"; //!< Motor port A - public const string OUTPUT_B = "outB"; //!< Motor port B - public const string OUTPUT_C = "outC"; //!< Motor port C - public const string OUTPUT_D = "outD"; //!< Motor port D - } - - 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 - { - AssertConnected(); - - 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) - { - AssertConnected(); - - using (StreamReader os = OpenStreamReader(name)) - { - return int.Parse(os.ReadToEnd()); - } - } - - public void SetAttrInt(string name, int value) - { - AssertConnected(); - - using (StreamWriter os = OpenStreamWriter(name)) - { - os.Write(value); - } - } - - public string GetAttrString(string name) - { - AssertConnected(); - - using (StreamReader os = OpenStreamReader(name)) - { - return os.ReadToEnd().TrimEnd(); - } - } - - public void SetAttrString(string name, - string value) - { - AssertConnected(); - - using (StreamWriter os = OpenStreamWriter(name)) - { - os.Write(value); - } - } - - public string GetAttrLine(string name) - { - AssertConnected(); - - 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)); - } - - private void AssertConnected() - { - if (!Connected) - throw new InvalidOperationException("no device connected"); - } - } - - public partial class Motor - { - //protected Motor(string port) - //{ - // Connect(new Dictionary - // { - // { "port_name", new[] { port } - // } - // }); - //} - - protected Motor(string port, string motorType) - { - Connect(new Dictionary - { - { "port_name", new[] { port } }, - { "driver_name", new[] { motorType } } - }); - } - - protected bool Connect(IDictionary match) - { - string classDir = Path.Combine(SYS_ROOT, "class", "tacho-motor"); - string pattern = "motor"; - - return Connect(classDir, pattern, match); - } - } - - public partial class LargeMotor - { - public LargeMotor(string port) - : base(port, "lego-ev3-l-motor") - { - - } - } - - public partial class MediumMotor - { - public MediumMotor(string port) - : base(port, "lego-ev3-m-motor") - { - - } - } - - public partial class DcMotor - { - public DcMotor() - { - throw new NotImplementedException(); - } - } - - public partial class ServoMotor - { - public ServoMotor() - { - throw new NotImplementedException(); - } - } - - public partial class Led - { - public Led() - { - throw new NotImplementedException(); - } - } - - public partial class Button - { - public Button() - { - throw new NotImplementedException(); - } - } - - public partial class Sensor - { - public Sensor(string port) - { - Connect(new Dictionary - { - { "port_name", new[] { port } - } - }); - } - - protected bool Connect(IDictionary match) - { - string classDir = Path.Combine(SYS_ROOT, "class", "lego-sensor"); - string pattern = "sensor"; - - return Connect(classDir, pattern, match); - } - - public Sensor(string port, string[] driverNames) - { - Connect(new Dictionary - { - { "port_name", new[] { port } }, - { "driver_name", driverNames } - }); - } - - - /// - /// Returns the value or values measured by the sensor. Check `num_values` to - /// see how many values there are. Values with index >= num_values will return - /// an error. The values are fixed point numbers, so check `decimals` to see - /// if you need to divide to get the actual value. - /// - public int GetInt(int index = 0) - { - if (index >= NumValues) - throw new ArgumentOutOfRangeException(); - - return GetAttrInt("value" + index); - } - - /// - /// The value converted to float using `decimals`. - /// - public double GetFloat(int index = 0) - { - return GetInt(index) * Math.Pow(10, -Decimals); - } - - /// - /// Human-readable name of the connected sensor. - /// - public string TypeName - { - get - { - var type = DriverName; - if (string.IsNullOrEmpty(type)) - { - return ""; - } - - var lookupTable = new Dictionary{ - { Drivers.LegoEv3Touch, "EV3 touch" }, - { Drivers.LegoEv3Color, "EV3 color" }, - { Drivers.LegoEv3Us, "EV3 ultrasonic" }, - { Drivers.LegoEv3Gyro, "EV3 gyro" }, - { Drivers.LegoEv3Ir, "EV3 infrared" }, - { Drivers.LegoNxtTouch, "NXT touch" }, - { Drivers.LegoNxtLight, "NXT light" }, - { Drivers.LegoNxtSound, "NXT sound" }, - { Drivers.LegoNxtUs, "NXT ultrasonic" }, - { Drivers.NxtI2cSensor, "I2C sensor" }, - }; - - string value; - if (lookupTable.TryGetValue(type, out value)) - return value; - - return type; - } - } - } - - public partial class I2cSensor - { - public I2cSensor(string port) - : base(port, new[] { Drivers.NxtI2cSensor }) - { - } - } - - public partial class ColorSensor - { - public ColorSensor(string port) - : base(port, new[] { Drivers.LegoEv3Color }) - { - } - - public ColorSensor(string port, string address) - : base(port, new[] { Drivers.LegoEv3Color }) - { - throw new NotImplementedException(); - } - } - - public partial class UltrasonicSensor - { - public UltrasonicSensor() - : base(port, new [] { Drivers.LegoEv3Us, Drivers.LegoNxtUs }) - { - } - } - - public partial class GyroSensor - { - public GyroSensor() - : base(port, new[] { Drivers.LegoEv3Gyro }) - { - } - } - - public partial class InfraredSensor - { - public InfraredSensor(string port) - : base(port, new[] { Drivers.LegoEv3Ir }) - { - - } - } - - public partial class SoundSensor - { - public SoundSensor() - : base(string.Empty) - { - throw new NotImplementedException(); - } - } - - public partial class LightSensor - { - public LightSensor() - : base(port, new[] { Drivers.LegoNxtLight }) - { - } - } - - public partial class TouchSensor - { - public TouchSensor(string port) - : base(port, new [] { Drivers.LegoEv3Touch, Drivers.LegoNxtTouch }) - { - } - } - - public partial class PowerSupply - { - public PowerSupply(string name) - { - string strClassDir = Path.Combine(SYS_ROOT, "class", "power_supply"); - - if (string.IsNullOrEmpty(name)) - name = "legoev3-battery"; - - Connect(strClassDir, - name, - new Dictionary()); - } - } - - public partial class LegoPort - { - public LegoPort() - { - throw new NotImplementedException(); - } - } -} \ No newline at end of file diff --git a/csharp/src/ev3dev/project.json b/csharp/src/ev3dev/project.json deleted file mode 100644 index 7d04daa..0000000 --- a/csharp/src/ev3dev/project.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "version": "1.0.0-*", - "description": "ev3dev Class Library", - "authors": [ "pgrudzien12" ], - "tags": [ "" ], - "projectUrl": "", - "licenseUrl": "", - - "frameworks": { - "dnx451": { } - } -} diff --git a/csharp/templates/autogen-header.liquid b/csharp/templates/autogen-header.liquid deleted file mode 100644 index ff071fb..0000000 --- a/csharp/templates/autogen-header.liquid +++ /dev/null @@ -1,2 +0,0 @@ - -// 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-drivers.liquid b/csharp/templates/csharp-class-drivers.liquid deleted file mode 100644 index 9d87fcb..0000000 --- a/csharp/templates/csharp-class-drivers.liquid +++ /dev/null @@ -1,7 +0,0 @@ -{% for item in classes %}{% - assign currentClass = item[1]; %}{% - assign className = currentClass.friendlyName | camel_case | capitalize %}{% - for driver in currentClass.driverName %} - public const string {{driver | camel_case | capitalize}} = "{{driver}}"; {% - endfor %}{% -endfor %} diff --git a/csharp/templates/csharp-class-propertyValues.liquid b/csharp/templates/csharp-class-propertyValues.liquid deleted file mode 100644 index 9f721b8..0000000 --- a/csharp/templates/csharp-class-propertyValues.liquid +++ /dev/null @@ -1,26 +0,0 @@ -{% for item in classes %}{% - assign currentClass = item[1]; %} - /// {% for line in currentClass.description %} - /// {{ line }}{% - endfor %} - /// {% - 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 %}{% - 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 %}{% - endfor %} - } - {%endfor %} - \ No newline at end of file diff --git a/csharp/templates/csharp-class-systemProperties.liquid b/csharp/templates/csharp-class-systemProperties.liquid deleted file mode 100644 index d28f5bc..0000000 --- a/csharp/templates/csharp-class-systemProperties.liquid +++ /dev/null @@ -1,47 +0,0 @@ -{% for item in classes %}{% - assign currentClass = item[1]; %} - /// {% for line in currentClass.description %} - /// {{ line }}{% - endfor %} - /// {% - 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.systemProperties %}{% - 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' %}{% - endif %}{% - 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}}("{{prop.systemName}}"); - } {% endif %}{% - if prop.writeAccess %} - set - { - SetAttr{{setter}}("{{prop.systemName}}", value); - } {% endif %} - } - {% endfor %} - } - {%endfor %} \ No newline at end of file diff --git a/csharp/templates/csharp-infraredsensor-modes.liquid b/csharp/templates/csharp-infraredsensor-modes.liquid deleted file mode 100644 index 1c19fb3..0000000 --- a/csharp/templates/csharp-infraredsensor-modes.liquid +++ /dev/null @@ -1,18 +0,0 @@ -{% for prop in currentClass.propertyValues %}{% - if prop.propertyName == 'Mode' %}{% - assign className = currentClass.friendlyName | camel_case | capitalize %}{% - for value in prop.values %}{% - assign modeName = value.name | camel_case | capitalize %}{% - if modeName == 'float' %}{% - assign modeName = 'float_' %}{% - endif %} - /// {% - for line in value.description %} - /// {{ line }}{% - endfor%} - /// - public void Set{{ modeName }}() { Mode = "{{ value.name }}"; } - public bool Is{{ modeName }}() { return Mode == "{{ value.name }}"; } -{% endfor %}{% - endif %}{% -endfor %} diff --git a/csharp/templates/csharp-motor-commands.liquid b/csharp/templates/csharp-motor-commands.liquid deleted file mode 100644 index f54bb43..0000000 --- a/csharp/templates/csharp-motor-commands.liquid +++ /dev/null @@ -1,17 +0,0 @@ -{% for prop in currentClass.propertyValues %}{% - if prop.propertyName == 'Command' %}{% - assign className = currentClass.friendlyName | camel_case | capitalize %}{% - for value in prop.values %}{% - assign commandName = value.name | camel_case | capitalize %}{% - if commandName == 'float' %}{% - assign commandName = 'float_' %}{% - endif %} - /// {% - for line in value.description %} - /// {{ line }}{% - endfor%} - /// - public void {{ commandName }}() { Command = "{{ value.name }}"; } -{% endfor %}{% - endif %}{% -endfor %}