MiniDisplay.cpp
author StephaneLenclud
Sat, 07 Feb 2015 13:50:11 +0100
changeset 32 2c844ef1ff4b
parent 31 0a2b658e0d56
child 35 638eb0763e20
permissions -rw-r--r--
MDM166AA: Improved icon APIs.
sl@2
     1
sl@2
     2
#include "MiniDisplay.h"
sl@8
     3
#include "FutabaGP1212A01.h"
sl@10
     4
#include "FutabaGP1212A02.h"
StephaneLenclud@25
     5
#include "FutabaMDM166AA.h"
sl@2
     6
StephaneLenclud@25
     7
/**
StephaneLenclud@25
     8
Make sure you update this list when adding a new display.
StephaneLenclud@25
     9
The order has to match the one from TMiniDisplayType.
StephaneLenclud@25
    10
*/
StephaneLenclud@24
    11
wchar_t* KDisplayNames[]=
StephaneLenclud@24
    12
	{
StephaneLenclud@24
    13
	L"Auto-Detect",
StephaneLenclud@24
    14
	L"Futaba GP1212A01",
StephaneLenclud@24
    15
	L"Futaba GP1212A02",
StephaneLenclud@25
    16
	L"Futaba MDM166AA",
StephaneLenclud@24
    17
	L"Unknown display device"
StephaneLenclud@24
    18
	};
StephaneLenclud@24
    19
StephaneLenclud@18
    20
MiniDisplayDevice MiniDisplayOpen(TMiniDisplayType aType, bool aAutoDetect)
sl@2
    21
	{
sl@10
    22
	GraphicDisplay* device=NULL;
sl@10
    23
sl@10
    24
	switch (aType)
sl@10
    25
		{
sl@10
    26
	case EMiniDisplayAutoDetect:
sl@10
    27
	case EMiniDisplayFutabaGP1212A01:
sl@10
    28
		device=new GP1212A01A();
sl@10
    29
		break;
sl@10
    30
		
sl@10
    31
	case EMiniDisplayFutabaGP1212A02:
sl@10
    32
		device=new GP1212A02A();
sl@10
    33
		break;
StephaneLenclud@18
    34
StephaneLenclud@25
    35
	case EMiniDisplayFutabaMDM166AA:
StephaneLenclud@25
    36
		device=new MDM166AA();
StephaneLenclud@25
    37
		break;
StephaneLenclud@25
    38
StephaneLenclud@18
    39
	case EMiniDisplayAutoDetectFailed:
StephaneLenclud@18
    40
		//Auto detect sequence failed
StephaneLenclud@18
    41
		return NULL;
StephaneLenclud@18
    42
		break;
sl@10
    43
		};
sl@10
    44
sl@2
    45
	int success = device->Open();
sl@2
    46
	if (!success)
sl@2
    47
		{
sl@2
    48
		delete device;
sl@10
    49
		device=NULL;
StephaneLenclud@18
    50
		if (aAutoDetect)
StephaneLenclud@18
    51
			{
StephaneLenclud@18
    52
			//Go recursive for auto detect
StephaneLenclud@18
    53
			int typeValue=(int)aType;
StephaneLenclud@18
    54
			typeValue++;
StephaneLenclud@18
    55
			TMiniDisplayType nextType=(TMiniDisplayType)typeValue;
StephaneLenclud@18
    56
			return MiniDisplayOpen(nextType,aAutoDetect);
StephaneLenclud@18
    57
			}
sl@2
    58
		}
sl@2
    59
sl@2
    60
	return device;
sl@2
    61
	}
sl@2
    62
StephaneLenclud@18
    63
StephaneLenclud@18
    64
//Open & Close functions
StephaneLenclud@18
    65
MiniDisplayDevice MiniDisplayOpen(TMiniDisplayType aType)
StephaneLenclud@18
    66
	{
StephaneLenclud@18
    67
	bool autoDetect=aType==EMiniDisplayAutoDetect;
sl@19
    68
	//If we want auto detect we need to pass in our first display type
sl@19
    69
	//If we don't want auto detect we just pass in the given display type. 
sl@19
    70
	return MiniDisplayOpen((autoDetect?EMiniDisplayFutabaGP1212A01:aType),autoDetect);
StephaneLenclud@18
    71
	}
