Arduino 0018 universe repo compile difference

I hope it's Ok to post this even if it's not really an official distribution (the universe repository).

By chance I discovered a difference with what should be the same IDE (arduino 0018).

My original sketch is somewhat large-ish, but I managed to narrow it down to a function I'm borrowing from an example for the IRremote library.

Note I don't think it is particular to this library, it will probably report similar errors with similar "code constructs", I haven't tested that. But it seems all other sketches, at least those I have atm, compile the same (same size and all) in both IDE's.

I think (pretty sure actually) that the arduino package added in the debian "universe" repository (Arduino Playground - Ubuntu) is at fault. And a very subtle one at that. At least I'd be hard pressed to find the error (or rather, that there are no errors in the sketch).

I usually starts the arduino IDE from the terminal, but recent experimentation with Ubuntu 10.04 and 64-bit led to me having this "universe-repo" arduino, and compiling a sketch I had, which didn't compile. And I knew it should. Btw I also discovered that I had installed that version on my main ubuntu box: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1270496961. Its the one with the theme-friendly Open/Save dialogs.

The error I receive is:

error: [ch8216]decode_results[ch8217] was not declared in this scope In function [ch8216]long unsigned int decodeHash(decode_results*)[ch8217]:
 In function [ch8216]void loop()[ch8217]:
 In function [ch8216]void blink_example_loop()[ch8217]:
Bad error line: -4

For my other sketch it was very similar.
(Btw, what is a "long unsigned int" anyway?)

This is the sketch used:

/*
 * IRhashdecode - decode an arbitrary IR code.
 * Instead of decoding using a standard encoding scheme
 * (e.g. Sony, NEC, RC5), the code is hashed to a 32-bit value.
 *
 * An IR detector/demodulator must be connected to the input RECV_PIN.
 * This uses the IRremote library: http://arcfn.com/2009/08/multi-protocol-infrared-remote-library.html
 *
 * The algorithm: look at the sequence of MARK signals, and see if each one
 * is shorter (0), the same length (1), or longer (2) than the previous.
 * Do the same with the SPACE signals.  Hszh the resulting sequence of 0's,
 * 1's, and 2's to a 32-bit value.  This will give a unique value for each
 * different code (probably), for most code systems.
 *
 * You're better off using real decoding than this technique, but this is
 * useful if you don't have a decoding algorithm.
 *
 * Copyright 2010 Ken Shirriff
 * http://arcfn.com
 */

#include <IRremote.h>

int RECV_PIN = 4;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  irrecv.enableIRIn(); // Start the receiver
  Serial.begin(9600);
}

// Compare two tick values, returning 0 if newval is shorter,
// 1 if newval is equal, and 2 if newval is longer
// Use a tolerance of 20%
int compare(unsigned int oldval, unsigned int newval) {
  if (newval < oldval * .8) {
    return 0;
  } 
  else if (oldval < newval * .8) {
    return 2;
  } 
  else {
    return 1;
  }
}

// Use FNV hash algorithm: http://isthe.com/chongo/tech/comp/fnv/#FNV-param
#define FNV_PRIME_32 16777619
#define FNV_BASIS_32 2166136261

/* Converts the raw code values into a 32-bit hash code.
 * Hopefully this code is unique for each button.
 */
unsigned long decodeHash(decode_results *results) {
  unsigned long hash = FNV_BASIS_32;
  for (int i = 1; i+2 < results->rawlen; i++) {
    int value =  compare(results->rawbuf[i], results->rawbuf[i+2]);
    // Add value into the hash
    hash = (hash * FNV_PRIME_32) ^ value;
  }
  return hash;
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.print("'real' decode: ");
    Serial.print(results.value, HEX);
    Serial.print(", hash decode: ");
    Serial.println(decodeHash(&results), HEX); // Do something interesting with this value
    irrecv.resume(); // Resume decoding (necessary!)
  }
}

#define LEDPIN 13
void blink() {
  digitalWrite(LEDPIN, HIGH);
  delay(200);
  digitalWrite(LEDPIN, LOW);
  delay(200);
}  

// Blink the LED the number of times indicated by the Philips remote control
// Replace loop() with this for the blinking LED example.
void blink_example_loop() {
  if (irrecv.decode(&results)) {
    unsigned long hash = decodeHash(&results);
    switch (hash) {
    case 0x322ddc47: // 0 (10)
      blink(); // fallthrough
    case 0xdb78c103: // 9
      blink();
    case 0xab57dd3b: // 8
      blink();
    case 0x715cc13f: // 7
      blink();
    case 0xdc685a5f: // 6
      blink();
    case 0x85b33f1b: // 5
      blink();
    case 0x4ff51b3f: // 4
      blink();
    case 0x15f9ff43: // 3
      blink();
    case 0x2e81ea9b: // 2
      blink();
    case 0x260a8662: // 1
      blink();
      break;
    default:
      Serial.print("Unknown ");
      Serial.println(hash, HEX);    
    }
    irrecv.resume(); // Resume decoding (necessary!)
  }
}

Note that in the official distribution it compiles just fine.

It's the same result on Ubuntu 9.10 32-bit, ubuntu 10.04 64-bit, and Ubuntu 10.04 32-bit.

Hi raron,
Yes, this is a bug. Thanks for posting.
I created a patch and send it to Alessio who manages uploading the packages to the PPA.

I guess a fixed version is available soon.

Eberhard

Wow! That was quick! :slight_smile:
I wasn't sure where to post/report this.

Hi,
the patched version is now available:

Eberhard

Wow! That was quick!

It was a really stupid bug I made, so I really wanted to be fixed quickly.

I wasn't sure where to post/report this.

If you think it is related to packaging the arduino this is the place :
https://bugs.launchpad.net/arduino/+filebug
Thanks again for spotting it :slight_smile:

Eberhard