Exemple #1
0
        public static byte[] SendTMStrings(TMStringMessage tmStringMessage)
        {
            int expectedLength = 1;

            foreach (var ut in tmStringMessage.UnitType)
            {
                if (ut)
                {
                    expectedLength += 16;
                }
                else
                {
                    expectedLength += 8;
                }
            }
            if (expectedLength < 2)
            {
                return(null);
            }
            byte[] messageData = new byte[expectedLength];
            int    serialCount = -1;

            messageData[++serialCount] = Convert.ToByte(IntValueCheck(tmStringMessage.Intensity, 0, Constants.MaxIntensityTM));
            for (int i = 0; i < tmStringMessage.Display.Count; i++)
            {
                //messageData[++serialCount] = Convert.ToByte(i+1); //unit number
                int      textLength;
                BitArray dotsArray;
                var      display = TMDisplayStringConverter(tmStringMessage, i, out textLength, out dotsArray);
                for (var k = 0; k < textLength; k++)
                {
                    if (display.Length - 1 < k)
                    {
                        messageData[++serialCount] = 0;
                    }
                    else
                    {
                        messageData[++serialCount] = display[k];
                    }
                    if (dotsArray[k])
                    {
                        messageData[serialCount] += 128; //doesn't increment serialCount because it alters last byte
                    }
                }
            }


            return(messageData);
        }
        private static byte[] TMDisplayStringConverter(
            TMStringMessage tmStringMessage, int i, out int textLength, out BitArray dotsArray)
        {
            // Process string
            byte[] display;
            if (tmStringMessage.UnitType[i])
            {
                //true means 16-segment display
                display = tmStringMessage.Display[i].Length > 0
                                  ? Encoding.ASCII.GetBytes(tmStringMessage.Display[i])
                                  : new byte[] { 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32 };
            }
            else
            {
                display = tmStringMessage.Display[i].Length > 0
                                  ? Encoding.ASCII.GetBytes(tmStringMessage.Display[i])
                                  : new byte[] { 32, 32, 32, 32, 32, 32, 32, 32 };
            }

            for (var j = 0; j < display.Length; j++)
            {
                display[j] = ArduinoLink.FontBytes[display[j] - 32];
            }
            //add dots
            byte[] tempDots;
            if (tmStringMessage.UnitType[i])
            {
                textLength  = 16;
                tempDots    = new byte[2];
                tempDots[0] = Convert.ToByte(tmStringMessage.Dots[i][0]);
                if (tmStringMessage.Dots[i].Length < 2)
                {
                    tempDots[1] = Convert.ToByte(0);
                }
                else
                {
                    tempDots[1] = Convert.ToByte(tmStringMessage.Dots[i][1]);
                }
            }
            else
            {
                tempDots    = new byte[1];
                tempDots[0] = Convert.ToByte(tmStringMessage.Dots[i][0]);
                textLength  = 8;
            }
            dotsArray = new BitArray(tempDots);
            return(display);
        }
        public static byte[] SendTMStrings(TMStringMessage tmStringMessage)
        {
            int expectedLength = 1;
            foreach (var ut in tmStringMessage.UnitType)
            {
                if (ut)
                {
                    expectedLength += 16;
                }
                else
                {
                    expectedLength += 8;
                }
            }
            if (expectedLength < 2) return null;
            byte[] messageData = new byte[expectedLength];
            int serialCount = -1;
            messageData[++serialCount] = Convert.ToByte(IntValueCheck(tmStringMessage.Intensity, 0, Constants.MaxIntensityTM));
            for (int i = 0; i < tmStringMessage.Display.Count; i++)
            {
                int textLength;
                BitArray dotsArray;
                var display = TMDisplayStringConverter(tmStringMessage, i, out textLength, out dotsArray);
                for (var k = 0; k < textLength; k++)
                {
                    if (display.Length - 1 < k)
                    {
                        messageData[++serialCount] = 0;
                    }
                    else
                    {
                        messageData[++serialCount] = display[k];
                    }
                    if (dotsArray[k])
                    {
                        messageData[serialCount] += 128; //doesn't increment serialCount because it alters last byte
                    }
                }

            }

            return messageData;
        }
        private void TestTimerTick(object sender, EventArgs e)
        {
            this.testCounter++;
            int numberUnits = this.unitTypes.Count;
            var displays    = new List <string>(numberUnits);
            var greens      = new List <byte>(numberUnits);
            var reds        = new List <byte>(numberUnits);
            var dotsList    = new List <byte[]>(numberUnits);

            byte green;
            byte red;
            byte dots;

            for (int t = 0; t < numberUnits; t++)
            {
                displays.Add("");
                greens.Add(0);
                reds.Add(0);
                dotsList.Add(this.unitTypes[t] ? new Byte[] { 0, 0 } : new Byte[] { 0 });
            }

            string display = this.TestSequence(this.testCounter, out green, out red, out dots);

            this.DuplicateDisplayAcrossAllUnits(display, green, red, dots, displays, greens, reds, dotsList, this.unitTypes);
            var tmLEDs = new TMLEDSMessage
            {
                Green     = greens,
                Red       = reds,
                Intensity = 3
            };
            var tmDisplay = new TMStringMessage
            {
                Display   = displays,
                Dots      = dotsList,
                Intensity = 3,
                UnitType  = this.unitTypes
            };

            this.arduinoConnection.SendSerialMessage(Constants.MessageID_TMLED, SendTMLEDS(tmLEDs));
            this.arduinoConnection.SendSerialMessage(Constants.MessageID_TMString, SendTMStrings(tmDisplay));
        }
 private void ShiftPreviewTick(object sender, EventArgs e)
 {
     if (this.shiftPreviewRpm <= 7000)
     {
         var displays = new List<string>();
         var dots = new List<byte[]>();
         var greens = new List<byte>();
         var reds = new List<byte>();
         var pastShift = false;
         foreach (DisplayUnitConfiguration t in this.configurationOptions.DisplayUnitConfigurations)
         {
             displays.Add(this.shiftPreviewRpm.ToString(CultureInfo.InvariantCulture));
             dots.Add(t.IsTM1640 ? new byte[] { 0, 0 } : new byte[] { 0 });
             if (t.LEDsConfigurations.ShowShiftLights)
             {
                 byte red;
                 byte green;
                 ShiftStyleEnum temp =
                     this.hostApp.DisplayMngr.Dictionarys.ShiftStyles[t.LEDsConfigurations.ShiftLightStyle];
                 LEDFunctions.GetShiftLights(this.hostApp.DisplayMngr.Dictionarys, this.shiftPreviewRpm, 6000, 7000, 6800,
                                                     temp, t.LEDsConfigurations.ShiftClumps, out pastShift, out red,
                                                     out green);
                 greens.Add(green);
                 reds.Add(red);
             }
             else
             {
                 greens.Add(0);
                 reds.Add(0);
             }
         }
         int newInt = this.configurationOptions.Intensity;
         if (pastShift && this.configurationOptions.ShiftIntensity)
         {
             if (this.configurationOptions.ShiftIntensityType)
             {
                 //relative
                 newInt += this.configurationOptions.ShiftIntensityAmount + 1;
             }
             else
             {
                 newInt += this.configurationOptions.ShiftIntensityAmount;
             }
         }
         var tmLEDs = new TMLEDSMessage
         {
             Green = greens,
             Red = reds,
             Intensity = newInt
         };
         var tmDisplay = new TMStringMessage
         {
             Display = displays,
             Dots = dots,
             Intensity = newInt,
             UnitType = this.hostApp.DisplayMngr.TM1640Units
         };
         this.hostApp.ArduinoConnection.SendSerialMessage(Constants.MessageID_TMLED, ArduinoMessagesSending.SendTMLEDS(tmLEDs));
         this.hostApp.ArduinoConnection.SendSerialMessage(Constants.MessageID_TMString, ArduinoMessagesSending.SendTMStrings(tmDisplay));
         this.shiftPreviewRpm += 50;
     }
     else
     {
         this.hostApp.ArduinoConnection.Clear();
         this.hostApp.DisplayMngr.Previewing = false;
         this.shiftPreviewTimer.Stop();
     }
 }
