First time building a library, compile issues
i working graphical lcd has large number of serial commands different functions.
in attempt clean workflow , simplify code have attempted build library, unfortunatly without success. have followed stock tutorial , compared against other libraries have downloaded yet cannot mine function.
as secondary question, have alternative arduino ide allow me edit these c based files highlighting, compiling , downloading arduino programs.
program file:
compiler report:
in file included sketch_apr09a.cpp:1:
c:\users\apothus\documents\arduino\libraries\lcd/lcd.h:15: error: expected unqualified-id before ')' token
sketch_apr09a:0: error: new types may not defined in return type
sketch_apr09a.cpp:4: note: (perhaps semicolon missing after definition of '<anonymous class>')
sketch_apr09a:0: error: 2 or more data types in declaration of 'setup'
sketch_apr09a:2: error: expected constructor, destructor, or type conversion before ';' token
header file lcd.h:
source file lcd.cpp
any advice on code appreciated. has been long time since have written librarys or header files. unclear on case requirements arduino, know c can little sensitive case @ times.
in attempt clean workflow , simplify code have attempted build library, unfortunatly without success. have followed stock tutorial , compared against other libraries have downloaded yet cannot mine function.
as secondary question, have alternative arduino ide allow me edit these c based files highlighting, compiling , downloading arduino programs.
program file:
code: [select]
#include <lcd.h>
lcd lcdlib()
void setup(){
}
void loop(){
}
compiler report:
in file included sketch_apr09a.cpp:1:
c:\users\apothus\documents\arduino\libraries\lcd/lcd.h:15: error: expected unqualified-id before ')' token
sketch_apr09a:0: error: new types may not defined in return type
sketch_apr09a.cpp:4: note: (perhaps semicolon missing after definition of '<anonymous class>')
sketch_apr09a:0: error: 2 or more data types in declaration of 'setup'
sketch_apr09a:2: error: expected constructor, destructor, or type conversion before ';' token
header file lcd.h:
code: [select]
//library header simple serial code.
#ifndef lcd
#define lcd
//attached libraries
#include "arduino.h"
class lcd
{
public:
lcd();
void clr();
int backlight(int level);
int circle(int x, int y, int radius, int set);
void crlftog();
void reset();
void fonttgl();
int fontmode(int mode);
int line(int xone, int yone, int xtwo, int ytwo, int setr);
int box(int xone, int yone, int xtwo, int ytwo, int setr);
int fbox(int xone, int yone, int xtwo, int ytwo, int setr);
int pixel(int x, int y, int setr);
void reverse();
void setx(int x);
void sety(int y);
private:
int coord(int xone, int yone, int xtwo, int ytwo, int setr);
void cmd();
}
#endif
source file lcd.cpp
code: [select]
// libarary source simple serial code
#include "arduino.h"
#include "lcd.h"
lcd::lcd()
{
//empty construct
}
void lcd::clr()
{
lcd.cmd(); //calls subroutine cmd, unsure if work though
serial.write((byte)0x00);
}
int lcd::backlight(int level)
{
int ok = 0;
if( level >=0 && level <=64){ //hexadecmial check
lcd.cmd();
serial.write((byte)0x02);
serial.write((byte)level);
ok = 1;
}
return ok;
}
int lcd::circle(int x, int y, int radius, int set) //draw circle on screen @ point x,y radius
{
int ok = 0;
if( x>=0 && x<= 0x7f){ // x error check, 0 if fail
if( y >= 0 && y <= 0x3f){ // y error check, 1 if fail
if( radius > 0 && radius <= 0x7f){ // radius error check, 2 if fail
if( set < 2){ // set error check, 3 if fail, 4 if ok
lcd.cmd();
ok = 4;
serial.write((byte)0x03);
serial.write((byte)x);
serial.write((byte)y);
serial.write((byte)radius);
serial.write((byte)set);
}
else{
ok = 3;
}
}
else{
ok = 2;
}
}
else{
ok = 1;
}
}
return ok;
}
void lcd::crlftog() // toggle automatic carridge return , line feed
{
lcd.cmd();
serial.write((byte)0x04);
}
void lcd::reset() //clear display , reset x&y offsets
{
lcd.cmd();
serial.write((byte)0x06);
}
void lcd::fonttgl() //toggle between primary , alternate font
{
lcd.cmd();
serial.write((byte)0x08);
}
int lcd::fontmode(int mode) //font draw mode setting
{
int ok = 0;
if( mode >= 0 && mode <= 7){
ok = 1;
cmd();
serial.write((byte)0x0a);
serial.write((byte)mode);
}
return ok;
}
int lcd::line(int xone, int yone, int xtwo, int ytwo, int setr) //draws line using cartesian co-ords
{
int ok = 0;
if(coord(xone, yone, xtwo, ytwo, setr) == 1){
ok = 1;
cmd();
serial.write((byte)0x0c);
serial.write((byte)xone);
serial.write((byte)yone);
serial.write((byte)xtwo);
serial.write((byte)ytwo);
serial.write((byte)setr);
}
return ok;
}
int lcd::box(int xone, int yone, int xtwo, int ytwo, int setr) //draws box, others
{
int ok = 0;
if(lcd.coord(xone, yone, xtwo, ytwo, setr) == 1){ //check if valid inputs coord routine
ok = 1;
cmd();
serial.write((byte)0x0f);
serial.write((byte)xone);
serial.write((byte)yone);
serial.write((byte)xtwo);
serial.write((byte)ytwo);
serial.write((byte)setr);
}
return ok;
}
int lcd::fbox(int xone, int yone, int xtwo, int ytwo, int setr) //draws filled in box
{
int ok = 0;
if(lcd.coord(xone, yone, xtwo, ytwo, setr) == 1){ //check if valid inputs coord routine
ok = 1;
lcd.cmd();
serial.write((byte)0x12);
serial.write((byte)xone);
serial.write((byte)yone);
serial.write((byte)xtwo);
serial.write((byte)ytwo);
serial.write((byte)setr);
}
return ok;
}
int lcd::pixel(int x, int y, int setr) //draw or clear specific pixel
{
int ok = 0;
if( x >= 0 && x <= 0x7f){
if( y>= 0 && y <= 0x3f){
if( setr ==0 | setr == 1){
ok = 1;
lcd.cmd();
serial.write((byte)0x10);
serial.write((byte)x);
serial.write((byte)y);
serial.write((byte)setr);
}
}
}
return ok;
}
void lcd::reverse() //inverts display
{
lcd.cmd();
serial.write((byte)0x14);
}
void lcd::setx(int x) //set x offset
{
if( x>= 0 && x<=0x7f){
lcd.cmd();
serial.write((byte)0x18);
serial.write((byte)x);
}
}
void lcd::sety(int y) //set y offset
{
if( y>= 0 && y<= 0x7f){
lcd.cmd();
serial.write((byte)0x19);
serial.write((byte)y);
}
}
void lcd::cmd() //writes command prefix lcd, preceeds command functions
{
serial.write((byte)0x7c);
}
int lcd::coord(int xone, int yone, int xtwo, int ytwo, int ster) // tests if value passed in range
{
int ok = 0;
if( xone >= 0 && xone <= 0x7f){
if( xtwo >= 0 && xtwo <= 0x7f){
if( yone >= 0 && yone <= 0x3f){
if( ytwo >= 0 && ytwo <= 0x3f){
if( setr == 0 | setr == 1 ){
ok = 1;
}
}
}
}
}
return ok;
}
any advice on code appreciated. has been long time since have written librarys or header files. unclear on case requirements arduino, know c can little sensitive case @ times.
Arduino Forum > Using Arduino > Programming Questions > First time building a library, compile issues
arduino
Comments
Post a Comment