margin state not match

Android Studio中报错如下:

看了好几遍代码,最终找到是因为事件传递优先级的问题
事件传递优先级:onTouchListener.onTouch > onTouchEvent > onClickListener.onClick

感觉是个小傻子

解释以下代码ISR(PCINT2_vect) { uint8_t mask; uint8_t pin; uint16_t cTime,dTime; static uint16_t edgeTime[8]; static uint8_t PCintLast; pin = PIND; mask = pin ^ PCintLast; // doing a ^ between the current interruption and the last one indicates wich pin changed sei(); // re enable other interrupts at this point, the rest of this interrupt is not so time critical and can be interrupted safely PCintLast = pin; // we memorize the current state of all PINs [D0-D7] cTime = micros(); // micros() return a uint32_t, but it is not usefull to keep the whole bits => we keep only 16 bits if (mask & 1<<2) { //indicates the bit 2 of the arduino port [D0-D7], that is to say digital pin 2, if 1 => this pin has just changed if (!(pin & 1<<2)) { //indicates if the bit 2 of the arduino port [D0-D7] is not at a high state (so that we match here only descending PPM pulse) dTime = cTime-edgeTime[2]; if (900<dTime && dTime<2200) rcValue[2] = dTime; // just a verification: the value must be in the range [1000;2000] + some margin } else edgeTime[2] = cTime; // if the bit 2 of the arduino port [D0-D7] is at a high state (ascending PPM pulse), we memorize the time } if (mask & 1<<4) { //same principle for other channels // avoiding a for() is more than twice faster, and it's important to minimize execution time in ISR if (!(pin & 1<<4)) { dTime = cTime-edgeTime[4]; if (900<dTime && dTime<2200) rcValue[4] = dTime; } else edgeTime[4] = cTime; } if (mask & 1<<5) { if (!(pin & 1<<5)) { dTime = cTime-edgeTime[5]; if (900<dTime && dTime<2200) rcValue[5] = dTime;//map(dTime,1016,2020,-128,128); } else edgeTime[5] = cTime; } if (mask & 1<<6) { if (!(pin & 1<<6)) { dTime = cTime-edgeTime[6]; if (900<dTime && dTime<2200) rcValue[6] = dTime;//map(dTime,1016,2020,-128,128); } else edgeTime[6] = cTime; } }
最新发布
07-17
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值