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