1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-30 16:24:09 +03:00

Run new astyle formatter against all the examples

This commit is contained in:
Federico Fissore
2013-10-21 09:58:40 +02:00
parent 3c6ee46828
commit b4c68b3dff
259 changed files with 5160 additions and 5217 deletions

View File

@ -1,5 +1,5 @@
/*
* IRrecord: record and play back IR signals as a minimal
* IRrecord: record and play back IR signals as a minimal
* An IR detector/demodulator must be connected to the input RECV_PIN.
* An IR LED must be connected to the output PWM pin 3.
* A button must be connected to the input BUTTON_PIN; this is the
@ -56,12 +56,12 @@ void storeCode(decode_results *results) {
for (int i = 1; i <= codeLen; i++) {
if (i % 2) {
// Mark
rawCodes[i - 1] = results->rawbuf[i]*USECPERTICK - MARK_EXCESS;
rawCodes[i - 1] = results->rawbuf[i] * USECPERTICK - MARK_EXCESS;
Serial.print(" m");
}
}
else {
// Space
rawCodes[i - 1] = results->rawbuf[i]*USECPERTICK + MARK_EXCESS;
rawCodes[i - 1] = results->rawbuf[i] * USECPERTICK + MARK_EXCESS;
Serial.print(" s");
}
Serial.print(rawCodes[i - 1], DEC);
@ -76,16 +76,16 @@ void storeCode(decode_results *results) {
Serial.println("repeat; ignoring.");
return;
}
}
}
else if (codeType == SONY) {
Serial.print("Received SONY: ");
}
}
else if (codeType == RC5) {
Serial.print("Received RC5: ");
}
}
else if (codeType == RC6) {
Serial.print("Received RC6: ");
}
}
else {
Serial.print("Unexpected codeType ");
Serial.print(codeType, DEC);
@ -102,18 +102,18 @@ void sendCode(int repeat) {
if (repeat) {
irsend.sendNEC(REPEAT, codeLen);
Serial.println("Sent NEC repeat");
}
}
else {
irsend.sendNEC(codeValue, codeLen);
Serial.print("Sent NEC ");
Serial.println(codeValue, HEX);
}
}
}
else if (codeType == SONY) {
irsend.sendSony(codeValue, codeLen);
Serial.print("Sent Sony ");
Serial.println(codeValue, HEX);
}
}
else if (codeType == RC5 || codeType == RC6) {
if (!repeat) {
// Flip the toggle bit for a new button press
@ -126,13 +126,13 @@ void sendCode(int repeat) {
Serial.print("Sent RC5 ");
Serial.println(codeValue, HEX);
irsend.sendRC5(codeValue, codeLen);
}
}
else {
irsend.sendRC6(codeValue, codeLen);
Serial.print("Sent RC6 ");
Serial.println(codeValue, HEX);
}
}
}
else if (codeType == UNKNOWN /* i.e. raw */) {
// Assume 38 KHz
irsend.sendRaw(rawCodes, codeLen, 38);
@ -156,7 +156,7 @@ void loop() {
sendCode(lastButtonState == buttonState);
digitalWrite(STATUS_PIN, LOW);
delay(50); // Wait a bit between retransmissions
}
}
else if (irrecv.decode(&results)) {
digitalWrite(STATUS_PIN, HIGH);
storeCode(&results);

View File

@ -30,26 +30,26 @@ void dump(decode_results *results) {
int count = results->rawlen;
if (results->decode_type == UNKNOWN) {
Serial.print("Unknown encoding: ");
}
}
else if (results->decode_type == NEC) {
Serial.print("Decoded NEC: ");
}
}
else if (results->decode_type == SONY) {
Serial.print("Decoded SONY: ");
}
}
else if (results->decode_type == RC5) {
Serial.print("Decoded RC5: ");
}
}
else if (results->decode_type == RC6) {
Serial.print("Decoded RC6: ");
}
else if (results->decode_type == PANASONIC) {
else if (results->decode_type == PANASONIC) {
Serial.print("Decoded PANASONIC - Address: ");
Serial.print(results->panasonicAddress,HEX);
Serial.print(results->panasonicAddress, HEX);
Serial.print(" Value: ");
}
else if (results->decode_type == JVC) {
Serial.print("Decoded JVC: ");
Serial.print("Decoded JVC: ");
}
Serial.print(results->value, HEX);
Serial.print(" (");
@ -62,7 +62,7 @@ void dump(decode_results *results) {
for (int i = 0; i < count; i++) {
if ((i % 2) == 1) {
Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
}
}
else {
Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC);
}

View File

@ -23,17 +23,17 @@ void dump(decode_results *results) {
int count = results->rawlen;
if (results->decode_type == UNKNOWN) {
Serial.println("Could not decode message");
}
}
else {
if (results->decode_type == NEC) {
Serial.print("Decoded NEC: ");
}
}
else if (results->decode_type == SONY) {
Serial.print("Decoded SONY: ");
}
}
else if (results->decode_type == RC5) {
Serial.print("Decoded RC5: ");
}
}
else if (results->decode_type == RC6) {
Serial.print("Decoded RC6: ");
}
@ -49,7 +49,7 @@ void dump(decode_results *results) {
for (int i = 0; i < count; i++) {
if ((i % 2) == 1) {
Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
}
}
else {
Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC);
}
@ -62,7 +62,7 @@ void setup()
{
pinMode(RELAY_PIN, OUTPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
@ -79,7 +79,7 @@ void loop() {
digitalWrite(13, on ? HIGH : LOW);
dump(&results);
}
last = millis();
last = millis();
irrecv.resume(); // Receive the next value
}
}

