public void TestRGBLED() { IWattCalculator test = new Breadboard(); Assert.AreEqual(3.50, test.Measure()); test = new RGBLED(test); Assert.AreEqual(15.48, test.Measure() - 3.50); }
public void UpdateState() { if (this.TakeReadings) { DateTime Sample = DateTime.Now; this.SystemSensor.UpdateState(); this.DrillSensor.UpdateState(); this.RailSensor.UpdateState(); double RailA = this.RailSensor.GetShuntVoltage(); double Drill = this.DrillSensor.GetCurrent(); double SysA = this.SystemSensor.GetCurrent(); double SysV = this.SystemSensor.GetBusVoltage(); double SysSV = this.SystemSensor.GetShuntVoltage(); double DrlSV = this.DrillSensor.GetShuntVoltage(); if (this.TraceLogging) { Log.Trace(this, string.Format("Sys: {0:N5}A, {1:N5}V (Shunt {2:N5}V). Drill: {3:N5}A. Rail: {4:N5}A. Test: {5}", SysA, SysV, SysSV, Drill, RailA, this.SystemSensor.Test())); } byte[] Data = UtilData.ToBytes(SysSV / 0.150).Concat(UtilData.ToBytes(DrlSV / 0.010)).Concat(UtilData.ToBytes(RailA / 0.002)).Concat(UtilData.ToBytes(SysV)).Concat(UtilData.ToBytes(Sample.Ticks)).ToArray(); // TODO: Decide if we want to calculate or use device Packet Packet = new Packet(new Message(ScienceConstants.Packets.SYS_SENSOR, Data), false); Client.Send(Packet); uint SysVoltColour; if (SysV <= 25) { SysVoltColour = RGBLED.RedGreenGradient(SysV, 22, 26); } else if (SysV <= 28) { SysVoltColour = 0x00FF00; } else { SysVoltColour = RGBLED.RedGreenGradient(SysV, 30, 28); } RoverMain.IOHandler.LEDController.SystemVoltage.SetOutput(SysVoltColour); uint SysCurrentColour; if (SysA <= 2) { SysCurrentColour = 0x00FF00; } else if (SysA >= 5) { SysCurrentColour = 0xFF0000; } else { SysCurrentColour = RGBLED.RedGreenGradient(SysA, 5, 2); } RoverMain.IOHandler.LEDController.SystemCurrent.SetOutput(SysCurrentColour); } }
public async Task PulseFadesOutCompletely() { //arrange var red = new PinStub(1); var green = new PinStub(2); var blue = new PinStub(3); var led = new RGBLED(red, green, blue); //act await led.Pulse(Color.White, TimeSpan.Zero); //assert Assert.Equal(PowerValue.Off, red.Power); Assert.Equal(PowerValue.Off, green.Power); Assert.Equal(PowerValue.Off, blue.Power); }
public async Task CanFadeOutToBlack() { //arrange var red = new PinStub(1); var green = new PinStub(2); var blue = new PinStub(3); var led = new RGBLED(red, green, blue); //act await led.FadeOut(TimeSpan.Zero); //assert Assert.Equal(PowerValue.Off, red.Power); Assert.Equal(PowerValue.Off, green.Power); Assert.Equal(PowerValue.Off, blue.Power); }
public void TurnOffTurnsOffAllPins() { //arrange var red = new PinStub(1); var green = new PinStub(2); var blue = new PinStub(3); var led = new RGBLED(red, green, blue); //act led.TurnOff(); //assert Assert.Equal(PowerValue.Off, red.Power); Assert.Equal(PowerValue.Off, green.Power); Assert.Equal(PowerValue.Off, blue.Power); }
public void TestBlue() { //arrange var red = new StubPinInterface(1); var green = new StubPinInterface(2); var blue = new StubPinInterface(3); var led = new RGBLED(red, green, blue); //act led.TurnBlue(); //assert Assert.Equal(PowerValue.Off, red.Power); Assert.Equal(PowerValue.Off, green.Power); Assert.Equal(PowerValue.On, blue.Power); }
public async Task CanFadeToColor() { //arrange var red = new PinStub(1); var green = new PinStub(2); var blue = new PinStub(3); var led = new RGBLED(red, green, blue); //act var ecoGreen = Color.FromArgb(83, 141, 67); await led.FadeTo(ecoGreen, TimeSpan.Zero); //assert Assert.Equal(32.5, red.Strength, 1); Assert.Equal(55.3, green.Strength, 1); Assert.Equal(26.3, blue.Strength, 1); }
public void TestComplicated() { double testWatts; IWattCalculator test = new ArduinoUno(); Assert.AreEqual(21.40, test.Measure()); testWatts = test.Measure(); test = new RGBLED(test); Assert.AreEqual(testWatts + 15.48, test.Measure()); testWatts = test.Measure(); test = new Buzzer(test); Assert.AreEqual(testWatts + 8.91, test.Measure()); testWatts = test.Measure(); test = new Resistor(test); Assert.AreEqual(testWatts + 17.24, test.Measure()); testWatts = test.Measure(); test = new LED(test); Assert.AreEqual(testWatts + 12.36, test.Measure()); }
public void ColorsMatch(Color color, double r, double g, double b) { //arrange var red = new PinStub(1); var green = new PinStub(2); var blue = new PinStub(3); var led = new RGBLED(red, green, blue); //act led.SetColor(color); //assert Assert.Equal(r, red.Strength); Assert.Equal(g, green.Strength); Assert.Equal(b, blue.Strength); Assert.Equal(r > 0 ? PowerValue.On : PowerValue.Off, red.Power); Assert.Equal(g > 0 ? PowerValue.On : PowerValue.Off, green.Power); Assert.Equal(b > 0 ? PowerValue.On : PowerValue.Off, blue.Power); }