IdwTest/Idw.cs
changeset 4 328515997e35
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/IdwTest/Idw.cs	Mon Apr 21 12:02:38 2014 +0200
     1.3 @@ -0,0 +1,358 @@
     1.4 +using System;
     1.5 +using System.Collections.Generic;
     1.6 +using System.Linq;
     1.7 +using System.Text;
     1.8 +using System.Threading.Tasks;
     1.9 +using System.Runtime.InteropServices;
    1.10 +
    1.11 +namespace iMON
    1.12 +{
    1.13 +    class Display
    1.14 +    {
    1.15 +        public string StatusMessage { get; set; }
    1.16 +        public DSPType Type { get; set; }
    1.17 +        public bool IsLcd() { return Type == DSPType.DSPN_DSP_LCD; }
    1.18 +        public bool IsVfd() { return Type == DSPType.DSPN_DSP_VFD; }
    1.19 +        public string Name()
    1.20 +        {
    1.21 +            if (Type == DSPType.DSPN_DSP_VFD)
    1.22 +            {
    1.23 +                return "SoundGraph iMON VFD";
    1.24 +            }
    1.25 +            else if (Type == DSPType.DSPN_DSP_LCD)
    1.26 +            {
    1.27 +                return "SoundGraph iMON LCD";
    1.28 +            }
    1.29 +            else //(DisplayType == DSPType.DSPN_DSP_NONE)
    1.30 +            {
    1.31 +                return "No display";
    1.32 +            }
    1.33 +        }
    1.34 +
    1.35 +        /// <summary>
    1.36 +        /// Do display initialization.
    1.37 +        /// Returns true on success
    1.38 +        /// </summary>
    1.39 +        public bool DoInit()
    1.40 +        {
    1.41 +            IDW_INITRESULT initResult = new IDW_INITRESULT();
    1.42 +            DSPResult ret = IDW_Init(initResult);
    1.43 +            //Check the API call worked
    1.44 +            if (ret != DSPResult.DSP_SUCCEEDED)
    1.45 +            {
    1.46 +                StatusMessage = DSPResult2String(ret);
    1.47 +                return false;
    1.48 +            }
    1.49 +            //Check that the initialization was carried out properly
    1.50 +            else if (initResult.iInitResult != DSPNInitResult.DSPN_SUCCEEDED)
    1.51 +            {
    1.52 +                StatusMessage = DSPNResult2String(initResult.iInitResult);
    1.53 +                return false;
    1.54 +            }
    1.55 +            //Check we that we have a display
    1.56 +            else if (initResult.iDspType == DSPType.DSPN_DSP_NONE)
    1.57 +            {
    1.58 +                StatusMessage = "Unsupported device";
    1.59 +                return false;
    1.60 +            }
    1.61 +
    1.62 +            Type = initResult.iDspType;
    1.63 +            return true;
    1.64 +        }
    1.65 +
    1.66 +        /// <summary>
    1.67 +        /// Do display de-initialization.
    1.68 +        /// Returns true on success
    1.69 +        /// </summary>
    1.70 +        public void DoUninit()
    1.71 +        {
    1.72 +            Type = DSPType.DSPN_DSP_NONE;
    1.73 +            IDW_Uninit();
    1.74 +        }
    1.75 +
    1.76 +
    1.77 +        /// <summary>
    1.78 +        /// Provide a string corresponding to the given DSPResult.
    1.79 +        /// </summary>
    1.80 +        protected string DSPResult2String(DSPResult result)
    1.81 +        {
    1.82 +            switch (result)
    1.83 +            {
    1.84 +                case DSPResult.DSP_SUCCEEDED:
    1.85 +                    return "Success";
    1.86 +                case DSPResult.DSP_E_FAIL:
    1.87 +                    return "An unknown error occurred";
    1.88 +                case DSPResult.DSP_E_OUTOFMEMORY:
    1.89 +                    return "Out of memory";
    1.90 +                case DSPResult.DSP_E_INVALIDARG:
    1.91 +                    return "One or more arguments are invalid";
    1.92 +                case DSPResult.DSP_E_NOT_INITED:
    1.93 +                    return "API is not initialized";
    1.94 +                case DSPResult.DSP_E_POINTER:
    1.95 +                    return "Pointer is invalid";
    1.96 +                default:
    1.97 +                    return "An unknown error occurred";
    1.98 +            }
    1.99 +        }
   1.100 +
   1.101 +        /// <summary>
   1.102 +        /// Provide a string corresponding to the given DSPNInitResult.
   1.103 +        /// </summary>
   1.104 +        protected string DSPNResult2String(DSPNInitResult result)
   1.105 +        {
   1.106 +            switch (result)
   1.107 +            {
   1.108 +                case DSPNInitResult.DSPN_SUCCEEDED:
   1.109 +                    return "Success";
   1.110 +                case DSPNInitResult.DSPN_ERR_IN_USE:
   1.111 +                    return "Display plug-in is already used by another application";
   1.112 +                case DSPNInitResult.DSPN_ERR_HW_DISCONNECTED:
   1.113 +                    return "iMON hardware is not connected";
   1.114 +                case DSPNInitResult.DSPN_ERR_NOT_SUPPORTED_HW:
   1.115 +                    return "The connected hardware does not support the plug-in mode";
   1.116 +                case DSPNInitResult.DSPN_ERR_PLUGIN_DISABLED:
   1.117 +                    return "The plug-in mode option is disabled";
   1.118 +                case DSPNInitResult.DSPN_ERR_IMON_NO_REPLY:
   1.119 +                    return "The latest iMON is not installed or iMON is not running";
   1.120 +                default:
   1.121 +                    return "An unknown error occurred";
   1.122 +            }
   1.123 +        }
   1.124 +
   1.125 +        //Possible return values from iMON Display APIs
   1.126 +        public enum DSPResult : int
   1.127 +        {
   1.128 +            DSP_SUCCEEDED = 0,
   1.129 +            DSP_E_FAIL = 1,
   1.130 +            DSP_E_OUTOFMEMORY = 2,
   1.131 +            DSP_E_INVALIDARG = 3,
   1.132 +            DSP_E_NOT_INITED = 4,
   1.133 +            DSP_E_POINTER = 5,
   1.134 +            DSP_S_INITED = 0x1000,
   1.135 +            DSP_S_NOT_INITED = 0x1001,
   1.136 +            DSP_S_IN_PLUGIN_MODE = 0x1002,
   1.137 +            DSP_S_NOT_IN_PLUGIN_MODE = 0x1003
   1.138 +        }
   1.139 +
   1.140 +        //Possible results from display initialization 
   1.141 +        public enum DSPNInitResult : int
   1.142 +        {
   1.143 +            DSPN_SUCCEEDED = 0,
   1.144 +            DSPN_ERR_IN_USE = 0x0100,
   1.145 +            DSPN_ERR_HW_DISCONNECTED = 0x0101,
   1.146 +            DSPN_ERR_NOT_SUPPORTED_HW = 0x0102,
   1.147 +            DSPN_ERR_PLUGIN_DISABLED = 0x0103,
   1.148 +            DSPN_ERR_IMON_NO_REPLY = 0x0104,
   1.149 +            DSPN_ERR_UNKNOWN = 0x0200
   1.150 +        }
   1.151 +
   1.152 +        //Type of display
   1.153 +        public enum DSPType : int
   1.154 +        {
   1.155 +            DSPN_DSP_NONE = 0,
   1.156 +            DSPN_DSP_VFD = 0x01,
   1.157 +            DSPN_DSP_LCD = 0x02
   1.158 +        };
   1.159 +
   1.160 +        //Notification code
   1.161 +        public enum DSPNotifyCode : int
   1.162 +        {
   1.163 +            DSPNM_PLUGIN_SUCCEED = 0,
   1.164 +            DSPNM_PLUGIN_FAILED,
   1.165 +            DSPNM_IMON_RESTARTED,
   1.166 +            DSPNM_IMON_CLOSED,
   1.167 +            DSPNM_HW_CONNECTED,
   1.168 +            DSPNM_HW_DISCONNECTED,
   1.169 +            DSPNM_LCD_TEXT_SCROLL_DONE = 0x1000
   1.170 +        };
   1.171 +
   1.172 +        [Flags]
   1.173 +        public enum OrangeDiskPieces : byte
   1.174 +        {
   1.175 +            Piece1 = 0x80, // top piece
   1.176 +            Piece2 = 0x40, // next piece counter-clockwise
   1.177 +            Piece3 = 0x20, // and so on...
   1.178 +            Piece4 = 0x10,
   1.179 +            Piece5 = 0x8,
   1.180 +            Piece6 = 0x4,
   1.181 +            Piece7 = 0x2,
   1.182 +            Piece8 = 0x1,
   1.183 +            None = 0x0
   1.184 +        }
   1.185 +
   1.186 +        public enum OrangeDiskIcon : byte
   1.187 +        {
   1.188 +            On = 0x80,
   1.189 +            Off = 0x0
   1.190 +        }
   1.191 +
   1.192 +        [Flags]
   1.193 +        public enum MediaTypes : byte
   1.194 +        {
   1.195 +            Music = 0x80,
   1.196 +            Movie = 0x40,
   1.197 +            Photo = 0x20,
   1.198 +            Cd_Dvd = 0x10,
   1.199 +            Tv = 0x8,
   1.200 +            WebCasting = 0x4,
   1.201 +            News_Weather = 0x2,
   1.202 +            None = 0x0
   1.203 +        }
   1.204 +
   1.205 +        [Flags]
   1.206 +        public enum Speakers : byte
   1.207 +        {
   1.208 +            L = 0x80,
   1.209 +            C = 0x40,
   1.210 +            R = 0x20,
   1.211 +            SL = 0x10,
   1.212 +            LFE = 0x8,
   1.213 +            SR = 0x4,
   1.214 +            RL = 0x2,
   1.215 +            SPDIF = 0x1,
   1.216 +            None = 0x0
   1.217 +        }
   1.218 +
   1.219 +        public enum SpeakersRR : byte
   1.220 +        {
   1.221 +            RR = 0x80,
   1.222 +            Off = 0x0
   1.223 +        }
   1.224 +
   1.225 +        [Flags]
   1.226 +        public enum VideoCodecs : byte
   1.227 +        {
   1.228 +            MPG = 0x80,
   1.229 +            DIVX = 0x40,
   1.230 +            XVID = 0x20,
   1.231 +            WMV = 0x10,
   1.232 +            MPG2 = 0x8,
   1.233 +            AC3 = 0x4,
   1.234 +            DTS = 0x2,
   1.235 +            WMA = 0x1,
   1.236 +            None = 0x0
   1.237 +        }
   1.238 +
   1.239 +        [Flags]
   1.240 +        public enum AudioCodecs : byte
   1.241 +        {
   1.242 +            MP3 = 0x80,
   1.243 +            OGG = 0x40,
   1.244 +            WMA = 0x20,
   1.245 +            WAV = 0x10,
   1.246 +            None = 0x0
   1.247 +        }
   1.248 +
   1.249 +        [Flags]
   1.250 +        public enum AspectRatios : byte
   1.251 +        {
   1.252 +            SRC = 0x80,
   1.253 +            FIT = 0x40,
   1.254 +            TV = 0x20,
   1.255 +            HDTV = 0x10,
   1.256 +            SCR1 = 0x8,
   1.257 +            SCR2 = 0x4,
   1.258 +            None = 0x0
   1.259 +        }
   1.260 +
   1.261 +        [Flags]
   1.262 +        public enum EtcIcons : byte
   1.263 +        {
   1.264 +            Repeat = 0x80,
   1.265 +            Shuffle = 0x40,
   1.266 +            Alarm = 0x20,
   1.267 +            Recording = 0x10,
   1.268 +            Volume = 0x8,
   1.269 +            Time = 0x4,
   1.270 +            None = 0x0
   1.271 +        }
   1.272 +
   1.273 +        //Provide results from our iMON Display initialization
   1.274 +        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 8)]
   1.275 +        protected class IDW_INITRESULT
   1.276 +        {
   1.277 +            [MarshalAs(UnmanagedType.U4)]
   1.278 +            public DSPNotifyCode iNotification;
   1.279 +            [MarshalAs(UnmanagedType.U4)]
   1.280 +            public DSPNInitResult iInitResult;
   1.281 +            [MarshalAs(UnmanagedType.U4)]
   1.282 +            public DSPType iDspType;
   1.283 +        }
   1.284 +
   1.285 +        //Provide result for our status query
   1.286 +        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 8)]
   1.287 +        protected class IDW_STATUS
   1.288 +        {
   1.289 +            [MarshalAs(UnmanagedType.U4)]
   1.290 +            public DSPNotifyCode iNotification;
   1.291 +        }
   1.292 +
   1.293 +        //Declare a struct to pass our EqData
   1.294 +        [StructLayout(LayoutKind.Sequential)]
   1.295 +        public class DSPEQDATA
   1.296 +        {
   1.297 +            public DSPEQDATA()
   1.298 +            {
   1.299 +                BandData = new int[16];
   1.300 +            }
   1.301 +
   1.302 +            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
   1.303 +            public readonly int[] BandData;
   1.304 +        }
   1.305 +
   1.306 +        [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   1.307 +        protected static extern DSPResult IDW_Init(IDW_INITRESULT initResult);
   1.308 +
   1.309 +        [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   1.310 +        protected static extern DSPResult IDW_Uninit();
   1.311 +
   1.312 +        [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   1.313 +        protected static extern DSPResult IDW_IsInitialized();
   1.314 +
   1.315 +        [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   1.316 +        protected static extern DSPResult IDW_GetStatus(IDW_STATUS status);
   1.317 +
   1.318 +        [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   1.319 +        public static extern DSPResult IDW_SetVfdText([MarshalAs(UnmanagedType.LPWStr)] string line1, [MarshalAs(UnmanagedType.LPWStr)] string line2);
   1.320 +
   1.321 +        //Import function to set VFD EQDATA
   1.322 +        [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   1.323 +        public static extern int IDW_SetVfdEqData(DSPEQDATA EqData);
   1.324 +
   1.325 +        //Import function to set LCD EQDATA
   1.326 +        [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   1.327 +        public static extern int IDW_SetLcdEqData(DSPEQDATA EqDataLeft, DSPEQDATA EqDataRight);
   1.328 +
   1.329 +        [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   1.330 +        public static extern DSPResult IDW_SetLcdText([MarshalAs(UnmanagedType.LPWStr)] string line);
   1.331 +
   1.332 +        [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   1.333 +        public static extern DSPResult IDW_SetLcdAllIcons([MarshalAs(UnmanagedType.Bool)] bool on);
   1.334 +
   1.335 +        [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   1.336 +        public static extern DSPResult IDW_SetLcdOrangeIcon(byte iconData1, byte iconData2);
   1.337 +
   1.338 +        [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   1.339 +        public static extern DSPResult IDW_SetLcdMediaTypeIcon(byte iconData);
   1.340 +
   1.341 +        [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   1.342 +        public static extern DSPResult IDW_SetLcdSpeakerIcon(byte iconData1, byte iconData2);
   1.343 +
   1.344 +        [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   1.345 +        public static extern DSPResult IDW_SetLcdVideoCodecIcon(byte iconData);
   1.346 +
   1.347 +        [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   1.348 +        public static extern DSPResult IDW_SetLcdAudioCodecIcon(byte iconData);
   1.349 +
   1.350 +        [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   1.351 +        public static extern DSPResult IDW_SetLcdAspectRatioIcon(byte iconData);
   1.352 +
   1.353 +        [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   1.354 +        public static extern DSPResult IDW_SetLcdEtcIcon(byte iconData);
   1.355 +
   1.356 +        [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   1.357 +        public static extern DSPResult IDW_SetLcdProgress(int currentPosition, int total);
   1.358 +
   1.359 +
   1.360 +    }
   1.361 +}