T++ 2.0 on Arduino IDE 1.8.2 'class USB' has no member named 'Init'

Status
Not open for further replies.

davedarko

Member
Hey there,

I've run into a little problem, I can't compile code that has worked before and still compiles on a customers Mac. I'm running Arduino 1.8.2 on my mac, to work with a Teensy++ 2.0 that is connected to a MAX3421E and needs the USB host shield to work. It seems to have no idea what the pins 'Pb0' to 'Pb3' are, too.

If anyone has any ideas, please tell, I'm not sure what went wrong here.

Code:
/*
  // http://www.angelaitp.com/2017/01/30/creating-a-game-controller/
  2016-03-21
  2016-10-08 UPDATES
  2018-02-02 starting on the EEPROM stuff again
  
  EEEPROM thoughts 
  - 100.000 write cycles
  - maybe external eeprom better suited (More than 1 Million Erase/Write Cycles)
  - 1k EEPROM ATMEGA32U4 (leonardo)
  - 4k EEPROM AT90USB1286 (teensie 2++)
  - max 408 customers / rides per day
  - with 10 reads of 16bytes

  https://github.com/felis/USB_Host_Shield_2.0/issues/286
  - had to remove RFID stuff for now, due to conflicting SPI stuff

*/

#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif

#include <Time.h>
#include <TimeLib.h>

#include <hidboot.h>
#include <usbhub.h>

#include <SPI.h>
#include <EtherCard.h>  // ENC28J60


#define OPTO_GATE       10    // 
#define OPTO_BTN        11    // 

#define RFID_SS         45    // 
#define RFID_RST        44    // 
#define ENC_SS          40    // A1 on older models? now A2
#define USB_YES         38    // A0 
#define BEEPER          43    // A0 
#define BUILTIN_LED      6    // A0 

#define USB_RST         25    // A0 
#define USB_INT         24    // A0 

#define RELAY_RED       14    // 
#define RELAY_YELLOW    15    // 
#define RELAY_GREEN     16    // 
#define RELAY           17    // 

#define IDLE_MAIN        0
#define REQUEST_CLIENT   1
#define REQUEST_RFID     2
#define WAIT_CLIENT      3
#define WAIT_RFID        4
#define FREE_ETHER       5
#define FREE_ETHER_FOR_RFID        6
#define IDLE_FOR_RFID    7
#define INIT             8
#define WAIT_TIME        9
#define USB_ONLY        10

#define TIMEOUT_MS 10000 // queries
#define GATE_TIMEOUT_MS 3500 // gate

byte Ethernet::buffer[800];

// static byte session;
const char website[] PROGMEM = "api.xserver.com";

uint32_t id;
char idToText[16];

// test-wasserski-wedau test
static byte mymac[] = { 0x74, 0x68, 0x68, 0x2D, 0x30, 0x2F };
const char link[24] = "bridge.php?cid=TEST0001";


const char link_id[5] = "&id=";
const char url_in0[6] = "&in=0";
const char url_in1[6] = "&in=1";
const char url_fR[5] = "&fR=";
const char url_rT[5] = "&rT=";
char json_response[16] = "";
char url[72];

int retry_cnt=0;

int8_t state;
int8_t statePrev = -1;
static uint32_t timer;
static uint32_t gate_timer;
static uint32_t rfid_timer;
static uint32_t timer_gate_btn;
static uint32_t usb_keyboard_timeout;

static uint32_t response_timer;
static uint32_t last_response_time;

boolean button_pressed = false;

int usbVCC;
int usbCap = 450;

uint32_t dataSize = 8;

USB     Usb;
HIDBoot<HID_PROTOCOL_KEYBOARD>    HidKeyboard(&Usb);

uint32_t next_time;

class KbdRptParser : public KeyboardReportParser
{
    void OnKeyDown  (uint8_t mod, uint8_t key);
};

void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key)
{

  uint8_t c = OemToAscii(mod, key);
  uint8_t l = strlen(idToText);

  if ((c == 10 || c == 13 || c == 19) && l > 5)
  {
    id = atoi(idToText);
    retry_cnt=0;
    state = REQUEST_CLIENT;
  }
  else if (c == '%' || c =='#')
  {
    usb_keyboard_timeout = millis();
    state = USB_ONLY;
    strcpy(idToText, "");
  }
  else
  {
    uint8_t l = strlen(idToText);
    idToText[l++] = c;
    idToText[l] = '\0';
  }
}

KbdRptParser Prs;

void setup ()
{
  pinMode(RELAY, OUTPUT);
  pinMode(RELAY_RED, OUTPUT);
  pinMode(RELAY_YELLOW, OUTPUT);
  pinMode(RELAY_GREEN, OUTPUT);
  pinMode(OPTO_GATE, INPUT);
  pinMode(OPTO_BTN, INPUT);

  pinMode(BUILTIN_LED, OUTPUT);
  digitalWrite(BUILTIN_LED, HIGH);

  pinMode(USB_RST, OUTPUT);
  digitalWrite(USB_RST, LOW);

  SPI.begin();

  Serial1.begin(9600);  // Hardware Serial SparkFun Pro Micro or serial barcode reader

  usbVCC = analogRead(USB_YES);
  if (usbVCC > usbCap)
  {
    Serial.println("USB connected");
    Serial.println(link);
  }

  init_enc();

  state = INIT;

  Serial.println("Starting USB controller");
  
  digitalWrite(USB_RST, HIGH);

  if (Usb.Init() == -1)
    Serial.println("OSC did not start.");

  delay( 200 );
  next_time = millis() + 5000;
  HidKeyboard.SetReportParser(0, (HIDReportParser*)&Prs);

}

