|
|
发表于 2015-3-24 17:43:43
|
显示全部楼层
之後, 當有需要時, 就是這樣執行你設定的 function:
- // behind the scenes function that is called when data is received
- void TwoWire::onReceiveService(uint8_t* inBytes, int numBytes)
- {
- // don't bother if user hasn't registered a callback
- if(!user_onReceive){
- return;
- }
- // don't bother if rx buffer is in use by a master requestFrom() op
- // i know this drops data, but it allows for slight stupidity
- // meaning, they may not have read all the master requestFrom() data yet
- if(rxBufferIndex < rxBufferLength){
- return;
- }
- // copy twi rx buffer into local read buffer
- // this enables new reads to happen in parallel
- for(uint8_t i = 0; i < numBytes; ++i){
- rxBuffer[i] = inBytes[i];
- }
- // set rx iterator vars
- rxBufferIndex = 0;
- rxBufferLength = numBytes;
- // alert user program
- user_onReceive(numBytes);
- }
- // behind the scenes function that is called when data is requested
- void TwoWire::onRequestService(void)
- {
- // don't bother if user hasn't registered a callback
- if(!user_onRequest){
- return;
- }
- // reset tx buffer iterator vars
- // !!! this will kill any pending pre-master sendTo() activity
- txBufferIndex = 0;
- txBufferLength = 0;
- // alert user program
- user_onRequest();
- }
复制代码 |
|