Hi.
I've just started trying to make my code into a library instead, as that would be easier.
The only problem is, that the code uses the NewSoftSerial library, and I don't know if it's possible for a library to include and use another library!
But anyways, I'm getting alot of errors when i start Arduino (it compiles the new library)
So here is my GPU.h file:
/*
GPU.h - Library for Serial GPU.
Created by Thomas Jespersen, May 8, 2009.
Released into the public domain.
*/
#ifndef GPU_h
#define GPU_h
#include "WConstants.h"
class GPU
{
public:
GPU(int ser1, int ser2, int ledPin);
void Transmit(byte msg);
void ClearTV();
void ChangeType(char type);
void WriteChar(char x, char y, char chr);
void WriteText(char x, char y, char str[])
void Pixel(char x, char y)
private:
int _ledPin;
};
#endif
And here is my GPU.cpp file:
/*
GPU.h - Library for Serial GPU.
Created by Thomas Jespersen, May 8, 2009.
Released into the public domain.
*/
#include "WProgram.h"
#include "GPU.h"
#include <NewSoftSerial.h>
GPU::GPU(int ser1, int ser2, int ledPin)
{
NewSoftSerial GPU(ser1,ser2);
GPU.begin(9600);
pinMode(ledPin, OUTPUT);
_ledPin = ledPin;
}
void GPU::Transmit(byte msg)
{
byte cnt = 0;
GPU.print(msg, BYTE);
while (true) {
if (GPU.available() > 0) {
incoming = GPU.read();
if (incoming == msg) {
break;
}
}
cnt++;
if (cnt >= 10) {
GPU.print(msg, BYTE);
cnt = 0;
}
delay(1); //Delay to wait for response
}
}
void GPU::ClearTV()
{
//Send "Clear Screen" command
digitalWrite(_ledPin, HIGH); // sets the LED on
Transmit(255);
digitalWrite(_ledPin, LOW); // sets the LED on
while (true) {
if (GPU.available() > 0) {
incoming = GPU.read();
if (incoming == 11) {
break;
}
}
}
}
void GPU::ChangeType(char type)
{
//Send "Clear Screen" command
digitalWrite(_ledPin, HIGH); // sets the LED on
Transmit(254);
digitalWrite(_ledPin, LOW); // sets the LED on
digitalWrite(_ledPin, HIGH); // sets the LED on
Transmit(type);
digitalWrite(_ledPin, LOW); // sets the LED on
while (true) {
if (GPU.available() > 0) {
incoming = GPU.read();
if (incoming == 11) {
break;
}
}
}
}
void GPU::WriteChar(char x, char y, char chr)
{
digitalWrite(_ledPin, HIGH); // sets the LED on
Transmit(x); // X
digitalWrite(_ledPin, LOW); // sets the LED on
digitalWrite(_ledPin, HIGH); // sets the LED on
Transmit(y); // Y
digitalWrite(_ledPin, LOW); // sets the LED on
digitalWrite(_ledPin, HIGH); // sets the LED on
Transmit(chr);
digitalWrite(_ledPin, LOW); // sets the LED on
digitalWrite(_ledPin, HIGH); // sets the LED on
Transmit(13);
digitalWrite(_ledPin, LOW); // sets the LED on
while (true) {
if (GPU.available() > 0) {
incoming = GPU.read();
if (incoming == 11) {
break;
}
}
}
}
void GPU::WriteText(char x, char y, char str[])
{
int i;
digitalWrite(_ledPin, HIGH); // sets the LED on
Transmit(x); // X
digitalWrite(_ledPin, LOW); // sets the LED on
digitalWrite(_ledPin, HIGH); // sets the LED on
Transmit(y); // Y
digitalWrite(_ledPin, LOW); // sets the LED on
for (i = 0; i <= strlen(str); i++) {
digitalWrite(_ledPin, HIGH); // sets the LED on
Transmit(str[i]);
digitalWrite(_ledPin, LOW); // sets the LED on
}
digitalWrite(_ledPin, HIGH); // sets the LED on
Transmit(13);
digitalWrite(_ledPin, LOW); // sets the LED on
while (true) {
if (GPU.available() > 0) {
incoming = GPU.read();
if (incoming == 11) {
break;
}
}
}
}
void GPU::Pixel(char x, char y)
{
int i;
digitalWrite(_ledPin, HIGH); // sets the LED on
Transmit(x); // X
digitalWrite(_ledPin, LOW); // sets the LED on
digitalWrite(_ledPin, HIGH); // sets the LED on
Transmit(y); // Y
digitalWrite(_ledPin, LOW); // sets the LED on
digitalWrite(_ledPin, HIGH); // sets the LED on
Transmit(13);
digitalWrite(_ledPin, LOW); // sets the LED on
while (true) {
if (GPU.available() > 0) {
incoming = GPU.read();
if (incoming == 11) {
break;
}
}
}
}