StephaneLenclud@18
    72
StephaneLenclud@18
    73
sl@10
    74
//
sl@10
    75
sl@2
    76
void MiniDisplayClose(MiniDisplayDevice aDevice)
sl@4
    77
	{
sl@10
    78
	delete ((GraphicDisplay*)aDevice);
sl@2
    79
	}
sl@2
    80
sl@2
    81
StephaneLenclud@24
    82
int MiniDisplayTypeCount()
StephaneLenclud@24
    83
	{
StephaneLenclud@24
    84
	return EMiniDisplayAutoDetectFailed;
StephaneLenclud@24
    85
	}
StephaneLenclud@24
    86
StephaneLenclud@24
    87
StephaneLenclud@24
    88
wchar_t* MiniDisplayTypeName(TMiniDisplayType aType)
StephaneLenclud@24
    89
	{
StephaneLenclud@24
    90
		if (aType>=EMiniDisplayAutoDetectFailed)
StephaneLenclud@24
    91
		{
StephaneLenclud@24
    92
			return KDisplayNames[EMiniDisplayAutoDetectFailed];
StephaneLenclud@24
    93
		}
StephaneLenclud@24
    94
StephaneLenclud@24
    95
		return KDisplayNames[aType];
StephaneLenclud@24
    96
	}
StephaneLenclud@24
    97
StephaneLenclud@24
    98
sl@2
    99
void MiniDisplayClear(MiniDisplayDevice aDevice)
sl@2
   100
	{
sl@2
   101
	if (!aDevice)
sl@2
   102
		{
sl@2
   103
		return;
sl@2
   104
		}
sl@2
   105
sl@10
   106
	((GraphicDisplay*)aDevice)->Clear();
sl@2
   107
	}
sl@2
   108
sl@2
   109
sl@2
   110
void MiniDisplayFill(MiniDisplayDevice aDevice)
sl@2
   111
	{
sl@2
   112
	if (!aDevice)
sl@2
   113
		{
sl@2
   114
		return;
sl@2
   115
		}
sl@4
   116
sl@10
   117
	((GraphicDisplay*)aDevice)->Fill();
sl@2
   118
	}
sl@2
   119
sl@2
   120
sl@2
   121
void MiniDisplaySwapBuffers(MiniDisplayDevice aDevice)
sl@2
   122
	{
sl@2
   123
	if (!aDevice)
sl@2
   124
		{
sl@2
   125
		return;
sl@2
   126
		}
sl@4
   127
sl@10
   128
	((GraphicDisplay*)aDevice)->SwapBuffers();
sl@2
   129
	}
sl@2
   130
sl@2
   131
//-------------------------------------------------------------
sl@2
   132
int MiniDisplayMaxBrightness(MiniDisplayDevice aDevice)
sl@2
   133
	{
sl@2
   134
	if (!aDevice)
sl@2
   135
		{
sl@2
   136
		return 0;
sl@2
   137
		}
sl@2
   138
sl@10
   139
	return ((GraphicDisplay*)aDevice)->MaxBrightness();
sl@2
   140
	}
sl@2
   141
sl@2
   142
//-------------------------------------------------------------
sl@2
   143
int MiniDisplayMinBrightness(MiniDisplayDevice aDevice)
sl@2
   144
	{
sl@2
   145
	if (!aDevice)
sl@2
   146
		{
sl@2
   147
		return 0;
sl@2
   148
		}
sl@2
   149
sl@10
   150
	return ((GraphicDisplay*)aDevice)->MinBrightness();
sl@2
   151
	}
sl@2
   152
sl@2
   153
//-------------------------------------------------------------
sl@2
   154
void MiniDisplaySetBrightness(MiniDisplayDevice aDevice, int aBrightness)
sl@2
   155
	{
sl@2
   156
	if (!aDevice)
sl@2
   157
		{
sl@2
   158
		return;
sl@2
   159
		}
sl@2
   160
sl@10
   161
	((GraphicDisplay*)aDevice)->SetBrightness(aBrightness);
sl@2
   162
	}
sl@2
   163
sl@3
   164
