Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit47e23cc

Browse files
committed
Add WCharacter to API
1 parent0d30531 commit47e23cc

File tree

6 files changed

+206
-35
lines changed

6 files changed

+206
-35
lines changed

‎api/ArduinoAPI.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include"Stream.h"
3939
#include"Udp.h"
4040
#include"USBAPI.h"
41+
#include"WCharacter.h"
4142
#endif
4243

4344
/* Standard C library includes */

‎api/Common.h‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,23 @@ typedef enum {
3838
}_spi_bitFirst_mode;
3939

4040
#ifndefmin
41-
#definemin(a,b) ((a)<(b)?(a):(b))
41+
#definemin(a,b) \
42+
({ __typeof__ (a) _a = (a); \
43+
__typeof__ (b) _b = (b); \
44+
_a < _b ? _a : _b; })
4245
#endif
4346

4447
#ifndefmax
45-
#definemax(a,b) ((a)>(b)?(a):(b))
46-
#endif
47-
48-
#ifndefabs
49-
#defineabs(x) ((x)>0?(x):-(x))
48+
#definemax(a,b) \
49+
({ __typeof__ (a) _a = (a); \
50+
__typeof__ (b) _b = (b); \
51+
_a > _b ? _a : _b; })
5052
#endif
5153

5254
#ifndefconstrain
5355
#defineconstrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
5456
#endif
5557

56-
#ifndefround
57-
#defineround(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
58-
#endif
59-
6058
#ifndefradians
6159
#defineradians(deg) ((deg)*DEG_TO_RAD)
6260
#endif

‎api/RingBuffer.cpp‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,30 @@
1818

1919
#include"RingBuffer.h"
2020
#include<string.h>
21+
#include<stdio.h>
22+
#include<stdlib.h>
2123

22-
RingBuffer::RingBuffer(void)
24+
RingBuffer::RingBuffer(rb_index_type size =64) : size(size)
2325
{
24-
memset( _aucBuffer,0, RINGBUFFER_SIZE ) ;
26+
_aucBuffer = (uint8_t*)malloc(size);
27+
memset( _aucBuffer,0, size ) ;
2528
clear();
2629
}
2730

