Skip to content

Commit 855e476

Browse files
transitdklstoll
transitdk
authored andcommitted
Update the arduino libraries to version 0012.
Signed-off-by: Lincoln Stoll <[email protected]>
1 parent 8001bad commit 855e476

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+7258
-74
lines changed

EEPROM/examples/eeprom_clear/eeprom_clear.pde

100644100755
File mode changed.

EEPROM/examples/eeprom_read/eeprom_read.pde

100644100755
File mode changed.

EEPROM/examples/eeprom_write/eeprom_write.pde

100644100755
File mode changed.

EEPROM/keywords.txt

100644100755
File mode changed.

Ethernet/Client.cpp

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
extern "C" {
2+
#include "types.h"
3+
#include "w5100.h"
4+
#include "socket.h"
5+
}
6+
7+
#include "Ethernet.h"
8+
#include "Client.h"
9+
#include "Server.h"
10+
11+
Client::Client(uint8_t sock) {
12+
_sock = sock;
13+
}
14+
15+
Client::Client(uint8_t *ip, uint16_t port) {
16+
_ip = ip;
17+
_port = port;
18+
}
19+
20+
uint8_t Client::connect() {
21+
_sock = 255;
22+
23+
for (int i = 0; i < MAX_SOCK_NUM; i++) {
24+
if (getSn_SR(i) == SOCK_CLOSED) {
25+
_sock = i;
26+
}
27+
}
28+
29+
if (_sock == 255)
30+
return 0;
31+
32+
// XXX: what port should we connect from?
33+
socket(_sock, Sn_MR_TCP, _port, 0);
34+
35+
if (!::connect(_sock, _ip, _port))
36+
return 0;
37+
38+
while (status() != SOCK_ESTABLISHED) {
39+
if (status() == SOCK_CLOSED)
40+
return 0;
41+
}
42+
43+
return 1;
44+
}
45+
46+
void Client::write(uint8_t b) {
47+
send(_sock, &b, 1);
48+
}
49+
50+
int Client::available() {
51+
return getSn_RX_RSR(_sock);
52+
}
53+
54+
int Client::read() {
55+
uint8_t b;
56+
if (!available())
57+
return -1;
58+
recv(_sock, &b, 1);
59+
return b;
60+
}
61+
62+
void Client::flush() {
63+
while (available())
64+
read();
65+
}
66+
67+
void Client::stop() {
68+
close(_sock);
69+
disconnect(_sock);
70+
EthernetClass::_server_port[_sock] = 0;
71+
}
72+
73+
uint8_t Client::connected() {
74+
uint8_t s = status();
75+
return !(s == SOCK_LISTEN || s == SOCK_CLOSED || (s == SOCK_CLOSE_WAIT && !available()));
76+
}
77+
78+
uint8_t Client::status() {
79+
return getSn_SR(_sock);
80+
}
81+
82+
// the next three functions are a hack so we can compare the client returned
83+
// by Server::available() to null, or use it as the condition in an
84+
// if-statement. this lets us stay compatible with the Processing network
85+
// library.
86+
87+
uint8_t Client::operator==(int p) {
88+
return _sock == 255;
89+
}
90+
91+
uint8_t Client::operator!=(int p) {
92+
return _sock != 255;
93+
}
94+
95+
Client::operator bool() {
96+
return _sock != 255;
97+
}

Ethernet/Client.h

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef Client_h
2+
#define Client_h
3+
4+
#include "Print.h"
5+
6+
class Client : public Print {
7+
private:
8+
uint8_t _sock;
9+
uint8_t *_ip;
10+
uint16_t _port;
11+
public:
12+
Client(uint8_t);
13+
Client(uint8_t *, uint16_t);
14+
uint8_t status();
15+
uint8_t connect();
16+
virtual void write(uint8_t);
17+
int available();
18+
int read();
19+
void flush();
20+
void stop();
21+
uint8_t connected();
22+
uint8_t operator==(int);
23+
uint8_t operator!=(int);
24+
operator bool();
25+
friend class Server;
26+
};
27+
28+
#endif

