Switch case for differentiating charateristics

3 posts / 0 new
Last post
Sam123
Offline
Last seen:5 years 7 months ago
加入:2015-02-19 05:43
Switch case for differentiating charateristics

Hi Dialog Team,

I have one handler function for the four characteristics which are used to turn on LEDs . Each characteristic should turn on only one LED . However, each characteristic can turn on all the 4 LEDs. I have used one handler function for all the four characteristics.
a) Should i use seperate handler functions?
b) Is there any way to differenciate between the data that i am writing in characteristics from one another.
I just want to check, in which characteristic the user inputs data and accordingly turn the LEDs on/off.

I am eagerly waiting for a reply.

Device:
VesaN
Offline
Last seen:5 years 4 months ago
Guru Master
加入:2014-06-26 08:49
Hello Sam123,

Hello Sam123,

1)Do you know the value of your AD converter result register (register is called GP_ADC_RESULT_REG)? Is it different to what you see in BlueLoupe? Do you read the register with GetWord16, not GetWord8/GetByte?

2)You only need one handler function for write. For example, if you open acceleration profilesaccel_task.c, you can find handler functionstatic int gattc_write_cmd_ind_handler. There the handling of different characteristic value attributes is managed with switch --- case statement:


switch (ACCEL_IDX(param->handle))
{
case ACCEL_IDX_ENABLE_VAL: ...
case ACCEL_IDX_ACCEL_DISPLAY1_VAL:
case ACCEL_IDX_ACCEL_DISPLAY2_VAL:
...

Sam123
Offline
Last seen:5 years 7 months ago
加入:2015-02-19 05:43
Hi,

Hi,

I have four characteristics which should turn on four different LEDs. Each characteristic should switch ON/OFF the LED assigned to its characteristic. However each characteristic can switch on/off all the 4 LEDs. There should be a switch case to differenciate between the characteristics so that writing to characteristic 1 will only turn on LED1 and not LED2/LED3/LED4. I am uncertain about the switch condition and the switch cases that should be implemented. I am attaching my handler function for your kind perusal. How to implement the switch case statement?

int sample128_val_ind_handler(ke_msg_id_t const msgid,
struct sample128_val_ind const *param,
ke_task_id_t const dest_id,
ke_task_id_t const src_id)
{
//Characteristic 1
memcpy(&sample128_my_new,¶m->val,sizeof(my_new_t));
get_value1=(*sample128_my_new);
if(get_value1 == set_value1)
{
GPIO_SetActive(GPIO_PORT_0, GPIO_PIN_7 );
}
else
{
GPIO_SetInactive(GPIO_PORT_0, GPIO_PIN_7 );
}

//2nd write characteristic
memcpy(&sample128_my_newer,¶m->val,sizeof(my_newer_t));
get_value2=(*sample128_my_newer);
if(get_value2 == set_value2)
{
GPIO_SetActive(GPIO_PORT_1, GPIO_PIN_0 );
}
else
{
GPIO_SetInactive(GPIO_PORT_1, GPIO_PIN_0 );
}

//3rd write characteristic
memcpy(&sample128_my_new3,¶m->val,sizeof(my_new_t3));
get_value3=(*sample128_my_new3);
if(get_value3 == set_value3)
{
GPIO_SetActive (GPIO_PORT_1 GPIO_PIN_2);
}
else
{
GPIO_SetInactive(GPIO_PORT_1, GPIO_PIN_2 );
}

//4th write characteristic
memcpy(&sample128_my_newer4,¶m->val,sizeof(my_newer_t4));
get_value4=(*sample128_my_newer4);
if(get_value4 == set_value4)
{
GPIO_SetActive(GPIO_PORT_1, GPIO_PIN_3 );
}
else
{
GPIO_SetInactive(GPIO_PORT_1, GPIO_PIN_3 );
}

return (KE_MSG_CONSUMED);
}