Got it now! its working with extern placed but i have tested compiling not real LCD play but then if it compiles it will 99% work as needed so more or less it seems the things are fine! thanks to extensive knowledge pool of your;s Mr.Paul.
I'm getting things compiled finely! BUT whatever i put in the .cpp file to print is not getting printing only the Arduino PDE file LCD prints are working, Below is the code:
PDE file:
#include <avr/pgmspace.h>
#include <avrpins.h>
#include <max3421e.h>
#include <usbhost.h>
#include <usb_ch9.h>
#include <Usb.h>
#include <usbhub.h>
#include <avr/pgmspace.h>
#include <address.h>
#include <hid.h>
#include <hiduniversal.h>
#include "hidjoystickrptparser.h"
#include <printhex.h>
#include <message.h>
#include <hexdump.h>
#include <parsetools.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(6,8,5,4,3,2);
USB Usb;
USBHub Hub(&Usb);
HIDUniversal Hid(&Usb);
JoystickEvents JoyEvents;
JoystickReportParser Joy(&JoyEvents);
void setup()
{
Serial.begin(9600);
lcd.begin(20, 4);
Serial.println("Start");
lcd.clear();
lcd.print("Start");
if (Usb.Init() == -1) {
lcd.print(" - OSC did not Start");
Serial.println("OSC did not start.");
}
delay( 200 );
if (!Hid.SetReportParser(0, &Joy))
ErrorMessage<uint8_t>(PSTR("SetReportParser"), 1 );
}
void loop()
{
Usb.Task();
}
.cpp file from which i want the LCD prints to work:
#include "hidjoystickrptparser.h"
#include <LiquidCrystal.h>
extern LiquidCrystal lcd;
JoystickReportParser::JoystickReportParser(JoystickEvents *evt) :
joyEvents(evt),
oldHat(0xDE),
oldButtons(0)
{
for (uint8_t i=0; i<RPT_GEMEPAD_LEN; i++)
oldPad[i] = 0xD;
}
void JoystickReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
{
bool match = true;
// Checking if there are changes in report since the method was last called
for (uint8_t i=0; i<RPT_GEMEPAD_LEN; i++)
if (buf[i] != oldPad[i])
{
match = false;
break;
}
// Calling Game Pad event handler
if (!match && joyEvents)
{
joyEvents->OnGamePadChanged((const GamePadEventData*)buf);
for (uint8_t i=0; i<RPT_GEMEPAD_LEN; i++) oldPad[i] = buf[i];
}
uint8_t hat = (buf[5] & 0xF);
// Calling Hat Switch event handler
if (hat != oldHat && joyEvents)
{
joyEvents->OnHatSwitch(hat);
oldHat = hat;
}
uint16_t buttons = (0x0000 | buf[6]);
buttons <<= 4;
buttons |= (buf[5] >> 4);
uint16_t changes = (buttons ^ oldButtons);
// Calling Button Event Handler for every button changed
if (changes)
{
for (uint8_t i=0; i<0x0C; i++)
{
uint16_t mask = (0x0001 << i);
if (((mask & changes) > 0) && joyEvents)
if ((buttons & mask) > 0)
joyEvents->OnButtonDn(i+1);
else
joyEvents->OnButtonUp(i+1);
}
oldButtons = buttons;
}
}
void JoystickEvents::OnGamePadChanged(const GamePadEventData *evt)
{
Serial.print("X: ");
PrintHex<uint8_t>(evt->X);
Serial.print(",");
Serial.println(evt->X, DEC);
Serial.print("\tY: ");
PrintHex<uint8_t>(evt->Y);
Serial.print(",");
Serial.println(evt->Y, DEC);
Serial.print("\tZ: ");
PrintHex<uint8_t>(evt->Z1);
Serial.print(",");
Serial.println(evt->Z1, DEC);
Serial.print("\tZ: ");
PrintHex<uint8_t>(evt->Z2);
Serial.print(",");
Serial.println(evt->Z2, DEC);
Serial.print("\tRz: ");
PrintHex<uint8_t>(evt->Rz);
Serial.print(",");
Serial.println(evt->Rz, DEC);
Serial.println("");
}
void JoystickEvents::OnHatSwitch(uint8_t hat)
{
Serial.print("Hat Switch: ");
lcd.begin(20, 4);
lcd.print(hat, DEC);
Serial.println(hat, DEC);
}
void JoystickEvents::OnButtonUp(uint8_t but_id)
{
Serial.print("Up: ");
Serial.println(but_id, DEC);
}
void JoystickEvents::OnButtonDn(uint8_t but_id)
{
Serial.print("Dn: ");
Serial.println(but_id, DEC);
}
.H header file remains unchanged!
Remedy?
void JoystickEvents::OnHatSwitch(uint8_t hat)
{
Serial.print("Hat Switch: ");
lcd.begin(20, 4);
lcd.print(hat, DEC);
Serial.println(hat, DEC);
}
Why are you calling lcd.begin() here? You've already called lcd.begin() in setup() in the sketch.
Why are you calling lcd.begin() here? You've already called lcd.begin() in setup() in the sketch.
Thought the way we are re instantiating stuff in .cpp file in the same way i need to to this again, Even with it nothing happens now just removed it.
Any Whereabouts? of why LCD prints aren't happening in the .cpp file?
You didn't position LCD cursor so how do you expect to see th print out?
You didn't position LCD cursor so how do you expect to see th print out?
Im doing it but is it not suppose to for default print on the first row and 1 column as be do just lcd.print in the hello world programme wihtout setting the cursor?
Default print starts the printing at whatever last position of the cursor is. You need to position the cursor to where you want to print before you print.
I did that but on the whole nothing shows up on the screen now at all.
I got the problem i think , The case is that the reset from the arduino is linked to the 7th pin of the USB shield(which is also connected to arduino inturn offcourse) to make this shield work and now the case is that LCD doesnot show anything/anychanges or even not working only when i try to use it along with the USB host shield , so now i need a remedy for this.
Is their any working out suggested here?
Regards--
Nishant