Exemple #6
0
        private void SendTMDisplay()
        {
            if (CurrentConfiguration == null) return;

            List<TMDisplayVariables> final = new List<TMDisplayVariables>();

            for (int i = 0; i < CurrentConfiguration.TMDisplaySettings.NumDisplayUnits; i++)
            {
                final.Add(new TMDisplayVariables());
                int result = DateTime.Now.CompareTo(this.WaitTimeTMDisplay[i]);
                if (result > 0) //dont wait
                {
                    //normal situation
                    if (this.SavedTelemetry.OnTrack && Wrapper.IsConnected)
                    {
                        //send normal message
                        ParseDisplayString(RequestedTMDisplayVariables[i].Display,
                                               out final[i].Display,
                                               out final[i].Dots,
                                               CurrentConfiguration.DisplayConfigurations[i].IsTM1640);
                    }
                    else
                    {
                        //send blank message please
                        final[i].Display = "        ";
                        if (CurrentConfiguration.DisplayConfigurations[i].IsTM1640)
                        {
                            final[i].Display += "                ";
                        }
                        for (int x = 0; x < final[i].Dots.Count(); x++)
                        {
                            final[i].Dots[x] = 0;
                        }

                        if (this.weAreClosing == false)
                        {
                            final[i].Display = DateTime.Now.ToString("HH-mm-ss");
                        }
                        else
                        {
                            final[i].Display = "        ";
                        }

                    }
                }
                else //do wait!!
                {
                    //check for testing
                    if (!Test && !Previewing) //if not testing then
                    {
                        ////
                        //send wait message and new lights
                        ////
                        ParseDisplayString(RequestedTMDisplayVariables[i].WaitString,
                                               out final[i].Display,
                                               out final[i].Dots,
                                               CurrentConfiguration.DisplayConfigurations[i].IsTM1640);
                    } //if testing then leave alone
                }
            }

            //send to display
            if (ArduinoConnection.Running && !Test)
            {
                //Merge
                var displayList = new List<string>();
                var dotsList = new List<byte[]>();
                for (int i = 0; i < final.Count; i++)
                {
                    displayList.Add(final[i].Display);

                    if (CurrentConfiguration.DisplayConfigurations[i].Inverted)
                    {
                        //Shift dots one place to the left
                        for (int y = 0; y < final[i].Dots.Count(); y++)
                        {
                            var temp = (byte)(final[i].Dots[y] << 1);
                            final[i].Dots[y] = temp;
                        }
                        dotsList.Add(final[i].Dots);
                    }
                    else
                    {
                        dotsList.Add(final[i].Dots);
                    }
                }

                int newInt = Intensity;
                if (this.pastShiftPoint && CurrentConfiguration.TMDisplaySettings.ShiftIntensity)
                {
                    if (CurrentConfiguration.TMDisplaySettings.ShiftIntensityType)
                    {
                        //relative
                        newInt += CurrentConfiguration.TMDisplaySettings.ShiftIntensityAmount + 1;
                    }
                    else
                    {
                        newInt += CurrentConfiguration.TMDisplaySettings.ShiftIntensityAmount;
                    }
                }
                var tmDisplay = new TMStringMessage
                {
                    Display = displayList,
                    Dots = dotsList,
                    Intensity = newInt,
                    UnitType = TM1640Units
                };
                ArduinoConnection.SendSerialMessage(Constants.MessageID_TMString, ArduinoMessagesSending.SendTMStrings(tmDisplay));
            }
        }
        private void TestTimerTick(object sender, EventArgs e)
        {
            this.testCounter++;
            int numberUnits = this.unitTypes.Count;
            var displays = new List<string>(numberUnits);
            var greens = new List<byte>(numberUnits);
            var reds = new List<byte>(numberUnits);
            var dotsList = new List<byte[]>(numberUnits);

            byte green;
            byte red;
            byte dots;

            for (int t = 0; t < numberUnits; t++)
            {
                displays.Add("");
                greens.Add(0);
                reds.Add(0);
                dotsList.Add(this.unitTypes[t] ? new Byte[] { 0, 0 } : new Byte[] { 0 });
            }

            string display = this.TestSequence(this.testCounter, out green, out red, out dots);

            this.DuplicateDisplayAcrossAllUnits(display, green, red, dots, displays, greens, reds, dotsList, this.unitTypes);
            var tmLEDs = new TMLEDSMessage
            {
                Green = greens,
                Red = reds,
                Intensity = 3
            };
            var tmDisplay = new TMStringMessage
            {
                Display = displays,
                Dots = dotsList,
                Intensity = 3,
                UnitType = this.unitTypes
            };
            this.arduinoConnection.SendSerialMessage(Constants.MessageID_TMLED, SendTMLEDS(tmLEDs));
            this.arduinoConnection.SendSerialMessage(Constants.MessageID_TMString, SendTMStrings(tmDisplay));
        }
        private static byte[] TMDisplayStringConverter(
                TMStringMessage tmStringMessage, int i, out int textLength, out BitArray dotsArray)
        {
            // Process string
            byte[] display;
            if (tmStringMessage.UnitType[i])
            {
                //true means 16-segment display
                display = tmStringMessage.Display[i].Length > 0
                                  ? Encoding.ASCII.GetBytes(tmStringMessage.Display[i])
                                  : new byte[] { 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32 };
            }
            else
            {
                display = tmStringMessage.Display[i].Length > 0
                                  ? Encoding.ASCII.GetBytes(tmStringMessage.Display[i])
                                  : new byte[] { 32, 32, 32, 32, 32, 32, 32, 32 };
            }

            for (var j = 0; j < display.Length; j++)
            {
                display[j] = ArduinoLink.FontBytes[display[j] - 32];
            }
            //add dots
            byte[] tempDots;
            if (tmStringMessage.UnitType[i])
            {
                textLength = 16;
                tempDots = new byte[2];
                tempDots[0] = Convert.ToByte(tmStringMessage.Dots[i][0]);
                if (tmStringMessage.Dots[i].Length < 2)
                {
                    tempDots[1] = Convert.ToByte(0);
                }
                else
                {
                    tempDots[1] = Convert.ToByte(tmStringMessage.Dots[i][1]);
                }
            }
            else
            {
                tempDots = new byte[1];
                tempDots[0] = Convert.ToByte(tmStringMessage.Dots[i][0]);
                textLength = 8;
            }
            dotsArray = new BitArray(tempDots);
            return display;
        }