void loop()
{
  if (statePrev != state)
  {
    printlnSerial(state);
    statePrev = state;
  }

  switch (state)
  {
    case USB_ONLY: // 10
      {
        // timer fuer check wenn keine Abbruchbedingung auftrat
        if (millis() - usb_keyboard_timeout > 2000)
        {
          state = IDLE_MAIN;
          strcpy(idToText, "");
        }
        else
        {
          Usb.Task(); // check for usb stuff happening 
        }
      }
      break;
    case INIT:
      {
        delay(200);
        ether.browseUrl(PSTR("/"), "time.php", website, cb_time);
        
        state = WAIT_TIME; // Go to state to wait for response from browseURL
        timer = millis() + TIMEOUT_MS;
      }
      break;
    case IDLE_MAIN:
      {
        Usb.Task(); // check for usb stuff happening 
        
        // just in case anything happens or the arp has to go somewhere - maybe this get's lost
        ether.packetLoop(ether.packetReceive()); 
        
        if (Serial1.available())
        {
          Serial1.readBytesUntil('\n', idToText, 15);
          uint8_t l = strlen(idToText);
          
          if (l > 5)
          {
            id = atoi(idToText);
            state = REQUEST_CLIENT;
            retry_cnt=0;
          }
        }

        if (
          !digitalRead(OPTO_BTN) &&
          !button_pressed
        ) {
          Serial.println("Button pressed");
          digitalWrite(RELAY, HIGH); // OPEN 
          delay(1);
          digitalWrite(RELAY_RED, HIGH); // through
          delay(1);
          digitalWrite(RELAY_YELLOW, HIGH); // through
          delay(1);
          digitalWrite(RELAY_GREEN, HIGH); // through
          delay(1);
          timer_gate_btn = millis() + GATE_TIMEOUT_MS;
          button_pressed = true;
        }
        else
        {
          if (
            (millis() > timer_gate_btn) && 
            button_pressed)
          {
            Serial.println("Button released");
            digitalWrite(RELAY, LOW); // timeout
            delay(1);
            digitalWrite(RELAY_RED, LOW); // through
            delay(1);
            digitalWrite(RELAY_YELLOW, LOW); // through
            delay(1);
            digitalWrite(RELAY_GREEN, LOW); // through
            delay(1);
            button_pressed = false;
          }
        }
      }
      break;

    case IDLE_FOR_RFID: //7 - basically second IDLE
      {
        ether.packetLoop(ether.packetReceive());
        
        if (!digitalRead(OPTO_GATE))
        {
          printlnSerial("OPN");
          digitalWrite(RELAY, LOW); // through
          delay(1);
          digitalWrite(RELAY_RED, LOW); // through
          delay(1);
          digitalWrite(RELAY_YELLOW, LOW); // through
          delay(1);
          digitalWrite(RELAY_GREEN, LOW); // through
          delay(1);

          state = REQUEST_RFID;
        }
        else
        {
          if (millis() > gate_timer)
          {
            printlnSerial("CLS");
            
            digitalWrite(RELAY, LOW); // through
            delay(1);
            digitalWrite(RELAY_RED, LOW); // through
            delay(1);
            digitalWrite(RELAY_YELLOW, LOW); // through
            delay(1);
            digitalWrite(RELAY_GREEN, LOW); // through
            delay(1);

            state = FREE_ETHER;
          }
        }
      }
      break;

    case REQUEST_CLIENT: //1

      {
        //while ( ether.packetLoop(ether.packetReceive()));
        // ether.packetLoop(ether.packetReceive());
        

        int fR = freeRam();
        char fRbuf[6];
        sprintf(fRbuf, "%i", fR);

        char rtbuf[11];
        sprintf(rtbuf, "%lu", last_response_time);

        // reset url char array
        strcpy(url, "");
        strcat(url, link);
        strcat(url, url_in0);
        // free Ram size
        strcat(url, url_fR);
        strcat(url, fRbuf);
        // last ressponse Time
        strcat(url, url_rT);
        strcat(url, rtbuf);
        
        strcat(url, link_id);
        strcat(url, idToText);

        usbVCC = analogRead(USB_YES);
        if (usbVCC > usbCap)
        {
          Keyboard.print('%');
          Keyboard.print(idToText);
          Keyboard.println();
        }

        response_timer = millis();
        printlnSerial(url);

        ether.browseUrl(PSTR("/"), url, website, cb_client);

        state = WAIT_CLIENT; // Go to state to wait for response from browseURL
        timer = millis() + TIMEOUT_MS; // 5 second timeout

      }
      break;

    case REQUEST_RFID: // 2
      {
        //while ( ether.packetLoop(ether.packetReceive()));
        // ether.packetLoop(ether.packetReceive());
        
        int fR = freeRam();
        char fRbuf[6];
        sprintf(fRbuf, "%i", fR);

        char rtbuf[11];
        sprintf(rtbuf, "%lu", last_response_time);

        // reset url char array
        strcpy(url, "");
        strcat(url, link);
        strcat(url, url_in1);
        // free Ram size
        strcat(url, url_fR);
        strcat(url, fRbuf);
        // last ressponse Time
        strcat(url, url_rT);
        strcat(url, rtbuf);

        strcat(url, link_id);
        strcat(url, idToText);

        printlnSerial(url);
        ether.browseUrl(PSTR("/"), url, website, cb_gate);
        
        state = WAIT_RFID;
        rfid_timer = millis() + TIMEOUT_MS;// 5 second timeout
      }
      break;

    // wait for response of gate gone through
    case WAIT_RFID: // 4
      {
        if (millis() > rfid_timer)
        {
          // timeout waiting for response
          
          printlnSerial("?ID");
          if (retry_cnt<5)
          {
            Serial.print("retry: ");
            Serial.println(retry_cnt);
            state = REQUEST_RFID;
            retry_cnt++;  
          }
          else
          {
            state = FREE_ETHER;
          }
        }
        // waiting for response from previois calback
        ether.packetLoop(ether.packetReceive());
      }
      break;

    // wait for response of customer check
    case WAIT_CLIENT: //3
      {
        if (millis() > timer)
        {
          // timeout waiting for response
          state = FREE_ETHER;
          printlnSerial("?CUS");
        }
        // waiting for response from previois calback
        ether.packetLoop(ether.packetReceive());
      }
      break;

    // wait for response of gate gone through
    case WAIT_TIME: // 9
      {

        if (millis() > timer)
        {
          // timeout waiting for response
          state = FREE_ETHER;
          printlnSerial("?TIME");
        }
        // waiting for response from previois calback
        ether.packetLoop(ether.packetReceive());
      }
      break;

    // Flush the content or at least wait for the response and just wait and reset
    case FREE_ETHER:

      {
        // waiting for response from previois calback
        // while ( ether.packetLoop(ether.packetReceive()));
        // ether.packetLoop(ether.packetReceive());
        state = IDLE_MAIN;
      }
      break;

    case FREE_ETHER_FOR_RFID:

      {
        // waiting for response from previois calback
        // while ( ether.packetLoop(ether.packetReceive()));
        // ether.packetLoop(ether.packetReceive());
        state = IDLE_FOR_RFID;
      }
      break;

    default:
      break;
  }
}

// time call back
static void cb_time (byte status, word off, word len)
{
  printlnSerial("CBTIME");
  
  Ethernet::buffer[off + 800] = 0;
  char* response = (char*) Ethernet::buffer + off;
  getResponseWithoutHeader(response, json_response);
  
  if (strtol(json_response, NULL, 0) > 0)
  {
    setTime(strtol(json_response, NULL, 0));
  }
  digitalClockDisplay();
  
  state = FREE_ETHER;

}

// called when the client request is complete
static void cb_gate (byte status, word off, word len)
{
  last_response_time = millis() - response_timer;
  printlnSerial("CBG");
  Ethernet::buffer[off + 800] = 0;
  char* response = (char*) Ethernet::buffer + off;
  getResponseWithoutHeader(response, json_response);

  if (strncmp(json_response, "OK", 2) == 0)
  {
    state = FREE_ETHER;
  }
  else
  {
    state = REQUEST_RFID;
  }
}

// called when the client request is complete
static void cb_client (byte status, word off, word len)
{
  last_response_time = millis() - response_timer;
  Ethernet::buffer[off + 800] = 0;
  char* response = (char*) Ethernet::buffer + off;

  printlnSerial("JSR");
  getResponseWithoutHeader(response, json_response);

  if (strncmp(json_response, "no school", 9) == 0)
  {
    printlnSerial("!SCL");
    state = FREE_ETHER;
  }
  else if (strncmp(json_response, "user_not_found", 14) == 0)
  {
    state = FREE_ETHER;
  }
  else if (strncmp(json_response, "user_no_ride", 12) == 0)
  {
    // red
    state = FREE_ETHER;
    printlnSerial("NOP");
  }
  else if (strtol(json_response, NULL, 0) > 0)
  {
    uint32_t timeForId = strtol(json_response, NULL, 0) + now();
      // green
    printlnSerial("THR");
    digitalWrite(RELAY, HIGH);
    delay(1);
    digitalWrite(RELAY_RED, HIGH); // through
    delay(1);
    digitalWrite(RELAY_YELLOW, HIGH); // through
    delay(1);
    digitalWrite(RELAY_GREEN, HIGH); // through
    delay(1);
  
    gate_timer = millis() + GATE_TIMEOUT_MS;
    state = FREE_ETHER_FOR_RFID;
  }
  else if (strtol(json_response, NULL, 0) < 0)
  {
    // red
    state = FREE_ETHER;
    printlnSerial("EXP");
  }
  else
  {
    state = REQUEST_CLIENT;
    printlnSerial(json_response);
  }
}

int freeRam ()
{
  extern int __heap_start, *__brkval;
  int v;
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}

void init_enc ()
{
  Serial.println("init ethernet");
  if (ether.begin(sizeof Ethernet::buffer, mymac, ENC_SS) == 0)
  {
    printlnSerial("!ENC");
    init_enc();
    return;
  }
  if (!ether.dhcpSetup())
  {
    printlnSerial("!DHC");
    init_enc();
    return;
  }

  ether.printIp("IP:  ", ether.myip);
  ether.printIp("GW:  ", ether.gwip);
  ether.printIp("DNS: ", ether.dnsip);

  if (!ether.dnsLookup(website))
  {
    printlnSerial("!DNS");
    init_enc();
    return;
  }
  ether.printIp("SRV: ", ether.hisip);
}

void getResponseWithoutHeader(char* response, char* new_response)
{

  strcpy(new_response, "");

  char * pch;
  pch = strstr (response, "\r\n\r\n");

  int length = 15;
  if (strlen(pch + 4) < 15)
  {
    length = strlen(pch + 4);
  }

  printlnSerial(pch + 4);

  strncpy (new_response, pch + 4, length);
  // strcat(new_response, '\0');
}

void printlnSerial(char const a[])
{
  usbVCC = analogRead(USB_YES);
  if (usbVCC > usbCap)
  {
    Serial.println(a);
  }
}

void printlnSerial(char *a)
{
  usbVCC = analogRead(USB_YES);
  if (usbVCC > usbCap)
  {
    Serial.println(a);
  }
}

void printlnSerial(int a)
{
  usbVCC = analogRead(USB_YES);
  if (usbVCC > usbCap)
  {
    Serial.println(a);
  }
}

void digitalClockDisplay() {
  // digital clock display of the time
  Serial.println(millis());
  Serial.print(year());
  Serial.print("-");
  printDigits(month());
  Serial.print("-");
  printDigits(day());
  Serial.print(" ");
  printDigits(hour());
  Serial.print(":");
  printDigits(minute());
  Serial.print(":");
  printDigits(second());
  Serial.println();
}

void printDigits(int digits) {
  if (digits < 10) Serial.print('0');
  Serial.print(digits);
}

