| 1 | /* |
| 2 | This file is part of IanniX, a graphical real-time open-source sequencer for digital art |
| 3 | Copyright (C) 2010-2015 — IanniX Association |
| 4 | |
| 5 | Project Manager: Thierry Coduys (http://www.le-hub.org) |
| 6 | Development: Guillaume Jacquemin (https://www.buzzinglight.com) |
| 7 | |
| 8 | This file was written by Guillaume Jacquemin. |
| 9 | |
| 10 | IanniX is a free software: you can redistribute it and/or modify |
| 11 | it under the terms of the GNU General Public License as published by |
| 12 | the Free Software Foundation, either version 3 of the License, or |
| 13 | any later version. |
| 14 | |
| 15 | This program is distributed in the hope that it will be useful, |
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | GNU General Public License for more details. |
| 19 | |
| 20 | You should have received a copy of the GNU General Public License |
| 21 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 22 | */ |
| 23 | |
| 24 | #include "iannix_lib.h" |
| 25 | |
| 26 | char IanniX::iannixBuffer[iannixBufferArgumentIndexMax][iannixBufferDataIndexMax]; |
| 27 | unsigned int IanniX::iannixBufferDataIndex = 0; |
| 28 | unsigned int IanniX::iannixBufferArgumentIndex = 0; |
| 29 | unsigned int IanniX::iannixBufferArgumentIndexCache = 0; |
| 30 | |
| 31 | boolean IanniX::hasData() { |
| 32 | boolean hasDataReturn = false; |
| 33 | while(Serial.available() > 0) { |
| 34 | //Received char |
| 35 | char iannixByte = Serial.read(); |
| 36 | |
| 37 | //End of frame |
| 38 | if((iannixByte == iannixBufferCharEnd1) || (iannixByte == iannixBufferCharEnd2)) { |
| 39 | hasDataReturn = true; |
| 40 | } |
| 41 | //Frame payload |
| 42 | else { |
| 43 | //Argument separator |
| 44 | if(iannixByte == iannixBufferCharSeparator) { |
| 45 | //Can store ? |
| 46 | if(iannixBufferArgumentIndex < iannixBufferArgumentIndexMax) { |
| 47 | //Close the previous argument |
| 48 | iannixBuffer[iannixBufferArgumentIndex][iannixBufferDataIndex] = 0; |
| 49 | //Open a new argument |
| 50 | iannixBufferArgumentIndex++; |
| 51 | iannixBufferDataIndex = 0; |
| 52 | } |
| 53 | //No more memory |
| 54 | else |
| 55 | hasDataReturn = true; |
| 56 | } |
| 57 | //Message content |
| 58 | else if(iannixBufferDataIndex < iannixBufferArgumentIndexMax) |
| 59 | iannixBuffer[iannixBufferArgumentIndex][iannixBufferDataIndex++] = iannixByte; |
| 60 | //No more memory |
| 61 | else |
| 62 | hasDataReturn = true; |
| 63 | } |
| 64 | } |
| 65 | //If the message is over (end of frame OR no more memory) |
| 66 | if(hasDataReturn) { |
| 67 | iannixBufferArgumentIndexCache = iannixBufferArgumentIndex; |
| 68 | iannixBufferDataIndex = 0; |
| 69 | iannixBufferArgumentIndex = 0; |
| 70 | } |
| 71 | |
| 72 | //Returns |
| 73 | return hasDataReturn; |
| 74 | } |
| 75 | |
| 76 | |
| 77 | |
| 78 |