Example #1
0
		/// <summary>
		/// Create a new connection to the API
		/// </summary>
		/// <param name="appFriendlyName">The display name of the Applet</param>
		/// <param name="extended">Determines whether or not extended keys of the G19-Keyboard should be used.</param>
		/// <returns>The new connection to the API</returns>
		public static Connection Connect(string appFriendlyName, bool extended = false)
		{
			if (!API.IsInitialized)
			{
				throw new InitializationException("API not initialized");
			}

			int handle;

			// Get the internal handle
			//If the extended flag is set, 
			handle = extended
				//get the extended connection,
				? DMcLgLCD.LcdConnectEx(appFriendlyName, 0, 0)
				//otherwise get the regular one
				: DMcLgLCD.LcdConnect(appFriendlyName, 0, 0);

			if (handle == Connection.InvalidConnectionHandle)
			{
				throw new APIException("Could not create connection to API");
			}


			Connection con = new Connection() { ConnectionHandle = handle };
			API.Connections.Add(con);
			return con;
		}
Example #2
0
		/// <summary>
		/// Opens a new keyboard from an existing API connection with the specified type.
		/// </summary>
		/// <<param name="connection">The connection to the API.</param>
		/// <returns>An initialized Keyboard</returns>
		public static Keyboard Open(Connection connection)
		{
			if (!API.IsInitialized)
			{
				throw new InitializationException("API not initialized");
			}
			if (connection == null || connection.ConnectionHandle == Connection.InvalidConnectionHandle)
			{
				throw new APIException("Connection invalid (likely already closed before)");
			}
			if (connection.Keyboard != null)
			{
				throw new APIException("Connection already has a keyboard associated");
			}

			Keyboard keyboard = Keyboard.Open(connection, Type.QVGA);
			if (keyboard == null)
			{
				keyboard = Keyboard.Open(connection, Type.BlackWhite);
				if (keyboard == null)
				{
					throw new APIException("API did not return a valid keyboard");
				}
			}

			return keyboard;
		}
Example #3
0
		/// <summary>
		/// Opens a new keyboard from an existing API connection and attempts to autodetect the keyboard type.
		/// </summary>
		/// <param name="connection">The connection to the API.</param>
		/// <param name="keyboardType">The type of the keyboard to open</param>
		/// <returns>An initialized Keyboard</returns>
		private static Keyboard Open(Connection connection, Keyboard.Type keyboardType)
		{
			if (!API.IsInitialized)
			{
				throw new InitializationException("API not initialized");
			}
			if (connection == null || connection.ConnectionHandle == Connection.InvalidConnectionHandle)
			{
				throw new APIException("Connection invalid (likely already closed before)");
			}
			if (connection.Keyboard != null)
			{
				throw new APIException("Connection already has a keyboard associated");
			}

			int tmp;

			//Switch on keyboard types, since it might be possible to sneak invalid values in via casts.
			switch (keyboardType)
			{
				case Type.BlackWhite:
				case Type.QVGA:
					tmp = DMcLgLCD.LcdOpenByType(connection.ConnectionHandle, (int)keyboardType);
					break;
				default:
					throw new APIException("Invalid device type");
			}

			//Protip: Catch this error, since you might not be sure which keyboard your user has.
			if (tmp == Keyboard.InvalidDeviceHandle)
			{
				return null;
			}

			Keyboard k = new Keyboard() { DeviceHandle = tmp, Connection = connection, KeyboardType = keyboardType };

			connection.Keyboard = k;
			return k;
		}