2831
voidRingBuffer::store_char(uint8_t c )
2932
{
30-
int i =nextIndex(_iHead);
33+
rb_index_type i =nextIndex(_iHead);
3134

3235
// if we should be storing the received character into the location
3336
// just before the tail (meaning that the head would advance to the
3437
// current location of the tail), we're about to overflow the buffer
3538
// and so we don't write the character or advance the head.
3639
if ( i != _iTail )
3740
{
38-
if (_iHead <RINGBUFFER_SIZE) {
41+
if (_iHead <size) {
3942
_aucBuffer[_iHead] = c ;
4043
}else {
41-
additionalBuffer[_iHead -RINGBUFFER_SIZE] = c;
44+
additionalBuffer[_iHead -size] = c;
4245
}
4346
_iHead = i ;
4447
}
@@ -56,10 +59,10 @@ int RingBuffer::read_char()
5659
return -1;
5760

5861
uint8_t value;
59-
if (_iTail <RINGBUFFER_SIZE) {
62+
if (_iTail <size) {
6063
value = _aucBuffer[_iTail];
6164
}else {
62-
value = additionalBuffer[_iTail -RINGBUFFER_SIZE];
65+
value = additionalBuffer[_iTail -size];
6366
}
6467
_iTail =nextIndex(_iTail);
6568

@@ -71,7 +74,7 @@ int RingBuffer::available()
7174
int delta = _iHead - _iTail;
7275

7376
if(delta <0)
74-
returnRINGBUFFER_SIZE + additionalSize + delta;
77+
returnsize + additionalSize + delta;
7578
else
7679
return delta;
7780
}
@@ -81,16 +84,16 @@ int RingBuffer::peek()
8184
if(_iTail == _iHead)
8285
return -1;
8386

84-
if (_iTail <RINGBUFFER_SIZE) {
87+
if (_iTail <size) {
8588
return _aucBuffer[_iTail];
8689
}else {
87-
return additionalBuffer[_iTail -RINGBUFFER_SIZE];
90+
return additionalBuffer[_iTail -size];
8891
}
8992
}
9093

91-
intRingBuffer::nextIndex(int index)
94+
rb_index_typeRingBuffer::nextIndex(rb_index_type index)
9295
{
93-
return (uint32_t)(index +1) % (RINGBUFFER_SIZE + additionalSize);
96+
return (rb_index_type)(index +1) % (size + additionalSize);
9497
}
9598

9699
boolRingBuffer::isFull()

‎api/RingBuffer.h‎

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,37 @@
2626
// to which to write the next incoming character and tail is the index of the
2727
// location from which to read.
2828

29-
#defineRINGBUFFER_SIZE64
29+
#defineRINGBUFFER_HAS_ADDITIONAL_STORAGE_API
30+
31+
#ifdef RINGBUFFER_FORCE_SMALL_SIZE
32+
typedefuint8_t rb_index_type;
33+
#else
34+
typedefunsignedint rb_index_type;
35+
#endif
3036

3137
classRingBuffer
3238
{
3339
public:
34-
uint8_t _aucBuffer[RINGBUFFER_SIZE] ;
35-
int _iHead ;
36-
int _iTail ;
37-
38-
public:
39-
RingBuffer(void ) ;
40+
RingBuffer( rb_index_type size ) ;
4041
voidstore_char(uint8_t c ) ;
4142
voidclear();
4243
intread_char();
4344
intavailable();
4445
intpeek();
4546
boolisFull();
46-
voidaddStorage(uint8_t* _buffer,int _size) {
47+
voidaddStorage(uint8_t* _buffer,rb_index_type _size) {
4748
additionalSize = _size;
4849
additionalBuffer = _buffer;
4950
};
5051

5152
private:
52-
intnextIndex(int index);
53+
rb_index_typenextIndex(rb_index_type index);
5354
uint8_t* additionalBuffer;
5455
int additionalSize =0;
56+
rb_index_type size;
57+
uint8_t* _aucBuffer;
58+
volatile rb_index_type _iHead ;
59+
volatile rb_index_type _iTail ;
5560
};
5661

5762
#endif/* _RING_BUFFER_*/

‎api/USBAPI.h‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ typedef struct __attribute__((packed))
5252
//================================================================================
5353
//================================================================================
5454

55-
#defineTRANSFER_PGM0x80
56-
#defineTRANSFER_RELEASE0x40
57-
#defineTRANSFER_ZERO0x20
58-
5955
intUSB_SendControl(uint8_t flags,constvoid* d,int len);
6056
intUSB_RecvControl(void* d,int len);
6157
intUSB_RecvControlLong(void* d,int len);

‎api/WCharacter.h‎

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
/*
2+
WCharacter.h - Character utility functions for Wiring & Arduino
3+
Copyright (c) 2010 Hernando Barragan. All right reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
#ifndefCharacter_h
21+
#defineCharacter_h
22+
23+
#include<ctype.h>
24+
25+
// WCharacter.h prototypes
26+
inlineboolisAlphaNumeric(intc) __attribute__((always_inline));
27+
inlineboolisAlpha(intc) __attribute__((always_inline));
28+
inlineboolisAscii(intc) __attribute__((always_inline));
29+
inlineboolisWhitespace(intc) __attribute__((always_inline));
30+
inlineboolisControl(intc) __attribute__((always_inline));
31+
inlineboolisDigit(intc) __attribute__((always_inline));
32+
inlineboolisGraph(intc) __attribute__((always_inline));
33+
inlineboolisLowerCase(intc) __attribute__((always_inline));
34+
inlineboolisPrintable(intc) __attribute__((always_inline));
35+
inlineboolisPunct(intc) __attribute__((always_inline));
36+
inlineboolisSpace(intc) __attribute__((always_inline));
37+
inlineboolisUpperCase(intc) __attribute__((always_inline));
38+
inlineboolisHexadecimalDigit(intc) __attribute__((always_inline));
39+
inlineinttoAscii(intc) __attribute__((always_inline));
40+
inlineinttoLowerCase(intc) __attribute__((always_inline));
41+
inlineinttoUpperCase(intc)__attribute__((always_inline));
42+
43+
44+
// Checks for an alphanumeric character.
45+
// It is equivalent to (isalpha(c) || isdigit(c)).
46+
inlineboolisAlphaNumeric(intc)
47+
{
48+
return (isalnum(c)==0 ? false : true);
49+
}
50+
51+
52+
// Checks for an alphabetic character.
53+
// It is equivalent to (isupper(c) || islower(c)).
54+
inlineboolisAlpha(intc)
55+
{
56+
return (isalpha(c)==0 ? false : true);
57+
}
58+
59+
60+
// Checks whether c is a 7-bit unsigned char value
61+
// that fits into the ASCII character set.
62+
inlineboolisAscii(intc)
63+
{
64+
return (isascii (c)==0 ? false : true);
65+
}
66+
67+
68+
// Checks for a blank character, that is, a space or a tab.
69+
inlineboolisWhitespace(intc)
70+
{
71+
return (isblank (c)==0 ? false : true);
72+
}
73+
74+
75+
// Checks for a control character.
76+
inlineboolisControl(intc)
77+
{
78+
return (iscntrl (c)==0 ? false : true);
79+
}
80+
81+
82+
// Checks for a digit (0 through 9).
83+
inlineboolisDigit(intc)
84+
{
85+
return (isdigit (c)==0 ? false : true);
86+
}
87+
88+
89+
// Checks for any printable character except space.
90+
inlineboolisGraph(intc)
91+
{
92+
return (isgraph (c)==0 ? false : true);
93+
}
94+
95+
96+
// Checks for a lower-case character.
97+
inlineboolisLowerCase(intc)
98+
{
99+
return (islower (c)==0 ? false : true);
100+
}
101+
102+
103+
// Checks for any printable character including space.
104+
inlineboolisPrintable(intc)
105+
{
106+
return (isprint (c)==0 ? false : true);
107+
}
108+
109+
110+
// Checks for any printable character which is not a space
111+
// or an alphanumeric character.
112+
inlineboolisPunct(intc)
113+
{
114+
return (ispunct (c)==0 ? false : true);
115+
}
116+
117+
118+
// Checks for white-space characters. For the avr-libc library,
119+
// these are: space, formfeed ('\f'), newline ('\n'), carriage
120+
// return ('\r'), horizontal tab ('\t'), and vertical tab ('\v').
121+
inlineboolisSpace(intc)
122+
{
123+
return (isspace (c)==0 ? false : true);
124+
}
125+
126+
127+
// Checks for an uppercase letter.
128+
inlineboolisUpperCase(intc)
129+
{
130+
return (isupper (c)==0 ? false : true);
131+
}
132+
133+
134+
// Checks for a hexadecimal digits, i.e. one of 0 1 2 3 4 5 6 7
135+
// 8 9 a b c d e f A B C D E F.
136+
inlineboolisHexadecimalDigit(intc)
137+
{
138+
return (isxdigit (c)==0 ? false : true);
139+
}
140+
141+
142+
// Converts c to a 7-bit unsigned char value that fits into the
143+
// ASCII character set, by clearing the high-order bits.
144+
inlineinttoAscii(intc)
145+
{
146+
returntoascii (c);
147+
}
148+
149+
150+
// Warning:
151+
// Many people will be unhappy if you use this function.
152+
// This function will convert accented letters into random
153+
// characters.
154+
155+
// Converts the letter c to lower case, if possible.
156+
inlineinttoLowerCase(intc)
157+
{
158+
returntolower (c);
159+
}
160+
161+
162+
// Converts the letter c to upper case, if possible.
163+
inlineinttoUpperCase(intc)
164+
{
165+
returntoupper (c);
166+
}
167+
168+
#endif

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp