Creating a Library ... no joy

Yep, its me again. This time I am trying to create a library but I have thus far been less that triumphant.
I have been over the two tutorials a dozen times (at least). I have used GOOGLE to search for help.
I have looked at the libraries that come with the Arduino IDE. Still lacking joy :frowning:

This is the header file with the errors embedded as comments.

// Reference: http://arduino.cc/en/Hacking/LibraryTutorial
// Reference: http://playground.arduino.cc/Code/Library
// http://n0m1.com/2012/05/17/writing-your-own-arduino-libraries/
// http://learn.adafruit.com/arduino-tips-tricks-and-techniques/arduino-libraries  (no help)
// http://stackoverflow.com/questions/13169714/creating-a-library-for-an-arduino
// http://arduino.cc/en/Reference/APIStyleGuide

#ifndef HEXDECASC
#define HEXDECASC
#include "Arduino.h"

 
class HexDecAsc 
{  
    Public: 
	byte hexDigit(byte n);
	  /* In file included from Develope_HexDec.ino:1:
         <user home>\Documents\Arduino\libraries\HexDecAsc/HexDecAsc.h:16: 
		     error: expected primary-expression before 'hexDigit'
         <user home>\Documents\Arduino\libraries\HexDecAsc/HexDecAsc.h:16: 
		     error: ISO C++ forbids declaration of 'Public' with no type
         <user home>\Documents\Arduino\libraries\HexDecAsc/HexDecAsc.h:16: 
		     error: expected ';' before 'hexDigit'

      */
	  
	  char asciiCode(byte n);
	  
	  char *formatByteAsHex(byte n, char tmp[]);
	  char *formatByteAsHex(char tmp[] );
	  
	  char *formatWordAsHex(word w, char tmp[]);
	  char *formatWordAsHex(char tmp[]);
	  
	  char *formatWordAsDec(word n, char tmp[]);
	  char *formatWordAsDec(char tmp[]);  
	  
	  char *formatRamDump(char hd, word addr, char data[], char buffer[]);
	  char *formatRamDump(word addr, char data[], char buffer[]);
	  char *formatRamDump(word addr,char buffer[]);
  Private:
}
      /*
         <user home>\Documents\Arduino\libraries\HexDecAsc/HexDecAsc.h:42: 
		     error: expected primary-expression before '}' token
         <user home>\Documents\Arduino\libraries\HexDecAsc/HexDecAsc.h:42: 
		     error: ISO C++ forbids declaration of 'Private' with no type
         <user home>\Documents\Arduino\libraries\HexDecAsc/HexDecAsc.h:42: 
		     error: expected ';' before '}' token
         <user home>\Documents\Arduino\libraries\HexDecAsc/HexDecAsc.h:42: 
	  	     error: expected `;' before '}' token
      */
#endif // end define HEXDECASC

/*
   In file included from Develope_HexDec.ino:11:
   <app pth>\Arduino\libraries\EEPROM/EEPROM.h:30: 
      error: multiple types in one declaration
*/

Attached are two ZIP files.
The first file is “This_Works.zip”. It contains the prototype program divided into three INO files.
Develope_HexDec.ino (contains startup() and loop() function)
Examples.ino (contains example/demo/test routines)
HexDecAsc.ino (contains functions for the library)

