/// <summary>
    /// This generates a random strip AND updates strip variables used for changing sections.
    /// This differs from GetRandomStrip as it chooses a strip for the appropriate section but
    /// GetRandomStrip doesn't update the state variables.
    /// </summary>
    /// <returns>Generates a random strip of the current section and updates.</returns>
    GameObject GetNextAppropriateStrip()
    {
        if (remainingStripSectionLength == 0)
        {
            remainingStripSectionLength = Random.Range(MinStripSectionLength, MaxStripSectionLength);
            //Change sections
            currentSection = (currentSection == StripType.Outside ? StripType.Office : StripType.Outside);

            // Used specifically after a wall to avoid props blocking walls.
            forceBlank = true;

            return(GetRandomStrip(StripType.Wall));
        }
        else if (remainingStripSectionLength > 0)
        {
            //Should generate a random strip from the current section it is on.
            remainingStripSectionLength--;

            // Used specifically after a wall to avoid props blocking walls.
            if (forceBlank)
            {
                forceBlank = false;
                return(currentSection == StripType.Office ? OfficeBlank : OutsideBlank);
            }
        }
        return(GetRandomStrip(currentSection));
    }
        /// <summary>
        /// Adds/Updates controller using default GPIO pin - should only be used with 40-PIN GPIO Boards.
        /// </summary>
        /// <param name="controllerType">type of controller - PWM, PCM, SPI</param>
        /// <param name="ledCount">number of LEDs</param>
        /// <param name="stripType">type of strip</param>
        /// <param name="brightness">maximum brightness for LEDs</param>
        /// <param name="invert">true if signal should be inverted because polarity is reversed</param>
        public Controller AddController(ControllerType controllerType, int ledCount,
                                        StripType stripType = StripType.Unknown,
                                        byte brightness     = 255,
                                        bool invert         = false)
        {
            Controller controller = null;

            switch (controllerType)
            {
            case ControllerType.PWM0:
                controller = AddController(ledCount, Pin.Gpio18, stripType, controllerType, brightness, invert);
                break;

            case ControllerType.PWM1:
                controller = AddController(ledCount, Pin.Gpio13, stripType, controllerType, brightness, invert);
                break;

            case ControllerType.PCM:
                controller = AddController(ledCount, Pin.Gpio21, stripType, controllerType, brightness, invert);
                break;

            case ControllerType.SPI:
                controller = AddController(ledCount, Pin.Gpio10, stripType, controllerType, brightness, invert);
                break;
            }
            return(controller);
        }
Exemple #3
0
        /// <summary>
        /// 建立ToolStrip系统
        /// </summary>
        public virtual ToolStrip BuildToolStrip(StripType striptype)
        {
            _striptype = striptype;
            ToolStrip strip = null;

            switch (striptype)
            {
            case StripType.Menu:
                strip = new MenuStrip();
                BuildStripSubMethod(strip);
                break;

            case StripType.Status:
                strip = new StatusStrip();
                BuildStripSubMethod(strip);
                break;

            case StripType.ToolBar:
                strip = new ToolStrip();
                BuildStripSubMethod(strip);
                break;

            case StripType.ContextMenu:
                strip = new ContextMenuStrip();
                BuildStripSubMethod(strip);
                break;

            default:
                throw new Exception("");
            }
            return(strip);
        }
Exemple #4
0
 /// <summary>
 /// Creates a <see cref="StripDefinition"/> with the provided size and type.
 /// </summary>
 /// <param name="type">The type of the strip to create</param>
 /// <param name="sizeValue">The value of the strip to create</param>
 public StripDefinition(StripType type, float sizeValue = 1)
 {
     Type        = type;
     SizeValue   = sizeValue;
     MaximumSize = float.PositiveInfinity;
     MinimumSize = 0;
 }
