qTask_Notification_Send and EventData - do not work once?
dashkova opened this issue · 2 comments
dashkova commented
Hi!
Example code:
producer:
typedef enum {NO_FLAG = 0, FLAG_ENLARGE, FLAG_REDUCE, FLAG_POWER_ON, FLAG_POWER_OFF} Flags_enum;
qSM_Status_t State_Button_Release (qSM_Handler_t m)
{
static qSTimer_t timeout;
Flags_enum flag[1];
switch (m->Signal)
{
case QSM_SIGNAL_ENTRY:
qSTimer_Set(&timeout, TIME_BUTTON_RELEASE);
break;
default:
break;
case QSM_SIGNAL_NONE:
if (qSTimer_Expired(&timeout))
{
m->NextState = State_Button_Wait;
switch (Button.Count)
{
case 1:
flag[0] = FLAG_ENLARGE;
break;
default:
case 2:
flag[0] = FLAG_REDUCE;
break;
}
qTask_Notification_Send(&Task_Set_Light, flag);
}
if (BUTTON_PRESS)
{
m->NextState = State_Button_Push;
}
break;
}
return qSM_EXIT_SUCCESS;
}
consumer:
typedef struct
{
Flags_enum flag;
}User_Data_t;
void Set_Light_Callback (qEvent_t e)
{
User_Data_t* Data = (User_Data_t*)e->EventData;
switch (Data->flag)
{
case FLAG_ENLARGE:
if (PWM.PWM_Phase == 100)
{
}
else
{
PWM.PWM_Phase++;
}
break;
case FLAG_REDUCE:
if (PWM.PWM_Phase == 0)
{
}
else
{
PWM.PWM_Phase--;
}
break;
case FLAG_POWER_ON:
PWM.PWM_Phase++;
if (PWM.PWM_Phase == PWM.Save)
{
}
break;
default:
break;
}
}
In the function Set_Light_Callback() I get NO_FLAG (sendings FLAG_ENLARGE or FLAG_REDUCE).
If the code is changed like this:
qSM_Status_t State_Button_Release (qSM_Handler_t m)
{
static qSTimer_t timeout;
Flags_enum flag[1];
switch (m->Signal)
{
case QSM_SIGNAL_ENTRY:
qSTimer_Set(&timeout, TIME_BUTTON_RELEASE);
break;
default:
//break; <- comment
case QSM_SIGNAL_NONE:
<....>
}
}
In this case, everything is fine, but the Set_Light_Callback() function is called 2 times. Is this a bug?
//Sorry for the english language
kmilo17pet commented
hi @dashkova ,
State_Button_Release only changes if the BUTTON_PRESS it's true, otherwise, the state remains, and later notifications can be sent to Task_Set_Light,
dashkova commented
Hi!
Hmmm...
Fixed the code (data via argument):
int main (void)
{
UserData_t Data;
qOS_Add_StateMachineTask(<...>, &Data )
It works!