/// <summary> /// /// </summary> public NxtRobot(bool connectNow, EventHandler onConnected = null, EventHandler onDisconnected = null, EventHandler onSensorModeChanged = null, EventHandler onBatteryValueUpdate = null, EventyList <Variable> .OnActionEventHandler onVariablesListChanged = null, string comPort = "") { // create public list for pattern classification categories Variables = new VariablesList(); // create sensor-dependant pattern classification variables and add to list _reflectedLight = new Variable("Reflected Light", new PercentValue(), this); _ambientLight = new Variable("Ambient Light", new PercentValue(), this); _soundIntensityDb = new Variable("Sound Intensity (dB)", new PercentValue(), this); _soundIntensityDba = new Variable("Sound Intensity (dBA)", new PercentValue(), this); _ultrasonicCm = new Variable("Distance (CM)", new ByteValue(), this); _batteryLevelMillivolts = new Variable("Battery Level (mV)", new GenericValue(0, 15000, "Millivolts"), this); // init sensor variables Variables.AddRange(new[] { _reflectedLight, _ambientLight, _soundIntensityDb, _soundIntensityDba, _ultrasonicCm, _batteryLevelMillivolts }); InitializeSensorVariables(); // subscribe to important events Connected += onConnected; Disconnected += onDisconnected; SensorModeHasChanged += onSensorModeChanged; NewBatteryLevelAvailable += onBatteryValueUpdate; Variables.OnAction += onVariablesListChanged; // connect if (!connectNow) { return; } Connect(comPort); if (!IsConnected) { throw new ApplicationException("Could not connect!"); } }
/// <summary> /// /// </summary> public NxtRobot(bool connectNow, string comPort = "") { // create public list for pattern classification categories Variables = new VariablesList(); // create sensor-dependant pattern classification variables and add to list _reflectedLight = new Variable("Reflected Light", new PercentValue(), this); _ambientLight = new Variable("Ambient Light", new PercentValue(), this); _soundIntensityDb = new Variable("Sound Intensity (dB)", new PercentValue(), this); _soundIntensityDba = new Variable("Sound Intensity (dBA)", new PercentValue(), this); _ultrasonicCm = new Variable("Distance (CM)", new ByteValue(), this); _batteryLevelMillivolts = new Variable("Battery Level (mV)", new GenericValue(0, 15000, "Millivolts"), this); // init sensor variables Variables.AddRange(new[] { _reflectedLight, _ambientLight, _soundIntensityDb, _soundIntensityDba, _ultrasonicCm, _batteryLevelMillivolts }); InitializeSensorVariables(); }