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