View File

@ -21,17 +21,17 @@ void dump(decode_results *results) {
int count = results->rawlen;
if (results->decode_type == UNKNOWN) {
Serial.println("Could not decode message");
}
}
else {
if (results->decode_type == NEC) {
Serial.print("Decoded NEC: ");
}
}
else if (results->decode_type == SONY) {
Serial.print("Decoded SONY: ");
}
}
else if (results->decode_type == RC5) {
Serial.print("Decoded RC5: ");
}
}
else if (results->decode_type == RC6) {
Serial.print("Decoded RC6: ");
}
@ -47,7 +47,7 @@ void dump(decode_results *results) {
for (int i = 0; i < count; i++) {
if ((i % 2) == 1) {
Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
}
}
else {
Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC);
}
@ -59,61 +59,61 @@ void dump(decode_results *results) {
IRrecv irrecv(0);
decode_results results;
class IRsendDummy :
public IRsend
class IRsendDummy :
public IRsend
{
public:
// For testing, just log the marks/spaces
public:
// For testing, just log the marks/spaces
#define SENDLOG_LEN 128
int sendlog[SENDLOG_LEN];
int sendlogcnt;
IRsendDummy() :
IRsend() {
}
void reset() {
sendlogcnt = 0;
}
void mark(int time) {
sendlog[sendlogcnt] = time;
if (sendlogcnt < SENDLOG_LEN) sendlogcnt++;
}
void space(int time) {
sendlog[sendlogcnt] = -time;
if (sendlogcnt < SENDLOG_LEN) sendlogcnt++;
}
// Copies the dummy buf into the interrupt buf
void useDummyBuf() {
int last = SPACE;
irparams.rcvstate = STATE_STOP;
irparams.rawlen = 1; // Skip the gap
for (int i = 0 ; i < sendlogcnt; i++) {
if (sendlog[i] < 0) {
if (last == MARK) {
// New space
irparams.rawbuf[irparams.rawlen++] = (-sendlog[i] - MARK_EXCESS) / USECPERTICK;
last = SPACE;
}
else {
// More space
irparams.rawbuf[irparams.rawlen - 1] += -sendlog[i] / USECPERTICK;
int sendlog[SENDLOG_LEN];
int sendlogcnt;
IRsendDummy() :
IRsend() {
}
void reset() {
sendlogcnt = 0;
}
void mark(int time) {
sendlog[sendlogcnt] = time;
if (sendlogcnt < SENDLOG_LEN) sendlogcnt++;
}
void space(int time) {
sendlog[sendlogcnt] = -time;
if (sendlogcnt < SENDLOG_LEN) sendlogcnt++;
}
// Copies the dummy buf into the interrupt buf
void useDummyBuf() {
int last = SPACE;
irparams.rcvstate = STATE_STOP;
irparams.rawlen = 1; // Skip the gap
for (int i = 0 ; i < sendlogcnt; i++) {
if (sendlog[i] < 0) {
if (last == MARK) {
// New space
irparams.rawbuf[irparams.rawlen++] = (-sendlog[i] - MARK_EXCESS) / USECPERTICK;
last = SPACE;
}
else {
// More space
irparams.rawbuf[irparams.rawlen - 1] += -sendlog[i] / USECPERTICK;
}
}
}
else if (sendlog[i] > 0) {
if (last == SPACE) {
// New mark
irparams.rawbuf[irparams.rawlen++] = (sendlog[i] + MARK_EXCESS) / USECPERTICK;
last = MARK;
}
else {
// More mark
irparams.rawbuf[irparams.rawlen - 1] += sendlog[i] / USECPERTICK;
else if (sendlog[i] > 0) {
if (last == SPACE) {
// New mark
irparams.rawbuf[irparams.rawlen++] = (sendlog[i] + MARK_EXCESS) / USECPERTICK;
last = MARK;
}
else {
// More mark
irparams.rawbuf[irparams.rawlen - 1] += sendlog[i] / USECPERTICK;
}
}
}
if (irparams.rawlen % 2) {
irparams.rawlen--; // Remove trailing space
}
}
if (irparams.rawlen % 2) {
irparams.rawlen--; // Remove trailing space
}
}
};
IRsendDummy irsenddummy;
@ -125,12 +125,12 @@ void verify(unsigned long val, int bits, int type) {
Serial.print(val, HEX);
if (results.value == val && results.bits == bits && results.decode_type == type) {
Serial.println(": OK");
}
}
else {
Serial.println(": Error");
dump(&results);
}
}
}
void testNEC(unsigned long val, int bits) {
irsenddummy.reset();

View File

@ -20,7 +20,7 @@
* The test software automatically decides which board is the sender and which is
* the receiver by looking for an input on the send pin, which will indicate
* the sender. You should hook the serial port to the receiver for debugging.
*
*
* Copyright 2010 Ken Shirriff
* http://arcfn.com
*/
@ -51,7 +51,7 @@ void setup()
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW);
Serial.println("Receiver mode");
}
}
else {
mode = SENDER;
Serial.println("Sender mode");
@ -64,7 +64,7 @@ void setup()
void waitForGap(int gap) {
Serial.println("Waiting for gap");
while (1) {
while (digitalRead(RECV_PIN) == LOW) {
while (digitalRead(RECV_PIN) == LOW) {
}
unsigned long time = millis();
while (digitalRead(RECV_PIN) == HIGH) {
@ -81,17 +81,17 @@ void dump(decode_results *results) {
int count = results->rawlen;
if (results->decode_type == UNKNOWN) {
Serial.println("Could not decode message");
}
}
else {
if (results->decode_type == NEC) {
Serial.print("Decoded NEC: ");
}
}
else if (results->decode_type == SONY) {
Serial.print("Decoded SONY: ");
}
}
else if (results->decode_type == RC5) {
Serial.print("Decoded RC5: ");
}
}
else if (results->decode_type == RC6) {
Serial.print("Decoded RC6: ");
}
@ -107,7 +107,7 @@ void dump(decode_results *results) {
for (int i = 0; i < count; i++) {
if ((i % 2) == 1) {
Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
}
}
else {
Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC);
}
@ -130,22 +130,22 @@ void test(char *label, int type, unsigned long value, int bits) {
Serial.println(label);
if (type == NEC) {
irsend.sendNEC(value, bits);
}
}
else if (type == SONY) {
irsend.sendSony(value, bits);
}
}
else if (type == RC5) {
irsend.sendRC5(value, bits);
}
}
else if (type == RC6) {
irsend.sendRC6(value, bits);
}
}
else {
Serial.print(label);
Serial.println("Bad type!");
}
delay(200);
}
}
else if (mode == RECEIVER) {
irrecv.resume(); // Receive the next value
unsigned long max_time = millis() + 30000;
@ -164,7 +164,7 @@ void test(char *label, int type, unsigned long value, int bits) {
digitalWrite(LED_PIN, HIGH);
delay(20);
digitalWrite(LED_PIN, LOW);
}
}
else {
Serial.println(": BAD");
dump(&results);
@ -180,7 +180,7 @@ void testRaw(char *label, unsigned int *rawbuf, int rawlen) {
Serial.println(label);
irsend.sendRaw(rawbuf, rawlen, 38 /* kHz */);
delay(200);
}
}
else if (mode == RECEIVER ) {
irrecv.resume(); // Receive the next value
unsigned long max_time = millis() + 30000;
@ -203,11 +203,11 @@ void testRaw(char *label, unsigned int *rawbuf, int rawlen) {
return;
}
for (int i = 0; i < rawlen; i++) {
long got = results.rawbuf[i+1] * USECPERTICK;
long got = results.rawbuf[i + 1] * USECPERTICK;
// Adjust for extra duration of marks
if (i % 2 == 0) {
if (i % 2 == 0) {
got -= MARK_EXCESS;
}
}
else {
got += MARK_EXCESS;
}
@ -225,7 +225,7 @@ void testRaw(char *label, unsigned int *rawbuf, int rawlen) {
delay(20);
digitalWrite(LED_PIN, LOW);
}
}
}
// This is the raw data corresponding to NEC 0x12345678
unsigned int sendbuf[] = { /* NEC format */
@ -238,15 +238,16 @@ unsigned int sendbuf[] = { /* NEC format */
560, 560, 560, 1690, 560, 1690, 560, 560, /* 6 */
560, 560, 560, 1690, 560, 1690, 560, 1690, /* 7 */
560, 1690, 560, 560, 560, 560, 560, 560, /* 8 */
560};
560
};
void loop() {
if (mode == SENDER) {
delay(2000); // Delay for more than gap to give receiver a better chance to sync.
}
}
else if (mode == RECEIVER) {
waitForGap(1000);
}
}
else if (mode == ERROR) {
// Light up for 5 seconds for error
digitalWrite(LED_PIN, HIGH);
@ -282,7 +283,7 @@ void loop() {
if (mode == SENDER) {
testRaw("RAW2", sendbuf, 67);
test("RAW3", NEC, 0x12345678, 32);
}
}
else {
test("RAW2", NEC, 0x12345678, 32);
testRaw("RAW3", sendbuf, 67);

View File

@ -7,7 +7,7 @@
* JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post)
*/
#include <IRremote.h>
#define PanasonicAddress 0x4004 // Panasonic address (Pre data)
#define PanasonicPower 0x100BCBD // Panasonic Power button
@ -20,10 +20,10 @@ void setup()
}
void loop() {
irsend.sendPanasonic(PanasonicAddress,PanasonicPower); // This should turn your TV on and off
irsend.sendJVC(JVCPower, 16,0); // hex value, 16 bits, no repeat
irsend.sendPanasonic(PanasonicAddress, PanasonicPower); // This should turn your TV on and off
irsend.sendJVC(JVCPower, 16, 0); // hex value, 16 bits, no repeat
delayMicroseconds(50); // see http://www.sbprojects.com/knowledge/ir/jvc.php for information
irsend.sendJVC(JVCPower, 16,1); // hex value, 16 bits, repeat
irsend.sendJVC(JVCPower, 16, 1); // hex value, 16 bits, repeat
delayMicroseconds(50);
}