MDM166AA: Improved icon APIs.
authorStephaneLenclud
Sat, 07 Feb 2015 13:50:11 +0100
changeset 322c844ef1ff4b
parent 31 0a2b658e0d56
child 33 fc42477ae80b
MDM166AA: Improved icon APIs.
Display.h
FutabaMDM166AA.cpp
FutabaMDM166AA.h
MiniDisplay.cpp
MiniDisplay.h
     1.1 --- a/Display.h	Thu Feb 05 22:26:15 2015 +0100
     1.2 +++ b/Display.h	Sat Feb 07 13:50:11 2015 +0100
     1.3 @@ -5,7 +5,7 @@
     1.4  #ifndef DISPLAY_H
     1.5  #define DISPLAY_H
     1.6  
     1.7 -
     1.8 +#include "MiniDisplay.h"
     1.9  #include "HidDevice.h"
    1.10  const int KMaxDisplayStringLength = 256;
    1.11  
    1.12 @@ -57,21 +57,9 @@
    1.13  
    1.14  	//Icon management
    1.15  	//Icon support queries return the number of segments an icon supports.
    1.16 -	virtual int IconNetworkCount(){return 0;}
    1.17 -	virtual int IconEmailCount(){return 0;}
    1.18 -	virtual int IconMuteCount(){return 0;}
    1.19 -	virtual int IconVolumeCount(){return 0;}
    1.20 -	virtual int IconPlayCount(){return 0;}
    1.21 -	virtual int IconPauseCount(){return 0;}
    1.22 -	virtual int IconRecordingCount(){return 0;}
    1.23 -	//
    1.24 -	virtual void SetIconNetwork(int /*aIndex*/, int /*aStatus*/){}
    1.25 -	virtual void SetIconEmail(int /*aIndex*/, int /*aStatus*/){}
    1.26 -	virtual void SetIconMute(int /*aIndex*/, int /*aStatus*/){}
    1.27 -	virtual void SetIconVolume(int /*aIndex*/, int /*aStatus*/){}
    1.28 -	virtual void SetIconPlay(int /*aIndex*/, int /*aStatus*/){}
    1.29 -	virtual void SetIconPause(int /*aIndex*/, int /*aStatus*/){}
    1.30 -	virtual void SetIconRecording(int /*aIndex*/, int /*aStatus*/){}
    1.31 +	virtual int IconCount(TMiniDisplayIconType /*aIcon*/){return 0;}
    1.32 +	virtual int IconStatusCount(TMiniDisplayIconType /*aIcon*/){return 0;}
    1.33 +	virtual void SetIconStatus(TMiniDisplayIconType /*aIcon*/, int /*aIndex*/, int /*aStatus*/){}
    1.34  
    1.35  protected:
    1.36  	void SetRequest(TMiniDisplayRequest aRequest) { iRequest=aRequest; }
     2.1 --- a/FutabaMDM166AA.cpp	Thu Feb 05 22:26:15 2015 +0100
     2.2 +++ b/FutabaMDM166AA.cpp	Sat Feb 07 13:50:11 2015 +0100
     2.3 @@ -9,6 +9,55 @@
     2.4  
     2.5  
     2.6  
     2.7 +typedef void (MDM166AA::*TSetIconStatus) (int aIndex, int aStatus);
     2.8 +
     2.9 +const TSetIconStatus KFunctionPerIcon[]=
    2.10 +	{
    2.11 +	&MDM166AA::SetIconNetwork,	//EMiniDisplayIconNetwork,
    2.12 +    &MDM166AA::SetIconEmail,	//EMiniDisplayIconEmail,
    2.13 +    &MDM166AA::SetIconMute,	//EMiniDisplayIconMute,
    2.14 +    &MDM166AA::SetIconVolume, //EMiniDisplayIconVolume,
    2.15 +	&MDM166AA::SetIconVolumeLabel,	//EMiniDisplayIconVolumeLabel,
    2.16 +	&MDM166AA::SetIconPlay,	//EMiniDisplayIconPlay,
    2.17 +	&MDM166AA::SetIconPause,	//EMiniDisplayIconPause,
    2.18 +	&MDM166AA::SetIconRecording	//EMiniDisplayIconRecording
    2.19 +	};
    2.20 +
    2.21 +const int KMaxIconType = sizeof(KFunctionPerIcon)/sizeof(TSetIconStatus);
    2.22 +
    2.23 +/**
    2.24 +Define how segments each of our icons have.
    2.25 +Order matters.
    2.26 +*/
    2.27 +const int KSegmentsPerIcon[]=
    2.28 +	{
    2.29 +	4,	//EMiniDisplayIconNetwork,
    2.30 +    2,	//EMiniDisplayIconEmail,
    2.31 +    1,	//EMiniDisplayIconMute,
    2.32 +    14, //EMiniDisplayIconVolume,
    2.33 +	1,	//EMiniDisplayIconVolumeLabel,
    2.34 +	1,	//EMiniDisplayIconPlay,
    2.35 +	1,	//EMiniDisplayIconPause,
    2.36 +	1	//EMiniDisplayIconRecording
    2.37 +	};
    2.38 +
    2.39 +/**
    2.40 +Define how status each of our icon can assume.
    2.41 +Its typically two for On and Off status.
    2.42 +*/
    2.43 +const int KStatusPerIcon[]=
    2.44 +	{
    2.45 +	2,	//EMiniDisplayIconNetwork,
    2.46 +    2,	//EMiniDisplayIconEmail,
    2.47 +    2,	//EMiniDisplayIconMute,
    2.48 +    3, //EMiniDisplayIconVolume,
    2.49 +	2,	//EMiniDisplayIconVolumeLabel,	2,	//EMiniDisplayIconPlay,
    2.50 +	2,	//EMiniDisplayIconPause,
    2.51 +	2	//EMiniDisplayIconRecording
    2.52 +	};
    2.53 +
    2.54 +
    2.55 +
    2.56  static void sleep(unsigned int mseconds)
    2.57  	{
    2.58      clock_t goal = mseconds + clock();
    2.59 @@ -387,12 +436,34 @@
    2.60  	Clear();
    2.61  	}
    2.62  
    2.63 +/**
    2.64 +*/
    2.65 +int MDM166AA::IconCount(TMiniDisplayIconType aIcon)
    2.66 +	{
    2.67 +	return KSegmentsPerIcon[aIcon];
    2.68 +	}
    2.69 +
    2.70 +int MDM166AA::IconStatusCount(TMiniDisplayIconType aIcon)
    2.71 +	{
    2.72 +	return KStatusPerIcon[aIcon];
    2.73 +	}
    2.74 +
    2.75 +void MDM166AA::SetIconStatus(TMiniDisplayIconType aIcon, int aIndex, int aStatus)
    2.76 +	{
    2.77 +	if (aIcon<0||aIcon>=KMaxIconType||(KFunctionPerIcon[aIcon]==NULL))
    2.78 +		{
    2.79 +		//Out of range or no function pointer for that icon
    2.80 +		return;
    2.81 +		}
    2.82 +
    2.83 +	(this->*KFunctionPerIcon[aIcon])(aIndex,aStatus);
    2.84 +	}
    2.85  
    2.86  /**
    2.87  */
    2.88  void MDM166AA::SetIconNetwork(int aIndex, int aStatus)
    2.89  	{
    2.90 -	if (aIndex<0||aIndex>=IconNetworkCount())
    2.91 +	if (aIndex<0||aIndex>=KSegmentsPerIcon[EMiniDisplayIconNetwork])
    2.92  		{
    2.93  		//Out of range
    2.94  		return;
    2.95 @@ -405,7 +476,7 @@
    2.96  */
    2.97  void MDM166AA::SetIconEmail(int aIndex, int aStatus)
    2.98  	{
    2.99 -	if (aIndex<0||aIndex>=IconEmailCount())
   2.100 +	if (aIndex<0||aIndex>=KSegmentsPerIcon[EMiniDisplayIconEmail])
   2.101  		{
   2.102  		//Out of range
   2.103  		return;
   2.104 @@ -418,7 +489,7 @@
   2.105  */
   2.106  void MDM166AA::SetIconMute(int aIndex, int aStatus)
   2.107  	{
   2.108 -	if (aIndex<0||aIndex>=IconMuteCount())
   2.109 +	if (aIndex<0||aIndex>=KSegmentsPerIcon[EMiniDisplayIconMute])
   2.110  		{
   2.111  		//Out of range
   2.112  		return;
   2.113 @@ -431,19 +502,36 @@
   2.114  */
   2.115  void MDM166AA::SetIconVolume(int aIndex, int aStatus)
   2.116  	{
   2.117 -	if (aIndex<0||aIndex>=IconVolumeCount())
   2.118 +	if (aIndex<0||aIndex>=KSegmentsPerIcon[EMiniDisplayIconVolume])
   2.119  		{
   2.120  		//Out of range
   2.121  		return;
   2.122  		}
   2.123  
   2.124 -	if (aStatus<EIconOff||aStatus>EIconOn)
   2.125 +	if (aStatus<EIconOff)
   2.126 +		{
   2.127 +		//Assuming we just want to turn it off then
   2.128 +		aStatus=EIconOff;
   2.129 +		}
   2.130 +
   2.131 +	//Make sure we cap at our highest status value
   2.132 +	aStatus = MIN(EIconOn,aStatus);
   2.133 +
   2.134 +	SendCommandSymbolControl((TIconId)(aIndex+EIconVolumeLevel01),(TIconStatus)aStatus);
   2.135 +	}
   2.136 +
   2.137 +
   2.138 +/**
   2.139 +*/
   2.140 +void MDM166AA::SetIconVolumeLabel(int aIndex, int aStatus)
   2.141 +	{
   2.142 +	if (aIndex<0||aIndex>=KSegmentsPerIcon[EMiniDisplayIconMute])
   2.143  		{
   2.144  		//Out of range
   2.145  		return;
   2.146  		}
   2.147  
   2.148 -	SendCommandSymbolControl((TIconId)(aIndex+EIconVolumeLevel01),(TIconStatus)aStatus);
   2.149 +	SendCommandSymbolControl((TIconId)(aIndex+EIconVolumeLabel),(aStatus==0?EIconOff:EIconOn));
   2.150  	}
   2.151  
   2.152  
   2.153 @@ -451,7 +539,7 @@
   2.154  */
   2.155  void MDM166AA::SetIconPlay(int aIndex, int aStatus)
   2.156  	{
   2.157 -	if (aIndex<0||aIndex>=IconPlayCount())
   2.158 +	if (aIndex<0||aIndex>=KSegmentsPerIcon[EMiniDisplayIconPlay])
   2.159  		{
   2.160  		//Out of range
   2.161  		return;
   2.162 @@ -465,7 +553,7 @@
   2.163  */
   2.164  void MDM166AA::SetIconPause(int aIndex, int aStatus)
   2.165  	{
   2.166 -	if (aIndex<0||aIndex>=IconPauseCount())
   2.167 +	if (aIndex<0||aIndex>=KSegmentsPerIcon[EMiniDisplayIconPause])
   2.168  		{
   2.169  		//Out of range
   2.170  		return;
   2.171 @@ -479,7 +567,7 @@
   2.172  */
   2.173  void MDM166AA::SetIconRecording(int aIndex, int aStatus)
   2.174  	{
   2.175 -	if (aIndex<0||aIndex>=IconRecordingCount())
   2.176 +	if (aIndex<0||aIndex>=KSegmentsPerIcon[EMiniDisplayIconRecording])
   2.177  		{
   2.178  		//Out of range
   2.179  		return;
     3.1 --- a/FutabaMDM166AA.h	Thu Feb 05 22:26:15 2015 +0100
     3.2 +++ b/FutabaMDM166AA.h	Sat Feb 07 13:50:11 2015 +0100
     3.3 @@ -36,21 +36,9 @@
     3.4  	virtual void HideClock();
     3.5  	virtual bool SupportClock(){return true;}
     3.6  		//Icons
     3.7 -	virtual int IconNetworkCount(){return 4;}
     3.8 -	virtual int IconEmailCount(){return 2;}
     3.9 -	virtual int IconMuteCount(){return 1;}
    3.10 -	virtual int IconVolumeCount(){return 14;} //TODO: What do we do with "VOL."
    3.11 -	virtual int IconPlayCount(){return 1;}
    3.12 -	virtual int IconPauseCount(){return 1;}
    3.13 -	virtual int IconRecordingCount(){return 1;}
    3.14 -	//
    3.15 -	virtual void SetIconNetwork(int aIndex, int aStatus);
    3.16 -	virtual void SetIconEmail(int aIndex, int aStatus);
    3.17 -	virtual void SetIconMute(int aIndex, int aStatus);
    3.18 -	virtual void SetIconVolume(int aIndex, int aStatus);
    3.19 -	virtual void SetIconPlay(int aIndex, int aStatus);
    3.20 -	virtual void SetIconPause(int aIndex, int aStatus);
    3.21 -	virtual void SetIconRecording(int aIndex, int aStatus);
    3.22 +	virtual int IconCount(TMiniDisplayIconType aIcon);
    3.23 +	virtual int IconStatusCount(TMiniDisplayIconType aIcon);
    3.24 +	virtual void SetIconStatus(TMiniDisplayIconType aIcon, int aIndex, int aStatus);
    3.25  
    3.26  	//From GraphicDisplay
    3.27      virtual int WidthInPixels() const {return KMDM166AAWidthInPixels;}
    3.28 @@ -68,6 +56,17 @@
    3.29      void SetOffScreenMode(bool aOn);
    3.30      bool OffScreenMode() const {return iOffScreenMode;}
    3.31  
    3.32 +		//Icon specific
    3.33 +	void SetIconNetwork(int aIndex, int aStatus);
    3.34 +	void SetIconEmail(int aIndex, int aStatus);
    3.35 +	void SetIconMute(int aIndex, int aStatus);
    3.36 +	void SetIconVolumeLabel(int aIndex, int aStatus);
    3.37 +	void SetIconVolume(int aIndex, int aStatus);
    3.38 +	void SetIconPlay(int aIndex, int aStatus);
    3.39 +	void SetIconPause(int aIndex, int aStatus);
    3.40 +	void SetIconRecording(int aIndex, int aStatus);
    3.41 +
    3.42 +
    3.43  private:
    3.44  
    3.45  	enum TClockFormat
     4.1 --- a/MiniDisplay.cpp	Thu Feb 05 22:26:15 2015 +0100
     4.2 +++ b/MiniDisplay.cpp	Sat Feb 07 13:50:11 2015 +0100
     4.3 @@ -293,85 +293,19 @@
     4.4      }
     4.5  
     4.6  //-------------------------------------------------------------
     4.7 -int MiniDisplayIconNetworkCount(MiniDisplayDevice aDevice)
     4.8 +int MiniDisplayIconCount(MiniDisplayDevice aDevice, TMiniDisplayIconType aIcon)
     4.9  	{
    4.10 -    return ((GraphicDisplay*)aDevice)->IconNetworkCount();
    4.11 -    }
    4.12 +	return ((GraphicDisplay*)aDevice)->IconCount(aIcon);
    4.13 +	}
    4.14  
    4.15  //-------------------------------------------------------------
    4.16 -int MiniDisplayIconEmailCount(MiniDisplayDevice aDevice)
    4.17 +int MiniDisplayIconStatusCount(MiniDisplayDevice aDevice, TMiniDisplayIconType aIcon)
    4.18  	{
    4.19 -    return ((GraphicDisplay*)aDevice)->IconEmailCount();
    4.20 -    }
    4.21 +	return ((GraphicDisplay*)aDevice)->IconStatusCount(aIcon);
    4.22 +	}
    4.23  
    4.24  //-------------------------------------------------------------
    4.25 -int MiniDisplayIconMuteCount(MiniDisplayDevice aDevice)
    4.26 +void MiniDisplaySetIconStatus(MiniDisplayDevice aDevice, TMiniDisplayIconType aIcon, int aIndex, int aStatus)
    4.27  	{
    4.28 -    return ((GraphicDisplay*)aDevice)->IconMuteCount();
    4.29 -    }
    4.30 -
    4.31 -//-------------------------------------------------------------
    4.32 -int MiniDisplayIconVolumeCount(MiniDisplayDevice aDevice)
    4.33 -	{
    4.34 -    return ((GraphicDisplay*)aDevice)->IconVolumeCount();
    4.35 -    }
    4.36 -
    4.37 -//-------------------------------------------------------------
    4.38 -int MiniDisplayIconPlayCount(MiniDisplayDevice aDevice)
    4.39 -	{
    4.40 -    return ((GraphicDisplay*)aDevice)->IconPlayCount();
    4.41 -    }
    4.42 -
    4.43 -//-------------------------------------------------------------
    4.44 -int MiniDisplayIconPauseCount(MiniDisplayDevice aDevice)
    4.45 -	{
    4.46 -    return ((GraphicDisplay*)aDevice)->IconPauseCount();
    4.47 -    }
    4.48 -
    4.49 -//-------------------------------------------------------------
    4.50 -int MiniDisplayIconRecordingCount(MiniDisplayDevice aDevice)
    4.51 -	{
    4.52 -    return ((GraphicDisplay*)aDevice)->IconRecordingCount();
    4.53 -    }
    4.54 -
    4.55 -//-------------------------------------------------------------
    4.56 -void MiniDisplaySetIconNetwork(MiniDisplayDevice aDevice, int aIndex, int aStatus)
    4.57 -    {
    4.58 -    ((GraphicDisplay*)aDevice)->SetIconNetwork(aIndex,aStatus);
    4.59 -    }
    4.60 -
    4.61 -//-------------------------------------------------------------
    4.62 -void MiniDisplaySetIconEmail(MiniDisplayDevice aDevice, int aIndex, int aStatus)
    4.63 -    {
    4.64 -    ((GraphicDisplay*)aDevice)->SetIconEmail(aIndex,aStatus);
    4.65 -    }
    4.66 -
    4.67 -//-------------------------------------------------------------
    4.68 -void MiniDisplaySetIconMute(MiniDisplayDevice aDevice, int aIndex, int aStatus)
    4.69 -    {
    4.70 -    ((GraphicDisplay*)aDevice)->SetIconMute(aIndex,aStatus);
    4.71 -    }
    4.72 -
    4.73 -//-------------------------------------------------------------
    4.74 -void MiniDisplaySetIconVolume(MiniDisplayDevice aDevice, int aIndex, int aStatus)
    4.75 -    {
    4.76 -    ((GraphicDisplay*)aDevice)->SetIconVolume(aIndex,aStatus);
    4.77 -    }
    4.78 -
    4.79 -//-------------------------------------------------------------
    4.80 -void MiniDisplaySetIconPlay(MiniDisplayDevice aDevice, int aIndex, int aStatus)
    4.81 -    {
    4.82 -    ((GraphicDisplay*)aDevice)->SetIconPlay(aIndex,aStatus);
    4.83 -    }
    4.84 -
    4.85 -//-------------------------------------------------------------
    4.86 -void MiniDisplaySetIconPause(MiniDisplayDevice aDevice, int aIndex, int aStatus)
    4.87 -    {
    4.88 -    ((GraphicDisplay*)aDevice)->SetIconPause(aIndex,aStatus);
    4.89 -    }
    4.90 -
    4.91 -//-------------------------------------------------------------
    4.92 -void MiniDisplaySetIconRecording(MiniDisplayDevice aDevice, int aIndex, int aStatus)
    4.93 -    {
    4.94 -    ((GraphicDisplay*)aDevice)->SetIconRecording(aIndex,aStatus);
    4.95 -    }
    4.96 +	((GraphicDisplay*)aDevice)->SetIconStatus(aIcon,aIndex,aStatus);
    4.97 +	}
    4.98 \ No newline at end of file
     5.1 --- a/MiniDisplay.h	Thu Feb 05 22:26:15 2015 +0100
     5.2 +++ b/MiniDisplay.h	Sat Feb 07 13:50:11 2015 +0100
     5.3 @@ -37,7 +37,7 @@
     5.4  
     5.5  typedef enum
     5.6      {
     5.7 -    EMiniDisplayRequestNone,
     5.8 +    EMiniDisplayRequestNone=0,
     5.9      EMiniDisplayRequestDeviceId,
    5.10      EMiniDisplayRequestFirmwareRevision,
    5.11      EMiniDisplayRequestPowerSupplyStatus
    5.12 @@ -45,6 +45,23 @@
    5.13  TMiniDisplayRequest;
    5.14  
    5.15  /**
    5.16 +Define the various type of icons we support.
    5.17 +For binary compatibility new entries must be added at the end.
    5.18 +*/
    5.19 +typedef enum
    5.20 +    {
    5.21 +    EMiniDisplayIconNetwork=0,
    5.22 +    EMiniDisplayIconEmail,
    5.23 +    EMiniDisplayIconMute,
    5.24 +    EMiniDisplayIconVolume,
    5.25 +	EMiniDisplayIconVolumeLabel,
    5.26 +	EMiniDisplayIconPlay,
    5.27 +	EMiniDisplayIconPause,
    5.28 +	EMiniDisplayIconRecording
    5.29 +    }
    5.30 +TMiniDisplayIconType;
    5.31 +
    5.32 +/**
    5.33  Attempt to establish a connection to with a display of the given type.
    5.34  Supports display auto-detection too.
    5.35  
    5.36 @@ -252,22 +269,33 @@
    5.37  */
    5.38  extern "C" MDAPI bool MiniDisplaySupportClock(MiniDisplayDevice aDevice);
    5.39  
    5.40 +/**
    5.41 +Tells how many icons of the given are supported by the specified device.
    5.42 +Typically icons on a VFD hardware have several segments that can be light up separately.
    5.43 +@param [IN] The device to apply this command to.
    5.44 +@param [IN] The type of icon we are interested in.
    5.45 +@return The number of icons of this kind this display supports.
    5.46 +*/
    5.47 +extern "C" MDAPI int MiniDisplayIconCount(MiniDisplayDevice aDevice, TMiniDisplayIconType aIcon);
    5.48  
    5.49 -extern "C" MDAPI int MiniDisplayIconNetworkCount(MiniDisplayDevice aDevice);
    5.50 -extern "C" MDAPI int MiniDisplayIconEmailCount(MiniDisplayDevice aDevice);
    5.51 -extern "C" MDAPI int MiniDisplayIconMuteCount(MiniDisplayDevice aDevice);
    5.52 -extern "C" MDAPI int MiniDisplayIconVolumeCount(MiniDisplayDevice aDevice);
    5.53 -extern "C" MDAPI int MiniDisplayIconPlayCount(MiniDisplayDevice aDevice);
    5.54 -extern "C" MDAPI int MiniDisplayIconPauseCount(MiniDisplayDevice aDevice);
    5.55 -extern "C" MDAPI int MiniDisplayIconRecordingCount(MiniDisplayDevice aDevice);
    5.56 -//
    5.57 -extern "C" MDAPI void MiniDisplaySetIconNetwork(MiniDisplayDevice aDevice, int aIndex, int aStatus);
    5.58 -extern "C" MDAPI void MiniDisplaySetIconEmail(MiniDisplayDevice aDevice, int aIndex, int aStatus);
    5.59 -extern "C" MDAPI void MiniDisplaySetIconMute(MiniDisplayDevice aDevice, int aIndex, int aStatus);
    5.60 -extern "C" MDAPI void MiniDisplaySetIconVolume(MiniDisplayDevice aDevice, int aIndex, int aStatus);
    5.61 -extern "C" MDAPI void MiniDisplaySetIconPlay(MiniDisplayDevice aDevice, int aIndex, int aStatus);
    5.62 -extern "C" MDAPI void MiniDisplaySetIconPause(MiniDisplayDevice aDevice, int aIndex, int aStatus);
    5.63 -extern "C" MDAPI void MiniDisplaySetIconRecording(MiniDisplayDevice aDevice, int aIndex, int aStatus);
    5.64 +/**
    5.65 +Tells how many status the icon of the specified type supports for the given device.
    5.66 +Status are typically brightness level on VFD hardware.
    5.67 +Most icon will just support 2 status: 0 for Off and 1 for On.
    5.68 +@param [IN] The device to apply this command to.
    5.69 +@param [IN] The type of icon we are interested in.
    5.70 +@return The number of icons of this kind this display supports.
    5.71 +*/
    5.72 +extern "C" MDAPI int MiniDisplayIconStatusCount(MiniDisplayDevice aDevice, TMiniDisplayIconType aIcon);
    5.73 +
    5.74 +/**
    5.75 +Set the status of the given icon for the specified device.
    5.76 +@param [IN] The device to apply this command to.
    5.77 +@param [IN] The type of icon we are interested in.
    5.78 +@param [IN] The index of the icon of the given type.
    5.79 +@param [IN] The status the icon is to assume.
    5.80 +*/
    5.81 +extern "C" MDAPI void MiniDisplaySetIconStatus(MiniDisplayDevice aDevice, TMiniDisplayIconType aIcon, int aIndex, int aStatus);
    5.82  
    5.83  
    5.84  #endif