//-------------------------------------------------------------
sl@3
   165
int MiniDisplayWidthInPixels(MiniDisplayDevice aDevice)
sl@3
   166
	{
sl@3
   167
	if (!aDevice)
sl@3
   168
		{
sl@3
   169
		return 0;
sl@3
   170
		}
sl@3
   171
sl@10
   172
	return ((GraphicDisplay*)aDevice)->WidthInPixels();
sl@3
   173
	}
sl@3
   174
sl@3
   175
//-------------------------------------------------------------
sl@3
   176
int MiniDisplayHeightInPixels(MiniDisplayDevice aDevice)
sl@3
   177
	{
sl@3
   178
	if (!aDevice)
sl@3
   179
		{
sl@3
   180
		return 0;
sl@3
   181
		}
sl@3
   182
sl@10
   183
	return ((GraphicDisplay*)aDevice)->HeightInPixels();
sl@3
   184
	}
sl@3
   185
sl@3
   186
//-------------------------------------------------------------
sl@22
   187
void MiniDisplaySetPixel(MiniDisplayDevice aDevice, int aX, int aY, unsigned int aPixel)
sl@3
   188
	{
sl@3
   189
	//aValue&=0x00FFFFFF; //Filter out alpha component
sl@22
   190
	return ((GraphicDisplay*)aDevice)->SetPixel(aX,aY,aPixel);
sl@3
   191
	}
sl@3
   192
sl@4
   193
//-------------------------------------------------------------
sl@4
   194
wchar_t* MiniDisplayVendor(MiniDisplayDevice aDevice)
sl@4
   195
    {
sl@15
   196
    return ((GraphicDisplay*)aDevice)->Vendor();
sl@4
   197
    }
sl@4
   198
sl@4
   199
//-------------------------------------------------------------
sl@4
   200
wchar_t* MiniDisplayProduct(MiniDisplayDevice aDevice)
sl@4
   201
    {
sl@15
   202
    return ((GraphicDisplay*)aDevice)->Product();
sl@4
   203
    }
sl@4
   204
sl@4
   205
//-------------------------------------------------------------
sl@4
   206
wchar_t* MiniDisplaySerialNumber(MiniDisplayDevice aDevice)
sl@4
   207
    {
sl@15
   208
    return ((GraphicDisplay*)aDevice)->SerialNumber();
sl@4
   209
    }
sl@4
   210
sl@4
   211
//-------------------------------------------------------------
sl@11
   212
void MiniDisplayRequest(MiniDisplayDevice aDevice, TMiniDisplayRequest aRequest)
sl@4
   213
    {
sl@11
   214
    ((GraphicDisplay*)aDevice)->Request(aRequest);
sl@4
   215
    }
sl@4
   216
sl@4
   217
//-------------------------------------------------------------
sl@4
   218
bool MiniDisplayRequestPending(MiniDisplayDevice aDevice)
sl@4
   219
    {
sl@12
   220
    return ((GraphicDisplay*)aDevice)->RequestPending();
sl@4
   221
    }
sl@4
   222
sl@4
   223
//-------------------------------------------------------------
sl@4
   224
TMiniDisplayRequest MiniDisplayCurrentRequest(MiniDisplayDevice aDevice)
sl@4
   225
    {
sl@12
   226
    return ((GraphicDisplay*)aDevice)->CurrentRequest();
sl@4
   227
    }
sl@4
   228
sl@4
   229
//-------------------------------------------------------------
sl@4
   230
void MiniDisplayCancelRequest(MiniDisplayDevice aDevice)
sl@4
   231
    {
sl@15
   232
    ((GraphicDisplay*)aDevice)->CancelRequest();
sl@4
   233
    }
sl@4
   234
sl@5
   235
//-------------------------------------------------------------
sl@6
   236
TMiniDisplayRequest MiniDisplayAttemptRequestCompletion(MiniDisplayDevice aDevice)
sl@5
   237
	{
sl@12
   238
	return ((GraphicDisplay*)aDevice)->AttemptRequestCompletion();
sl@5
   239
	}
sl@5
   240
sl@5
   241
//-------------------------------------------------------------
sl@5
   242
