Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
ezfit:clarujust:clarujust_api [2009/09/16 16:58] smayr |
ezfit:clarujust:clarujust_api [2014/02/11 18:04] (current) smayr [Exposed Clarujust Methods/Objects] |
||
---|---|---|---|
Line 1: | Line 1: | ||
== Clarujust API == | == Clarujust API == | ||
- | The following represents the expected methods/ | + | The following represents the expected methods/ |
- | This is a work in progress and, I’m sure, is far from complete. | + | == The ezFIT API == |
- | + | ||
- | == The Audina | + | |
It is assumed Clarujust will be initialized with a reference to some kind of object that communicates with the hearing aids. The following shows this interface: | It is assumed Clarujust will be initialized with a reference to some kind of object that communicates with the hearing aids. The following shows this interface: | ||
I’m guessing the method names will be similar to what has previously been provided by ezOrange. | I’m guessing the method names will be similar to what has previously been provided by ezOrange. | ||
- | It is assumed the hearing devices will already be connect | + | It is assumed the hearing devices will already be connected |
Here’s a short description of the methods: | Here’s a short description of the methods: | ||
+ | |||
+ | === Initialize Hearing Instrument === | ||
+ | <code csharp> | ||
Boolean GetHAInitialized() | Boolean GetHAInitialized() | ||
+ | </ | ||
Returns true if the API has initialized the hearing devices; otherwise, false. | Returns true if the API has initialized the hearing devices; otherwise, false. | ||
+ | === Ear Side === | ||
<code csharp> | <code csharp> | ||
Int16 GetEar() | Int16 GetEar() | ||
void SetEar(Int16 value) | void SetEar(Int16 value) | ||
</ | </ | ||
- | Gets or sets the current ear. 0 = left, 1 = right. | + | Gets or sets the current ear. 0 = left, 1 = right. |
+ | |||
+ | For example: the following code shows how to get the bump values from the right-ear hearing device: | ||
<code csharp> | <code csharp> | ||
void GetBumpExample(AudinaAPI api) | void GetBumpExample(AudinaAPI api) | ||
Line 34: | Line 39: | ||
</ | </ | ||
+ | === Memory === | ||
<code csharp> | <code csharp> | ||
short GetMemory() | short GetMemory() | ||
Line 39: | Line 45: | ||
Returns the current memory slot of the current ear. | Returns the current memory slot of the current ear. | ||
+ | === Circuit Parameters === | ||
<code csharp> | <code csharp> | ||
int[] GetEthosArray() | int[] GetEthosArray() | ||
Line 44: | Line 51: | ||
Returns an array containing all current hearing device parameters in the current ear. | Returns an array containing all current hearing device parameters in the current ear. | ||
+ | === Bump === | ||
<code csharp> | <code csharp> | ||
short GetBumpCF() | short GetBumpCF() | ||
- | void SetBumpCF(short value) | + | void SetBumpCF(short value) |
short GetBumpQ() | short GetBumpQ() | ||
- | void SetBumpQ(short value) | + | void SetBumpQ(short value) |
short GetBumpGain() | short GetBumpGain() | ||
- | void SetBumpGain(short value) | + | void SetBumpGain(short value) |
short GetGain() | short GetGain() | ||
- | void SetGain(short value) | + | void SetGain(short value) |
short GetTiltSlope() | short GetTiltSlope() | ||
- | void SetTiltSlope(short value) | + | void SetTiltSlope(short value) |
</ | </ | ||
Gets or sets the associated parameter values in the current ear. | Gets or sets the associated parameter values in the current ear. | ||
- | I don’t know if we need the GetBias or SetBias methods, or if we’re going to handle the compression via the SetCompression method, but those can be added if needed. | + | NOTE: It is unclear |
== Exposed Clarujust Methods/ | == Exposed Clarujust Methods/ | ||
- | The following shows what will be exposed to ezFit. | + | The following shows what will be exposed to ezFIT: |
+ | (see full source code in [[ezfit: | ||
+ | === Instantiating Clarujust === | ||
The ClarujustApp static class provides one method: | The ClarujustApp static class provides one method: | ||
<code csharp> | <code csharp> | ||
Line 70: | Line 80: | ||
Returns an instance of a Clarujust window. | Returns an instance of a Clarujust window. | ||
- | The IClarujustWindow interface defines the methods that will be exposed to ezFit while Clarujust is running. | + | === Clarujust Window === |
+ | The IClarujustWindow interface defines the methods that will be exposed to ezFIT while Clarujust is running. | ||
<code csharp> | <code csharp> | ||
Line 87: | Line 98: | ||
Hides the Clarujust window. | Hides the Clarujust window. | ||
+ | == Running Clarujust Proxy == | ||
+ | The DLL files needed to run the Clarujust proxy server. | ||
+ | COM DLLs built in .NET need to use a different app to register ('' | ||
+ | '' | ||
+ | |||
+ | Use that to register the libraries. | ||
+ | |||
+ | To register: | ||
+ | |||
+ | <code msdos> | ||
+ | path C: | ||
+ | regasm C: | ||
+ | pause | ||
+ | </ | ||
+ | Or: | ||
+ | <code msdos> | ||
+ | CD C:\TEMP | ||
+ | C: | ||
+ | pause | ||
+ | </ | ||
+ | |||
+ | To unregister: | ||
+ | |||
+ | <code msdos> | ||
+ | path C: | ||
+ | regasm C: | ||
+ | pause | ||
+ | </ | ||
+ | Or: | ||
+ | <code msdos> | ||
+ | CD C:\TEMP | ||
+ | C: | ||
+ | pause | ||
+ | </ | ||
+ | |||
+ | The other libraries just need to be placed in the same location as the proxy DLL and it should work. | ||
+ | |||
+ | Sample code (in C#) on how to call it: | ||
+ | |||
+ | <code csharp> | ||
+ | static void Main(string[] args) | ||
+ | { | ||
+ | //Create and initialize the optimizer object however you choose... | ||
+ | EzFITOptimizerSvr.IEzFITOptimizerClarujust optimizer = ... | ||
+ | Clarujust.Proxy.IClarujustApp app = new Clarujust.Proxy.ClarujustApp(); | ||
+ | app.Initialize(optimizer); | ||
+ | app.ShowModal(); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Sample code in Delphi: | ||
+ | <code delphi> | ||
+ | procedure TEzFITOptimizerClarujust.LaunchClarujustApp; | ||
+ | var | ||
+ | // ClarujustApp: | ||
+ | ClarujustApp: | ||
+ | ThisOptSvr: OleVariant; | ||
+ | begin | ||
+ | ThisOptSvr := IEzFitOptimizerClarujust(self); | ||
+ | ClarujustApp := CoClarujustApp.Create(); | ||
+ | ClarujustApp.Initialize(ThisOptSvr); | ||
+ | ClarujustApp.ShowModal; | ||
+ | |||
+ | // ThisOptSvr := IEzFitOptimizerClarujust(self); | ||
+ | // ClarujustApp := CreateOleObject(' | ||
+ | // ClarujustApp.Initialize(ThisOptSvr); | ||
+ | // ClarujustApp.ShowModal; | ||
+ | end; | ||
+ | </ | ||
+ | |||
+ | == Sample ClarujustApp proxy source code == | ||
+ | <code csharp> | ||
+ | using System; | ||
+ | using System.IO; | ||
+ | using System.Text; | ||
+ | using System.Threading; | ||
+ | using System.Reflection; | ||
+ | using System.Windows.Forms; | ||
+ | using System.Runtime.InteropServices; | ||
+ | |||
+ | using ezFITOptimizerSvr; | ||
+ | |||
+ | namespace Clarujust.Proxy | ||
+ | { | ||
+ | /// < | ||
+ | /// Represents the worker class responsible for launching and managing the Clarujust application. | ||
+ | /// </ | ||
+ | [Guid(" | ||
+ | ClassInterface(ClassInterfaceType.None), | ||
+ | ComVisible(true)] | ||
+ | public class ClarujustApp : IClarujustApp | ||
+ | { | ||
+ | #region Properties | ||
+ | |||
+ | /// < | ||
+ | /// Gets or sets the worker thread representing the Clarujust application. | ||
+ | /// </ | ||
+ | /// < | ||
+ | private static Thread ClarujustThread { get; set; } | ||
+ | |||
+ | #endregion | ||
+ | |||
+ | #region Methods | ||
+ | |||
+ | #region Public | ||
+ | |||
+ | /// < | ||
+ | /// Initializes the Clarujust application. | ||
+ | /// </ | ||
+ | /// <param name=" | ||
+ | /// < | ||
+ | /// This method handles any initialization required by the Clarujust application. | ||
+ | /// The < | ||
+ | /// for communicating with the hearing aids and the ezFit application. | ||
+ | /// must be specified, and must be an object of type <see cref=" | ||
+ | [STAThread()] | ||
+ | public void Initialize(Object framework) | ||
+ | { | ||
+ | // Stop any existing threads | ||
+ | ClarujustApp.JoinThread(); | ||
+ | |||
+ | if (framework == null) | ||
+ | MessageBox.Show(" | ||
+ | else | ||
+ | { | ||
+ | // Check the framework object | ||
+ | ClarujustApp.LogMessage(String.Format(" | ||
+ | IEzFITOptimizerClarujust fwk = framework as IEzFITOptimizerClarujust; | ||
+ | if (fwk == null) | ||
+ | MessageBox.Show(String.Format( | ||
+ | "An IEzFITOptimizerClarujust type object must be provided. | ||
+ | framework.GetType().ToString())); | ||
+ | else | ||
+ | { | ||
+ | // Create and start the Clarujust thread | ||
+ | ClarujustApp.ClarujustThread = new Thread(new ParameterizedThreadStart(thread_Clarujust)); | ||
+ | ClarujustApp.ClarujustThread.Name = "Main Clarujust Thread"; | ||
+ | ClarujustApp.ClarujustThread.SetApartmentState(ApartmentState.STA); | ||
+ | ClarujustApp.ClarujustThread.Start(framework); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | /// < | ||
+ | /// Shows the Clarujust application window. | ||
+ | /// </ | ||
+ | [STAThread()] | ||
+ | public void Show() | ||
+ | { | ||
+ | } | ||
+ | |||
+ | /// < | ||
+ | /// Shows the Clarujust application window as a modal dialog box. | ||
+ | /// </ | ||
+ | [STAThread()] | ||
+ | public void ShowModal() | ||
+ | { | ||
+ | } | ||
+ | |||
+ | /// < | ||
+ | /// Closes the Clarujust application window. | ||
+ | /// </ | ||
+ | [STAThread()] | ||
+ | public void Close() | ||
+ | { | ||
+ | } | ||
+ | |||
+ | #endregion | ||
+ | |||
+ | #region Private | ||
+ | |||
+ | /// < | ||
+ | /// Prepares the ezFit optimizer framework interface. | ||
+ | /// </ | ||
+ | /// <param name=" | ||
+ | /// < | ||
+ | private static Boolean PrepareInterface(IEzFITOptimizerClarujust fwk) | ||
+ | { | ||
+ | Boolean isInitialized = false; | ||
+ | String deviceId = null; | ||
+ | String serialNumber = null; | ||
+ | Int32 earCount = 0; | ||
+ | Int32 error = 0; | ||
+ | String appDirectory = null; | ||
+ | |||
+ | try | ||
+ | { | ||
+ | ClarujustApp.LogMessage(String.Format(" | ||
+ | appDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); | ||
+ | ClarujustApp.LogMessage(String.Format(" | ||
+ | } | ||
+ | catch (Exception e) | ||
+ | { | ||
+ | ClarujustApp.LogException(e); | ||
+ | } | ||
+ | catch | ||
+ | { | ||
+ | ClarujustApp.LogMessage(String.Format(" | ||
+ | } | ||
+ | |||
+ | try | ||
+ | { | ||
+ | ClarujustApp.LogMessage(String.Format(" | ||
+ | Environment.CurrentDirectory = appDirectory; | ||
+ | ClarujustApp.LogMessage(String.Format(" | ||
+ | } | ||
+ | catch (Exception e) | ||
+ | { | ||
+ | ClarujustApp.LogException(e); | ||
+ | } | ||
+ | catch | ||
+ | { | ||
+ | ClarujustApp.LogMessage(String.Format(" | ||
+ | } | ||
+ | |||
+ | try | ||
+ | { | ||
+ | ClarujustApp.LogMessage(String.Format(" | ||
+ | error = fwk.GetHAInitialized(out isInitialized); | ||
+ | ClarujustApp.LogMessage(String.Format(" | ||
+ | } | ||
+ | catch (Exception e) | ||
+ | { | ||
+ | ClarujustApp.LogException(e); | ||
+ | } | ||
+ | catch | ||
+ | { | ||
+ | ClarujustApp.LogMessage(String.Format(" | ||
+ | } | ||
+ | |||
+ | try | ||
+ | { | ||
+ | ClarujustApp.LogMessage(String.Format(" | ||
+ | error = fwk.Setup60(); | ||
+ | ClarujustApp.LogMessage(String.Format(" | ||
+ | } | ||
+ | catch (Exception e) | ||
+ | { | ||
+ | ClarujustApp.LogException(e); | ||
+ | } | ||
+ | catch | ||
+ | { | ||
+ | ClarujustApp.LogMessage(String.Format(" | ||
+ | } | ||
+ | |||
+ | try | ||
+ | { | ||
+ | ClarujustApp.LogMessage(String.Format(" | ||
+ | error = fwk.GetEarCount(out earCount); | ||
+ | ClarujustApp.LogMessage(String.Format(" | ||
+ | } | ||
+ | catch (Exception e) | ||
+ | { | ||
+ | ClarujustApp.LogException(e); | ||
+ | } | ||
+ | catch | ||
+ | { | ||
+ | ClarujustApp.LogMessage(String.Format(" | ||
+ | } | ||
+ | |||
+ | if (earCount == EAR_COUNT_LEFT || | ||
+ | earCount == EAR_COUNT_BOTH) | ||
+ | { | ||
+ | try | ||
+ | { | ||
+ | ClarujustApp.LogMessage(String.Format(" | ||
+ | error = fwk.GetDeviceID(out deviceId, 0); | ||
+ | ClarujustApp.LogMessage(String.Format(" | ||
+ | } | ||
+ | catch (Exception e) | ||
+ | { | ||
+ | ClarujustApp.LogException(e); | ||
+ | } | ||
+ | catch | ||
+ | { | ||
+ | ClarujustApp.LogMessage(String.Format(" | ||
+ | } | ||
+ | |||
+ | try | ||
+ | { | ||
+ | ClarujustApp.LogMessage(String.Format(" | ||
+ | error = fwk.GetSerialNumber(out serialNumber, | ||
+ | ClarujustApp.LogMessage(String.Format(" | ||
+ | } | ||
+ | catch (Exception e) | ||
+ | { | ||
+ | ClarujustApp.LogException(e); | ||
+ | } | ||
+ | catch | ||
+ | { | ||
+ | ClarujustApp.LogMessage(String.Format(" | ||
+ | } | ||
+ | } | ||
+ | else if (earCount == EAR_COUNT_RIGHT) | ||
+ | { | ||
+ | try | ||
+ | { | ||
+ | ClarujustApp.LogMessage(String.Format(" | ||
+ | error = fwk.GetDeviceID(out deviceId, 1); | ||
+ | ClarujustApp.LogMessage(String.Format(" | ||
+ | } | ||
+ | catch (Exception e) | ||
+ | { | ||
+ | ClarujustApp.LogException(e); | ||
+ | } | ||
+ | catch | ||
+ | { | ||
+ | ClarujustApp.LogMessage(String.Format(" | ||
+ | } | ||
+ | |||
+ | try | ||
+ | { | ||
+ | ClarujustApp.LogMessage(String.Format(" | ||
+ | error = fwk.GetSerialNumber(out serialNumber, | ||
+ | ClarujustApp.LogMessage(String.Format(" | ||
+ | } | ||
+ | catch (Exception e) | ||
+ | { | ||
+ | ClarujustApp.LogException(e); | ||
+ | } | ||
+ | catch | ||
+ | { | ||
+ | ClarujustApp.LogMessage(String.Format(" | ||
+ | } | ||
+ | } | ||
+ | return true; | ||
+ | } | ||
+ | |||
+ | /// < | ||
+ | /// Stops and joins the Clarujust worker thread. | ||
+ | /// </ | ||
+ | private static void JoinThread() | ||
+ | { | ||
+ | if (ClarujustApp.ClarujustThread != null) | ||
+ | { | ||
+ | ClarujustApp.ClarujustThread.Abort(); | ||
+ | ClarujustApp.ClarujustThread.Join(); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | /// < | ||
+ | /// Logs a message to the log file. | ||
+ | /// </ | ||
+ | /// <param name=" | ||
+ | private static void LogMessage(String message) | ||
+ | { | ||
+ | String text = String.Format( | ||
+ | " | ||
+ | DateTime.Now.ToString(" | ||
+ | message); | ||
+ | using (StreamWriter writer = new StreamWriter(new FileStream(" | ||
+ | { | ||
+ | writer.BaseStream.Position = writer.BaseStream.Length; | ||
+ | writer.WriteLine(message); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | /// < | ||
+ | /// Logs the exception message to the log file. | ||
+ | /// </ | ||
+ | /// <param name=" | ||
+ | private static void LogException(Exception e) | ||
+ | { | ||
+ | if (e == null) | ||
+ | return; | ||
+ | |||
+ | StringBuilder text = new StringBuilder(); | ||
+ | text.Append(String.Empty.PadLeft(100, | ||
+ | text.Append(" | ||
+ | text.Append(" | ||
+ | text.Append(" | ||
+ | text.Append(e.StackTrace + " | ||
+ | while (e.InnerException != null) | ||
+ | { | ||
+ | text.Append(String.Empty.PadLeft(100, | ||
+ | text.Append(" | ||
+ | text.Append(" | ||
+ | text.Append(" | ||
+ | text.Append(e.InnerException.StackTrace + " | ||
+ | e = e.InnerException; | ||
+ | } | ||
+ | |||
+ | ClarujustApp.LogMessage(text.ToString()); | ||
+ | } | ||
+ | |||
+ | #endregion | ||
+ | |||
+ | #region Threads | ||
+ | |||
+ | /// < | ||
+ | /// The Clarujust worker thread. | ||
+ | /// </ | ||
+ | /// <param name=" | ||
+ | private static void thread_Clarujust(Object data) | ||
+ | { | ||
+ | ClarujustApp.PrepareInterface((IEzFITOptimizerClarujust)data); | ||
+ | } | ||
+ | |||
+ | #endregion | ||
+ | |||
+ | #endregion | ||
+ | |||
+ | #region Data Constants | ||
+ | |||
+ | private static readonly Int32 EAR_COUNT_LEFT = 1; | ||
+ | private static readonly Int32 EAR_COUNT_RIGHT = 2; | ||
+ | private static readonly Int32 EAR_COUNT_BOTH = 3; | ||
+ | |||
+ | #endregion | ||
+ | } | ||
+ | } | ||
+ | </ |