Ethernet/Ethernet.cpp

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
extern "C" {
2+
#include "types.h"
3+
#include "w5100.h"
4+
}
5+
6+
#include "Ethernet.h"
7+
8+
// XXX: don't make assumptions about the value of MAX_SOCK_NUM.
9+
uint8_t EthernetClass::_state[MAX_SOCK_NUM] = { 0, 0, 0, 0 };
10+
uint16_t EthernetClass::_server_port[MAX_SOCK_NUM] = { 0, 0, 0, 0 };
11+
12+
void EthernetClass::begin(uint8_t *mac, uint8_t *ip)
13+
{
14+
uint8_t gateway[4];
15+
gateway[0] = ip[0];
16+
gateway[1] = ip[1];
17+
gateway[2] = ip[2];
18+
gateway[3] = 1;
19+
begin(mac, ip, gateway);
20+
}
21+
22+
void EthernetClass::begin(uint8_t *mac, uint8_t *ip, uint8_t *gateway)
23+
{
24+
uint8_t subnet[] = { 255, 255, 255, 0 };
25+
begin(mac, ip, gateway, subnet);
26+
}
27+
28+
void EthernetClass::begin(uint8_t *mac, uint8_t *ip, uint8_t *gateway, uint8_t *subnet)
29+
{
30+
iinchip_init();
31+
sysinit(0x55, 0x55);
32+
setSHAR(mac);
33+
setSIPR(ip);
34+
setGAR(gateway);
35+
setSUBR(subnet);
36+
}
37+
38+
EthernetClass Ethernet;

Ethernet/Ethernet.h

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef Ethernet_h
2+
#define Ethernet_h
3+
4+
#include <inttypes.h>
5+
#include "Client.h"
6+
#include "Server.h"
7+
8+
class EthernetClass {
9+
private:
10+
public:
11+
static uint8_t _state[MAX_SOCK_NUM];
12+
static uint16_t _server_port[MAX_SOCK_NUM];
13+
void begin(uint8_t *, uint8_t *);
14+
void begin(uint8_t *, uint8_t *, uint8_t *);
15+
void begin(uint8_t *, uint8_t *, uint8_t *, uint8_t *);
16+
friend class Client;
17+
friend class Server;
18+
};
19+
20+
extern EthernetClass Ethernet;
21+
22+
#endif

Ethernet/Print.cpp

+156
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
/*
2+
HarwareSerial.cpp - Hardware serial library for Wiring
3+
Copyright (c) 2006 Nicholas Zambetti. 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+
Modified 23 November 2006 by David A. Mellis
20+
*/
21+
22+
#include <stdio.h>
23+
#include <string.h>
24+
#include <inttypes.h>
25+
#include "wiring.h"
26+
27+
#include "Print.h"
28+
29+
// Public Methods //////////////////////////////////////////////////////////////
30+
31+
void Print::print(uint8_t b)
32+
{
33+
write(b);
34+
}
35+
36+
void Print::print(char c)
37+
{
38+
print((byte) c);
39+
}
40+
41+
void Print::print(const char c[])
42+
{
43+
while (*c)
44+
print(*c++);
45+
}
46+
47+
void Print::print(int n)
48+
{
49+
print((long) n);
50+
}
51+
52+
void Print::print(unsigned int n)
53+
{
54+
print((unsigned long) n);
55+
}
56+
57+
void Print::print(long n)
58+
{
59+
if (n < 0) {
60+
print('-');
61+
n = -n;
62+
}
63+
printNumber(n, 10);
64+
}
65+
66+
void Print::print(unsigned long n)
67+
{
68+
printNumber(n, 10);
69+
}
70+
71+
void Print::print(long n, int base)
72+
{
73+
if (base == 0)
74+
print((char) n);
75+
else if (base == 10)
76+
print(n);
77+
else
78+
printNumber(n, base);
79+
}
80+
81+
void Print::println(void)
82+
{
83+
print('\r');
84+
print('\n');
85+
}
86+
87+
void Print::println(char c)
88+
{
89+
print(c);
90+
println();
91+
}
92+
93+
void Print::println(const char c[])
94+
{
95+
print(c);
96+
println();
97+
}
98+
99+
void Print::println(uint8_t b)
100+
{
101+
print(b);
102+
println();
103+
}
104+
105+
void Print::println(int n)
106+
{
107+
print(n);
108+
println();
109+
}
110+
111+
void Print::println(unsigned int n)
112+
{
113+
print(n);
114+
println();
115+
}
116+
117+
void Print::println(long n)
118+
{
119+
print(n);
120+
println();
121+
}
122+
123+
void Print::println(unsigned long n)
124+
{
125+
print(n);
126+
println();
127+
}
128+
129+
void Print::println(long n, int base)
130+
{
131+
print(n, base);
132+
println();
133+
}
134+
135+
// Private Methods /////////////////////////////////////////////////////////////
136+
137+
void Print::printNumber(unsigned long n, uint8_t base)
138+
{
139+
unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars.
140+
unsigned long i = 0;
141+
142+
if (n == 0) {
143+
print('0');
144+
return;
145+
}
146+
147+
while (n > 0) {
148+
buf[i++] = n % base;
149+
n /= base;
150+
}
151+
152+
for (; i > 0; i--)
153+
print((char) (buf[i - 1] < 10 ?
154+
'0' + buf[i - 1] :
155+
'A' + buf[i - 1] - 10));
156+
}

0 commit comments

Comments
 (0)