cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 4 MCU

dhsa_4485611
New Contributor II

Hi community members,

We have used the following loop to get the continue switch press time.


while (CapSense_IsWidgetActive(CapSense_BTN_WDGT_ID)) {
while (CapSense_IsBusy() != 0);
t_count++;
CapSense_ProcessAllWidgets();
CapSense_ScanAllWidgets(); /* Start next scan */
}

Our code is sticking at while (CapSense_IsBusy() != 0); line.

How can we get out from this loop ?

Please suggest us better code for exception handling.

 

We have tried multiple iteration to make capsense work again.

while (CapSense_IsBusy() != 0) {
ctime++;
CyDelay(1u);
if (ctime > 500) {
ctime = 0;

/*  Function to make capsense work again */

iteration 1 :  CapSense_InitializeAllBaselines();

iteration 2 :  CapSense_ProcessAllWidgets();

iteration 3 : CapSense_UpdateAllBaselines();
break;
}
}

0 Likes
1 Solution
LinglingG_46
Moderator
Moderator

Hi,

please refer to the blow code:

#include "project.h"
#define OFF 0
#define ON 1

 

struct buttonstatus {
uint16 counter;
}button_status;
uint8 button_status_pre=OFF;
uint8 button_staus_now =OFF;
int main()
{
__enable_irq(); /* Enable global interrupts. */
EZI2C_Start(); /* Start EZI2C Component */
/*
* Set up communication and initialize data buffer to CapSense data structure
* to use Tuner application
*/
EZI2C_EzI2CSetBuffer1(sizeof(button_status), sizeof(button_status), (uint8_t *)&(button_status));
CapSense_Start(); /* Initialize Component */
CapSense_ScanAllWidgets(); /* Scan all widgets */
for(;;)
{
/* Do this only when a scan is done */
if(CapSense_NOT_BUSY == CapSense_IsBusy())
{
CapSense_ProcessAllWidgets(); /* Process all widgets */

if (CapSense_IsAnyWidgetActive()) /* Scan result verification */
{
button_staus_now = ON;
if(button_status_pre == ON)
{
button_status.counter++;
}
else
{
button_status_pre = ON;
}

}
else
{
button_staus_now = OFF;
button_status.counter =0;
}

button_status_pre = button_staus_now;

CapSense_ScanAllWidgets(); /* Start next scan */
}
}
}

View solution in original post

1 Reply
LinglingG_46
Moderator
Moderator

Hi,

please refer to the blow code:

#include "project.h"
#define OFF 0
#define ON 1

 

struct buttonstatus {
uint16 counter;
}button_status;
uint8 button_status_pre=OFF;
uint8 button_staus_now =OFF;
int main()
{
__enable_irq(); /* Enable global interrupts. */
EZI2C_Start(); /* Start EZI2C Component */
/*
* Set up communication and initialize data buffer to CapSense data structure
* to use Tuner application
*/
EZI2C_EzI2CSetBuffer1(sizeof(button_status), sizeof(button_status), (uint8_t *)&(button_status));
CapSense_Start(); /* Initialize Component */
CapSense_ScanAllWidgets(); /* Scan all widgets */
for(;;)
{
/* Do this only when a scan is done */
if(CapSense_NOT_BUSY == CapSense_IsBusy())
{
CapSense_ProcessAllWidgets(); /* Process all widgets */

if (CapSense_IsAnyWidgetActive()) /* Scan result verification */
{
button_staus_now = ON;
if(button_status_pre == ON)
{
button_status.counter++;
}
else
{
button_status_pre = ON;
}

}
else
{
button_staus_now = OFF;
button_status.counter =0;
}

button_status_pre = button_staus_now;

CapSense_ScanAllWidgets(); /* Start next scan */
}
}
}

View solution in original post