Code:
Warning: Board tiny:avr:nyan doesn't define a 'build.board' preference. Auto-set to: AVR_NYAN
In file included from /var/folders/rk/5m9lbt8n3l9841wwpztr4kf40000gn/T/arduino_build_601125/sketch/usb_host/Usb.h:36:0,
                 from /var/folders/rk/5m9lbt8n3l9841wwpztr4kf40000gn/T/arduino_build_601125/sketch/usb_host/hid.h:20,
                 from /var/folders/rk/5m9lbt8n3l9841wwpztr4kf40000gn/T/arduino_build_601125/sketch/usb_host/hidboot.h:20,
                 from /somewhere/something.ino:39:
/var/folders/rk/5m9lbt8n3l9841wwpztr4kf40000gn/T/arduino_build_601125/sketch/usb_host/usbhost.h:89:14: error: 'Pb1' was not declared in this scope
 typedef SPi< Pb1, Pb2, Pb3, Pb0 > spi;
              ^
/var/folders/rk/5m9lbt8n3l9841wwpztr4kf40000gn/T/arduino_build_601125/sketch/usb_host/usbhost.h:89:19: error: 'Pb2' was not declared in this scope
 typedef SPi< Pb1, Pb2, Pb3, Pb0 > spi;
                   ^
/var/folders/rk/5m9lbt8n3l9841wwpztr4kf40000gn/T/arduino_build_601125/sketch/usb_host/usbhost.h:89:24: error: 'Pb3' was not declared in this scope
 typedef SPi< Pb1, Pb2, Pb3, Pb0 > spi;
                        ^
/var/folders/rk/5m9lbt8n3l9841wwpztr4kf40000gn/T/arduino_build_601125/sketch/usb_host/usbhost.h:89:29: error: 'Pb0' was not declared in this scope
 typedef SPi< Pb1, Pb2, Pb3, Pb0 > spi;
                             ^
/var/folders/rk/5m9lbt8n3l9841wwpztr4kf40000gn/T/arduino_build_601125/sketch/usb_host/usbhost.h:89:33: error: template argument 1 is invalid
 typedef SPi< Pb1, Pb2, Pb3, Pb0 > spi;
                                 ^
/var/folders/rk/5m9lbt8n3l9841wwpztr4kf40000gn/T/arduino_build_601125/sketch/usb_host/usbhost.h:89:33: error: template argument 2 is invalid
/var/folders/rk/5m9lbt8n3l9841wwpztr4kf40000gn/T/arduino_build_601125/sketch/usb_host/usbhost.h:89:33: error: template argument 3 is invalid
/var/folders/rk/5m9lbt8n3l9841wwpztr4kf40000gn/T/arduino_build_601125/sketch/usb_host/usbhost.h:89:33: error: template argument 4 is invalid
/var/folders/rk/5m9lbt8n3l9841wwpztr4kf40000gn/T/arduino_build_601125/sketch/usb_host/usbhost.h:89:38: error: invalid type in declaration before ';' token
 typedef SPi< Pb1, Pb2, Pb3, Pb0 > spi;
                                      ^
/var/folders/rk/5m9lbt8n3l9841wwpztr4kf40000gn/T/arduino_build_601125/sketch/usb_host/usbhost.h: In member function 'int8_t MAX3421e<SPI_SS, INTR>::Init()':
/var/folders/rk/5m9lbt8n3l9841wwpztr4kf40000gn/T/arduino_build_601125/sketch/usb_host/usbhost.h:394:18: error: qualified-id in declaration before '(' token
         spi::init();
                  ^
/var/folders/rk/5m9lbt8n3l9841wwpztr4kf40000gn/T/arduino_build_601125/sketch/usb_host/usbhost.h: In member function 'int8_t MAX3421e<SPI_SS, INTR>::Init(int)':
/var/folders/rk/5m9lbt8n3l9841wwpztr4kf40000gn/T/arduino_build_601125/sketch/usb_host/usbhost.h:431:18: error: qualified-id in declaration before '(' token
         spi::init();
                  ^
In file included from /var/folders/rk/5m9lbt8n3l9841wwpztr4kf40000gn/T/arduino_build_601125/sketch/usb_host/Usb.h:37:0,
                 from /var/folders/rk/5m9lbt8n3l9841wwpztr4kf40000gn/T/arduino_build_601125/sketch/usb_host/hid.h:20,
                 from /var/folders/rk/5m9lbt8n3l9841wwpztr4kf40000gn/T/arduino_build_601125/sketch/usb_host/hidboot.h:20,
                 from /somewhere/something.ino:39:
/var/folders/rk/5m9lbt8n3l9841wwpztr4kf40000gn/T/arduino_build_601125/sketch/usb_host/UsbCore.h: At global scope:
/var/folders/rk/5m9lbt8n3l9841wwpztr4kf40000gn/T/arduino_build_601125/sketch/usb_host/UsbCore.h:36:18: error: 'P20' was not declared in this scope
 typedef MAX3421e<P20, P24> MAX3421E; // Teensy++ 1.0 and 2.0 
                  ^
/var/folders/rk/5m9lbt8n3l9841wwpztr4kf40000gn/T/arduino_build_601125/sketch/usb_host/UsbCore.h:36:23: error: 'P24' was not declared in this scope
 typedef MAX3421e<P20, P24> MAX3421E; // Teensy++ 1.0 and 2.0 
                       ^
/var/folders/rk/5m9lbt8n3l9841wwpztr4kf40000gn/T/arduino_build_601125/sketch/usb_host/UsbCore.h:36:26: error: template argument 1 is invalid
 typedef MAX3421e<P20, P24> MAX3421E; // Teensy++ 1.0 and 2.0 
                          ^