The second file is “Lib_no_Joy.zip”. It contains the library files.
HexDecAsc.cpp (source code)
HexDecAsc.h (header file)
keywords.txt (library keywords)
Develope_HexDec.ino (updated source that ‘#includes <HexDecAsc.h>’)
Examples.ino (update examples with HexDecAsc class names use for function calls)

From researching the error messages on the internet I am thinking the problem may have something to do with ‘namespace’ (or lack of it).
There are additional errors when compiling (mostly about undefined functions, and a few about multiple definitions of functions).
I will change the example code to use the clas functions AFTER I get the library to compile.

I have tried so many variations that I can not remember most of them but they have involved things using the keywords static, virtual, vector, namespace …
I have tried commenting out the first declaration for “hexDigit” … it falls through to the declaration for “asciiCode” and fails on it.

This_Works.zip (5.16 KB)

Lib_No_Joy.zip (5.92 KB)

Just from looking at what you posted, public and private should not be capitalized. I'll look over the rest of the code and see what else could be a possible error, but for now, fix those.

HazardsMind:
Just from looking at what you posted, public and private should not be capitalized. I'll look over the rest of the code and see what else could be a possible error, but for now, fix those.

da.... that was it.
does not seem related to the error messages though.
Thank you ... now to fix the other errors.

This one is really strange because it comes from a system library:

C:\Program Files (x86)\Arduino\libraries\EEPROM/EEPROM.h:30: error: multiple types in one declaration

25: class EEPROMClass
26: {
27: public:
28: uint8_t read(int);
29: void write(int, uint8_t);
30: };

maybe it will go away when I have the other problems resolved ...

From you code

// — example nine — (EEPROMDump)
void EEPROMDump()
{ char buffer[60];
word addr=0;
Serial.println(“EEPROM Dump:”);
while (addr < E2END)
{ for (byte i=0; i<16; i++)
{ buffer_=EEPROM.read(addr++);[/quote]_
From actual library
> 25: class EEPROMClass
> 26: {
> 27: public:
> 28: uint8_t read(int);
> 29: void write(int, uint8_t);
> 30: };
Your passing in a word when the library is calling for an int. You can use a cast and change buffer_=EEPROM.read(addr++); [/color] to buffer*=EEPROM.read((int)addr++);[/color]*_

HazardsMind:
Your passing in a word when the library is calling for an int. You can use a cast and change buffer_=EEPROM.read(addr++); [/color] to buffer*=EEPROM.read((int)addr++);[/color]_
_
[/quote]_
That problem went away when I moved the include for EEPROM lib above the include for my HexDecAsc.
I am not sure what a ‘unit8_t’ is but I am guessing ‘unsigned Integer, 8 bits’ ?
word, int, unsigned Integer are all two bytes.
Thanks for pointing it out: I changed the code to use unsigned int.
Still unable to get the library to compile but it is no longer generating an error for either of the library files.
It is bombing out before it compile the library though before the errors I am getting tell me that HexDecAsc is not a proper class name.
The error that is most confusing is the one that tells me that I might be missing a semicolon after the definition of HexDecAsc.
I tried putting semicolons in numerous places to no avail.
_
*_ <em>*Develope_HexDec:15: error: new types may not be defined in a return type Develope_HexDec.ino:15: note: (perhaps a semicolon is missing after the definition of 'HexDecAsc') Develope_HexDec:15: error: two or more data types in declaration of 'setup' Examples.ino: In function 'void PrintASCIItable()': Examples:47: error: expected unqualified-id before '.' token Examples.ino: In function 'void PrintHexByteOne()': Examples:60: error: expected primary-expression before '.' token ...*</em> _**_
I have updated the files in the first message with the current edit library files and INO files that call the library.

uint8_t is indeed 8 bits unsigned an ALL Arduino type boards. unsigned int is 16 bits on the 8 bit boards but 32 bits on the newer 32bit boards (like DUE)

@nicoverduin
Thank you nic

This whole process of creating a class library to include a couple of reusable functions seems overly complicated to me.
I found some other code where someone just buried the functions in the header file under empty declarations.

#ifndef HEXDECASC
#define HEXDECASC
#include "Arduino.h"

byte hexDigit();
char asciiCode();
char *formatByteAsHex();
char *formatWordAsHex();
char *formatWordAsDec();
char *formatRamDump();

function ...
....
function ...

#endif

That works perfectly and is a whole lot less work but probably not the proper way to do things.

I will leave creating a proper class library for another day.

HexDecAsc.h (6.71 KB)