IdwTest/Idw.cs
author sl
Mon, 21 Apr 2014 12:02:38 +0200
changeset 4 328515997e35
permissions -rw-r--r--
Adding first draft of our text application.
This is most useful for testing stuff without MediaPortal.
     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.Threading.Tasks;
     6 using System.Runtime.InteropServices;
     7 
     8 namespace iMON
     9 {
    10     class Display
    11     {
    12         public string StatusMessage { get; set; }
    13         public DSPType Type { get; set; }
    14         public bool IsLcd() { return Type == DSPType.DSPN_DSP_LCD; }
    15         public bool IsVfd() { return Type == DSPType.DSPN_DSP_VFD; }
    16         public string Name()
    17         {
    18             if (Type == DSPType.DSPN_DSP_VFD)
    19             {
    20                 return "SoundGraph iMON VFD";
    21             }
    22             else if (Type == DSPType.DSPN_DSP_LCD)
    23             {
    24                 return "SoundGraph iMON LCD";
    25             }
    26             else //(DisplayType == DSPType.DSPN_DSP_NONE)
    27             {
    28                 return "No display";
    29             }
    30         }
    31 
    32         /// <summary>
    33         /// Do display initialization.
    34         /// Returns true on success
    35         /// </summary>
    36         public bool DoInit()
    37         {
    38             IDW_INITRESULT initResult = new IDW_INITRESULT();
    39             DSPResult ret = IDW_Init(initResult);
    40             //Check the API call worked
    41             if (ret != DSPResult.DSP_SUCCEEDED)
    42             {
    43                 StatusMessage = DSPResult2String(ret);
    44                 return false;
    45             }
    46             //Check that the initialization was carried out properly
    47             else if (initResult.iInitResult != DSPNInitResult.DSPN_SUCCEEDED)
    48             {
    49                 StatusMessage = DSPNResult2String(initResult.iInitResult);
    50                 return false;
    51             }
    52             //Check we that we have a display
    53             else if (initResult.iDspType == DSPType.DSPN_DSP_NONE)
    54             {
    55                 StatusMessage = "Unsupported device";
    56                 return false;
    57             }
    58 
    59             Type = initResult.iDspType;
    60             return true;
    61         }
    62 
    63         /// <summary>
    64         /// Do display de-initialization.
    65         /// Returns true on success
    66         /// </summary>
    67         public void DoUninit()
    68         {
    69             Type = DSPType.DSPN_DSP_NONE;
    70             IDW_Uninit();
    71         }
    72 
    73 
    74         /// <summary>
    75         /// Provide a string corresponding to the given DSPResult.
    76         /// </summary>
    77         protected string DSPResult2String(DSPResult result)
    78         {
    79             switch (result)
    80             {
    81                 case DSPResult.DSP_SUCCEEDED:
    82                     return "Success";
    83                 case DSPResult.DSP_E_FAIL:
    84                     return "An unknown error occurred";
    85                 case DSPResult.DSP_E_OUTOFMEMORY:
    86                     return "Out of memory";
    87                 case DSPResult.DSP_E_INVALIDARG:
    88                     return "One or more arguments are invalid";
    89                 case DSPResult.DSP_E_NOT_INITED:
    90                     return "API is not initialized";
    91                 case DSPResult.DSP_E_POINTER:
    92                     return "Pointer is invalid";
    93                 default:
    94                     return "An unknown error occurred";
    95             }
    96         }
    97 
    98         /// <summary>
    99         /// Provide a string corresponding to the given DSPNInitResult.
   100         /// </summary>
   101         protected string DSPNResult2String(DSPNInitResult result)
   102         {
   103             switch (result)
   104             {
   105                 case DSPNInitResult.DSPN_SUCCEEDED:
   106                     return "Success";
   107                 case DSPNInitResult.DSPN_ERR_IN_USE:
   108                     return "Display plug-in is already used by another application";
   109                 case DSPNInitResult.DSPN_ERR_HW_DISCONNECTED:
   110                     return "iMON hardware is not connected";
   111                 case DSPNInitResult.DSPN_ERR_NOT_SUPPORTED_HW:
   112                     return "The connected hardware does not support the plug-in mode";
   113                 case DSPNInitResult.DSPN_ERR_PLUGIN_DISABLED:
   114                     return "The plug-in mode option is disabled";
   115                 case DSPNInitResult.DSPN_ERR_IMON_NO_REPLY:
   116                     return "The latest iMON is not installed or iMON is not running";
   117                 default:
   118                     return "An unknown error occurred";
   119             }
   120         }
   121 
   122         //Possible return values from iMON Display APIs
   123         public enum DSPResult : int
   124         {
   125             DSP_SUCCEEDED = 0,
   126             DSP_E_FAIL = 1,
   127             DSP_E_OUTOFMEMORY = 2,
   128             DSP_E_INVALIDARG = 3,
   129             DSP_E_NOT_INITED = 4,
   130             DSP_E_POINTER = 5,
   131             DSP_S_INITED = 0x1000,
   132             DSP_S_NOT_INITED = 0x1001,
   133             DSP_S_IN_PLUGIN_MODE = 0x1002,
   134             DSP_S_NOT_IN_PLUGIN_MODE = 0x1003
   135         }
   136 
   137         //Possible results from display initialization 
   138         public enum DSPNInitResult : int
   139         {
   140             DSPN_SUCCEEDED = 0,
   141             DSPN_ERR_IN_USE = 0x0100,
   142             DSPN_ERR_HW_DISCONNECTED = 0x0101,
   143             DSPN_ERR_NOT_SUPPORTED_HW = 0x0102,
   144             DSPN_ERR_PLUGIN_DISABLED = 0x0103,
   145             DSPN_ERR_IMON_NO_REPLY = 0x0104,
   146             DSPN_ERR_UNKNOWN = 0x0200
   147         }
   148 
   149         //Type of display
   150         public enum DSPType : int
   151         {
   152             DSPN_DSP_NONE = 0,
   153             DSPN_DSP_VFD = 0x01,
   154             DSPN_DSP_LCD = 0x02
   155         };
   156 
   157         //Notification code
   158         public enum DSPNotifyCode : int
   159         {
   160             DSPNM_PLUGIN_SUCCEED = 0,
   161             DSPNM_PLUGIN_FAILED,
   162             DSPNM_IMON_RESTARTED,
   163             DSPNM_IMON_CLOSED,
   164             DSPNM_HW_CONNECTED,
   165             DSPNM_HW_DISCONNECTED,
   166             DSPNM_LCD_TEXT_SCROLL_DONE = 0x1000
   167         };
   168 
   169         [Flags]
   170         public enum OrangeDiskPieces : byte
   171         {
   172             Piece1 = 0x80, // top piece
   173             Piece2 = 0x40, // next piece counter-clockwise
   174             Piece3 = 0x20, // and so on...
   175             Piece4 = 0x10,
   176             Piece5 = 0x8,
   177             Piece6 = 0x4,
   178             Piece7 = 0x2,
   179             Piece8 = 0x1,
   180             None = 0x0
   181         }
   182 
   183         public enum OrangeDiskIcon : byte
   184         {
   185             On = 0x80,
   186             Off = 0x0
   187         }
   188 
   189         [Flags]
   190         public enum MediaTypes : byte
   191         {
   192             Music = 0x80,
   193             Movie = 0x40,
   194             Photo = 0x20,
   195             Cd_Dvd = 0x10,
   196             Tv = 0x8,
   197             WebCasting = 0x4,
   198             News_Weather = 0x2,
   199             None = 0x0
   200         }
   201 
   202         [Flags]
   203         public enum Speakers : byte
   204         {
   205             L = 0x80,
   206             C = 0x40,
   207             R = 0x20,
   208             SL = 0x10,
   209             LFE = 0x8,
   210             SR = 0x4,
   211             RL = 0x2,
   212             SPDIF = 0x1,
   213             None = 0x0
   214         }
   215 
   216         public enum SpeakersRR : byte
   217         {
   218             RR = 0x80,
   219             Off = 0x0
   220         }
   221 
   222         [Flags]
   223         public enum VideoCodecs : byte
   224         {
   225             MPG = 0x80,
   226             DIVX = 0x40,
   227             XVID = 0x20,
   228             WMV = 0x10,
   229             MPG2 = 0x8,
   230             AC3 = 0x4,
   231             DTS = 0x2,
   232             WMA = 0x1,
   233             None = 0x0
   234         }
   235 
   236         [Flags]
   237         public enum AudioCodecs : byte
   238         {
   239             MP3 = 0x80,
   240             OGG = 0x40,
   241             WMA = 0x20,
   242             WAV = 0x10,
   243             None = 0x0
   244         }
   245 
   246         [Flags]
   247         public enum AspectRatios : byte
   248         {
   249             SRC = 0x80,
   250             FIT = 0x40,
   251             TV = 0x20,
   252             HDTV = 0x10,
   253             SCR1 = 0x8,
   254             SCR2 = 0x4,
   255             None = 0x0
   256         }
   257 
   258         [Flags]
   259         public enum EtcIcons : byte
   260         {
   261             Repeat = 0x80,
   262             Shuffle = 0x40,
   263             Alarm = 0x20,
   264             Recording = 0x10,
   265             Volume = 0x8,
   266             Time = 0x4,
   267             None = 0x0
   268         }
   269 
   270         //Provide results from our iMON Display initialization
   271         [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 8)]
   272         protected class IDW_INITRESULT
   273         {
   274             [MarshalAs(UnmanagedType.U4)]
   275             public DSPNotifyCode iNotification;
   276             [MarshalAs(UnmanagedType.U4)]
   277             public DSPNInitResult iInitResult;
   278             [MarshalAs(UnmanagedType.U4)]
   279             public DSPType iDspType;
   280         }
   281 
   282         //Provide result for our status query
   283         [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 8)]
   284         protected class IDW_STATUS
   285         {
   286             [MarshalAs(UnmanagedType.U4)]
   287             public DSPNotifyCode iNotification;
   288         }
   289 
   290         //Declare a struct to pass our EqData
   291         [StructLayout(LayoutKind.Sequential)]
   292         public class DSPEQDATA
   293         {
   294             public DSPEQDATA()
   295             {
   296                 BandData = new int[16];
   297             }
   298 
   299             [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
   300             public readonly int[] BandData;
   301         }
   302 
   303         [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   304         protected static extern DSPResult IDW_Init(IDW_INITRESULT initResult);
   305 
   306         [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   307         protected static extern DSPResult IDW_Uninit();
   308 
   309         [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   310         protected static extern DSPResult IDW_IsInitialized();
   311 
   312         [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   313         protected static extern DSPResult IDW_GetStatus(IDW_STATUS status);
   314 
   315         [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   316         public static extern DSPResult IDW_SetVfdText([MarshalAs(UnmanagedType.LPWStr)] string line1, [MarshalAs(UnmanagedType.LPWStr)] string line2);
   317 
   318         //Import function to set VFD EQDATA
   319         [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   320         public static extern int IDW_SetVfdEqData(DSPEQDATA EqData);
   321 
   322         //Import function to set LCD EQDATA
   323         [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   324         public static extern int IDW_SetLcdEqData(DSPEQDATA EqDataLeft, DSPEQDATA EqDataRight);
   325 
   326         [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   327         public static extern DSPResult IDW_SetLcdText([MarshalAs(UnmanagedType.LPWStr)] string line);
   328 
   329         [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   330         public static extern DSPResult IDW_SetLcdAllIcons([MarshalAs(UnmanagedType.Bool)] bool on);
   331 
   332         [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   333         public static extern DSPResult IDW_SetLcdOrangeIcon(byte iconData1, byte iconData2);
   334 
   335         [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   336         public static extern DSPResult IDW_SetLcdMediaTypeIcon(byte iconData);
   337 
   338         [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   339         public static extern DSPResult IDW_SetLcdSpeakerIcon(byte iconData1, byte iconData2);
   340 
   341         [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   342         public static extern DSPResult IDW_SetLcdVideoCodecIcon(byte iconData);
   343 
   344         [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   345         public static extern DSPResult IDW_SetLcdAudioCodecIcon(byte iconData);
   346 
   347         [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   348         public static extern DSPResult IDW_SetLcdAspectRatioIcon(byte iconData);
   349 
   350         [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   351         public static extern DSPResult IDW_SetLcdEtcIcon(byte iconData);
   352 
   353         [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   354         public static extern DSPResult IDW_SetLcdProgress(int currentPosition, int total);
   355 
   356 
   357     }
   358 }