Go Down

Topic: No class definition in Usb.h, how to pass a uart* pointer to Usb.cpp? (Read 119 times) previous topic - next topic

boggydew

Hi

I'm trying to debug some library code on the zero with Serial1. Usually when I do this I declare
HardwareSerial * mySerial; as a private variable in the class definition (usually found in the .h file).

Then I pass a pointer in my sketch, such as  myUSBHostObject.init(&Serial1) or some such, then modify the .cpp code like USBHost::init(HardwareSerial * serial){ mySerial = serial}. Then I can print to serial monitor with mySerial->println();

I can't seem to do this with the USBHost class because I can't find a class definition in the .h file.
ref: https://github.com/gdsports/USB_Host_Library_SAMD/blob/master/src/Usb.h
ref: https://github.com/gdsports/USB_Host_Library_SAMD/blob/master/src/Usb.cpp

This is the entire Usb.h file
Code: [Select]
#ifndef USB_H_INCLUDED
#define USB_H_INCLUDED
#define _usb_h_

#include <stdint.h>

// Uncomment to enable debug
//#define DEBUG_USB_HOST 1

////////////////////////////////////////////////////////////////////////////////
// MASS STORAGE
////////////////////////////////////////////////////////////////////////////////
// <<<<<<<<<<<<<<<< IMPORTANT >>>>>>>>>>>>>>>
// Set this to 1 to support single LUN devices, and save RAM. -- I.E. thumb drives.
// Each LUN needs ~13 bytes to be able to track the state of each unit.
#ifndef MASS_MAX_SUPPORTED_LUN
#define MASS_MAX_SUPPORTED_LUN  1 ///// 8  WHG
#endif

//#include "Arduino.h"
#include "macros.h"
// None of these should ever be included by a driver, or a user's sketch.

#include "variant.h"
#define USB_HOST_SERIAL SERIAL_PORT_MONITOR
#include "Print.h"
#include "printhex.h"
#include "message.h"
#include "hexdump.h"
#include "sink_parser.h"

#include "address.h"

#include "usb_ch9.h"
//#include "usbhost.h"
#include "UsbCore.h"
#include "parsetools.h"

#include "confdescparser.h"

#endif /* USB_H_INCLUDED */




Here is the the constructor from the .cpp
Code: [Select]
#include <stdio.h>
#include "Arduino.h"
#include "Usb.h"


//#ifdef ARDUINO_SAMD_ZERO

static uint32_t usb_error = 0;
static uint32_t usb_task_state = USB_DETACHED_SUBSTATE_INITIALIZE;

/* constructor */
USBHost::USBHost() : bmHubPre(0) {
    // Set up state machine
    usb_task_state = USB_DETACHED_SUBSTATE_INITIALIZE; //set up state machine
}

/* Initialize data structures */
uint32_t USBHost::Init() {
    //devConfigIndex = 0;
    // Init host stack

    bmHubPre = 0;
    UHD_Init();
    return 0;
}





pylon



gfvalvo

Usually when I do this I declare
HardwareSerial * mySerial; as a private variable in the class definition (usually found in the .h file).

Then I pass a pointer in my sketch, such as  myUSBHostObject.init(&Serial1) or some such, then modify the .cpp code like USBHost::init(HardwareSerial * serial){ mySerial = serial}. Then I can print to serial monitor with mySerial->println();
That's a perfect application for Polymorphism. Pass a pointer to a object of the Stream class. Or, if you're only printing to it (and not also reading from it), pass a pointer to an object of the Print class. Then, your code will work with ANY object that inherits from those classes.
No technical questions via PM. They will be ignored. Post your questions in the forum so that all may learn.

Go Up