void LoadUserInterfaceSmartObjectGraphics(BasicTriListWithSmartObject currentDevice)
 {
     try
     {
         string location = Directory.GetApplicationDirectory() + "\\" + SgdFileName;
         if (File.Exists(location))
         {
             currentDevice.LoadSmartObjects(location);
             OnDebug(eDebugEventType.Info, "{0} SmartObject items loaded", currentDevice.SmartObjects.Count.ToString());
             foreach (KeyValuePair <uint, SmartObject> kvp in currentDevice.SmartObjects)
             {
                 kvp.Value.SigChange += new SmartObjectSigChangeEventHandler(SmartObject_SigChange);
                 SG.PrintSmartObjectSigNames(kvp.Value);
             }
         }
         else
         {
             OnDebug(eDebugEventType.Info, "SmartObject file{0} does not exist", location);
         }
     }
     catch (Exception e)
     {
         OnDebug(eDebugEventType.Error, "Exception in LoadUserInterfaceSmartObjectGraphics: {0}", e.Message);
     }
 }
        void SmartObject_BtnList_SigChange(BasicTriListWithSmartObject currentDevice, SmartObjectEventArgs args)
        {
            SmartObject so            = currentDevice.SmartObjects[args.SmartObjectArgs.ID];
            SmartObject soDynBtnList  = currentDevice.SmartObjects[SG_DYNAMIC_BTN_LIST];
            SmartObject soDynIconList = currentDevice.SmartObjects[SG_DYNAMIC_ICON_LIST];
            Sig         sig           = args.Sig;

            switch (sig.Type)
            {
            case eSigType.Bool:
                if (sig.BoolValue)
                {
                    OnDebug(eDebugEventType.Info, "Press event");
                    switch (sig.Number)
                    {
                    //case 1: break;
                    default:
                        //SG.ToggleSmartObjectVisible(soDynBtnList , (int)sig.Number);       // toggle visibility
                        //SG.ToggleSmartObjectVisible(soDynIconList, (int)sig.Number);       // toggle visibility

                        // toggle the button feedback and put some text onto it
                        string buttonText = "Item " + sig.Number.ToString();
                        SG.ToggleSmartObjectSelected(so, (int)sig.Number);         // standard button lists don't support feedback  so this doesn't do anything
                        SG.SetSmartObjectText(so, (int)sig.Number, buttonText);

                        // soDynBtnList uses dynamic IconAnalogs, of type MediaTransports
                        SG.ToggleSmartObjectVisible(soDynBtnList, (int)sig.Number);                     // toggle visibility
                        SG.SetSmartObjectEnabled(soDynBtnList, (int)sig.Number, true);                  // enable
                        SG.SetSmartObjectIconAnalog(soDynBtnList, (int)sig.Number, (ushort)sig.Number); // set icon to the next analog

                        // soDynIconList uses dynamic IconSerials, of type IconsLg
                        SG.ToggleSmartObjectVisible(soDynIconList, (int)sig.Number);               // toggle visibility
                        SG.SetSmartObjectEnabled(soDynIconList, (int)sig.Number, true);            // enable
                        string icon = UI.IconsLgDict[0];
                        SG.SetSmartObjectIconSerial(soDynIconList, (int)sig.Number, icon);         // set icon to the next serial
                        break;
                    }
                }
                else
                {
                    OnDebug(eDebugEventType.Info, "Release event");
                }
                break;

            case eSigType.UShort:
                OnDebug(eDebugEventType.Info, "UShortValue: {0}", sig.UShortValue.ToString());
                break;

            case eSigType.String:
                OnDebug(eDebugEventType.Info, "StringValue: {0}", sig.StringValue);
                break;

            default:
                OnDebug(eDebugEventType.Info, "Unhandled sig type: {0}", sig.Type.ToString());
                break;
            }
        }
        void SmartObject_DynIconList_SigChange(BasicTriListWithSmartObject currentDevice, SmartObjectEventArgs args)
        {
            SmartObject so           = currentDevice.SmartObjects[args.SmartObjectArgs.ID];
            SmartObject soBtnList    = currentDevice.SmartObjects[SG_BTN_LIST];
            SmartObject soDynBtnList = currentDevice.SmartObjects[SG_DYNAMIC_BTN_LIST];
            Sig         sig          = args.Sig;

            switch (sig.Type)
            {
            case eSigType.Bool:
                if (sig.BoolValue)
                {
                    OnDebug(eDebugEventType.Info, "Press event");
                    switch (sig.Number)
                    {
                    default:
                        int number = StringHelper.Atoi(sig.Name);         // Number is offset by 10 so we need item with no offset
                        // toggle the button feedback and put some text onto it
//                                SG.ToggleSmartObjectDigitalJoin(so, (int)sig.Number);
                        string buttonText = "Item " + sig.Number.ToString() + " " + SG.GetSmartObjectDigitalJoin(so, (int)sig.Number).ToString();
                        //SG.SetSmartObjectText        (so, (int)sig.Number, buttonText);
//                                SG.SetSmartObjectText          (so, number, buttonText);
                        string icon = UI.IconsLgDict[(ushort)number];
                        SG.SetSmartObjectIconSerial(so, number, icon);             // set icon to the next serial

                        //SG.ToggleSmartObjectEnabled(soDynBtnList, number);       // enable

                        //SG.ToggleSmartObjectDigitalJoin(soBtnList, number);
                        //SG.SetSmartObjectText          (soBtnList, number, buttonText);
                        break;
                    }
                }
                else
                {
                    OnDebug(eDebugEventType.Info, "Release event");
                }
                break;

            case eSigType.UShort:
                OnDebug(eDebugEventType.Info, "UShortValue: {0}", sig.UShortValue.ToString());
                break;

            case eSigType.String:
                OnDebug(eDebugEventType.Info, "StringValue: {0}", sig.StringValue);
                break;

            default:
                OnDebug(eDebugEventType.Info, "Unhandled sig type: {0}", sig.Type.ToString());
                break;
            }
        }
        void ui_OnlineStatusChange(GenericBase currentDevice, OnlineOfflineEventArgs args)
        {
            OnDebug(eDebugEventType.Info, "{0} online status {1}", currentDevice.ToString(), args.DeviceOnLine.ToString());
            Type type = currentDevice.GetType();

            SmartObject so            = ((BasicTriListWithSmartObject)currentDevice).SmartObjects[SG_DYNAMIC_BTN_LIST];
            int         i             = 0;
            ushort      fontsize      = 16;
            string      formattedText = UI.FormatTextForUi(currentDevice.Name, fontsize, UI.eCrestronFont.Crestron_Sans_Pro, UI.eNamedColour.White);

            SG.SetSmartObjectVisible(so, ++i, true);
            SG.SetSmartObjectText(so, i, formattedText);

            formattedText = String.Format("IPID: 0x{0:X2}", currentDevice.ID);
            formattedText = UI.FormatTextForUi(formattedText, fontsize, UI.eCrestronFont.Crestron_Sans_Pro, UI.eNamedColour.White);
            SG.SetSmartObjectVisible(so, ++i, true);
            SG.SetSmartObjectText(so, i, formattedText);

            formattedText = "Type: " + type.Name.ToString();
            formattedText = UI.FormatTextForUi(formattedText, fontsize, UI.eCrestronFont.Crestron_Sans_Pro, UI.eNamedColour.White);
            SG.SetSmartObjectVisible(so, ++i, true);
            SG.SetSmartObjectText(so, i, formattedText);

            try
            {
                if (typeof(TswFt5Button).IsAssignableFrom(currentDevice.GetType()))
                {
                    formattedText = "IP: " + ((TswFt5Button)currentDevice).ExtenderEthernetReservedSigs.IpAddressFeedback.ToString();
                    formattedText = UI.FormatTextForUi(formattedText, fontsize, UI.eCrestronFont.Crestron_Sans_Pro, UI.eNamedColour.White);
                    SG.SetSmartObjectVisible(so, ++i, true);
                    SG.SetSmartObjectText(so, i, formattedText);

                    formattedText = "MAC: " + ((TswFt5Button)currentDevice).ExtenderEthernetReservedSigs.MacAddressFeedback.ToString();
                    formattedText = UI.FormatTextForUi(formattedText, fontsize, UI.eCrestronFont.Crestron_Sans_Pro, UI.eNamedColour.White);
                    SG.SetSmartObjectVisible(so, ++i, true);
                    SG.SetSmartObjectText(so, i, formattedText);
                }

                if (typeof(TswX60BaseClass).IsAssignableFrom(currentDevice.GetType()))
                {
                    ((TswX60BaseClass)currentDevice).ExtenderHardButtonReservedSigs.DeviceExtenderSigChange -= ui_HardButton_SigChange; // remove existing event from invocation list
                    ((TswX60BaseClass)currentDevice).ExtenderHardButtonReservedSigs.DeviceExtenderSigChange += ui_HardButton_SigChange;
                }
            }
            catch (Exception e)
            {
                OnDebug(eDebugEventType.Info, "ui_OnlineStatusChange exception: {0}", e.Message);
            }
        }
        void SmartObject_DynBtnList_SigChange(BasicTriListWithSmartObject currentDevice, SmartObjectEventArgs args)
        {
            SmartObject so            = currentDevice.SmartObjects[args.SmartObjectArgs.ID];
            SmartObject soBtnList     = currentDevice.SmartObjects[SG_BTN_LIST];
            SmartObject soDynIconList = currentDevice.SmartObjects[SG_DYNAMIC_ICON_LIST];
            Sig         sig           = args.Sig;

            switch (sig.Type)
            {
            case eSigType.Bool:
                if (sig.BoolValue)
                {
                    OnDebug(eDebugEventType.Info, "Press event");
                    switch (sig.Number)
                    {
                    default:
                        int number = AVPlus.Utils.StringHelper.Atoi(sig.Name);         // Number is offset by 10 so we need item with no offset
                        // toggle the button feedback and put some text onto it
                        SG.ToggleSmartObjectDigitalJoin(so, (int)sig.Number);
                        string buttonText    = "Item " + sig.Number.ToString() + " " + SG.GetSmartObjectDigitalJoin(so, (int)sig.Number).ToString();
                        string formattedText = UI.FormatTextForUi(buttonText, 20, UI.eCrestronFont.Crestron_Sans_Pro, UI.eNamedColour.White);
                        SG.SetSmartObjectText(so, number, formattedText);

                        SG.ToggleSmartObjectEnabled(soDynIconList, number);               // enable
                        break;
                    }
                }
                else
                {
                    OnDebug(eDebugEventType.Info, "Release event");
                }
                break;

            case eSigType.UShort:
                OnDebug(eDebugEventType.Info, "UShortValue: {0}", sig.UShortValue.ToString());
                break;

            case eSigType.String:
                OnDebug(eDebugEventType.Info, "StringValue: {0}", sig.StringValue);
                break;

            default:
                OnDebug(eDebugEventType.Info, "Unhandled sig type: {0}", sig.Type.ToString());
                break;
            }
        }