Пример #1
0
 public void BeginSendInfo()
 {
     Task.Run(async() =>
     {
         while (true)
         {
             for (int i = 0; i < LEDs.Count(); i++)
             {
                 await Task.Delay(500);
                 if (LEDs[i] != null)
                 {
                     if (MQs.TryGetValue(LEDs[i].LEDIP, out Queue <string> mq))
                     {
                         if (mq.Count > 0)
                         {
                             string msg = mq.Dequeue();
                             int n      = LEDs[i].SendLedInfo(msg);
                             if (i != 0)
                             {
                                 var option = Options.FirstOrDefault(t => t.IP == LEDs[i].LEDIP);
                                 if (option != null)
                                 {
                                     LEDs[i] = new LED(option.IP, option.Port, option.Timesec);
                                     LEDs[i].SendLedInfo(msg);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     });
 }
Пример #2
0
        public IOHandler()
        {
            RaspberryPi.Initialize();
            this.I2C            = new I2CBusPi();
            this.SPI            = new SPIBusPi(0);
            this.PWMGenHighFreq = new PCA9685(this.I2C, 0x4C, -1, PCA9685.OutputInvert.Inverted, PCA9685.OutputDriverMode.OpenDrain);
            this.PWMGenLowFreq  = new PCA9685(this.I2C, 0x74, -1, PCA9685.OutputInvert.Inverted, PCA9685.OutputDriverMode.OpenDrain);
            this.PWMGenHighFreq.SetFrequency(333);
            this.PWMGenLowFreq.SetFrequency(50);

            this.RailController = new Rail(this.PWMGenHighFreq.Outputs[0], new DigitalInPi(11), this.SPI, new DigitalOutPi(29), this.I2C, null)
            {
                TraceLogging = true
            };
            this.DrillController  = new Drill(this.PWMGenHighFreq.Outputs[1], this.PWMGenLowFreq.Outputs[0]);
            this.SampleController = new Sample(this.PWMGenLowFreq.Outputs[1]);
            this.LEDController    = new LEDs(this.PWMGenLowFreq.Outputs, this.PWMGenHighFreq.Outputs);
            this.AuxSensors       = new AuxSensors(this.SPI, this.I2C)
            {
                TraceLogging = false
            };
            this.SysSensors = new SysSensors();
            this.Music      = new MusicPlayer();

            this.InitProcedure   = new ISubsystem[] { this.RailController, this.DrillController, this.LEDController, this.AuxSensors, this.SysSensors, this.Music };
            this.EStopProcedure  = new ISubsystem[] { this.Music, this.RailController, this.DrillController, this.LEDController, this.AuxSensors, this.SysSensors };
            this.UpdateProcedure = new ISubsystem[] { this.RailController, this.DrillController, this.LEDController /*, this.AuxSensors, this.SysSensors*/ };
            if (this.EStopProcedure.Length < this.InitProcedure.Length || this.EStopProcedure.Length < this.UpdateProcedure.Length)
            {
                throw new Exception("A system is registered for init or updates, but not for emergency stop. For safety reasons, this is not permitted.");
            }
        }
Пример #3
0
        /*public LEDs LEDs {
         *      get {
         *              LEDs leds = LEDs.None;
         *              if (LED1) leds |= LEDs.LED1;
         *              if (LED2) leds |= LEDs.LED2;
         *              if (LED3) leds |= LEDs.LED3;
         *              if (LED4) leds |= LEDs.LED4;
         *              return leds;
         *      }
         *      set {
         *              LED1 = value.HasFlag(LEDs.LED1);
         *              LED2 = value.HasFlag(LEDs.LED2);
         *              LED3 = value.HasFlag(LEDs.LED3);
         *              LED4 = value.HasFlag(LEDs.LED4);
         *      }
         * }*/

        internal void Parse(byte[] buff, int off)
        {
            /*BatteryLow     = (buff[off + 0] & 0x01) != 0;
             * Extension  = (buff[off + 0] & 0x02) != 0;
             * Speaker    = (buff[off + 0] & 0x04) != 0;
             * IREnabled  = (buff[off + 0] & 0x08) != 0;
             *
             * LEDs = (LEDs) ((buff[off + 0] >> 4) & 0x0F);
             *
             * LED1 = (buff[off + 0] & 0x10) != 0;
             * LED2 = (buff[off + 0] & 0x20) != 0;
             * LED3 = (buff[off + 0] & 0x40) != 0;
             * LED4 = (buff[off + 0] & 0x80) != 0;*/

            BatteryLow = buff.GetBit(off + 0, 0);
            Extension  = buff.GetBit(off + 0, 1);
            Speaker    = buff.GetBit(off + 0, 2);
            IREnabled  = buff.GetBit(off + 0, 3);

            LEDs = (LEDs)((buff[off + 0] >> 4) & 0x0F);

            /*LED1 = buff.GetBit(off + 0, 4);
            *  LED2 = buff.GetBit(off + 0, 5);
            *  LED3 = buff.GetBit(off + 0, 6);
            *  LED4 = buff.GetBit(off + 0, 7);*/

            BatteryRaw = buff[off + 3];
            Battery    = ((100f * 48f * (float)((int)BatteryRaw / 48f))) / 176f;
            //Battery = BatteryRaw / 2.55f;// ((100f * 48f * (float)((int)BatteryRaw / 48f))) / 192f;
        }
Пример #4
0
 public DefaultLEDImplement(List <LEDCreateOption> options)
 {
     Options = options;
     foreach (var item in options)
     {
         LEDs.Add(new LED(item.IP, item.Port, item.Timesec));
     }
 }
Пример #5
0
 public void SetLED(LEDs led, bool state)
 {
     if (state)
     {
         LEDStates = (LEDStates | (int)led);
     }
     else
     {
         LEDStates = (LEDStates & ~((int)led));
     }
 }
        private void SetLEDState(LEDs led, bool state)
        {
            Image image = (Image)FindName("imageGlow" + led);

            if (state)
            {
                image.Visibility = Visibility.Visible;
            }
            else
            {
                image.Visibility = Visibility.Hidden;
            }
        }
Пример #7
0
        /// <summary>
        /// Renders the content of the channels
        /// </summary>
        public void Show()
        {
            int[] ledColor = LEDs.Select(x => x.GetRGBColorWIthBrightness()).ToArray();
            Marshal.Copy(ledColor, 0, ws2811_.channel[0].leds, ledColor.Count());

            var result = NativeMethods.ws2811_render(ref ws2811_);

            if (result != ws2811_return_t.WS2811_SUCCESS)
            {
                string returnMessage = GetMessageForStatusCode(result);
                throw new Exception($"Error while rendering.{Environment.NewLine}Error code: {result.ToString()}{Environment.NewLine}Message: {returnMessage}");
            }
        }
 private void SetLEDState(LEDs led, LEDs leds)
 {
     SetLEDState(led, leds.HasFlag(led));
 }
Пример #9
0
 public LedUnit GetLEDByName(string name)
 {
     return(LEDs.FirstOrDefault(x => x.LEDName == name));
 }
Пример #10
0
 public LEDMatrix(LEDs leds, ushort startPixel, byte width, byte height, Corner firstPixelPosition, Orientation secondPixelPosition)
 {
     offset = startPixel;
     target = leds;
     map    = new ushort[width, height];
     if (firstPixelPosition == Corner.TopRight)
     {
         byte   x   = (byte)(width - 1);
         byte   y   = 0;
         ushort led = offset;
         do
         {
             map[x, y] = led++;
             // 321
             // 456
             // 987
             if (secondPixelPosition == Orientation.Rows)
             {
                 if (y % 2 == 0)
                 {
                     if (x > 0)
                     {
                         x--;
                     }
                     else
                     {
                         y++;
                     }
                 }
                 else
                 {
                     if (x < (byte)(width - 1))
                     {
                         x++;
                     }
                     else
                     {
                         y++;
                     }
                 }
             }
             // 761
             // 852
             // 943
             else // (secondPixelPosition == Orientation.Colums)
             {
                 if (x % 2 == width % 2)
                 {
                     if (y > 0)
                     {
                         y--;
                     }
                     else
                     {
                         x--;
                     }
                 }
                 else
                 {
                     if (y < (byte)(height - 1))
                     {
                         y++;
                     }
                     else
                     {
                         x--;
                     }
                 }
             }
         } while (led < offset + width * height);
     }
     else if (firstPixelPosition == Corner.TopLeft)
     {
         byte   x   = 0;
         byte   y   = 0;
         ushort led = offset;
         do
         {
             map[x, y] = led++;
             // 123
             // 654
             // 789
             if (secondPixelPosition == Orientation.Rows)
             {
                 if (y % 2 == 0)
                 {
                     if (x < (byte)(width - 1))
                     {
                         x++;
                     }
                     else
                     {
                         y++;
                     }
                 }
                 else
                 {
                     if (x > 0)
                     {
                         x--;
                     }
                     else
                     {
                         y++;
                     }
                 }
             }
             // 167
             // 258
             // 349
             else // (secondPixelPosition == Orientation.Colums)
             {
                 if (x % 2 == 0)
                 {
                     if (y < (byte)(height - 1))
                     {
                         y++;
                     }
                     else
                     {
                         x++;
                     }
                 }
                 else
                 {
                     if (y > 0)
                     {
                         y--;
                     }
                     else
                     {
                         x++;
                     }
                 }
             }
         } while (led < offset + width * height);
     }
     else if (firstPixelPosition == Corner.BottomLeft)
     {
         byte   x   = 0;
         byte   y   = (byte)(height - 1);
         ushort led = offset;
         do
         {
             map[x, y] = led++;
             // 789
             // 654
             // 123
             if (secondPixelPosition == Orientation.Rows)
             {
                 if (y % 2 == height % 2)
                 {
                     if (x < (byte)(width - 1))
                     {
                         x++;
                     }
                     else
                     {
                         y--;
                     }
                 }
                 else
                 {
                     if (x > 0)
                     {
                         x--;
                     }
                     else
                     {
                         y--;
                     }
                 }
             }
             // 349
             // 258
             // 167
             else // (secondPixelPosition == Orientation.Colums)
             {
                 if (x % 2 == 0)
                 {
                     if (y > 0)
                     {
                         y--;
                     }
                     else
                     {
                         x++;
                     }
                 }
                 else
                 {
                     if (y < (byte)(height - 1))
                     {
                         y++;
                     }
                     else
                     {
                         x++;
                     }
                 }
             }
         } while (led < offset + width * height);
     }
     else // (firstPixelPosition == Corner.BottomRight)
     {
         byte   x   = (byte)(width - 1);
         byte   y   = (byte)(height - 1);
         ushort led = offset;
         do
         {
             map[x, y] = led++;
             // 987
             // 456
             // 321
             if (secondPixelPosition == Orientation.Rows)
             {
                 if (y % 2 == height % 2)
                 {
                     if (x > 0)
                     {
                         x--;
                     }
                     else
                     {
                         y--;
                     }
                 }
                 else
                 {
                     if (x < (byte)(width - 1))
                     {
                         x++;
                     }
                     else
                     {
                         y--;
                     }
                 }
             }
             // 943
             // 852
             // 761
             else // (secondPixelPosition == Orientation.Colums)
             {
                 if (x % 2 == width % 2)
                 {
                     if (y > 0)
                     {
                         y--;
                     }
                     else
                     {
                         x--;
                     }
                 }
                 else
                 {
                     if (y < (byte)(height - 1))
                     {
                         y++;
                     }
                     else
                     {
                         x--;
                     }
                 }
             }
         } while (led < offset + width * height);
     }
 }
Пример #11
0
        static void Main(string[] args)
        {
            LEDs strip = new LEDs(256);

            /*
             * for (int r = 0; r < 256; r += 16)
             * {
             *  for (uint g = 0; g < 256; g += 16)
             *  {
             *      for (uint b = 0; b < 256; b += 16)
             *      {
             *          for (ushort i = 0; i < 256; i++)
             *          {
             *           //   strip.setPixel(i, (byte)r, (byte)g, (byte)b);
             *          }
             *          strip.show();
             *      }
             *  }
             * }
             */
            LEDColorMap map = new LEDColorMap(new LEDColor[, ] {
                { new LEDColor(255, 0, 0), new LEDColor(0, 255, 0) }, { new LEDColor(0, 255, 0), new LEDColor(0, 0, 255) }, { new LEDColor(0, 0, 255), new LEDColor(255, 0, 0) }
            }, 8);
            LEDColorMap map2 = new LEDColorMap(new LEDColor[, ] {
                { new LEDColor(255, 255, 0), new LEDColor(0, 255, 255) }, { new LEDColor(0, 255, 255), new LEDColor(255, 0, 255) }, { new LEDColor(255, 0, 255), new LEDColor(255, 255, 0) }
            }, 8);
            LEDColorMap empty = new LEDColorMap(new LEDColor[, ] {
                { new LEDColor(0, 0, 0) }
            }, 1);

            LEDMatrix m = new LEDMatrix(strip, 0, 16, 16, LEDMatrix.Corner.TopRight, LEDMatrix.Orientation.Rows);

            /*
             * //m.setPixel(0, 0, 255, 0, 0);
             * m.show();
             * //Thread.Sleep(2000);
             *
             * //m.setPixel(15,0, 0, 0, 255);
             * m.show();
             * //Thread.Sleep(2000);
             *
             * //m.setPixel(15, 15, 255, 255, 255);
             * m.show();
             * //Thread.Sleep(2000);
             *
             * //m.setPixel(0, 15, 0, 255, 0);
             * m.show();
             * //Thread.Sleep(2000);
             *
             * //m.drawRectangle(0, 0, 16, 16, 255, 0, 0);
             * m.show();
             * //Thread.Sleep(2000);
             *
             * //m.drawRectangle(1, 1, 14, 14, 0, 255, 0);
             * m.show();
             * //Thread.Sleep(2000);
             *
             * //m.drawRectangle(2, 2, 12, 12, 0, 0, 255);
             * m.show();
             * //Thread.Sleep(2000);
             *
             * //m.drawRectangle(3, 3, 10, 10, 255, 0, 0);
             * m.show();
             * //Thread.Sleep(2000);
             *
             * //m.drawRectangle(4, 4, 8, 8, 0, 255, 0);
             * m.show();
             * //Thread.Sleep(2000);
             *
             * //m.drawRectangle(5, 5, 6, 6, 0, 0, 255);
             * m.show();
             * //Thread.Sleep(2000);
             *
             * //m.fillRectangle(0, 0, 8, 16, 255, 0, 0);
             * //m.show();
             * //Thread.Sleep(2000);
             *
             * //m.fillRectangle(8, 0, 8, 16, 0, 255, 0);
             * // m.show();
             * Thread.Sleep(2000);
             *
             * //m.fillRectangle(0, 0,16, 16, 0, 0, 0);
             * // m.show();
             */
            LEDText txt = new LEDText(m, 0, 0, 16, empty, map2);

            txt.setText("Localhorst");

            LEDText txt2 = new LEDText(m, 0, 8, 16, map, empty);

            txt2.setText("LOCALHORST");

            while (true)
            {
                txt.writeNext();
                txt2.writeNext();
                Thread.Sleep(50);
                txt2.writeNext();
                Thread.Sleep(50);
            }



            Console.WriteLine("END");
        }