# How to use the Keypad?

**URL:** <https://forum.sierrawireless.com/t/how-to-use-the-keypad/5345>\
**Category:** Open AT\
**Created:** [November 21, 2011, 2:54pm UTC](https://forum.sierrawireless.com/t/how-to-use-the-keypad/5345 "2011-11-21T14:54:50Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![CAA](https://avatars.discourse-cdn.com/v4/letter/c/3da27b/32.png) [@CAA](https://forum.sierrawireless.com/u/CAA)\
**Post date:** [November 21, 2011, 2:54pm UTC](https://forum.sierrawireless.com/t/how-to-use-the-keypad/5345/1 "2011-11-21T14:54:50Z")

</div>

hi everyone

im using a Airprime SL6087 Development Kit.  
Im trying to write an application (in c) which shall do “some things” when the buttons on the bottom left corner are pressed.  
Those buttons are labeled with “SW900”, “SW901”, … , “SW905” and are in a square which is labeld with “keypad”.  
They are neither mentioned in the “AirPrime\_SL6087\_Development\_Kit\_User\_Guide-Rev001.pdf” which i got together with it or in the adl manual. ☹

How do i subscripe to keypressed (or keyreleased) events(, which should be SOMEWHERE)?

---

<div class="post-metadata">

**Author:** ![tomridl](https://sea1.discourse-cdn.com/flex025/user_avatar/forum.sierrawireless.com/tomridl/32/2704_2.png) [@tomridl](https://forum.sierrawireless.com/u/tomridl)\
**Post date:** [November 21, 2011, 4:32pm UTC](https://forum.sierrawireless.com/t/how-to-use-the-keypad/5345/2 "2011-11-21T16:32:21Z")

</div>

Have a look at the Keyboard Library Sample included in the ADL Samples. To access this, create a new Library project, and select Keyboard from the samples. You can either use this library to subscribe to keyboard events, or look at the code to implement your own handlers.

---

<div class="post-metadata">

**Author:** ![CAA](https://avatars.discourse-cdn.com/v4/letter/c/3da27b/32.png) [@CAA](https://forum.sierrawireless.com/u/CAA)\
**Post date:** [November 22, 2011, 8:42am UTC](https://forum.sierrawireless.com/t/how-to-use-the-keypad/5345/3 "2011-11-22T08:42:34Z")

</div>

uehm… library project? 😮

how do i create such a project?  
im using “M2M Developer Suite 2.5” and i cant find it anywhere… neither on file-\>new -\> projekt nor on file -\> new -\> other

the only example which sounded like something with keyboard is the dmtf keyboard example. It is using a keyhandler but the method doesnt get called when i press a button, so… whatever it is, thats not it 😃

on the [sierra page](http://www.sierrawireless.com/en/sitecore/content/Sierra%20Wireless/Support/Downloads/AirPrime/SL_Series/AirPrime_SL6087.aspx) one can download 2.35… i oehm… am i using the right software?! (currently i cant download it due to proxy problems…)

---

<div class="post-metadata">

**Author:** ![tomridl](https://sea1.discourse-cdn.com/flex025/user_avatar/forum.sierrawireless.com/tomridl/32/2704_2.png) [@tomridl](https://forum.sierrawireless.com/u/tomridl)\
**Post date:** [November 22, 2011, 12:34pm UTC](https://forum.sierrawireless.com/t/how-to-use-the-keypad/5345/4 "2011-11-22T12:34:24Z")

</div>

File -\> New -\> Open AT Project

In the Project Type section choose “Library”.

Latest version of Developer Studio is 2.1.0. Be careful not to look at the installer version, which is not the Developer Studio Version. You can see the Developer Studio Version in Help -\> About Developer Studio.

---

<div class="post-metadata">

**Author:** ![CAA](https://avatars.discourse-cdn.com/v4/letter/c/3da27b/32.png) [@CAA](https://forum.sierrawireless.com/u/CAA)\
**Post date:** [November 22, 2011, 1:52pm UTC](https://forum.sierrawireless.com/t/how-to-use-the-keypad/5345/5 "2011-11-22T13:52:28Z")

</div>

a good place to hide an example 😒  
thx so far

i cant get it running 😊 , so…  
if i understand the at command manual (page 155) correctly i should get responses on the hyperterminal after ive sended the “at+cmer=,1” command (which gives me an “ok”), but i get no responses at all no matter how often or long i press the buttons…

if im just misunderstang it, this is my sourcecode  
basicly ive taken the example and put a key\_subscribe call into a main function (and every function creates an output when its called… but no function gets called after the key\_subscribe at all

```auto
/* Keyboard Handler */
key_Handler_f key_Handler;

/* First Subscription flag */
bool bOnce = TRUE;

/* Timer for key repetition */
adl_tmr_t * tRepeat;

/* Constants */
#define KEY_NONE 0xFF

/* Timer delays */
u32 key_RepeatTickTime; // Timer before each repeat
u32 key_RepeatTickDelay; // Delay before repeat

/* Prototypes */
bool key_UnsoHandler ( adl_atUnsolicited_t * Param );
void key_TimerHandler ( u8 Id, void * Context );

/* Keyboard Timer Handler */
void key_TimerHandler ( u8 Id, void * Context )
{
	adl_atSendResponse(ADL_AT_UNS, "key_TimerHandler\n");
	/* ReStart the Key timer, faster */
	tRepeat = adl_tmrSubscribe ( FALSE, key_RepeatTickTime, ADL_TMR_TYPE_TICK, key_TimerHandler );

	/* Call Unsolicited handler */
	key_UnsoHandler ( ( adl_atUnsolicited_t * ) NULL );
}

/* Keyboard unsolicited handler */
bool key_UnsoHandler ( adl_atUnsolicited_t * Param )
{
	adl_atSendResponse(ADL_AT_UNS, "key_UnsoHandler\n");
	u8 iKey = KEY_NONE,
			iPressed = 1;
	ascii lBuffer[3];

	/* Last pressed key */
	static u8 iPressedKey = KEY_NONE;

	/* Get Key code */
	if ( Param )
	{
		iKey = wm_atoi ( wm_strGetParameterString ( lBuffer, Param->StrData, 1 ) );
		iPressed = wm_atoi ( wm_strGetParameterString ( lBuffer, Param->StrData, 2 ) );
	}

	if ( iPressed )
	{
		/* Key Pressed */
		if ( iKey != KEY_NONE )
		{
			/* Save the pressed key */
			iPressedKey = iKey;

			/* Start the Key timer on the first time */
			if ( key_RepeatTickDelay )
			{
				tRepeat = adl_tmrSubscribe ( FALSE, key_RepeatTickDelay, ADL_TMR_TYPE_TICK, key_TimerHandler );
			}
		}

		//TRACE (( key_TraceLevel, "Key pressed %d", iPressedKey ));

		/* Call Key handler */
		if ( key_Handler )
		{
			key_Handler ( iPressedKey, iPressed );
		}
	}
	else
	{
		/* Stop the Key timer */
		adl_tmrUnSubscribe ( tRepeat, key_TimerHandler, ADL_TMR_TYPE_TICK );
		tRepeat = NULL;

		//TRACE (( key_TraceLevel, "Key released %d", iPressedKey ));

		/* Call Key handler */
		if ( key_Handler )
		{
			key_Handler ( iPressedKey, iPressed );
		}

		/* Reset the saved key */
		iPressedKey = KEY_NONE;
	}

	/* Do not display keyboard events */
	return FALSE;
}

void KeyHandler(u8 Key, u8 Pressed){
	adl_atSendResponse(ADL_AT_UNS, "key_Handler\n");

}

/* Keyboard handler subscription */
void key_Subscribe ( key_Handler_f KeyHandler, u32 RepeatTickTime, u32 RepeatTickDelay )
{
	adl_atSendResponse(ADL_AT_UNS, "key_Subscribe\n");
	//TRACE (( key_TraceLevel, "Keyboard Handler Subscription (%d,%d)", RepeatTickTime, RepeatTickDelay ));

	/* Set Keyboard Handler */
	key_Handler = KeyHandler;

	/* Set Repeat Timers parameters */
	key_RepeatTickTime = RepeatTickTime ? RepeatTickTime : 1;
	key_RepeatTickDelay = RepeatTickDelay;

	if ( bOnce )
	{
		/* Only first time */
		bOnce = FALSE;

		/* Send command to get keyboard events */
		adl_atCmdCreate ( "at+cmer=,1", FALSE, ( adl_atRspHandler_t ) NULL, NULL );

		/* Subscribe to Keyboard events */
		adl_atUnSoSubscribe ( "+CKEV: ", key_UnsoHandler );
	}

}

/* Keyboard handler Unsubscription */
void key_Unsubscribe ( key_Handler_f KeyHandler )
{
	adl_atSendResponse(ADL_AT_UNS, "key_unSubscribe\n");
	//TRACE (( key_TraceLevel, "Keyboard Handler Unsubscription" ));

	if ( KeyHandler == key_Handler )
	{
		/* Unsubscribe from keyboard handler */
		adl_atCmdCreate ( "at+cmer=,0", FALSE, ( adl_atRspHandler_t ) NULL, NULL );
		adl_atUnSoUnSubscribe ( "+CKEV: ", key_UnsoHandler );
		key_Handler = NULL;

		/* Unsubscribe from all timers */
		if ( tRepeat )
		{
			adl_tmrUnSubscribe ( tRepeat, key_TimerHandler, ADL_TMR_TYPE_TICK );
			tRepeat = NULL;
		}

		bOnce = TRUE;
	}
}

void adl_main(adl_InitType_e adlInitType)
{
	adl_atSendResponse(ADL_AT_UNS, "Start of the Programm\n");
	key_Subscribe(KeyHandler, 1, 1);
}
```

and this is the entire output from when i start the programm via the “run as…” button

```auto
at+cfun=1ý
atatat
OK
OK
OK
OK
+WIND: 3
+WIND: 13
Start of the Programm
key_Subscribe
at+wopen=1
OK
```

---

<div class="post-metadata">

**Author:** ![tomridl](https://sea1.discourse-cdn.com/flex025/user_avatar/forum.sierrawireless.com/tomridl/32/2704_2.png) [@tomridl](https://forum.sierrawireless.com/u/tomridl)\
**Post date:** [November 22, 2011, 2:33pm UTC](https://forum.sierrawireless.com/t/how-to-use-the-keypad/5345/6 "2011-11-22T14:33:48Z")

</div>

Ok, perform the following steps. This is what I did to get the keypad working on a WMP dev kit, it should be exactly the same on an SL dev kit:

1. Click File -\> New -\> Open AT Project
2. Name the project keyboard\_sample\_library, and select the Library type from the Project Type box
3. Click Next, Next and select keyboard from the list of samples, Click Finish. A new library project should be opened in your workspace.
4. Click File -\> New -\> Open AT Project
5. Name the project and select Application from the Project Type box
6. Click Next, Next, Next and check the box in Dependencies for keyboard\_library\_sample and click finish. A new application project should be created in your workspace.
7. Add the following code to main.c in the application project:

```auto
#include "adl_global.h"
#include "keyboard.h"

void key_handler (u8 KeyIdx, u8 KeyPressed);
u8 KEY_LIB_TRACE_LEVEL = 2;

void main_task ( void )
{
    // TODO Insert your task initialization code here
    key_Subscribe(key_handler, 500, 1000);
}

void key_handler (u8 KeyIdx, u8 KeyPressed)
{
    TRACE((1, "[key_handler] A key was pressed: %d %d", KeyIdx, KeyPressed));
}
```

1. Compile the code, and download to dev kit if no errors in complile
2. Make sure you have level 1 traces enabled.
3. Every time you press a button on the dev kit, you will see a trace telling you which key was pressed or released.

---

<div class="post-metadata">

**Author:** ![CAA](https://avatars.discourse-cdn.com/v4/letter/c/3da27b/32.png) [@CAA](https://forum.sierrawireless.com/u/CAA)\
**Post date:** [November 22, 2011, 3:17pm UTC](https://forum.sierrawireless.com/t/how-to-use-the-keypad/5345/7 "2011-11-22T15:17:29Z")

</div>

😊

doesnt work either.  
The subscribe method gets called but then nothing happens no matter how often or long i press any button

---

<div class="post-metadata">

**Author:** ![tomridl](https://sea1.discourse-cdn.com/flex025/user_avatar/forum.sierrawireless.com/tomridl/32/2704_2.png) [@tomridl](https://forum.sierrawireless.com/u/tomridl)\
**Post date:** [November 23, 2011, 7:14am UTC](https://forum.sierrawireless.com/t/how-to-use-the-keypad/5345/8 "2011-11-23T07:14:07Z")

</div>

What version of the development kit do you have? Looking at the Universal Development Kit v3.0 User Guide, there are no keypad switches at all The following interfaces are listed for the SL6087:

External board to board connector and test point (TP) to access all signals for the adaptor board  
Serial link RS232, UART1\* with full signals  
Ring Indicator  
Serial link RS232, UART2\* with four signals  
Slave USB\*, with SoftConnect™ signal. USB 2.0 Compliant (full speed)  
SIM\* (1.8/3V)  
1 Audio connector (AUDIO2)  
LEDs for several indications  
Power supply connectors  
RESET Pushbutton  
ON/OFF switch  
BOOT switch  
Buzzer LED  
Flash LED

Looking at the Product Technical specifications for the SL6087, there is NO keyboard interface at all. To access the swithes (assuming that are connected to GPIO), you would have to subscribe to the relevant GPIO using the GPIO services, and then receive events in the related callback.

---

<div class="post-metadata">

**Author:** ![CAA](https://avatars.discourse-cdn.com/v4/letter/c/3da27b/32.png) [@CAA](https://forum.sierrawireless.com/u/CAA)\
**Post date:** [November 23, 2011, 10:58am UTC](https://forum.sierrawireless.com/t/how-to-use-the-keypad/5345/9 "2011-11-23T10:58:32Z")

</div>

good question…  
it needed a bit of search (cause the model number of the develpment board is well hidden under the sl6087 modul…)  
wm0502301-12-20 (only 1 [google result](http://www.google.de/search?q=P-1018-2025+a5398+-+memory&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:de:official&client=firefox-a#sclient=psy-ab&hl=de&client=firefox-a&hs=gl&rls=org.mozilla:de%3Aofficial&source=hp&q=wm0502301-12-20&pbx=1&oq=wm0502301-12-20&aq=f&aqi=&aql=&gs_sm=e&gs_upl=23335l24515l0l24753l6l5l0l0l0l0l1395l1395l7-1l1l0&bav=on.2,or.r_gc.r_pw.,cf.osb&fp=6b289c5fb340582&biw=1280&bih=868)… wow…)

i subscribed a function to the gpio events (adl\_ioEventSubscribe) but it doesnt get called either T.T

the pdf found per google 😃 says that the buttons connect rows with cols, which are (or seem) to be avaible on the j110 connector (which is to add an external board to the board, right? - so it doesnt help me)  
the GPIOs are 4-12

ive run the gpio adl\_ioGetCapabilitiesList example and the result is

```auto
Ressources : 26 GPIO, 0 GPI and 0 GPO 
List of GPIO :
GPIO 25 
GPIO 24 
GPIO 23 
GPIO 22 
GPIO 21 
GPIO 20 
GPIO 19 
GPIO 17 
GPIO 16 
GPIO 15 
GPIO 14 
GPIO 13 
GPIO 12 
GPIO 3 
GPIO 2 
GPIO 1 
GPIO 0
```

i hope that the gpio numbers in internal use are the same as for the extern connector…  
guess in addition to sl6087 not having a keyboard interface, that means i cant use the keypad which is on the board? 😢

---

<div class="post-metadata">

**Author:** ![tomridl](https://sea1.discourse-cdn.com/flex025/user_avatar/forum.sierrawireless.com/tomridl/32/2704_2.png) [@tomridl](https://forum.sierrawireless.com/u/tomridl)\
**Post date:** [November 23, 2011, 11:22am UTC](https://forum.sierrawireless.com/t/how-to-use-the-keypad/5345/10 "2011-11-23T11:22:20Z")

</div>

Looking under the GPIO section in the SL6087 PTS, GPIO 4 to GPIO 11 are multiplexed with UART1. This means that you will have to disable UART 1 and enable UART2 or USB for application download (See the AT command user guide for how to do this). Once UART1 is disabled, you should be able to subsribe to the required GPIO, and recieve switch events in the GPIO event handler (if the swithes are actually connected!).

---

<div class="post-metadata">

**Author:** ![CAA](https://avatars.discourse-cdn.com/v4/letter/c/3da27b/32.png) [@CAA](https://forum.sierrawireless.com/u/CAA)\
**Post date:** [November 25, 2011, 11:27am UTC](https://forum.sierrawireless.com/t/how-to-use-the-keypad/5345/11 "2011-11-25T11:27:52Z")

</div>

deactivating the UART1 for… im starting to feel very uncomfortable with this developmentboard and its documentation…

since the at+whcnf command responses only with “error” if i try to change anything. So my next idea was to use the pins on the board…  
there are plenty which are labeld with GPIOXX. At GPIO21 i even have an LED which shows the logical state of this GPIO :mrgreen:

> [@](#):
>
> “CHARGER” indicator is a green LED connected to the GPIO21. The indicator is managed via the  
> Sierra Wireless
> 
> Software Suite. This LED represents only the logic state of the GPIO21.

When i connect it with the 2v8 pin (the docu says its I/O type is 2v8) the led burns. (so there should be a GPIO Event due to my understanding)

i subscribed a method via adl\_ioEventSubscribe()

> [@](#):
>
> This function allows the Open AT® application to provide ADL with a call-back for GPIO related events.

but it doesnt get called when the LED starts or stops to burn (which should mean that the status of GPIO21 Changes - which should be an event).  
all i need is the “recognition” that a button has been pressed (which is now whired with the 2v8 and the GPIO21 pin). I need no periodic polling or whatsoever…

---

<div class="post-metadata">

**Author:** ![tomridl](https://sea1.discourse-cdn.com/flex025/user_avatar/forum.sierrawireless.com/tomridl/32/2704_2.png) [@tomridl](https://forum.sierrawireless.com/u/tomridl)\
**Post date:** [November 25, 2011, 12:25pm UTC](https://forum.sierrawireless.com/t/how-to-use-the-keypad/5345/12 "2011-11-25T12:25:44Z")

</div>

Have a look at the code below to make sure you are doing something similar (this is using a multitasking application, with a single task named gpioTask. Make sure this is indicated in your task table) :

```auto
#include "adl_global.h"
#include "generated.h"

/ *************************************************************************** /
/* Local variables                                                                   
/ *************************************************************************** /
adl_ioDefs_t gpio_Input[1] =
{ ADL_IO_GPIO | 21| ADL_IO_DIR_IN };
s32 GPIO_event_handle = 0;
s32 Polling_handle;
/ *************************************************************************** /
/* Local functions                                                                   
/ *************************************************************************** /
void GPIO_event_Handler(s32 GpioHandle, adl_ioEvent_e Event, u32 Size, void *Param);

void gpioTask(void)
{
	// Subscribe to the GPIO Event System
	GPIO_event_handle = adl_ioEventSubscribe(GPIO_event_Handler);

	//subscribe to GPIO service with polling every 100ms for GPIO
	Polling_handle = adl_ioSubscribe(1, gpio_Input, ADL_TMR_TYPE_100MS, 1, GPIO_event_handle);

	// If both subscriptions were ok, return OK
	if ((GPIO_event_handle > 0) && (Polling_handle > 0))
	{
		TRACE((1, "Subscribed to GPIO Events: OK"));
	}
	else
	{
		TRACE((1, "Subscribed to GPIO Events: FAILED %d, %d",GPIO_event_handle, Polling_handle ));
	}
}

void GPIO_event_Handler(s32 GpioHandle, adl_ioEvent_e Event, u32 Size, void *Param)
{
	switch (Event)
	{
		case ADL_IO_EVENT_INPUT_CHANGED:
		{
			if (adl_ioReadSingle(Polling_handle, &gpio_Input[0]) == 1) 
			{
				TRACE((1, "GPIO TOGGLED HIGH"));
			}
			else
			{
				TRACE((1, "GPIO TOGGLED LOW"));
			}
		}
		break;
	}
}
```
