diff -r d5f6b2119a13 -r 328515997e35 IdwTest/Idw.cs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/IdwTest/Idw.cs Mon Apr 21 12:02:38 2014 +0200
@@ -0,0 +1,358 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Runtime.InteropServices;
+
+namespace iMON
+{
+ class Display
+ {
+ public string StatusMessage { get; set; }
+ public DSPType Type { get; set; }
+ public bool IsLcd() { return Type == DSPType.DSPN_DSP_LCD; }
+ public bool IsVfd() { return Type == DSPType.DSPN_DSP_VFD; }
+ public string Name()
+ {
+ if (Type == DSPType.DSPN_DSP_VFD)
+ {
+ return "SoundGraph iMON VFD";
+ }
+ else if (Type == DSPType.DSPN_DSP_LCD)
+ {
+ return "SoundGraph iMON LCD";
+ }
+ else //(DisplayType == DSPType.DSPN_DSP_NONE)
+ {
+ return "No display";
+ }
+ }
+
+ ///
+ /// Do display initialization.
+ /// Returns true on success
+ ///
+ public bool DoInit()
+ {
+ IDW_INITRESULT initResult = new IDW_INITRESULT();
+ DSPResult ret = IDW_Init(initResult);
+ //Check the API call worked
+ if (ret != DSPResult.DSP_SUCCEEDED)
+ {
+ StatusMessage = DSPResult2String(ret);
+ return false;
+ }
+ //Check that the initialization was carried out properly
+ else if (initResult.iInitResult != DSPNInitResult.DSPN_SUCCEEDED)
+ {
+ StatusMessage = DSPNResult2String(initResult.iInitResult);
+ return false;
+ }
+ //Check we that we have a display
+ else if (initResult.iDspType == DSPType.DSPN_DSP_NONE)
+ {
+ StatusMessage = "Unsupported device";
+ return false;
+ }
+
+ Type = initResult.iDspType;
+ return true;
+ }
+
+ ///
+ /// Do display de-initialization.
+ /// Returns true on success
+ ///
+ public void DoUninit()
+ {
+ Type = DSPType.DSPN_DSP_NONE;
+ IDW_Uninit();
+ }
+
+
+ ///
+ /// Provide a string corresponding to the given DSPResult.
+ ///
+ protected string DSPResult2String(DSPResult result)
+ {
+ switch (result)
+ {
+ case DSPResult.DSP_SUCCEEDED:
+ return "Success";
+ case DSPResult.DSP_E_FAIL:
+ return "An unknown error occurred";
+ case DSPResult.DSP_E_OUTOFMEMORY:
+ return "Out of memory";
+ case DSPResult.DSP_E_INVALIDARG:
+ return "One or more arguments are invalid";
+ case DSPResult.DSP_E_NOT_INITED:
+ return "API is not initialized";
+ case DSPResult.DSP_E_POINTER:
+ return "Pointer is invalid";
+ default:
+ return "An unknown error occurred";
+ }
+ }
+
+ ///
+ /// Provide a string corresponding to the given DSPNInitResult.
+ ///
+ protected string DSPNResult2String(DSPNInitResult result)
+ {
+ switch (result)
+ {
+ case DSPNInitResult.DSPN_SUCCEEDED:
+ return "Success";
+ case DSPNInitResult.DSPN_ERR_IN_USE:
+ return "Display plug-in is already used by another application";
+ case DSPNInitResult.DSPN_ERR_HW_DISCONNECTED:
+ return "iMON hardware is not connected";
+ case DSPNInitResult.DSPN_ERR_NOT_SUPPORTED_HW:
+ return "The connected hardware does not support the plug-in mode";
+ case DSPNInitResult.DSPN_ERR_PLUGIN_DISABLED:
+ return "The plug-in mode option is disabled";
+ case DSPNInitResult.DSPN_ERR_IMON_NO_REPLY:
+ return "The latest iMON is not installed or iMON is not running";
+ default:
+ return "An unknown error occurred";
+ }
+ }
+
+ //Possible return values from iMON Display APIs
+ public enum DSPResult : int
+ {
+ DSP_SUCCEEDED = 0,
+ DSP_E_FAIL = 1,
+ DSP_E_OUTOFMEMORY = 2,
+ DSP_E_INVALIDARG = 3,
+ DSP_E_NOT_INITED = 4,
+ DSP_E_POINTER = 5,
+ DSP_S_INITED = 0x1000,
+ DSP_S_NOT_INITED = 0x1001,
+ DSP_S_IN_PLUGIN_MODE = 0x1002,
+ DSP_S_NOT_IN_PLUGIN_MODE = 0x1003
+ }
+
+ //Possible results from display initialization
+ public enum DSPNInitResult : int
+ {
+ DSPN_SUCCEEDED = 0,
+ DSPN_ERR_IN_USE = 0x0100,
+ DSPN_ERR_HW_DISCONNECTED = 0x0101,
+ DSPN_ERR_NOT_SUPPORTED_HW = 0x0102,
+ DSPN_ERR_PLUGIN_DISABLED = 0x0103,
+ DSPN_ERR_IMON_NO_REPLY = 0x0104,
+ DSPN_ERR_UNKNOWN = 0x0200
+ }
+
+ //Type of display
+ public enum DSPType : int
+ {
+ DSPN_DSP_NONE = 0,
+ DSPN_DSP_VFD = 0x01,
+ DSPN_DSP_LCD = 0x02
+ };
+
+ //Notification code
+ public enum DSPNotifyCode : int
+ {
+ DSPNM_PLUGIN_SUCCEED = 0,
+ DSPNM_PLUGIN_FAILED,
+ DSPNM_IMON_RESTARTED,
+ DSPNM_IMON_CLOSED,
+ DSPNM_HW_CONNECTED,
+ DSPNM_HW_DISCONNECTED,
+ DSPNM_LCD_TEXT_SCROLL_DONE = 0x1000
+ };
+
+ [Flags]
+ public enum OrangeDiskPieces : byte
+ {
+ Piece1 = 0x80, // top piece
+ Piece2 = 0x40, // next piece counter-clockwise
+ Piece3 = 0x20, // and so on...
+ Piece4 = 0x10,
+ Piece5 = 0x8,
+ Piece6 = 0x4,
+ Piece7 = 0x2,
+ Piece8 = 0x1,
+ None = 0x0
+ }
+
+ public enum OrangeDiskIcon : byte
+ {
+ On = 0x80,
+ Off = 0x0
+ }
+
+ [Flags]
+ public enum MediaTypes : byte
+ {
+ Music = 0x80,
+ Movie = 0x40,
+ Photo = 0x20,
+ Cd_Dvd = 0x10,
+ Tv = 0x8,
+ WebCasting = 0x4,
+ News_Weather = 0x2,
+ None = 0x0
+ }
+
+ [Flags]
+ public enum Speakers : byte
+ {
+ L = 0x80,
+ C = 0x40,
+ R = 0x20,
+ SL = 0x10,
+ LFE = 0x8,
+ SR = 0x4,
+ RL = 0x2,
+ SPDIF = 0x1,
+ None = 0x0
+ }
+
+ public enum SpeakersRR : byte
+ {
+ RR = 0x80,
+ Off = 0x0
+ }
+
+ [Flags]
+ public enum VideoCodecs : byte
+ {
+ MPG = 0x80,
+ DIVX = 0x40,
+ XVID = 0x20,
+ WMV = 0x10,
+ MPG2 = 0x8,
+ AC3 = 0x4,
+ DTS = 0x2,
+ WMA = 0x1,
+ None = 0x0
+ }
+
+ [Flags]
+ public enum AudioCodecs : byte
+ {
+ MP3 = 0x80,
+ OGG = 0x40,
+ WMA = 0x20,
+ WAV = 0x10,
+ None = 0x0
+ }
+
+ [Flags]
+ public enum AspectRatios : byte
+ {
+ SRC = 0x80,
+ FIT = 0x40,
+ TV = 0x20,
+ HDTV = 0x10,
+ SCR1 = 0x8,
+ SCR2 = 0x4,
+ None = 0x0
+ }
+
+ [Flags]
+ public enum EtcIcons : byte
+ {
+ Repeat = 0x80,
+ Shuffle = 0x40,
+ Alarm = 0x20,
+ Recording = 0x10,
+ Volume = 0x8,
+ Time = 0x4,
+ None = 0x0
+ }
+
+ //Provide results from our iMON Display initialization
+ [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 8)]
+ protected class IDW_INITRESULT
+ {
+ [MarshalAs(UnmanagedType.U4)]
+ public DSPNotifyCode iNotification;
+ [MarshalAs(UnmanagedType.U4)]
+ public DSPNInitResult iInitResult;
+ [MarshalAs(UnmanagedType.U4)]
+ public DSPType iDspType;
+ }
+
+ //Provide result for our status query
+ [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 8)]
+ protected class IDW_STATUS
+ {
+ [MarshalAs(UnmanagedType.U4)]
+ public DSPNotifyCode iNotification;
+ }
+
+ //Declare a struct to pass our EqData
+ [StructLayout(LayoutKind.Sequential)]
+ public class DSPEQDATA
+ {
+ public DSPEQDATA()
+ {
+ BandData = new int[16];
+ }
+
+ [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
+ public readonly int[] BandData;
+ }
+
+ [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
+ protected static extern DSPResult IDW_Init(IDW_INITRESULT initResult);
+
+ [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
+ protected static extern DSPResult IDW_Uninit();
+
+ [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
+ protected static extern DSPResult IDW_IsInitialized();
+
+ [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
+ protected static extern DSPResult IDW_GetStatus(IDW_STATUS status);
+
+ [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
+ public static extern DSPResult IDW_SetVfdText([MarshalAs(UnmanagedType.LPWStr)] string line1, [MarshalAs(UnmanagedType.LPWStr)] string line2);
+
+ //Import function to set VFD EQDATA
+ [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
+ public static extern int IDW_SetVfdEqData(DSPEQDATA EqData);
+
+ //Import function to set LCD EQDATA
+ [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
+ public static extern int IDW_SetLcdEqData(DSPEQDATA EqDataLeft, DSPEQDATA EqDataRight);
+
+ [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
+ public static extern DSPResult IDW_SetLcdText([MarshalAs(UnmanagedType.LPWStr)] string line);
+
+ [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
+ public static extern DSPResult IDW_SetLcdAllIcons([MarshalAs(UnmanagedType.Bool)] bool on);
+
+ [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
+ public static extern DSPResult IDW_SetLcdOrangeIcon(byte iconData1, byte iconData2);
+
+ [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
+ public static extern DSPResult IDW_SetLcdMediaTypeIcon(byte iconData);
+
+ [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
+ public static extern DSPResult IDW_SetLcdSpeakerIcon(byte iconData1, byte iconData2);
+
+ [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
+ public static extern DSPResult IDW_SetLcdVideoCodecIcon(byte iconData);
+
+ [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
+ public static extern DSPResult IDW_SetLcdAudioCodecIcon(byte iconData);
+
+ [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
+ public static extern DSPResult IDW_SetLcdAspectRatioIcon(byte iconData);
+
+ [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
+ public static extern DSPResult IDW_SetLcdEtcIcon(byte iconData);
+
+ [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
+ public static extern DSPResult IDW_SetLcdProgress(int currentPosition, int total);
+
+
+ }
+}