# HG changeset patch # User StephaneLenclud # Date 1423313411 -3600 # Node ID 2c844ef1ff4b343cbc055d1fed0920b0fbed74f0 # Parent 0a2b658e0d5679898bd0fa2e8f56136f85797695 MDM166AA: Improved icon APIs. diff -r 0a2b658e0d56 -r 2c844ef1ff4b Display.h --- a/Display.h Thu Feb 05 22:26:15 2015 +0100 +++ b/Display.h Sat Feb 07 13:50:11 2015 +0100 @@ -5,7 +5,7 @@ #ifndef DISPLAY_H #define DISPLAY_H - +#include "MiniDisplay.h" #include "HidDevice.h" const int KMaxDisplayStringLength = 256; @@ -57,21 +57,9 @@ //Icon management //Icon support queries return the number of segments an icon supports. - virtual int IconNetworkCount(){return 0;} - virtual int IconEmailCount(){return 0;} - virtual int IconMuteCount(){return 0;} - virtual int IconVolumeCount(){return 0;} - virtual int IconPlayCount(){return 0;} - virtual int IconPauseCount(){return 0;} - virtual int IconRecordingCount(){return 0;} - // - virtual void SetIconNetwork(int /*aIndex*/, int /*aStatus*/){} - virtual void SetIconEmail(int /*aIndex*/, int /*aStatus*/){} - virtual void SetIconMute(int /*aIndex*/, int /*aStatus*/){} - virtual void SetIconVolume(int /*aIndex*/, int /*aStatus*/){} - virtual void SetIconPlay(int /*aIndex*/, int /*aStatus*/){} - virtual void SetIconPause(int /*aIndex*/, int /*aStatus*/){} - virtual void SetIconRecording(int /*aIndex*/, int /*aStatus*/){} + virtual int IconCount(TMiniDisplayIconType /*aIcon*/){return 0;} + virtual int IconStatusCount(TMiniDisplayIconType /*aIcon*/){return 0;} + virtual void SetIconStatus(TMiniDisplayIconType /*aIcon*/, int /*aIndex*/, int /*aStatus*/){} protected: void SetRequest(TMiniDisplayRequest aRequest) { iRequest=aRequest; } diff -r 0a2b658e0d56 -r 2c844ef1ff4b FutabaMDM166AA.cpp --- a/FutabaMDM166AA.cpp Thu Feb 05 22:26:15 2015 +0100 +++ b/FutabaMDM166AA.cpp Sat Feb 07 13:50:11 2015 +0100 @@ -9,6 +9,55 @@ +typedef void (MDM166AA::*TSetIconStatus) (int aIndex, int aStatus); + +const TSetIconStatus KFunctionPerIcon[]= + { + &MDM166AA::SetIconNetwork, //EMiniDisplayIconNetwork, + &MDM166AA::SetIconEmail, //EMiniDisplayIconEmail, + &MDM166AA::SetIconMute, //EMiniDisplayIconMute, + &MDM166AA::SetIconVolume, //EMiniDisplayIconVolume, + &MDM166AA::SetIconVolumeLabel, //EMiniDisplayIconVolumeLabel, + &MDM166AA::SetIconPlay, //EMiniDisplayIconPlay, + &MDM166AA::SetIconPause, //EMiniDisplayIconPause, + &MDM166AA::SetIconRecording //EMiniDisplayIconRecording + }; + +const int KMaxIconType = sizeof(KFunctionPerIcon)/sizeof(TSetIconStatus); + +/** +Define how segments each of our icons have. +Order matters. +*/ +const int KSegmentsPerIcon[]= + { + 4, //EMiniDisplayIconNetwork, + 2, //EMiniDisplayIconEmail, + 1, //EMiniDisplayIconMute, + 14, //EMiniDisplayIconVolume, + 1, //EMiniDisplayIconVolumeLabel, + 1, //EMiniDisplayIconPlay, + 1, //EMiniDisplayIconPause, + 1 //EMiniDisplayIconRecording + }; + +/** +Define how status each of our icon can assume. +Its typically two for On and Off status. +*/ +const int KStatusPerIcon[]= + { + 2, //EMiniDisplayIconNetwork, + 2, //EMiniDisplayIconEmail, + 2, //EMiniDisplayIconMute, + 3, //EMiniDisplayIconVolume, + 2, //EMiniDisplayIconVolumeLabel, 2, //EMiniDisplayIconPlay, + 2, //EMiniDisplayIconPause, + 2 //EMiniDisplayIconRecording + }; + + + static void sleep(unsigned int mseconds) { clock_t goal = mseconds + clock(); @@ -387,12 +436,34 @@ Clear(); } +/** +*/ +int MDM166AA::IconCount(TMiniDisplayIconType aIcon) + { + return KSegmentsPerIcon[aIcon]; + } + +int MDM166AA::IconStatusCount(TMiniDisplayIconType aIcon) + { + return KStatusPerIcon[aIcon]; + } + +void MDM166AA::SetIconStatus(TMiniDisplayIconType aIcon, int aIndex, int aStatus) + { + if (aIcon<0||aIcon>=KMaxIconType||(KFunctionPerIcon[aIcon]==NULL)) + { + //Out of range or no function pointer for that icon + return; + } + + (this->*KFunctionPerIcon[aIcon])(aIndex,aStatus); + } /** */ void MDM166AA::SetIconNetwork(int aIndex, int aStatus) { - if (aIndex<0||aIndex>=IconNetworkCount()) + if (aIndex<0||aIndex>=KSegmentsPerIcon[EMiniDisplayIconNetwork]) { //Out of range return; @@ -405,7 +476,7 @@ */ void MDM166AA::SetIconEmail(int aIndex, int aStatus) { - if (aIndex<0||aIndex>=IconEmailCount()) + if (aIndex<0||aIndex>=KSegmentsPerIcon[EMiniDisplayIconEmail]) { //Out of range return; @@ -418,7 +489,7 @@ */ void MDM166AA::SetIconMute(int aIndex, int aStatus) { - if (aIndex<0||aIndex>=IconMuteCount()) + if (aIndex<0||aIndex>=KSegmentsPerIcon[EMiniDisplayIconMute]) { //Out of range return; @@ -431,19 +502,36 @@ */ void MDM166AA::SetIconVolume(int aIndex, int aStatus) { - if (aIndex<0||aIndex>=IconVolumeCount()) + if (aIndex<0||aIndex>=KSegmentsPerIcon[EMiniDisplayIconVolume]) { //Out of range return; } - if (aStatusEIconOn) + if (aStatus=KSegmentsPerIcon[EMiniDisplayIconMute]) { //Out of range return; } - SendCommandSymbolControl((TIconId)(aIndex+EIconVolumeLevel01),(TIconStatus)aStatus); + SendCommandSymbolControl((TIconId)(aIndex+EIconVolumeLabel),(aStatus==0?EIconOff:EIconOn)); } @@ -451,7 +539,7 @@ */ void MDM166AA::SetIconPlay(int aIndex, int aStatus) { - if (aIndex<0||aIndex>=IconPlayCount()) + if (aIndex<0||aIndex>=KSegmentsPerIcon[EMiniDisplayIconPlay]) { //Out of range return; @@ -465,7 +553,7 @@ */ void MDM166AA::SetIconPause(int aIndex, int aStatus) { - if (aIndex<0||aIndex>=IconPauseCount()) + if (aIndex<0||aIndex>=KSegmentsPerIcon[EMiniDisplayIconPause]) { //Out of range return; @@ -479,7 +567,7 @@ */ void MDM166AA::SetIconRecording(int aIndex, int aStatus) { - if (aIndex<0||aIndex>=IconRecordingCount()) + if (aIndex<0||aIndex>=KSegmentsPerIcon[EMiniDisplayIconRecording]) { //Out of range return; diff -r 0a2b658e0d56 -r 2c844ef1ff4b FutabaMDM166AA.h --- a/FutabaMDM166AA.h Thu Feb 05 22:26:15 2015 +0100 +++ b/FutabaMDM166AA.h Sat Feb 07 13:50:11 2015 +0100 @@ -36,21 +36,9 @@ virtual void HideClock(); virtual bool SupportClock(){return true;} //Icons - virtual int IconNetworkCount(){return 4;} - virtual int IconEmailCount(){return 2;} - virtual int IconMuteCount(){return 1;} - virtual int IconVolumeCount(){return 14;} //TODO: What do we do with "VOL." - virtual int IconPlayCount(){return 1;} - virtual int IconPauseCount(){return 1;} - virtual int IconRecordingCount(){return 1;} - // - virtual void SetIconNetwork(int aIndex, int aStatus); - virtual void SetIconEmail(int aIndex, int aStatus); - virtual void SetIconMute(int aIndex, int aStatus); - virtual void SetIconVolume(int aIndex, int aStatus); - virtual void SetIconPlay(int aIndex, int aStatus); - virtual void SetIconPause(int aIndex, int aStatus); - virtual void SetIconRecording(int aIndex, int aStatus); + virtual int IconCount(TMiniDisplayIconType aIcon); + virtual int IconStatusCount(TMiniDisplayIconType aIcon); + virtual void SetIconStatus(TMiniDisplayIconType aIcon, int aIndex, int aStatus); //From GraphicDisplay virtual int WidthInPixels() const {return KMDM166AAWidthInPixels;} @@ -68,6 +56,17 @@ void SetOffScreenMode(bool aOn); bool OffScreenMode() const {return iOffScreenMode;} + //Icon specific + void SetIconNetwork(int aIndex, int aStatus); + void SetIconEmail(int aIndex, int aStatus); + void SetIconMute(int aIndex, int aStatus); + void SetIconVolumeLabel(int aIndex, int aStatus); + void SetIconVolume(int aIndex, int aStatus); + void SetIconPlay(int aIndex, int aStatus); + void SetIconPause(int aIndex, int aStatus); + void SetIconRecording(int aIndex, int aStatus); + + private: enum TClockFormat diff -r 0a2b658e0d56 -r 2c844ef1ff4b MiniDisplay.cpp --- a/MiniDisplay.cpp Thu Feb 05 22:26:15 2015 +0100 +++ b/MiniDisplay.cpp Sat Feb 07 13:50:11 2015 +0100 @@ -293,85 +293,19 @@ } //------------------------------------------------------------- -int MiniDisplayIconNetworkCount(MiniDisplayDevice aDevice) +int MiniDisplayIconCount(MiniDisplayDevice aDevice, TMiniDisplayIconType aIcon) { - return ((GraphicDisplay*)aDevice)->IconNetworkCount(); - } + return ((GraphicDisplay*)aDevice)->IconCount(aIcon); + } //------------------------------------------------------------- -int MiniDisplayIconEmailCount(MiniDisplayDevice aDevice) +int MiniDisplayIconStatusCount(MiniDisplayDevice aDevice, TMiniDisplayIconType aIcon) { - return ((GraphicDisplay*)aDevice)->IconEmailCount(); - } + return ((GraphicDisplay*)aDevice)->IconStatusCount(aIcon); + } //------------------------------------------------------------- -int MiniDisplayIconMuteCount(MiniDisplayDevice aDevice) +void MiniDisplaySetIconStatus(MiniDisplayDevice aDevice, TMiniDisplayIconType aIcon, int aIndex, int aStatus) { - return ((GraphicDisplay*)aDevice)->IconMuteCount(); - } - -//------------------------------------------------------------- -int MiniDisplayIconVolumeCount(MiniDisplayDevice aDevice) - { - return ((GraphicDisplay*)aDevice)->IconVolumeCount(); - } - -//------------------------------------------------------------- -int MiniDisplayIconPlayCount(MiniDisplayDevice aDevice) - { - return ((GraphicDisplay*)aDevice)->IconPlayCount(); - } - -//------------------------------------------------------------- -int MiniDisplayIconPauseCount(MiniDisplayDevice aDevice) - { - return ((GraphicDisplay*)aDevice)->IconPauseCount(); - } - -//------------------------------------------------------------- -int MiniDisplayIconRecordingCount(MiniDisplayDevice aDevice) - { - return ((GraphicDisplay*)aDevice)->IconRecordingCount(); - } - -//------------------------------------------------------------- -void MiniDisplaySetIconNetwork(MiniDisplayDevice aDevice, int aIndex, int aStatus) - { - ((GraphicDisplay*)aDevice)->SetIconNetwork(aIndex,aStatus); - } - -//------------------------------------------------------------- -void MiniDisplaySetIconEmail(MiniDisplayDevice aDevice, int aIndex, int aStatus) - { - ((GraphicDisplay*)aDevice)->SetIconEmail(aIndex,aStatus); - } - -//------------------------------------------------------------- -void MiniDisplaySetIconMute(MiniDisplayDevice aDevice, int aIndex, int aStatus) - { - ((GraphicDisplay*)aDevice)->SetIconMute(aIndex,aStatus); - } - -//------------------------------------------------------------- -void MiniDisplaySetIconVolume(MiniDisplayDevice aDevice, int aIndex, int aStatus) - { - ((GraphicDisplay*)aDevice)->SetIconVolume(aIndex,aStatus); - } - -//------------------------------------------------------------- -void MiniDisplaySetIconPlay(MiniDisplayDevice aDevice, int aIndex, int aStatus) - { - ((GraphicDisplay*)aDevice)->SetIconPlay(aIndex,aStatus); - } - -//------------------------------------------------------------- -void MiniDisplaySetIconPause(MiniDisplayDevice aDevice, int aIndex, int aStatus) - { - ((GraphicDisplay*)aDevice)->SetIconPause(aIndex,aStatus); - } - -//------------------------------------------------------------- -void MiniDisplaySetIconRecording(MiniDisplayDevice aDevice, int aIndex, int aStatus) - { - ((GraphicDisplay*)aDevice)->SetIconRecording(aIndex,aStatus); - } + ((GraphicDisplay*)aDevice)->SetIconStatus(aIcon,aIndex,aStatus); + } \ No newline at end of file diff -r 0a2b658e0d56 -r 2c844ef1ff4b MiniDisplay.h --- a/MiniDisplay.h Thu Feb 05 22:26:15 2015 +0100 +++ b/MiniDisplay.h Sat Feb 07 13:50:11 2015 +0100 @@ -37,7 +37,7 @@ typedef enum { - EMiniDisplayRequestNone, + EMiniDisplayRequestNone=0, EMiniDisplayRequestDeviceId, EMiniDisplayRequestFirmwareRevision, EMiniDisplayRequestPowerSupplyStatus @@ -45,6 +45,23 @@ TMiniDisplayRequest; /** +Define the various type of icons we support. +For binary compatibility new entries must be added at the end. +*/ +typedef enum + { + EMiniDisplayIconNetwork=0, + EMiniDisplayIconEmail, + EMiniDisplayIconMute, + EMiniDisplayIconVolume, + EMiniDisplayIconVolumeLabel, + EMiniDisplayIconPlay, + EMiniDisplayIconPause, + EMiniDisplayIconRecording + } +TMiniDisplayIconType; + +/** Attempt to establish a connection to with a display of the given type. Supports display auto-detection too. @@ -252,22 +269,33 @@ */ extern "C" MDAPI bool MiniDisplaySupportClock(MiniDisplayDevice aDevice); +/** +Tells how many icons of the given are supported by the specified device. +Typically icons on a VFD hardware have several segments that can be light up separately. +@param [IN] The device to apply this command to. +@param [IN] The type of icon we are interested in. +@return The number of icons of this kind this display supports. +*/ +extern "C" MDAPI int MiniDisplayIconCount(MiniDisplayDevice aDevice, TMiniDisplayIconType aIcon); -extern "C" MDAPI int MiniDisplayIconNetworkCount(MiniDisplayDevice aDevice); -extern "C" MDAPI int MiniDisplayIconEmailCount(MiniDisplayDevice aDevice); -extern "C" MDAPI int MiniDisplayIconMuteCount(MiniDisplayDevice aDevice); -extern "C" MDAPI int MiniDisplayIconVolumeCount(MiniDisplayDevice aDevice); -extern "C" MDAPI int MiniDisplayIconPlayCount(MiniDisplayDevice aDevice); -extern "C" MDAPI int MiniDisplayIconPauseCount(MiniDisplayDevice aDevice); -extern "C" MDAPI int MiniDisplayIconRecordingCount(MiniDisplayDevice aDevice); -// -extern "C" MDAPI void MiniDisplaySetIconNetwork(MiniDisplayDevice aDevice, int aIndex, int aStatus); -extern "C" MDAPI void MiniDisplaySetIconEmail(MiniDisplayDevice aDevice, int aIndex, int aStatus); -extern "C" MDAPI void MiniDisplaySetIconMute(MiniDisplayDevice aDevice, int aIndex, int aStatus); -extern "C" MDAPI void MiniDisplaySetIconVolume(MiniDisplayDevice aDevice, int aIndex, int aStatus); -extern "C" MDAPI void MiniDisplaySetIconPlay(MiniDisplayDevice aDevice, int aIndex, int aStatus); -extern "C" MDAPI void MiniDisplaySetIconPause(MiniDisplayDevice aDevice, int aIndex, int aStatus); -extern "C" MDAPI void MiniDisplaySetIconRecording(MiniDisplayDevice aDevice, int aIndex, int aStatus); +/** +Tells how many status the icon of the specified type supports for the given device. +Status are typically brightness level on VFD hardware. +Most icon will just support 2 status: 0 for Off and 1 for On. +@param [IN] The device to apply this command to. +@param [IN] The type of icon we are interested in. +@return The number of icons of this kind this display supports. +*/ +extern "C" MDAPI int MiniDisplayIconStatusCount(MiniDisplayDevice aDevice, TMiniDisplayIconType aIcon); + +/** +Set the status of the given icon for the specified device. +@param [IN] The device to apply this command to. +@param [IN] The type of icon we are interested in. +@param [IN] The index of the icon of the given type. +@param [IN] The status the icon is to assume. +*/ +extern "C" MDAPI void MiniDisplaySetIconStatus(MiniDisplayDevice aDevice, TMiniDisplayIconType aIcon, int aIndex, int aStatus); #endif