#ifndef _PLATFORM_H
#define _PLATFORM_H
#if defined(PC)
#if defined(SENDTOEMULATOR) || defined(SENDTOEMULATORMSGS)
#include <winsock.h>
#endif
#define ERRORPIN 8
#define PROGRESSPIN 9
#elif defined(RASPBERRY)
#include <stdint.h>
#include <stdlib.h>
#include <sys/time.h>
#define TRUE 1
#define FALSE 0
#define ERRORPIN 8
#define PROGRESSPIN 9
#else
#define ERRORPIN 11
#define PROGRESSPIN 13
#define DEBUG1 24
#define DEBUG2 22
#endif
#define MSG_CRITICAL 0
#define MSG_IMPORTANT 1
#define MSG_SUMMARY 2
#define MSG_DETAIL 3
#define MSG_SUPERDETAIL 4
// Base class for all platforms
class Platform
{
public:
virtual void InitialisePins() = 0;
//virtual void WritePinAndSendToEmulator(byte pin, byte value);
virtual void WritePin(byte pin, byte value) = 0;
virtual void SendToEmulator(byte pin, byte value) = 0;
virtual void SendToEmulator(byte value) = 0;
virtual void SendToEmulator(const char* msg) = 0;
virtual void SendStartToEmulator() = 0;
virtual void WriteParallel(byte b) = 0;
#ifdef MINMEMORY
virtual void WriteMessage(const char* message) = 0;
#else
virtual void WriteMessage(const char* message, ...) = 0;
#endif
virtual unsigned DelayUntil(unsigned until) = 0;
virtual void Delay(unsigned long millisecs) = 0;
virtual void DelayMicroseconds(unsigned long microsecs) = 0;
virtual void Randomise() = 0;
virtual void Error(byte err);
#ifdef INCLUDE_DEBUG_PATTERNS
virtual bool ReadPin(byte pin) = 0;
#endif
#if defined(PC) || defined(RASPBERRY)
Platform() {};
#endif
};
#ifdef PC
// PC Platform
class Win32 : public Platform
{
#if defined(SENDTOEMULATOR) || defined(SENDTOEMULATORMSGS)
SOCKET _sClient;
char _addr[20];
void ConnectTCPIP();
#endif
public:
void InitialisePins();
void WritePin(byte pin, byte value);
void SendToEmulator(byte pin, byte value);
void SendToEmulator(byte value);
void SendToEmulator(const char* msg);
void SendStartToEmulator();
void WriteParallel(byte b);
#ifdef MINMEMORY
void WriteMessage(const char* message);
#else
void WriteMessage(const char* message, ...);
#endif
void Delay(unsigned long millisecs);
void DelayMicroseconds(unsigned long microsecs);
unsigned DelayUntil(unsigned until) { return 0; };
void Randomise();
Win32();
};
#elif defined(RASPBERRY)
// Raspberry Platform
class Raspberry : public Platform
{
protected:
volatile uint32_t *gpio;
volatile uint32_t *timer;
#ifdef USEINTERRUPT
volatile uint32_t *timerIrqRaw;
#endif
#if defined(SENDTOEMULATOR) || defined(SENDTOEMULATORMSGS)
int sockfd;
char _addr[20];
#endif
void MapController(volatile uint32_t** controller, off_t offset);
void pinMode(int pin, int mode);
void pullUpDnControl(int pin, int pud);
uint32_t GetSet(byte b, int pin);
uint32_t GetClr(byte b, int pin);
void ConnectTCPIP();
public:
void InitialisePins();
void WritePin(byte pin, byte value);
void SendToEmulator(byte pin, byte value);
void SendToEmulator(byte value);
void SendToEmulator(const char* msg);
void SendStartToEmulator();
void WriteParallel(byte b);
#ifdef MINMEMORY
void WriteMessage(const char* message);
#else
void WriteMessage(const char* message, ...);
#endif
void Delay(unsigned long millisecs);
void DelayMicroseconds(unsigned long microsecs);
unsigned DelayUntil(unsigned until);
void Randomise();
Raspberry();
};
#else
// Arduino Platform
class Arduino : public Platform
{
//byte lastByte; // records the last values sent to each string
int freeRam();
public:
void InitialisePins();
void WritePin(byte pin, byte value);
#ifdef INCLUDE_DEBUG_PATTERNS
bool ReadPin(byte pin);
#endif
void SendToEmulator(byte pin, byte value);
void SendToEmulator(byte value);
void SendToEmulator(const char* msg);
void SendStartToEmulator();
void WriteParallel(byte b);
#ifdef MINMEMORY
void WriteMessage(const char* message);
#else
void WriteMessage(const char* message, ...);
#endif
void Delay(unsigned long millisecs);
void DelayMicroseconds(unsigned long microsecs);
unsigned DelayUntil(unsigned until) { return 0; };
void Randomise();
//Arduino() {};
};
#endif
extern Platform* _platform;
#endif // _PLATFORM_H