360 Chatpad.cpp Error (Need Help)

Hello,

Upon interfacing an xbox 360 ChatPad to my arduino(Mega 1280) I ran into a few errors in my code.

"Errors"

/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:26:20: error: wiring.h: No such file or directory
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:32: error: ‘byte’ does not name a type
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:33: error: ‘byte’ does not name a type
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:34: error: ‘byte’ does not name a type
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:35: error: ‘byte’ does not name a type
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:38: error: ‘byte’ does not name a type
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:39: error: ‘byte’ does not name a type
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp: In member function ‘void Chatpad::init(HardwareSerial&, void (*)(Chatpad&, Chatpad::keycode_t, Chatpad::eventtype_t))’:
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:49: error: ‘kInitMessage’ was not declared in this scope
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp: In member function ‘void Chatpad::poll()’:
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:87: error: ‘byte’ was not declared in this scope
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:87: error: expected `;' before ‘modifiers’
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:88: error: expected `;' before ‘key0’
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:89: error: expected `;' before ‘key1’
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:92: error: expected `;' before ‘modifier_changes’
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:93: error: ‘modifier_changes’ was not declared in this scope
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:93: error: ‘kShiftMask’ was not declared in this scope
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:94: error: ‘modifiers’ was not declared in this scope
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:96: error: ‘modifier_changes’ was not declared in this scope
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:96: error: ‘kGreenSquareMask’ was not declared in this scope
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:97: error: ‘modifiers’ was not declared in this scope
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:99: error: ‘modifier_changes’ was not declared in this scope
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:99: error: ‘kOrangeCircleMask’ was not declared in this scope
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:100: error: ‘modifiers’ was not declared in this scope
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:102: error: ‘modifier_changes’ was not declared in this scope
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:102: error: ‘kPeopleMask’ was not declared in this scope
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:103: error: ‘modifiers’ was not declared in this scope
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:105: error: ‘modifiers’ was not declared in this scope
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:108: error: ‘key0’ was not declared in this scope
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:111: error: ‘key1’ was not declared in this scope
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:114: error: ‘key0’ was not declared in this scope
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:114: error: ‘key1’ was not declared in this scope
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:117: error: ‘key0’ was not declared in this scope
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:117: error: ‘key1’ was not declared in this scope
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:120: error: ‘key0’ was not declared in this scope
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:121: error: ‘key1’ was not declared in this scope
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:124: error: ‘millis’ was not declared in this scope
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:127: error: ‘kAwakeMessage’ was not declared in this scope
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp: In member function ‘bool Chatpad::isShiftDown() const’:
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:132: error: ‘kShiftMask’ was not declared in this scope
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp: In member function ‘bool Chatpad::isGreenSquareDown() const’:
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:136: error: ‘kGreenSquareMask’ was not declared in this scope
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp: In member function ‘bool Chatpad::isOrangeCircleDown() const’:
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:140: error: ‘kOrangeCircleMask’ was not declared in this scope
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp: In member function ‘bool Chatpad::isPeopleDown() const’:
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:144: error: ‘kPeopleMask’ was not declared in this scope
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp: In member function ‘char Chatpad::toAscii(Chatpad::keycode_t)’:
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:288: error: ‘byte’ was not declared in this scope
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:288: error: expected `;' before ‘index’
/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:289: error: ‘index’ was not declared in this scope

I could not make sense of these errors after looking inside chatpad.cpp. Any insight where I should go to? I will take all advice and/or tips, and work from those.

Here is a copy of chatpad.cpp

"chatpacd.cpp"

/*
 * Copyright (C) 2011 Cliff L. Biffle, all rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * - Redistributions of source code must retain the above copyright notice, this
 *   list of conditions and the following disclaimer.
 * - Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation
 *   and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
#include "Chatpad.h"
#include "wiring.h"
#include "HardwareSerial.h"

#include <avr/pgmspace.h>

// Masks for modifier bits
static const byte kShiftMask = (1 << 0);
static const byte kGreenSquareMask = (1 << 1);
static const byte kOrangeCircleMask = (1 << 2);
static const byte kPeopleMask = (1 << 3);

// Voodoo protocol messages
static const byte kInitMessage[] = { 0x87, 0x02, 0x8C, 0x1F, 0xCC };
static const byte kAwakeMessage[] = { 0x87, 0x02, 0x8C, 0x1B, 0xD0 };

void Chatpad::init(HardwareSerial &serial, Chatpad::callback_t callback) {
  _serial = &serial;
  _callback = callback;
  _last_modifiers = 0;
  _last_key0 = 0;
  _last_key1 = 0;
  _last_ping = 0;
  _serial->begin(19200);
  _serial->write(kInitMessage, sizeof(kInitMessage));
}

void Chatpad::poll() {
  // Only act if a full message is available.
  if (_serial->available() >= 8) {
    for (int i = 0; i < 8; i++) {
      _buffer[i] = _serial->read();
    }

    // We expect "status report" packets beginning with 0xA5, but don't know
    // what to do with them -- so we silently discard them.
    if (_buffer[0] == 0xA5) return;

    // We *do not* expect other types of packets.  If we find one, complain
    // to the user.
    if (_buffer[0] != 0xB4) {
      Serial.print("Unexpected packet type: ");
      Serial.println(_buffer[0], HEX);
      return;
    }
    if (_buffer[1] != 0xC5) {
      Serial.print("Unexpected second byte: ");
      Serial.println(_buffer[1], HEX);
      return;
    }

    // Check the checksum.
    unsigned char checksum = _buffer[0];
    for (int i = 1; i < 7; i++) checksum += _buffer[i];
    checksum = -checksum;
    if (checksum != _buffer[7]) {
      Serial.println("Checksum failure");
      return;
    }

    // Packet looks good!
    // Dissect the parts we care about:
    byte modifiers = _buffer[3];
    byte key0 = _buffer[4];
    byte key1 = _buffer[5];

    // Check for changes in the modifiers.
    byte modifier_changes = modifiers ^ _last_modifiers;
    if (modifier_changes & kShiftMask) {
      dispatch(KeyShift, modifiers & kShiftMask);
    }
    if (modifier_changes & kGreenSquareMask) {
      dispatch(KeyGreenSquare, modifiers & kGreenSquareMask);
    }
    if (modifier_changes & kOrangeCircleMask) {
      dispatch(KeyOrangeCircle, modifiers & kOrangeCircleMask);
    }
    if (modifier_changes & kPeopleMask) {
      dispatch(KeyPeople, modifiers & kPeopleMask);
    }
    _last_modifiers = modifiers;

    // Check for changes in the other keys
    if (key0 && key0 != _last_key0 && key0 != _last_key1) {
      dispatch(key0, Down);
    }
    if (key1 && key1 != _last_key0 && key1 != _last_key1) {
      dispatch(key1, Down);
    }
    if (_last_key0 && _last_key0 != key0 && _last_key0 != key1) {
      dispatch(_last_key0, Up);
    }
    if (_last_key1 && _last_key1 != key0 && _last_key1 != key1) {
      dispatch(_last_key1, Up);
    }
    _last_key0 = key0;
    _last_key1 = key1;
  }

  uint32_t time = millis();
  if (time - _last_ping > 1000) {
    _last_ping = time;
    _serial->write(kAwakeMessage, sizeof(kAwakeMessage));
  }
}

bool Chatpad::isShiftDown() const {
  return _last_modifiers & kShiftMask;
}

bool Chatpad::isGreenSquareDown() const {
  return _last_modifiers & kGreenSquareMask;
}

bool Chatpad::isOrangeCircleDown() const {
  return _last_modifiers & kOrangeCircleMask;
}

bool Chatpad::isPeopleDown() const {
  return _last_modifiers & kPeopleMask;
}

void Chatpad::dispatch(uint8_t code, int is_down) {
  _callback(*this, (keycode_t) code, is_down? Down : Up);
}

/**************
 * Translation
 */

// These tables have been compacted and must be accessed using this formula:
//  index = (((keycode & 0xF0) - 0x10) >> 1) | ((keycode & 0x0F) - 1)
static const char kAsciiTable[] PROGMEM = {
  '7', /* 11 Key7 */
  '6', /* 12 Key6 */
  '5', /* 13 Key5 */
  '4', /* 14 Key4 */
  '3', /* 15 Key3 */
  '2', /* 16 Key2 */
  '1', /* 17 Key1 */
  0, /* 18 Unused */

  'u', /* 21 KeyU */
  'y', /* 22 KeyY */
  't', /* 23 KeyT */
  'r', /* 24 KeyR */
  'e', /* 25 KeyE */
  'w', /* 26 KeyW */
  'q', /* 27 KeyQ */
  0, /* 28 Unused */

  'j', /* 31 KeyJ */
  'h', /* 32 KeyH */
  'g', /* 33 KeyG */
  'f', /* 34 KeyF */
  'd', /* 35 KeyD */
  's', /* 36 KeyS */
  'a', /* 37 KeyA */
  0, /* 38 Unused */

  'n', /* 41 KeyN */
  'b', /* 42 KeyB */
  'v', /* 43 KeyV */
  'c', /* 44 KeyC */
  'x', /* 45 KeyX */
  'z', /* 46 KeyZ */
  0, /* 47 Unused */
  0, /* 48 Unused */

  0, /* 51 KeyRight */
  'm', /* 52 KeyM */
  '.', /* 53 KeyPeriod */
  ' ', /* 54 KeySpace */
  0, /* 55 KeyLeft */
  0, /* 56 Unused */
  0, /* 57 Unused */
  0, /* 58 Unused */

  0, /* 61 Unused */
  ',', /* 62 KeyComma */
  '\n', /* 63 KeyEnter */
  'p', /* 64 KeyP */
  '0', /* 65 Key0 */
  '9', /* 66 Key9 */
  '8', /* 67 Key8 */
  0, /* 68 Unused */

  '\b', /* 71 KeyBackspace */
  'l', /* 72 KeyL */
  0, /* 73 Unused */
  0, /* 74 Unused */
  'o', /* 75 KeyO */
  'i', /* 76 KeyI */
  'k', /* 77 KeyK */
  0, /* 78 Unused */
};

static const char kAsciiTable_Shifted[] PROGMEM = {
  '&', /* 11 Key7 */
  '^', /* 12 Key6 */
  '%', /* 13 Key5 */
  '

, /* 14 Key4 /
  '#', /
15 Key3 /
  '@', /
16 Key2 /
  '!', /
17 Key1 /
  0, /
18 Unused */

'U', /* 21 KeyU /
  'Y', /
22 KeyY /
  'T', /
23 KeyT /
  'R', /
24 KeyR /
  'E', /
25 KeyE /
  'W', /
26 KeyW /
  'Q', /
27 KeyQ /
  0, /
28 Unused */

'J', /* 31 KeyJ /
  'H', /
32 KeyH /
  'G', /
33 KeyG /
  'F', /
34 KeyF /
  'D', /
35 KeyD /
  'S', /
36 KeyS /
  'A', /
37 KeyA /
  0, /
38 Unused */

'N', /* 41 KeyN /
  'B', /
42 KeyB /
  'V', /
43 KeyV /
  'C', /
44 KeyC /
  'X', /
45 KeyX /
  'Z', /
46 KeyZ /
  0, /
47 Unused /
  0, /
48 Unused */

0, /* 51 KeyRight /
  'M', /
52 KeyM /
  '>', /
53 KeyPeriod /
  ' ', /
54 KeySpace /
  0, /
55 KeyLeft /
  0, /
56 Unused /
  0, /
57 Unused /
  0, /
58 Unused */

0, /* 61 Unused /
  '<', /
62 KeyComma /
  '\n', /
63 KeyEnter /
  'P', /
64 KeyP /
  ')', /
65 Key0 /
  '(', /
66 Key9 /
  '
', /* 67 Key8 /
  0, /
68 Unused */

'\b', /* 71 KeyBackspace /
  'L', /
72 KeyL /
  0, /
73 Unused /
  0, /
74 Unused /
  'O', /
75 KeyO /
  'I', /
76 KeyI /
  'K', /
77 KeyK /
  0, /
78 Unused */
};

char Chatpad::toAscii(keycode_t code) {
  byte index;
  index = (((code - 0x11) & 0x70) >> 1) | ((code - 0x11) & 0x7);
  if (index >= sizeof(kAsciiTable)) return 0;

if (isShiftDown()) {
    return pgm_read_byte_near(kAsciiTable_Shifted + index);
  } else {
    return pgm_read_byte_near(kAsciiTable + index);
  }
}

Start at the top correcting errors.

/home/jacob/Desktop/arduino-1.0.2/libraries/Chatpad/Chatpad.cpp:26:20: error: wiring.h: No such file or directory

This library appears to have been designed for wiring, not Arduino. You might be able to use it with an Arduino, but you'll need to change wiring.h to Arduino.h.

Yes. Problem solved, as for syntax errors at least. I must be more observant next time as not to miss things like that. I am going to have to go over the code a few times to understand some of these inputs though.

hey, did you ever get your chatpad/arduino code working? im getting these messages....

libraries\Chatpad.cpp.o: In function `Chatpad::init(HardwareSerial&, void (*)(Chatpad&, Chatpad::keycode_t, Chatpad::eventtype_t))':
C:\Program Files (x86)\Arduino\libraries\libraries/Chatpad.cpp:42: multiple definition of `Chatpad::init(HardwareSerial&, void (*)(Chatpad&, Chatpad::keycode_t, Chatpad::eventtype_t))'
duke.cpp.o:C:\Program Files (x86)\Arduino/duke.ino:42: first defined here
libraries\Chatpad.cpp.o: In function `Chatpad::init(HardwareSerial&, void (*)(Chatpad&, Chatpad::keycode_t, Chatpad::eventtype_t))':
C:\Program Files (x86)\Arduino\libraries\libraries/Chatpad.cpp:42: multiple definition of `Chatpad::isShiftDown() const'
duke.cpp.o:C:\Program Files (x86)\Arduino/duke.ino:42: first defined here
libraries\Chatpad.cpp.o: In function `Chatpad::init(HardwareSerial&, void (*)(Chatpad&, Chatpad::keycode_t, Chatpad::eventtype_t))':
C:\Program Files (x86)\Arduino\libraries\libraries/Chatpad.cpp:42: multiple definition of `Chatpad::isGreenSquareDown() const'
duke.cpp.o:C:\Program Files (x86)\Arduino/duke.ino:42: first defined here
libraries\Chatpad.cpp.o: In function `Chatpad::init(HardwareSerial&, void (*)(Chatpad&, Chatpad::keycode_t, Chatpad::eventtype_t))':
C:\Program Files (x86)\Arduino\libraries\libraries/Chatpad.cpp:42: multiple definition of `Chatpad::isOrangeCircleDown() const'
duke.cpp.o:C:\Program Files (x86)\Arduino/duke.ino:42: first defined here
libraries\Chatpad.cpp.o: In function `Chatpad::init(HardwareSerial&, void (*)(Chatpad&, Chatpad::keycode_t, Chatpad::eventtype_t))':
C:\Program Files (x86)\Arduino\libraries\libraries/Chatpad.cpp:42: multiple definition of `Chatpad::isPeopleDown() const'
duke.cpp.o:C:\Program Files (x86)\Arduino/duke.ino:42: first defined here
libraries\Chatpad.cpp.o: In function `Chatpad::init(HardwareSerial&, void (*)(Chatpad&, Chatpad::keycode_t, Chatpad::eventtype_t))':
C:\Program Files (x86)\Arduino\libraries\libraries/Chatpad.cpp:42: multiple definition of `Chatpad::dispatch(unsigned char, int)'
duke.cpp.o:C:\Program Files (x86)\Arduino/duke.ino:42: first defined here
libraries\Chatpad.cpp.o: In function `Chatpad::init(HardwareSerial&, void (*)(Chatpad&, Chatpad::keycode_t, Chatpad::eventtype_t))':
C:\Program Files (x86)\Arduino\libraries\libraries/Chatpad.cpp:42: multiple definition of `Chatpad::poll()'
duke.cpp.o:C:\Program Files (x86)\Arduino/duke.ino:42: first defined here
libraries\Chatpad.cpp.o: In function `Chatpad::init(HardwareSerial&, void (*)(Chatpad&, Chatpad::keycode_t, Chatpad::eventtype_t))':
C:\Program Files (x86)\Arduino\libraries\libraries/Chatpad.cpp:42: multiple definition of `Chatpad::toAscii(Chatpad::keycode_t)'
duke.cpp.o:C:\Program Files (x86)\Arduino/duke.ino:42: first defined here
C:\Windows\system32\config\SYSTEM~1\AppData\Local\Temp\build8927311067225383967.tmp/core.a(main.cpp.o): In function `main':
C:\Windows\system32\config\systemprofile\AppData\Roaming\Arduino15\packages\arduino\hardware\avr\1.6.2\cores\arduino/main.cpp:40: undefined reference to `setup'
C:\Windows\system32\config\systemprofile\AppData\Roaming\Arduino15\packages\arduino\hardware\avr\1.6.2\cores\arduino/main.cpp:43: undefined reference to `loop'
collect2.exe: error: ld returned 1 exit status
Error compiling.