Andriy Makukha / Mbed 2 deprecated football_project_wo_output

Dependencies:   mbed

Fork of football_project by MZJ

Committer:
AntonLS
Date:
Fri Feb 12 21:13:14 2016 +0000
Revision:
69:a3295b74209e
Parent:
67:5650f461722a
Child:
75:1b357bee1839
Radio-to-Standby prevention edge and corner cases.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elmbed 17:d8b901d791fd 1 #ifndef TA_H
elmbed 17:d8b901d791fd 2 #define TA_H
elmbed 17:d8b901d791fd 3
elmbed 17:d8b901d791fd 4 #include <mbed.h>
elmbed 17:d8b901d791fd 5
elmbed 17:d8b901d791fd 6 #include "ByteBuffer.h"
elmbed 17:d8b901d791fd 7 #include "neopixel.h"
AntonLS 67:5650f461722a 8 #include "types.h"
elmbed 17:d8b901d791fd 9
elmbed 17:d8b901d791fd 10 #define DATA_SIZE 24
AntonLS 45:1eb335c00cb2 11
AntonLS 45:1eb335c00cb2 12 #define MAX_LEN 24 // buffer input commands up to this length
AntonLS 45:1eb335c00cb2 13
elmbed 17:d8b901d791fd 14 #define SILENT 0x20
elmbed 17:d8b901d791fd 15
AntonLS 46:28c29ef61276 16 #define TOUCHLIGHTS 0x7 /* We'll use bit 2 for the power button */
AntonLS 52:060fdec99780 17 #define DEFTOUCHMASK (TOUCHLIGHTS & (6 | 1 /* test/bott */)) /* Note: No longer using "bottom" touch sensor/lights */
AntonLS 46:28c29ef61276 18 #define DIS_ON_DARK 0x40 /* Used for disabling touch sensor(s) when in dark mode */
AntonLS 30:c60b0d52b067 19
elmbed 17:d8b901d791fd 20 class TA
elmbed 17:d8b901d791fd 21 {
elmbed 17:d8b901d791fd 22 private:
elmbed 17:d8b901d791fd 23 // You will need to initialize the radio by telling it what ID it has and what network it's on
elmbed 17:d8b901d791fd 24 // The NodeID takes values from 1-127, 0 is reserved for sending broadcast messages (send to all nodes)
elmbed 17:d8b901d791fd 25 // The Network ID takes values from 0-255
elmbed 17:d8b901d791fd 26 // 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}
elmbed 17:d8b901d791fd 27 static uint8_t node_id; // 1 //network ID used for this unit
elmbed 17:d8b901d791fd 28 static uint8_t network_id;// 99 //network ID used for this network
elmbed 17:d8b901d791fd 29 static uint8_t gateway_id;// 1 //the ID of the network controller
elmbed 17:d8b901d791fd 30 static uint8_t ack_time;// 50 // # of ms to wait for an ack
elmbed 17:d8b901d791fd 31
elmbed 17:d8b901d791fd 32 static ByteBuffer send_buffer;
elmbed 17:d8b901d791fd 33 static ByteBuffer receive_buffer;
elmbed 17:d8b901d791fd 34
elmbed 17:d8b901d791fd 35 //encryption is OPTIONAL
elmbed 17:d8b901d791fd 36 //to enable encryption you will need to:
elmbed 17:d8b901d791fd 37 // - provide a 16-byte encryption KEY (same on all nodes that talk encrypted)
elmbed 17:d8b901d791fd 38 // - to call .Encrypt(KEY) to start encrypting
elmbed 17:d8b901d791fd 39 // - to stop encrypting call .Encrypt(NULL)
elmbed 17:d8b901d791fd 40 static uint8_t KEY[];// = "ABCDABCDABCDABCD";
elmbed 17:d8b901d791fd 41 static uint16_t interPacketDelay;// = 1000; //wait this many ms between sending packets
elmbed 17:d8b901d791fd 42
elmbed 17:d8b901d791fd 43 // Need an instance of the Radio Module
elmbed 17:d8b901d791fd 44 unsigned char sendSize;//=0;
elmbed 17:d8b901d791fd 45 char payload[];// = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
elmbed 17:d8b901d791fd 46 bool requestACK;//=true;
elmbed 17:d8b901d791fd 47
elmbed 17:d8b901d791fd 48 //static neopixels_spi neopixels;
elmbed 17:d8b901d791fd 49
elmbed 17:d8b901d791fd 50 // LED controller
elmbed 17:d8b901d791fd 51 static DigitalOut SDI;
elmbed 17:d8b901d791fd 52 static DigitalOut CKI;
elmbed 17:d8b901d791fd 53
elmbed 17:d8b901d791fd 54 //static uint32_t last_rgb;
elmbed 17:d8b901d791fd 55
elmbed 17:d8b901d791fd 56 // outputs
elmbed 17:d8b901d791fd 57 //static uint8_t buzzPin;
elmbed 17:d8b901d791fd 58 //static uint8_t capPin;
elmbed 17:d8b901d791fd 59 static uint8_t red;
elmbed 17:d8b901d791fd 60 static uint8_t green;
elmbed 17:d8b901d791fd 61 static uint8_t blue;
elmbed 17:d8b901d791fd 62
elmbed 17:d8b901d791fd 63 static DigitalOut enable_1;
elmbed 17:d8b901d791fd 64 static DigitalOut enable_2;
elmbed 17:d8b901d791fd 65 static DigitalOut enable_3;
elmbed 17:d8b901d791fd 66
elmbed 17:d8b901d791fd 67 static DigitalOut cap_enable;
elmbed 17:d8b901d791fd 68 static DigitalOut buzzPin;
elmbed 17:d8b901d791fd 69
AntonLS 50:efe0f3017848 70 static DigitalIn touch_1;
AntonLS 69:a3295b74209e 71 // static class EdgeDigIn touch_2; // Reverted to original hw: Light bit 1 is top touch.
AntonLS 69:a3295b74209e 72 static DigitalIn touch_2; // Reverted to original hw: Light bit 1 is top touch. ////
AntonLS 50:efe0f3017848 73 // static DigitalIn touch_2;
elmbed 17:d8b901d791fd 74 static DigitalIn touch_3;
elmbed 17:d8b901d791fd 75
elmbed 17:d8b901d791fd 76
elmbed 17:d8b901d791fd 77 // lights
elmbed 17:d8b901d791fd 78 static uint8_t mask;
elmbed 17:d8b901d791fd 79
elmbed 17:d8b901d791fd 80 // beeping
elmbed 17:d8b901d791fd 81 bool beeping;
elmbed 17:d8b901d791fd 82 unsigned long beep_start;
elmbed 17:d8b901d791fd 83 unsigned long beep_duration;
elmbed 17:d8b901d791fd 84
elmbed 17:d8b901d791fd 85 // pulsing
elmbed 17:d8b901d791fd 86 uint32_t current_color;
elmbed 17:d8b901d791fd 87 bool pulsing;
elmbed 17:d8b901d791fd 88 unsigned long pulse_start;
elmbed 17:d8b901d791fd 89 unsigned long pulse_period;
elmbed 17:d8b901d791fd 90 unsigned long pulse_on;
elmbed 17:d8b901d791fd 91 unsigned long pulse_duration;
elmbed 17:d8b901d791fd 92
elmbed 17:d8b901d791fd 93 bool powering_up1;
elmbed 17:d8b901d791fd 94 bool powering_up2;
elmbed 17:d8b901d791fd 95 unsigned long powerup_start;
elmbed 17:d8b901d791fd 96 unsigned long powerup_toggle;
elmbed 17:d8b901d791fd 97
elmbed 17:d8b901d791fd 98 // private functions
elmbed 17:d8b901d791fd 99 bool waitForAck(int cone);
elmbed 17:d8b901d791fd 100 void ledSetup(void);
elmbed 17:d8b901d791fd 101 bool _send(char *message, uint8_t cone);
elmbed 17:d8b901d791fd 102 bool _recieve(void);
elmbed 17:d8b901d791fd 103 public:
elmbed 17:d8b901d791fd 104 //constructor
elmbed 17:d8b901d791fd 105 TA();
elmbed 17:d8b901d791fd 106
elmbed 17:d8b901d791fd 107 char data[DATA_SIZE];
elmbed 17:d8b901d791fd 108 //static uint8_t networkID; // network group
elmbed 17:d8b901d791fd 109
AntonLS 67:5650f461722a 110 static uint8_t msg_id; // Message ID which replaces '%' in radio send packet for duplicate message detection.
AntonLS 67:5650f461722a 111
AntonLS 54:2878d62714d6 112 static bool batteryLow;
AntonLS 31:a6110950f385 113 static uint8_t buttonsRising;
AntonLS 31:a6110950f385 114
elmbed 17:d8b901d791fd 115 void post_color(uint32_t rgb);
elmbed 17:d8b901d791fd 116 void mask_color(uint32_t rgb);
elmbed 17:d8b901d791fd 117 void beep(uint16_t ms);
elmbed 17:d8b901d791fd 118 void beep_off(void);
elmbed 17:d8b901d791fd 119 void powerup(uint8_t);
elmbed 17:d8b901d791fd 120 void pulse(uint16_t on_time, uint16_t period, uint16_t ms, uint32_t rgb);
elmbed 17:d8b901d791fd 121 void pulse_off(void);
AntonLS 54:2878d62714d6 122 bool isPulsing(void){ return pulsing; }
elmbed 17:d8b901d791fd 123 int get_buffer_size(void);
elmbed 17:d8b901d791fd 124 bool send(Message *m);
elmbed 17:d8b901d791fd 125 void send_immediate(Message *m);
elmbed 17:d8b901d791fd 126 bool sendRaw(uint8_t *message, uint8_t len, uint8_t cone);
elmbed 17:d8b901d791fd 127 bool recieve(Message *m);
elmbed 17:d8b901d791fd 128 void spin(void);
elmbed 17:d8b901d791fd 129 bool activated(void);
AntonLS 46:28c29ef61276 130 void resetTouch();
elmbed 17:d8b901d791fd 131 bool tripped(void);
elmbed 17:d8b901d791fd 132 uint8_t buttons(void);
elmbed 17:d8b901d791fd 133 void setMask(uint8_t the_mask);
elmbed 17:d8b901d791fd 134 void initialize(uint8_t address);
elmbed 17:d8b901d791fd 135
elmbed 17:d8b901d791fd 136 void Ram_TableDisplay(void);
elmbed 17:d8b901d791fd 137 void get_free_memory(void);
elmbed 17:d8b901d791fd 138 void check_mem(void);
elmbed 17:d8b901d791fd 139
elmbed 17:d8b901d791fd 140 };
elmbed 17:d8b901d791fd 141
AntonLS 31:a6110950f385 142 class EdgeDigIn : public InterruptIn
AntonLS 31:a6110950f385 143 {
AntonLS 31:a6110950f385 144 public:
AntonLS 31:a6110950f385 145 uint8_t btnMsk;
AntonLS 50:efe0f3017848 146 EdgeDigIn( PinName pin, PinMode pull=PullNone, uint8_t btnMsk=2 ) : InterruptIn( pin ), btnMsk( btnMsk )
AntonLS 31:a6110950f385 147 {
AntonLS 31:a6110950f385 148 mode( pull ); // Set pull mode
AntonLS 31:a6110950f385 149 rise( this, &EdgeDigIn::risen ); // Attach ISR for rise
AntonLS 31:a6110950f385 150 }
AntonLS 31:a6110950f385 151 void risen()
AntonLS 31:a6110950f385 152 {
AntonLS 39:b1f864b71318 153 TA::buttonsRising |= btnMsk;
AntonLS 31:a6110950f385 154 }
AntonLS 31:a6110950f385 155 };
elmbed 17:d8b901d791fd 156
elmbed 17:d8b901d791fd 157 #endif