Exemple #5
0
        internal Controller(int ledCount, Pin pin, byte brightness, bool invert, StripType stripType, ControllerType controllerType)
        {
            Pin            = pin;
            GPIOPin        = (int)pin;
            Invert         = invert;
            Brightness     = brightness;
            StripType      = stripType;
            ControllerType = controllerType;

            LEDColors = Enumerable.Range(0, ledCount).Select(x => new LED()).ToList();
        }
        /// <summary>
        /// Set LED to a Color
        /// </summary>
        /// <param name="ledID">LED to set (0 based)</param>
        /// <param name="color">Color to use</param>
        public void SetLED(int ledID, Color color)
        {
            var cName = StripType.ToString();

            if (cName.Contains("W") && cName.Contains("SK"))
            {
                color = ColorClamp.ClampAlpha(color);
            }
            LEDColors[ledID] = color;
            IsDirty          = true;
        }
        /// <summary>
        /// Adds/Updates controller using provided settings.
        /// </summary>
        /// <param name="ledCount">number of LEDs</param>
        /// <param name="pin">GPIO pin used to controller strip</param>
        /// <param name="stripType">type of strip</param>
        /// <param name="controllerType">type of controller - should be supported by selected pin</param>
        /// <param name="brightness">maximum brightness for LEDs</param>
        /// <param name="invert">true if signal should be inverted because polarity is reversed</param>
        public Controller AddController(int ledCount, Pin pin,
                                        StripType stripType           = StripType.Unknown,
                                        ControllerType controllerType = ControllerType.PWM0,
                                        byte brightness = 255,
                                        bool invert     = false)
        {
            int channelNumber = (controllerType == ControllerType.PWM1) ? 1 : 0;

            Controllers[channelNumber] = new Controller(ledCount, pin, brightness, invert, stripType, controllerType);

            return(Controllers[channelNumber]);
        }
Exemple #8
0
        private static Grid CreateGrid(int colums, int rows, int layers, StripType stripType)
        {
            var generator = (Func <StripDefinition>)(() => new StripDefinition {
                Type = stripType
            });
            var grid = new Grid();

            grid.ColumnDefinitions.AddRange(generator.Repeat(colums));
            grid.RowDefinitions.AddRange(generator.Repeat(rows));
            grid.LayerDefinitions.AddRange(generator.Repeat(layers));
            return(grid);
        }
Exemple #9
0
 public string Get(StripType t = StripType.NONE)
 {
     lock (_Lock)
     {
         List<string> list = new List<string>();
         foreach (var s in _Strips)
         {
             if (t == StripType.NONE || t == s.Type) list.Add(s.Message);
         }
         return string.Join(Environment.NewLine, list);
     }
 }
Exemple #10
0
        public Channel(long ledCount, int gpioPin, byte brightness, bool invert, StripType stripType)
        {
            GPIOPin    = gpioPin;
            Invert     = invert;
            Brightness = brightness;
            StripType  = stripType;

            var ledList = new List <Light>();

            for (int i = 0; i <= ledCount - 1; i++)
            {
                ledList.Add(new Light(i));
            }
            Lights = new ReadOnlyCollection <Light>(ledList);
        }
        /// <summary>
        /// Set all the LEDs in the strip to same color
        /// </summary>
        /// <param name="color">color to set all the LEDs</param>
        public void SetAll(Color color)
        {
            var cName = StripType.ToString();

            if (cName.Contains("W") && cName.Contains("SK"))
            {
                color = ColorClamp.ClampAlpha(color);
            }

            for (var i = 0; i < LEDColors.Length; i++)
            {
                LEDColors[i] = color;
            }
            IsDirty = true;
        }
Exemple #12
0
        public Channel(int ledCount, StripType stripType, int gpioPin = 18, byte brightness = 255, bool invert = false)
        {
            this.GpioPin    = gpioPin;
            this.Invert     = invert;
            this.Brightness = brightness;
            this.StripType  = stripType;

            var ledList = new List <Light>();

            for (var i = 0; i <= ledCount - 1; i++)
            {
                ledList.Add(new Light());
            }

            this.Lights = new ReadOnlyCollection <Light>(ledList);
        }
        internal Controller(int ledCount, Pin pin, byte brightness, bool invert, StripType stripType, ControllerType controllerType)
        {
            IsDirty = false;

            Pin            = pin;
            GPIOPin        = (int)pin;
            Invert         = invert;
            Brightness     = brightness;
            StripType      = stripType;
            ControllerType = controllerType;

            LEDColors = new Color[ledCount];
            for (var i = 0; i < ledCount; i++)
            {
                LEDColors[i] = Color.Empty;
            }
        }
