Andriy Makukha / Mbed 2 deprecated football_project_wo_output

Dependencies:   mbed

Fork of football_project by MZJ

TA.h

Committer:
AntonLS
Date:
2016-01-16
Revision:
54:2878d62714d6
Parent:
52:060fdec99780
Child:
67:5650f461722a

File content as of revision 54:2878d62714d6:

#ifndef TA_H
#define TA_H

#include <mbed.h>

#include "ByteBuffer.h"
#include "neopixel.h"

#define DATA_SIZE 24

#define MAX_LEN   24  // buffer input commands up to this length

#define SILENT 0x20

#define TOUCHLIGHTS  0x7                                      /* We'll use bit 2 for the power button */
#define DEFTOUCHMASK (TOUCHLIGHTS & (6 | 1 /* test/bott */))  /* Note:  No longer using "bottom" touch sensor/lights */
#define DIS_ON_DARK 0x40                                      /* Used for disabling touch sensor(s) when in dark mode */

struct Message 
{
    char command;
    uint32_t value;
    uint8_t cone;
};

class TA
{
private:
// You will need to initialize the radio by telling it what ID it has and what network it's on
// The NodeID takes values from 1-127, 0 is reserved for sending broadcast messages (send to all nodes)
// The Network ID takes values from 0-255
// By default the SPI-SS line used is D10 on Atmega328. You can change it by calling .SetCS(pin) where pin can be {8,9,10}
static uint8_t node_id; //        1  //network ID used for this unit
static uint8_t network_id;//    99  //network ID used for this network
static uint8_t gateway_id;//     1  //the ID of the network controller
static uint8_t ack_time;//     50  // # of ms to wait for an ack

static ByteBuffer send_buffer; 
static ByteBuffer receive_buffer;

//encryption is OPTIONAL
//to enable encryption you will need to:
// - provide a 16-byte encryption KEY (same on all nodes that talk encrypted)
// - to call .Encrypt(KEY) to start encrypting
// - to stop encrypting call .Encrypt(NULL)
static uint8_t KEY[];// = "ABCDABCDABCDABCD";
static uint16_t interPacketDelay;// = 1000; //wait this many ms between sending packets

// Need an instance of the Radio Module
unsigned char sendSize;//=0;
char payload[];// = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
bool requestACK;//=true;

//static neopixels_spi neopixels;

// LED controller
static DigitalOut SDI;
static DigitalOut CKI;

//static uint32_t last_rgb;

// outputs
//static uint8_t buzzPin;
//static uint8_t capPin;
static uint8_t red;
static uint8_t green;
static uint8_t blue;

static DigitalOut enable_1;
static DigitalOut enable_2;
static DigitalOut enable_3;

static DigitalOut cap_enable;
static DigitalOut buzzPin;

static DigitalIn touch_1;
static class EdgeDigIn touch_2;  // Reverted to original hw: Light bit 1 is top touch.
// static DigitalIn touch_2;
static DigitalIn touch_3;


// lights
static uint8_t mask;

// beeping
bool beeping;
unsigned long beep_start;
unsigned long beep_duration;

// pulsing
uint32_t current_color;
bool pulsing;
unsigned long pulse_start;
unsigned long pulse_period;
unsigned long pulse_on;
unsigned long pulse_duration;

bool powering_up1;
bool powering_up2;
unsigned long powerup_start;
unsigned long powerup_toggle;

// private functions
bool waitForAck(int cone);
void ledSetup(void);
bool _send(char *message, uint8_t cone);
bool _recieve(void);  
public:
//constructor
TA();

char data[DATA_SIZE];
//static uint8_t networkID;         // network group

static bool    batteryLow;
static uint8_t buttonsRising;

void post_color(uint32_t rgb);
void mask_color(uint32_t rgb);
void beep(uint16_t ms);
void beep_off(void);
void powerup(uint8_t);
void pulse(uint16_t on_time, uint16_t period, uint16_t ms, uint32_t rgb);
void pulse_off(void);
bool isPulsing(void){  return  pulsing;  }
int get_buffer_size(void);
bool send(Message *m);
void send_immediate(Message *m);
bool sendRaw(uint8_t *message, uint8_t len, uint8_t cone);
bool recieve(Message *m);
void spin(void);
bool activated(void);
void resetTouch();
bool tripped(void);
uint8_t buttons(void);
void setMask(uint8_t the_mask);
void initialize(uint8_t address);

void Ram_TableDisplay(void);
void get_free_memory(void);
void check_mem(void);

};

class EdgeDigIn : public InterruptIn
{
  public:
    uint8_t btnMsk;
    EdgeDigIn( PinName pin, PinMode pull=PullNone, uint8_t btnMsk=2 ) : InterruptIn( pin ), btnMsk( btnMsk )
    {
        mode( pull );                      // Set pull mode
        rise( this, &EdgeDigIn::risen  );  // Attach ISR for rise
    }
    void risen()
    {
        TA::buttonsRising |= btnMsk;
    }
};

#endif