joystick.h File Reference


Detailed Description

AVR32 UC3 Control Panel joystick sensor interface.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file joystick.h.

#include "compiler.h"
#include "FreeRTOS.h"
#include "datalog.h"

Go to the source code of this file.

Functions

Bool b_joystick_get_value (xLogDef *pxLog)
 Get the current joystick state.
Bool b_joystick_init (void)
 Init the joystick sensor.
eExecStatus e_joystick_get_config (signed portCHAR **ppcStringReply)
 Get the joystick sensor config.
eExecStatus e_joystick_set_config (signed portCHAR **ppcStringReply, int ac, signed portCHAR *av[])
 Set the sensor config.
void v_joystick_stop (void)
 Stop the joystick sensor.


Function Documentation

Bool b_joystick_get_value ( xLogDef pxLog  ) 

Get the current joystick state.

Parameters:
pxLog a Log structure.
Returns:
TRUE upon success, FALSE if error.

Definition at line 254 of file joystick.c.

References acpc_js_events, LogDef::pcStringLog, LogDef::pfFreeStringLog, and x_joystick.

Referenced by b_sensor_get_value().

00255 {
00256 
00257    // Build the log string.
00258    pxLog->pfFreeStringLog = NULL; // We use a constant.
00259    pxLog->pcStringLog = (portCHAR *)acpc_js_events[x_joystick];
00260 
00261    return( TRUE );
00262 }

Bool b_joystick_init ( void   ) 

Init the joystick sensor.

Returns:
TRUE upon success, FALSE if error.

Definition at line 133 of file joystick.c.

References bAlarm, config_file_get_value(), SENSOR_JS_CONFIG_FILE, vjoystick_ISR(), x_supervisor_SemaphoreGive(), x_supervisor_SemaphoreTake(), and xCFGMutex.

00134 {
00135 portCHAR token[6];
00136 
00137    // Get the xCFGMutex.
00138    if( pdTRUE == x_supervisor_SemaphoreTake( xCFGMutex, 0 ) )
00139    {
00140        // get the field
00141        if (config_file_get_value(SENSOR_JS_CONFIG_FILE, "alarm" , token) >= 0)
00142        {
00143          // update value
00144          if (!strcmp(token, "on"))
00145          {
00146            bAlarm = pdTRUE;
00147          }
00148        }
00149      // Release the xCFGMutex.
00150      x_supervisor_SemaphoreGive( xCFGMutex );
00151    }
00152    /* configure joystick up to produce IT on all state change */
00153    gpio_enable_pin_interrupt(GPIO_JOYSTICK_UP , GPIO_PIN_CHANGE);
00154    /* configure joystick down to produce IT on all state change */
00155    gpio_enable_pin_interrupt(GPIO_JOYSTICK_DOWN , GPIO_PIN_CHANGE);
00156    /* configure joystick right to produce IT on all state change */
00157    gpio_enable_pin_interrupt(GPIO_JOYSTICK_RIGHT , GPIO_PIN_CHANGE);
00158    /* configure joystick left to produce IT on all state change */
00159    gpio_enable_pin_interrupt(GPIO_JOYSTICK_LEFT , GPIO_PIN_CHANGE);
00160    /* configure joystick press to produce IT on all state change */
00161    gpio_enable_pin_interrupt(GPIO_JOYSTICK_PUSH , GPIO_PIN_CHANGE);
00162    /* Disable all interrupts */
00163    Disable_global_interrupt();
00164    /* register joystick handler on level 3 */
00165    INTC_register_interrupt( (__int_handler)&vjoystick_ISR, AVR32_GPIO_IRQ_0 + (GPIO_JOYSTICK_UP/8), AVR32_INTC_INT3);
00166    INTC_register_interrupt( (__int_handler)&vjoystick_ISR, AVR32_GPIO_IRQ_0 + (GPIO_JOYSTICK_PUSH/8), AVR32_INTC_INT3);
00167    /* Enable all interrupts */
00168    Enable_global_interrupt();
00169    return (TRUE);
00170 }