char* MiniDisplayDeviceId(MiniDisplayDevice aDevice)
sl@5
   243
	{
sl@12
   244
	return ((GraphicDisplay*)aDevice)->DeviceId();
sl@5
   245
	}
sl@5
   246
sl@5
   247
//-------------------------------------------------------------
sl@5
   248
char* MiniDisplayFirmwareRevision(MiniDisplayDevice aDevice)
sl@5
   249
	{
sl@12
   250
	return ((GraphicDisplay*)aDevice)->FirmwareRevision();
sl@6
   251
	}
sl@6
   252
sl@6
   253
//-------------------------------------------------------------
sl@6
   254
bool MiniDisplayPowerSupplyStatus(MiniDisplayDevice aDevice)
sl@6
   255
	{
sl@16
   256
	return ((GraphicDisplay*)aDevice)->IsPowerOn();
sl@16
   257
	}
sl@16
   258
sl@16
   259
//-------------------------------------------------------------
sl@16
   260
void MiniDisplayPowerOn(MiniDisplayDevice aDevice)
sl@16
   261
    {
sl@16
   262
    ((GraphicDisplay*)aDevice)->TurnPowerOn();
sl@16
   263
    }
sl@16
   264
sl@16
   265
//-------------------------------------------------------------
sl@16
   266
void MiniDisplayPowerOff(MiniDisplayDevice aDevice)
sl@16
   267
    {
sl@16
   268
    ((GraphicDisplay*)aDevice)->TurnPowerOff();
sl@16
   269
    }
sl@16
   270
sl@16
   271
//-------------------------------------------------------------
sl@16
   272
bool MiniDisplaySupportPowerOnOff(MiniDisplayDevice aDevice)
sl@16
   273
    {
sl@16
   274
    return ((GraphicDisplay*)aDevice)->SupportPowerOnOff();
sl@17
   275
    }
sl@17
   276
sl@17
   277
//-------------------------------------------------------------
sl@17
   278
void MiniDisplayShowClock(MiniDisplayDevice aDevice)
sl@17
   279
    {
sl@17
   280
    ((GraphicDisplay*)aDevice)->ShowClock();
sl@17
   281
    }
sl@17
   282
sl@17
   283
//-------------------------------------------------------------
sl@17
   284
void MiniDisplayHideClock(MiniDisplayDevice aDevice)
sl@17
   285
    {
sl@17
   286
    ((GraphicDisplay*)aDevice)->HideClock();
sl@17
   287
    }
sl@17
   288
sl@17
   289
//-------------------------------------------------------------
sl@17
   290
bool MiniDisplaySupportClock(MiniDisplayDevice aDevice)
sl@17
   291
    {
sl@17
   292
    return ((GraphicDisplay*)aDevice)->SupportClock();
StephaneLenclud@31
   293
    }
StephaneLenclud@31
   294
StephaneLenclud@31
   295
//-------------------------------------------------------------
StephaneLenclud@32
   296
int MiniDisplayIconCount(MiniDisplayDevice aDevice, TMiniDisplayIconType aIcon)
StephaneLenclud@31
   297
	{
StephaneLenclud@32
   298
	return ((GraphicDisplay*)aDevice)->IconCount(aIcon);
StephaneLenclud@32
   299
	}
StephaneLenclud@31
   300
StephaneLenclud@31
   301
//-------------------------------------------------------------
StephaneLenclud@32
   302
int MiniDisplayIconStatusCount(MiniDisplayDevice aDevice, TMiniDisplayIconType aIcon)
StephaneLenclud@31
   303
	{
StephaneLenclud@32
   304
	return ((GraphicDisplay*)aDevice)->IconStatusCount(aIcon);
StephaneLenclud@32
   305
	}
StephaneLenclud@31
   306
StephaneLenclud@31
   307
//-------------------------------------------------------------
StephaneLenclud@32
   308
void MiniDisplaySetIconStatus(MiniDisplayDevice aDevice, TMiniDisplayIconType aIcon, int aIndex, int aStatus)
StephaneLenclud@31
   309
	{
StephaneLenclud@32
   310
	((GraphicDisplay*)aDevice)->SetIconStatus(aIcon,aIndex,aStatus);
StephaneLenclud@32
   311
	}