Exemple #14
0
        /// <summary>
        /// Settings to initialize the WS281x controller
        /// </summary>
        /// <param name="gpioPin">RaspberryPi GPIO pin to which NeoPixel chain is connected</param>
        /// <param name="frequency">Set frequency in Hz</param>
        /// <param name="dmaChannel">Set DMA channel to use</param>
        /// <param name="ledCount">Number of LEDs in chain</param>
        /// <param name="invert">If bytes should be inverted</param>
        /// <param name="autoShow">If <value>true</value> color will be displayed automatically, when <value>false</value> Show() function must be called to see the effect</param>
        /// <param name="stripType">Type of the LED chain</param>
        public NeoPixelPWM(int ledCount, int gpioPin, uint frequency = 800000, int dmaChannel = 10, bool invert = false, bool autoShow = true, StripType stripType = StripType.WS2812_STRIP)
        {
            Frequency  = frequency;
            DMAChannel = dmaChannel;
            GPIOPin    = gpioPin;
            Invert     = invert;
            AutoShow   = false;
            StripType  = stripType;

            var ledList = new List <LED>(ledCount);

            for (int i = 0; i <= ledCount - 1; i++)
            {
                ledList.Add(new LED(i, this));
            }

            LEDs = new ReadOnlyCollection <LED>(ledList);

            ws2811_ = new ws2811_t {
                dmanum  = DMAChannel,
                freq    = Frequency,
                channel = new[] {
                    new ws2811_channel_t {
                        count      = ledCount,
                        brightness = 255,
                        gpionum    = GPIOPin,
                        invert     = Convert.ToInt32(Invert),
                        strip_type = (int)stripType,
                    },
                    new ws2811_channel_t(),
                }
            };

            // _ws2811Handle = GCHandle.Alloc(_ws2811, GCHandleType.Pinned);

            var initResult = NativeMethods.ws2811_init(ref ws2811_);

            if (initResult != ws2811_return_t.WS2811_SUCCESS)
            {
                string returnMessage = GetMessageForStatusCode(initResult);
                throw new Exception($"Error while initializing.{Environment.NewLine}Error code: {initResult.ToString()}{Environment.NewLine}Message: {returnMessage}");
            }

            AutoShow = autoShow;
        }
    GameObject GetRandomStrip(StripType stripType)
    {
        switch (stripType)
        {
        case StripType.Office:
            return(OfficeStrips[Random.Range(0, OfficeStrips.Length)]);

        case StripType.Outside:
            return(OutsideStrips[Random.Range(0, OutsideStrips.Length)]);

        case StripType.Wall:
            var x = WallStrips[Random.Range(0, WallStrips.Length)];
            Debug.Log(x);
            return(x);

        default:
            Debug.Log("ERROR");
            return(new GameObject());
        }
    }
    void InitialGameLoad()
    {
        //REMOVE ALL STRIPS
        var existingStrips = GameObject.FindGameObjectsWithTag("Strip");

        foreach (var s in existingStrips)
        {
            GameObject.Destroy(s);
        }

        currentSection = StripType.Outside;

        MapStrips.Add(MarkerStrip);

        // PRE-GENERATE
        for (var x = 0; x < preloadStripCount; x++)
        {
            SpawnNewStrip();
        }
    }
Exemple #17
0
        public Controller AddController(ControllerType controllerType, int ledCount, StripType stripType = StripType.Unknown)
        {
            Controller controller = null;

            switch (controllerType)
            {
            case ControllerType.PWM0:
                controller = AddController(ledCount, Pin.Gpio18, stripType, controllerType);
                break;

            case ControllerType.PWM1:
                controller = AddController(ledCount, Pin.Gpio13, stripType, controllerType);
                break;

            case ControllerType.PCM:
                controller = AddController(ledCount, Pin.Gpio21, stripType, controllerType);
                break;

            case ControllerType.SPI:
                controller = AddController(ledCount, Pin.Gpio10, stripType, controllerType);
                break;
            }
            return(controller);
        }
Exemple #18
0
 /// <summary>
 /// Creates a <see cref="StripDefinition"/> with the provided size and type.
 /// </summary>
 /// <param name="type">The type of the strip to create</param>
 /// <param name="sizeValue">The value of the strip to create</param>
 public StripDefinition(StripType type, float sizeValue = 1.0f)
 {
     Type      = type;
     SizeValue = sizeValue;
 }
Exemple #19
0
 public Channel(int ledCount, int pin, byte brightness, bool invert, StripType stripType)
     : base(ledCount, (Pin)pin, brightness, invert, stripType, ControllerType.Unknown)
 {
 }