Skip to content

Commit

Permalink
MP1-5184: MiniDisplayLibrary: Add x64 support to SoundGraph iMON disp…
Browse files Browse the repository at this point in the history
…lay driver 8.01.0419
  • Loading branch information
epbk committed Nov 29, 2023
1 parent 2a6b03d commit dbae6d8
Show file tree
Hide file tree
Showing 10 changed files with 1,307 additions and 587 deletions.
52 changes: 27 additions & 25 deletions Tools/MPx86Proxy/MPx86Proxy/CommandEnum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,33 @@

namespace MPx86Proxy
{
public enum CommandEnum
{
Unknown = 0,
DriverMethod,
public enum CommandEnum
{
Unknown = 0,
DriverMethod,

ImonInit = 120,
ImonUninit,
ImonIsInited,
ImonSetText,
ImonSetEQ,
ImonSetLCDData2,
ImonSendData,
ImonSendDataBuffer,
ImonDisplayWrapper = 100,

ImonRCInit = 130,
ImonRCUninit,
ImonRCIsInited,
ImonRCGetHWType,
ImonRCGetFirmwareVer,
ImonRCCheckDriverVersion,
ImonRCChangeiMONRCSet,
ImonRCChangeRC6,
ImonRCGetLastRFMode,
ImonRCGetPacket,
ImonRCRegisterForEvents,
ImonRCUnregisterFromEvents
}
ImonInit = 120,
ImonUninit,
ImonIsInited,
ImonSetText,
ImonSetEQ,
ImonSetLCDData2,
ImonSendData,
ImonSendDataBuffer,

ImonRCInit = 130,
ImonRCUninit,
ImonRCIsInited,
ImonRCGetHWType,
ImonRCGetFirmwareVer,
ImonRCCheckDriverVersion,
ImonRCChangeiMONRCSet,
ImonRCChangeRC6,
ImonRCGetLastRFMode,
ImonRCGetPacket,
ImonRCRegisterForEvents,
ImonRCUnregisterFromEvents
}
}
21 changes: 18 additions & 3 deletions Tools/MPx86Proxy/MPx86Proxy/ConnectionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@ namespace MPx86Proxy
{
public class ConnectionHandler
{
private const int _BUFFER_SIZE = 1024 * 16;

[DllImport("msvcrt.dll", EntryPoint = "memcpy", CallingConvention = CallingConvention.Cdecl, SetLastError = false)]
public static extern IntPtr memcpy(IntPtr dest, IntPtr src, UIntPtr count);

public bool ExtensiveLogging = false;

class Client
{
public byte[] Buffer = new byte[256];
public byte[] Buffer = new byte[_BUFFER_SIZE];
public Socket Socket;
public StringBuilder Sb = new StringBuilder(256);
public byte[] Response = new byte[256];
public byte[] Response = new byte[_BUFFER_SIZE];

public List<object> Args = new List<object>();
public volatile int Received = 0;
Expand All @@ -53,7 +55,7 @@ class Client

private Client _ClientRequest = null;

private byte[] _BufferEvent = new byte[256];
private byte[] _BufferEvent = new byte[_BUFFER_SIZE];

private object _Padlock = new object();
private volatile bool _Abort = false;
Expand Down Expand Up @@ -370,6 +372,19 @@ private void process()

switch (cmd)
{
case CommandEnum.ImonDisplayWrapper:
int iRespLng;
Drivers.iMONDisplayWrapper.ImonDisplayWrapperCommandEnum cmdSub = (Drivers.iMONDisplayWrapper.ImonDisplayWrapperCommandEnum)data[iIdx++];
iResult = Drivers.iMONDisplayWrapper.HandleRequest(cmdSub, data, iIdx, iSize - 6, out iRespLng);

if (iRespLng > 0)
{
Buffer.BlockCopy(data, 6, this._ClientRequest.Response, 4, iRespLng);
iResultLength = 4 + iRespLng;
}

goto resp;

case CommandEnum.ImonInit:
if (iLength == 13)
iResult = Drivers.iMONDisplay.iMONDisplay_Init(BitConverter.ToInt32(data, iIdx), BitConverter.ToInt32(data, iIdx + 4)) ? 1 : 0;
Expand Down
174 changes: 174 additions & 0 deletions Tools/MPx86Proxy/MPx86Proxy/Drivers/iMONDisplayWrapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace MPx86Proxy.Drivers
{
public class iMONDisplayWrapper
{
//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
}

public enum ImonDisplayWrapperCommandEnum
{
Init = 0,
UnInit,
IsInitialized,
GetStatus,
SetVfdText,
SetVfdEqData,
SetLcdEqData,
SetLcdText,
SetLcdAllIcons,
SetLcdOrangeIcon,
SetLcdMediaTypeIcon,
SetLcdSpeakerIcon,
SetLcdVideoCodecIcon,
SetLcdAudioCodecIcon,
SetLcdAspectRatioIcon,
SetLcdEtcIcon,
SetLcdProgress
}



[DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
static extern DSPResult IDW_Init(IntPtr result);

[DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
static extern DSPResult IDW_Uninit();

[DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
static extern DSPResult IDW_IsInitialized();

[DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
static extern DSPResult IDW_GetStatus(IntPtr status);

[DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
static extern DSPResult IDW_SetVfdText(IntPtr line1, IntPtr line2);

//Import function to set VFD EQDATA
[DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
static extern int IDW_SetVfdEqData(IntPtr eqData);

//Import function to set LCD EQDATA
[DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
static extern int IDW_SetLcdEqData(IntPtr eqDataLeft, IntPtr eqDataRight);

[DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
static extern DSPResult IDW_SetLcdText(IntPtr line);

[DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
static extern DSPResult IDW_SetLcdAllIcons([MarshalAs(UnmanagedType.Bool)] bool on);

[DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
static extern DSPResult IDW_SetLcdOrangeIcon(byte iconData1, byte iconData2);

[DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
static extern DSPResult IDW_SetLcdMediaTypeIcon(byte iconData);

[DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
static extern DSPResult IDW_SetLcdSpeakerIcon(byte iconData1, byte iconData2);

[DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
static extern DSPResult IDW_SetLcdVideoCodecIcon(byte iconData);

[DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
static extern DSPResult IDW_SetLcdAudioCodecIcon(byte iconData);

[DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
static extern DSPResult IDW_SetLcdAspectRatioIcon(byte iconData);

[DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
static extern DSPResult IDW_SetLcdEtcIcon(byte iconData);

[DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
static extern DSPResult IDW_SetLcdProgress(int currentPosition, int total);


public static int HandleRequest(ImonDisplayWrapperCommandEnum cmd, byte[] data, int iOffset, int iLength, out int iResponseLength)
{
iResponseLength = 0;

unsafe
{
fixed (byte* p = data)
{
switch (cmd)
{
case ImonDisplayWrapperCommandEnum.Init:
iResponseLength = iLength;
return (int)IDW_Init((IntPtr)(p + iOffset));

case ImonDisplayWrapperCommandEnum.UnInit:
return (int)IDW_Uninit();

case ImonDisplayWrapperCommandEnum.IsInitialized:
return (int)IDW_IsInitialized();

case ImonDisplayWrapperCommandEnum.GetStatus:
iResponseLength = iLength;
return (int)IDW_GetStatus((IntPtr)(p + iOffset));

case ImonDisplayWrapperCommandEnum.SetVfdText:
return (int)IDW_SetVfdText((IntPtr)(p + iOffset + 2), (IntPtr)(p + iOffset + BitConverter.ToUInt16(data, iOffset) + 6));

case ImonDisplayWrapperCommandEnum.SetVfdEqData:
return (int)IDW_SetVfdEqData((IntPtr)(p + iOffset));

case ImonDisplayWrapperCommandEnum.SetLcdEqData:
return (int)IDW_SetLcdEqData((IntPtr)(p + iOffset), (IntPtr)(p + iOffset + (16 * 4)));

case ImonDisplayWrapperCommandEnum.SetLcdText:
return (int)IDW_SetLcdText((IntPtr)(p + iOffset + 2));

case ImonDisplayWrapperCommandEnum.SetLcdAllIcons:
return (int)IDW_SetLcdAllIcons(data[iOffset] != 0);

case ImonDisplayWrapperCommandEnum.SetLcdOrangeIcon:
return (int)IDW_SetLcdOrangeIcon(data[iOffset], data[iOffset + 1]);

case ImonDisplayWrapperCommandEnum.SetLcdMediaTypeIcon:
return (int)IDW_SetLcdMediaTypeIcon(data[iOffset]);

case ImonDisplayWrapperCommandEnum.SetLcdSpeakerIcon:
return (int)IDW_SetLcdSpeakerIcon(data[iOffset], data[iOffset + 1]);

case ImonDisplayWrapperCommandEnum.SetLcdVideoCodecIcon:
return (int)IDW_SetLcdVideoCodecIcon(data[iOffset]);

case ImonDisplayWrapperCommandEnum.SetLcdAudioCodecIcon:
return (int)IDW_SetLcdAudioCodecIcon(data[iOffset]);

case ImonDisplayWrapperCommandEnum.SetLcdAspectRatioIcon:
return (int)IDW_SetLcdAspectRatioIcon(data[iOffset]);

case ImonDisplayWrapperCommandEnum.SetLcdEtcIcon:
return (int)IDW_SetLcdEtcIcon(data[iOffset]);

case ImonDisplayWrapperCommandEnum.SetLcdProgress:
return (int)IDW_SetLcdProgress(BitConverter.ToInt32(data, iOffset), BitConverter.ToInt32(data, iOffset + 4));

default:
return (int)DSPResult.DSP_E_FAIL;
}

}
}
}
}
}
1 change: 1 addition & 0 deletions Tools/MPx86Proxy/MPx86Proxy/MPx86Proxy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
</Compile>
<Compile Include="Drivers\iMONApi.cs" />
<Compile Include="Drivers\iMONDisplay.cs" />
<Compile Include="Drivers\iMONDisplayWrapper.cs" />
<Compile Include="Forms\AboutBox.cs">
<SubType>Form</SubType>
</Compile>
Expand Down
Loading

0 comments on commit dbae6d8

Please sign in to comment.