/var/folders/rk/5m9lbt8n3l9841wwpztr4kf40000gn/T/arduino_build_601125/sketch/usb_host/UsbCore.h:36:26: error: template argument 2 is invalid
/var/folders/rk/5m9lbt8n3l9841wwpztr4kf40000gn/T/arduino_build_601125/sketch/usb_host/UsbCore.h:36:36: error: invalid type in declaration before ';' token
 typedef MAX3421e<P20, P24> MAX3421E; // Teensy++ 1.0 and 2.0 
                                    ^
In file included from /var/folders/rk/5m9lbt8n3l9841wwpztr4kf40000gn/T/arduino_build_601125/sketch/usb_host/Usb.h:37:0,
                 from /var/folders/rk/5m9lbt8n3l9841wwpztr4kf40000gn/T/arduino_build_601125/sketch/usb_host/hid.h:20,
                 from /var/folders/rk/5m9lbt8n3l9841wwpztr4kf40000gn/T/arduino_build_601125/sketch/usb_host/hidboot.h:20,
                 from /somewhere/somewhere.ino:39:
/var/folders/rk/5m9lbt8n3l9841wwpztr4kf40000gn/T/arduino_build_601125/sketch/usb_host/UsbCore.h:201:29: error: expected class-name before '{' token
 class USB : public MAX3421E {
                             ^
WS17_DREHKREUZ: In function 'void setup()':
WS17_DREHKREUZ:217: error: 'class USB' has no member named 'Init'
   if (Usb.Init() == -1)
           ^
WS17_DREHKREUZ: In function 'void cb_client(byte, word, word)':
WS17_DREHKREUZ:581: warning: unused variable 'timeForId' 
     uint32_t timeForId = strtol(json_response, NULL, 0) + now();
              ^
In file included from /somewhere/something.ino:39:0:
/var/folders/rk/5m9lbt8n3l9841wwpztr4kf40000gn/T/arduino_build_601125/sketch/usb_host/hidboot.h: In instantiation of 'uint8_t HIDBoot<BOOT_PROTOCOL>::Init(uint8_t, uint8_t, bool) [with unsigned char BOOT_PROTOCOL = 1u; uint8_t = unsigned char]':
/somewhere/something.ino:712:1:   required from here
/var/folders/rk/5m9lbt8n3l9841wwpztr4kf40000gn/T/arduino_build_601125/sketch/usb_host/hidboot.h:348:30: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
         epInfo[0].maxPktSize = (uint8_t)((USB_DEVICE_DESCRIPTOR*)buf)->bMaxPacketSize0;
                              ^
/var/folders/rk/5m9lbt8n3l9841wwpztr4kf40000gn/T/arduino_build_601125/sketch/usb_host/hidboot.h:379:21: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
         num_of_conf = ((USB_DEVICE_DESCRIPTOR*)buf)->bNumConfigurations;
                     ^
Multiple libraries were found for "TimeLib.h"
 Used: /somewhere/Sketchbook/libraries/Time
 Not used: /Applications/Arduino copy.app/Contents/Java/hardware/teensy/avr/libraries/Time
 Not used: /Applications/Arduino copy.app/Contents/Java/hardware/teensy/avr/libraries/Time
 Not used: /Applications/Arduino copy.app/Contents/Java/hardware/teensy/avr/libraries/Time
 Not used: /Applications/Arduino copy.app/Contents/Java/hardware/teensy/avr/libraries/Time
'class USB' has no member named 'Init'
 
Right, should have written that I've tried changing the board from teensy++ 2.0 to another chip/board and back again, but it didn't help.
 
Please try again and if it still doesn't work, copy and paste the errors you get.

Your first message has this:

Code:
Warning: Board tiny:avr:nyan doesn't define a 'build.board' preference. Auto-set to: AVR_NYAN

"Board tiny:avr:nyan" definitely means something other than Teensy is selected in Tools > Boards.
 
this is something I get with every board I select, even with compiling for the ESP8266 boards... not saying that it's not weird, but it didn't seem important so far.
 
Well, I tried just now on Arduino 1.8.5 with Teensyduino 1.42-beta3 (the latest). I installed the libraries from these two locations (you didn't give specific versions or info where to get the copies you are using).

https://github.com/felis/USB_Host_Shield_2.0

https://github.com/jcw/ethercard

When I click Verify, it doesn't compile, but I get very different errors.

Code:
sketch_mar26a:109: error: 'HID_PROTOCOL_KEYBOARD' was not declared in this scope
 HIDBoot<HID_PROTOCOL_KEYBOARD>    HidKeyboard(&Usb);
         ^
sketch_mar26a:109: error: template argument 1 is invalid
 HIDBoot<HID_PROTOCOL_KEYBOARD>    HidKeyboard(&Usb);
                              ^
sketch_mar26a:109: error: invalid type in declaration before '(' token
 HIDBoot<HID_PROTOCOL_KEYBOARD>    HidKeyboard(&Usb);
                                           ^
sketch_mar26a:109: error: invalid conversion from 'USB*' to 'int' [-fpermissive]
 HIDBoot<HID_PROTOCOL_KEYBOARD>    HidKeyboard(&Usb);
                                                ^
sketch_mar26a: In function 'void setup()':
sketch_mar26a:185: error: request for member 'SetReportParser' in 'HidKeyboard', which is of non-class type 'int'
   HidKeyboard.SetReportParser(0, (HIDReportParser*)&Prs);
               ^
sketch_mar26a: In function 'void cb_client(byte, word, word)':
sketch_mar26a:544: warning: unused variable 'timeForId' 
     uint32_t timeForId = strtol(json_response, NULL, 0) + now();
 
Ok, I did a little digging... it seems the problem is pretty simple. Newer versions of USB Host Shield 2.0 have renamed "HID_PROTOCOL_KEYBOARD" to "USB_HID_PROTOCOL_KEYBOARD".

To make your program compile with the latest version of Arduino, Teensyduino, USB Host Shield 2.0 and EtherCard, all you need to do is add "USB_" to that name on line 109 of your program. Easy, right?

Your program also uses USB Keyboard, so Keyboard needs to be selected in Tools > USB Type. Otherwise you'll get: 'Keyboard' was not declared in this scope

Here's a complete copy of your program, with that 1 line edited for compatibility with the newer USB Host Shield 2.0 library.

Code:
/*
  // http://www.angelaitp.com/2017/01/30/creating-a-game-controller/
  2016-03-21
  2016-10-08 UPDATES
  2018-02-02 starting on the EEPROM stuff again
  
  EEEPROM thoughts 
  - 100.000 write cycles
  - maybe external eeprom better suited (More than 1 Million Erase/Write Cycles)
  - 1k EEPROM ATMEGA32U4 (leonardo)
  - 4k EEPROM AT90USB1286 (teensie 2++)
  - max 408 customers / rides per day
  - with 10 reads of 16bytes

  https://github.com/felis/USB_Host_Shield_2.0/issues/286
  - had to remove RFID stuff for now, due to conflicting SPI stuff

*/

#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif

#include <Time.h>
#include <TimeLib.h>

#include <hidboot.h>
#include <usbhub.h>

#include <SPI.h>
#include <EtherCard.h>  // ENC28J60


#define OPTO_GATE       10    // 
#define OPTO_BTN        11    // 

#define RFID_SS         45    // 
#define RFID_RST        44    // 
#define ENC_SS          40    // A1 on older models? now A2
#define USB_YES         38    // A0 
#define BEEPER          43    // A0 
#define BUILTIN_LED      6    // A0 

#define USB_RST         25    // A0 
#define USB_INT         24    // A0 

#define RELAY_RED       14    // 
#define RELAY_YELLOW    15    // 
#define RELAY_GREEN     16    // 
#define RELAY           17    // 

#define IDLE_MAIN        0
#define REQUEST_CLIENT   1
#define REQUEST_RFID     2
#define WAIT_CLIENT      3
#define WAIT_RFID        4
#define FREE_ETHER       5
#define FREE_ETHER_FOR_RFID        6
#define IDLE_FOR_RFID    7
#define INIT             8
#define WAIT_TIME        9
#define USB_ONLY        10

#define TIMEOUT_MS 10000 // queries
#define GATE_TIMEOUT_MS 3500 // gate

byte Ethernet::buffer[800];

// static byte session;
const char website[] PROGMEM = "api.xserver.com";

uint32_t id;
char idToText[16];

// test-wasserski-wedau test
static byte mymac[] = { 0x74, 0x68, 0x68, 0x2D, 0x30, 0x2F };
const char link[24] = "bridge.php?cid=TEST0001";


const char link_id[5] = "&id=";
const char url_in0[6] = "&in=0";
const char url_in1[6] = "&in=1";
const char url_fR[5] = "&fR=";
const char url_rT[5] = "&rT=";
char json_response[16] = "";
char url[72];

int retry_cnt=0;

int8_t state;
int8_t statePrev = -1;
static uint32_t timer;
static uint32_t gate_timer;
static uint32_t rfid_timer;
static uint32_t timer_gate_btn;
static uint32_t usb_keyboard_timeout;

static uint32_t response_timer;
static uint32_t last_response_time;

boolean button_pressed = false;

int usbVCC;
int usbCap = 450;

uint32_t dataSize = 8;

USB     Usb;
HIDBoot<USB_HID_PROTOCOL_KEYBOARD>    HidKeyboard(&Usb);

uint32_t next_time;

class KbdRptParser : public KeyboardReportParser
{
    void OnKeyDown  (uint8_t mod, uint8_t key);
};

void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key)
{

  uint8_t c = OemToAscii(mod, key);
  uint8_t l = strlen(idToText);

  if ((c == 10 || c == 13 || c == 19) && l > 5)
  {
    id = atoi(idToText);
    retry_cnt=0;
    state = REQUEST_CLIENT;
  }
  else if (c == '%' || c =='#')
  {
    usb_keyboard_timeout = millis();
    state = USB_ONLY;
    strcpy(idToText, "");
  }
  else
  {
    uint8_t l = strlen(idToText);
    idToText[l++] = c;
    idToText[l] = '\0';
  }
}

KbdRptParser Prs;

void setup ()
{
  pinMode(RELAY, OUTPUT);
  pinMode(RELAY_RED, OUTPUT);
  pinMode(RELAY_YELLOW, OUTPUT);
  pinMode(RELAY_GREEN, OUTPUT);
  pinMode(OPTO_GATE, INPUT);
  pinMode(OPTO_BTN, INPUT);

  pinMode(BUILTIN_LED, OUTPUT);
  digitalWrite(BUILTIN_LED, HIGH);

  pinMode(USB_RST, OUTPUT);
  digitalWrite(USB_RST, LOW);

  SPI.begin();

  Serial1.begin(9600);  // Hardware Serial SparkFun Pro Micro or serial barcode reader

  usbVCC = analogRead(USB_YES);
  if (usbVCC > usbCap)
  {
    Serial.println("USB connected");
    Serial.println(link);
  }

  init_enc();

  state = INIT;

  Serial.println("Starting USB controller");
  
  digitalWrite(USB_RST, HIGH);

  if (Usb.Init() == -1)
    Serial.println("OSC did not start.");

  delay( 200 );
  next_time = millis() + 5000;
  HidKeyboard.SetReportParser(0, (HIDReportParser*)&Prs);

}

void loop()
{
  if (statePrev != state)
  {
    printlnSerial(state);
    statePrev = state;
  }

  switch (state)
  {
    case USB_ONLY: // 10
      {
        // timer fuer check wenn keine Abbruchbedingung auftrat
        if (millis() - usb_keyboard_timeout > 2000)
        {
          state = IDLE_MAIN;
          strcpy(idToText, "");
        }
        else
        {
          Usb.Task(); // check for usb stuff happening 
        }
      }
      break;
    case INIT:
      {
        delay(200);
        ether.browseUrl(PSTR("/"), "time.php", website, cb_time);
        
        state = WAIT_TIME; // Go to state to wait for response from browseURL
        timer = millis() + TIMEOUT_MS;
      }
      break;
    case IDLE_MAIN:
      {
        Usb.Task(); // check for usb stuff happening 
        
        // just in case anything happens or the arp has to go somewhere - maybe this get's lost
        ether.packetLoop(ether.packetReceive()); 
        
        if (Serial1.available())
        {
          Serial1.readBytesUntil('\n', idToText, 15);
          uint8_t l = strlen(idToText);
          
          if (l > 5)
          {
            id = atoi(idToText);
            state = REQUEST_CLIENT;
            retry_cnt=0;
          }
        }

        if (
          !digitalRead(OPTO_BTN) &&
          !button_pressed
        ) {
          Serial.println("Button pressed");
          digitalWrite(RELAY, HIGH); // OPEN 
          delay(1);
          digitalWrite(RELAY_RED, HIGH); // through
          delay(1);
          digitalWrite(RELAY_YELLOW, HIGH); // through
          delay(1);
          digitalWrite(RELAY_GREEN, HIGH); // through
          delay(1);
          timer_gate_btn = millis() + GATE_TIMEOUT_MS;
          button_pressed = true;
        }
        else
        {
          if (
            (millis() > timer_gate_btn) && 
            button_pressed)
          {
            Serial.println("Button released");
            digitalWrite(RELAY, LOW); // timeout
            delay(1);
            digitalWrite(RELAY_RED, LOW); // through
            delay(1);
            digitalWrite(RELAY_YELLOW, LOW); // through
            delay(1);
            digitalWrite(RELAY_GREEN, LOW); // through
            delay(1);
            button_pressed = false;
          }
        }
      }
      break;

    case IDLE_FOR_RFID: //7 - basically second IDLE
      {
        ether.packetLoop(ether.packetReceive());
        
        if (!digitalRead(OPTO_GATE))
        {
          printlnSerial("OPN");
          digitalWrite(RELAY, LOW); // through
          delay(1);
          digitalWrite(RELAY_RED, LOW); // through
          delay(1);
          digitalWrite(RELAY_YELLOW, LOW); // through
          delay(1);
          digitalWrite(RELAY_GREEN, LOW); // through
          delay(1);

          state = REQUEST_RFID;
        }
        else
        {
          if (millis() > gate_timer)
          {
            printlnSerial("CLS");
            
            digitalWrite(RELAY, LOW); // through
            delay(1);
            digitalWrite(RELAY_RED, LOW); // through
            delay(1);
            digitalWrite(RELAY_YELLOW, LOW); // through
            delay(1);
            digitalWrite(RELAY_GREEN, LOW); // through
            delay(1);

            state = FREE_ETHER;
          }
        }
      }
      break;

    case REQUEST_CLIENT: //1

      {
        //while ( ether.packetLoop(ether.packetReceive()));
        // ether.packetLoop(ether.packetReceive());
        

        int fR = freeRam();
        char fRbuf[6];
        sprintf(fRbuf, "%i", fR);

        char rtbuf[11];
        sprintf(rtbuf, "%lu", last_response_time);

        // reset url char array
        strcpy(url, "");
        strcat(url, link);
        strcat(url, url_in0);
        // free Ram size
        strcat(url, url_fR);
        strcat(url, fRbuf);
        // last ressponse Time
        strcat(url, url_rT);
        strcat(url, rtbuf);
        
        strcat(url, link_id);
        strcat(url, idToText);

        usbVCC = analogRead(USB_YES);
        if (usbVCC > usbCap)
        {
          Keyboard.print('%');
          Keyboard.print(idToText);
          Keyboard.println();
        }

        response_timer = millis();
        printlnSerial(url);

        ether.browseUrl(PSTR("/"), url, website, cb_client);

        state = WAIT_CLIENT; // Go to state to wait for response from browseURL
        timer = millis() + TIMEOUT_MS; // 5 second timeout

      }
      break;

    case REQUEST_RFID: // 2
      {
        //while ( ether.packetLoop(ether.packetReceive()));
        // ether.packetLoop(ether.packetReceive());
        
        int fR = freeRam();
        char fRbuf[6];
        sprintf(fRbuf, "%i", fR);

        char rtbuf[11];
        sprintf(rtbuf, "%lu", last_response_time);

        // reset url char array
        strcpy(url, "");
        strcat(url, link);
        strcat(url, url_in1);
        // free Ram size
        strcat(url, url_fR);
        strcat(url, fRbuf);
        // last ressponse Time
        strcat(url, url_rT);
        strcat(url, rtbuf);

        strcat(url, link_id);
        strcat(url, idToText);

        printlnSerial(url);
        ether.browseUrl(PSTR("/"), url, website, cb_gate);
        
        state = WAIT_RFID;
        rfid_timer = millis() + TIMEOUT_MS;// 5 second timeout
      }
      break;

    // wait for response of gate gone through
    case WAIT_RFID: // 4
      {
        if (millis() > rfid_timer)
        {
          // timeout waiting for response
          
          printlnSerial("?ID");
          if (retry_cnt<5)
          {
            Serial.print("retry: ");
            Serial.println(retry_cnt);
            state = REQUEST_RFID;
            retry_cnt++;  
          }
          else
          {
            state = FREE_ETHER;
          }
        }
        // waiting for response from previois calback
        ether.packetLoop(ether.packetReceive());
      }
      break;

    // wait for response of customer check
    case WAIT_CLIENT: //3
      {
        if (millis() > timer)
        {
          // timeout waiting for response
          state = FREE_ETHER;
          printlnSerial("?CUS");
        }
        // waiting for response from previois calback
        ether.packetLoop(ether.packetReceive());
      }
      break;

    // wait for response of gate gone through
    case WAIT_TIME: // 9
      {

        if (millis() > timer)
        {
          // timeout waiting for response
          state = FREE_ETHER;
          printlnSerial("?TIME");
        }
        // waiting for response from previois calback
        ether.packetLoop(ether.packetReceive());
      }
      break;

    // Flush the content or at least wait for the response and just wait and reset
    case FREE_ETHER:

      {
        // waiting for response from previois calback
        // while ( ether.packetLoop(ether.packetReceive()));
        // ether.packetLoop(ether.packetReceive());
        state = IDLE_MAIN;
      }
      break;

    case FREE_ETHER_FOR_RFID:

      {
        // waiting for response from previois calback
        // while ( ether.packetLoop(ether.packetReceive()));
        // ether.packetLoop(ether.packetReceive());
        state = IDLE_FOR_RFID;
      }
      break;

    default:
      break;
  }
}

// time call back
static void cb_time (byte status, word off, word len)
{
  printlnSerial("CBTIME");
  
  Ethernet::buffer[off + 800] = 0;
  char* response = (char*) Ethernet::buffer + off;
  getResponseWithoutHeader(response, json_response);
  
  if (strtol(json_response, NULL, 0) > 0)
  {
    setTime(strtol(json_response, NULL, 0));
  }
  digitalClockDisplay();
  
  state = FREE_ETHER;

}

// called when the client request is complete
static void cb_gate (byte status, word off, word len)
{
  last_response_time = millis() - response_timer;
  printlnSerial("CBG");
  Ethernet::buffer[off + 800] = 0;
  char* response = (char*) Ethernet::buffer + off;
  getResponseWithoutHeader(response, json_response);

  if (strncmp(json_response, "OK", 2) == 0)
  {
    state = FREE_ETHER;
  }
  else
  {
    state = REQUEST_RFID;
  }
}

// called when the client request is complete
static void cb_client (byte status, word off, word len)
{
  last_response_time = millis() - response_timer;
  Ethernet::buffer[off + 800] = 0;
  char* response = (char*) Ethernet::buffer + off;

  printlnSerial("JSR");
  getResponseWithoutHeader(response, json_response);

  if (strncmp(json_response, "no school", 9) == 0)
  {
    printlnSerial("!SCL");
    state = FREE_ETHER;
  }
  else if (strncmp(json_response, "user_not_found", 14) == 0)
  {
    state = FREE_ETHER;
  }
  else if (strncmp(json_response, "user_no_ride", 12) == 0)
  {
    // red
    state = FREE_ETHER;
    printlnSerial("NOP");
  }
  else if (strtol(json_response, NULL, 0) > 0)
  {
    uint32_t timeForId = strtol(json_response, NULL, 0) + now();
      // green
    printlnSerial("THR");
    digitalWrite(RELAY, HIGH);
    delay(1);
    digitalWrite(RELAY_RED, HIGH); // through
    delay(1);
    digitalWrite(RELAY_YELLOW, HIGH); // through
    delay(1);
    digitalWrite(RELAY_GREEN, HIGH); // through
    delay(1);
  
    gate_timer = millis() + GATE_TIMEOUT_MS;
    state = FREE_ETHER_FOR_RFID;
  }
  else if (strtol(json_response, NULL, 0) < 0)
  {
    // red
    state = FREE_ETHER;
    printlnSerial("EXP");
  }
  else
  {
    state = REQUEST_CLIENT;
    printlnSerial(json_response);
  }
}

int freeRam ()
{
  extern int __heap_start, *__brkval;
  int v;
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}

void init_enc ()
{
  Serial.println("init ethernet");
  if (ether.begin(sizeof Ethernet::buffer, mymac, ENC_SS) == 0)
  {
    printlnSerial("!ENC");
    init_enc();
    return;
  }
  if (!ether.dhcpSetup())
  {
    printlnSerial("!DHC");
    init_enc();
    return;
  }

  ether.printIp("IP:  ", ether.myip);
  ether.printIp("GW:  ", ether.gwip);
  ether.printIp("DNS: ", ether.dnsip);

  if (!ether.dnsLookup(website))
  {
    printlnSerial("!DNS");
    init_enc();
    return;
  }
  ether.printIp("SRV: ", ether.hisip);
}

void getResponseWithoutHeader(char* response, char* new_response)
{

  strcpy(new_response, "");

  char * pch;
  pch = strstr (response, "\r\n\r\n");

  int length = 15;
  if (strlen(pch + 4) < 15)
  {
    length = strlen(pch + 4);
  }

  printlnSerial(pch + 4);

  strncpy (new_response, pch + 4, length);
  // strcat(new_response, '\0');
}

void printlnSerial(char const a[])
{
  usbVCC = analogRead(USB_YES);
  if (usbVCC > usbCap)
  {
    Serial.println(a);
  }
}

void printlnSerial(char *a)
{
  usbVCC = analogRead(USB_YES);
  if (usbVCC > usbCap)
  {
    Serial.println(a);
  }
}

void printlnSerial(int a)
{
  usbVCC = analogRead(USB_YES);
  if (usbVCC > usbCap)
  {
    Serial.println(a);
  }
}

void digitalClockDisplay() {
  // digital clock display of the time
  Serial.println(millis());
  Serial.print(year());
  Serial.print("-");
  printDigits(month());
  Serial.print("-");
  printDigits(day());
  Serial.print(" ");
  printDigits(hour());
  Serial.print(":");
  printDigits(minute());
  Serial.print(":");
  printDigits(second());
  Serial.println();
}

void printDigits(int digits) {
  if (digits < 10) Serial.print('0');
  Serial.print(digits);
}

Here's a screenshot of a successful Verify using all the latest versions of all the software.

sc.png
 
I'm sorry about the missing information and thank you very much for trying this. The truth is, I just copied it a long time ago and never thought about versions and can't find what version I used. I had hopes that the "USB init" would be indicating something more obvious.

I should refresh before posting - Paul, thank you very much!
 
Last edited:
Status
Not open for further replies.
Back
Top