eExecStatus e_joystick_get_config ( signed portCHAR **  ppcStringReply  ) 

Get the joystick sensor config.

Parameters:
ppcStringReply Input/Output. The response string. NEVER NULL AS INPUT. A malloc for the response string is performed here; the caller must free this string.
Returns:
the status of the command execution.

Definition at line 195 of file joystick.c.

References bAlarm, SENSOR_MSG_ALARM_OFF, SENSOR_MSG_ALARM_ON, and SHELL_EXECSTATUS_OK_NO_FREE.

00196 {
00197    // if alarm is set, set status to ON
00198    if ( bAlarm == TRUE )
00199      *ppcStringReply = (signed portCHAR *)SENSOR_MSG_ALARM_ON;
00200    else
00201      // set status to OFF
00202      *ppcStringReply = (signed portCHAR *)SENSOR_MSG_ALARM_OFF;
00203    return( SHELL_EXECSTATUS_OK_NO_FREE );
00204 }

eExecStatus e_joystick_set_config ( signed portCHAR **  ppcStringReply,
int  ac,
signed portCHAR *  av[] 
)

Set the sensor config.

Parameters:
ppcStringReply Input/Output. The response string. NEVER NULL AS INPUT.
ac Input. Number of args
av Input. pointer to args
Returns:
the status of the command execution.

Definition at line 215 of file joystick.c.

References bAlarm, config_file_set_value(), SENSOR_JS_CONFIG_FILE, SENSOR_MSG_ALARM_OFF, SENSOR_MSG_ALARM_ON, SHELL_ERRMSG_CONFIGERROR, SHELL_EXECSTATUS_KO, and SHELL_EXECSTATUS_OK_NO_FREE.

00216 {
00217 
00218   // set the field value
00219   if (config_file_set_value(SENSOR_JS_CONFIG_FILE, ac, av) != 0)
00220   {
00221     *ppcStringReply = (signed portCHAR *)SHELL_ERRMSG_CONFIGERROR;
00222     // return error
00223     return( SHELL_EXECSTATUS_KO );
00224   }
00225   // alarm=on
00226   if (!strcmp((char *)av[1] , "on"))
00227   {
00228     bAlarm = pdTRUE;
00229     *ppcStringReply = (signed portCHAR *)SENSOR_MSG_ALARM_ON;
00230     return( SHELL_EXECSTATUS_OK_NO_FREE );
00231   }
00232   // alarm=off
00233   else if (!strcmp( (char *)av[1], "off"))
00234   {
00235     bAlarm = pdFALSE;
00236     *ppcStringReply = (signed portCHAR *)SENSOR_MSG_ALARM_OFF;
00237     return( SHELL_EXECSTATUS_OK_NO_FREE );
00238   }
00239   // error
00240   else
00241   {
00242     *ppcStringReply = (signed portCHAR *)SHELL_ERRMSG_CONFIGERROR;
00243     return( SHELL_EXECSTATUS_KO );
00244   }
00245 }

void v_joystick_stop ( void   ) 

Stop the joystick sensor.

Definition at line 175 of file joystick.c.

00176 {
00177   /* Disable joystick input change ITs. */
00178   gpio_disable_pin_interrupt( GPIO_JOYSTICK_UP );
00179   gpio_disable_pin_interrupt( GPIO_JOYSTICK_DOWN );
00180   gpio_disable_pin_interrupt( GPIO_JOYSTICK_RIGHT );
00181   gpio_disable_pin_interrupt( GPIO_JOYSTICK_LEFT );
00182   gpio_disable_pin_interrupt( GPIO_JOYSTICK_PUSH );
00183 }


Generated on Fri Feb 19 02:22:46 2010 for AVR32 - Control Panel demonstration. by  doxygen 1.5.5