Andriy Makukha / Mbed 2 deprecated football_project_wo_output

Dependencies:   mbed

Fork of football_project by MZJ

Committer:
AntonLS
Date:
Sat Jan 09 22:36:55 2016 +0000
Revision:
45:1eb335c00cb2
Parent:
39:b1f864b71318
Child:
46:28c29ef61276
Buf size consistency

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"
elmbed 17:d8b901d791fd 8
elmbed 17:d8b901d791fd 9 #define DATA_SIZE 24
AntonLS 45:1eb335c00cb2 10
AntonLS 45:1eb335c00cb2 11 #define MAX_LEN 24 // buffer input commands up to this length
AntonLS 45:1eb335c00cb2 12
elmbed 17:d8b901d791fd 13 #define SILENT 0x20
elmbed 17:d8b901d791fd 14
AntonLS 30:c60b0d52b067 15 #define TOUCHLIGHTS 0x7
AntonLS 30:c60b0d52b067 16 #define DEFTOUCHMASK (TOUCHLIGHTS & (5 | 2 /* test/bott */)) /* Note: No longer using "bottom" touch sensor/lights */
AntonLS 30:c60b0d52b067 17
elmbed 17:d8b901d791fd 18 struct Message
elmbed 17:d8b901d791fd 19 {
elmbed 17:d8b901d791fd 20 char command;
elmbed 17:d8b901d791fd 21 uint32_t value;
elmbed 17:d8b901d791fd 22 uint8_t cone;
elmbed 17:d8b901d791fd 23 };
elmbed 17:d8b901d791fd 24
elmbed 17:d8b901d791fd 25 class TA
elmbed 17:d8b901d791fd 26 {
elmbed 17:d8b901d791fd 27 private:
elmbed 17:d8b901d791fd 28 // You will need to initialize the radio by telling it what ID it has and what network it's on
elmbed 17:d8b901d791fd 29 // The NodeID takes values from 1-127, 0 is reserved for sending broadcast messages (send to all nodes)
elmbed 17:d8b901d791fd 30 // The Network ID takes values from 0-255
elmbed 17:d8b901d791fd 31 // 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 32 static uint8_t node_id; // 1 //network ID used for this unit
elmbed 17:d8b901d791fd 33 static uint8_t network_id;// 99 //network ID used for this network
elmbed 17:d8b901d791fd 34 static uint8_t gateway_id;// 1 //the ID of the network controller
elmbed 17:d8b901d791fd 35 static uint8_t ack_time;// 50 // # of ms to wait for an ack
elmbed 17:d8b901d791fd 36
elmbed 17:d8b901d791fd 37 static ByteBuffer send_buffer;
elmbed 17:d8b901d791fd 38 static ByteBuffer receive_buffer;
elmbed 17:d8b901d791fd 39
elmbed 17:d8b901d791fd 40 //encryption is OPTIONAL
elmbed 17:d8b901d791fd 41 //to enable encryption you will need to:
elmbed 17:d8b901d791fd 42 // - provide a 16-byte encryption KEY (same on all nodes that talk encrypted)
elmbed 17:d8b901d791fd 43 // - to call .Encrypt(KEY) to start encrypting
elmbed 17:d8b901d791fd 44 // - to stop encrypting call .Encrypt(NULL)
elmbed 17:d8b901d791fd 45 static uint8_t KEY[];// = "ABCDABCDABCDABCD";
elmbed 17:d8b901d791fd 46 static uint16_t interPacketDelay;// = 1000; //wait this many ms between sending packets
elmbed 17:d8b901d791fd 47
elmbed 17:d8b901d791fd 48 // Need an instance of the Radio Module
elmbed 17:d8b901d791fd 49 unsigned char sendSize;//=0;
elmbed 17:d8b901d791fd 50 char payload[];// = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
elmbed 17:d8b901d791fd 51 bool requestACK;//=true;
elmbed 17:d8b901d791fd 52
elmbed 17:d8b901d791fd 53 //static neopixels_spi neopixels;
elmbed 17:d8b901d791fd 54
elmbed 17:d8b901d791fd 55 // LED controller
elmbed 17:d8b901d791fd 56 static DigitalOut SDI;
elmbed 17:d8b901d791fd 57 static DigitalOut CKI;
elmbed 17:d8b901d791fd 58
elmbed 17:d8b901d791fd 59 //static uint32_t last_rgb;
elmbed 17:d8b901d791fd 60
elmbed 17:d8b901d791fd 61 // outputs
elmbed 17:d8b901d791fd 62 //static uint8_t buzzPin;
elmbed 17:d8b901d791fd 63 //static uint8_t capPin;
elmbed 17:d8b901d791fd 64 static uint8_t red;
elmbed 17:d8b901d791fd 65 static uint8_t green;
elmbed 17:d8b901d791fd 66 static uint8_t blue;
elmbed 17:d8b901d791fd 67
elmbed 17:d8b901d791fd 68 static DigitalOut enable_1;
elmbed 17:d8b901d791fd 69 static DigitalOut enable_2;
elmbed 17:d8b901d791fd 70 static DigitalOut enable_3;
elmbed 17:d8b901d791fd 71
elmbed 17:d8b901d791fd 72 static DigitalOut cap_enable;
elmbed 17:d8b901d791fd 73 static DigitalOut buzzPin;
elmbed 17:d8b901d791fd 74
AntonLS 31:a6110950f385 75 static class EdgeDigIn touch_1;
AntonLS 31:a6110950f385 76 // static DigitalIn touch_1;
elmbed 17:d8b901d791fd 77 static DigitalIn touch_2;
elmbed 17:d8b901d791fd 78 static DigitalIn touch_3;
elmbed 17:d8b901d791fd 79
elmbed 17:d8b901d791fd 80
elmbed 17:d8b901d791fd 81 // lights
elmbed 17:d8b901d791fd 82 static uint8_t mask;
elmbed 17:d8b901d791fd 83
elmbed 17:d8b901d791fd 84 // beeping
elmbed 17:d8b901d791fd 85 bool beeping;
elmbed 17:d8b901d791fd 86 unsigned long beep_start;
elmbed 17:d8b901d791fd 87 unsigned long beep_duration;
elmbed 17:d8b901d791fd 88
elmbed 17:d8b901d791fd 89 // pulsing
elmbed 17:d8b901d791fd 90 uint32_t current_color;
elmbed 17:d8b901d791fd 91 bool pulsing;
elmbed 17:d8b901d791fd 92 unsigned long pulse_start;
elmbed 17:d8b901d791fd 93 unsigned long pulse_period;
elmbed 17:d8b901d791fd 94 unsigned long pulse_on;
elmbed 17:d8b901d791fd 95 unsigned long pulse_duration;
elmbed 17:d8b901d791fd 96
elmbed 17:d8b901d791fd 97 bool powering_up1;
elmbed 17:d8b901d791fd 98 bool powering_up2;
elmbed 17:d8b901d791fd 99 unsigned long powerup_start;
elmbed 17:d8b901d791fd 100 unsigned long powerup_toggle;
elmbed 17:d8b901d791fd 101
elmbed 17:d8b901d791fd 102 // private functions
elmbed 17:d8b901d791fd 103 bool waitForAck(int cone);
elmbed 17:d8b901d791fd 104 void ledSetup(void);
elmbed 17:d8b901d791fd 105 bool _send(char *message, uint8_t cone);
elmbed 17:d8b901d791fd 106 bool _recieve(void);
elmbed 17:d8b901d791fd 107 public:
elmbed 17:d8b901d791fd 108 //constructor
elmbed 17:d8b901d791fd 109 TA();
elmbed 17:d8b901d791fd 110
elmbed 17:d8b901d791fd 111 char data[DATA_SIZE];
elmbed 17:d8b901d791fd 112 //static uint8_t networkID; // network group
elmbed 17:d8b901d791fd 113
AntonLS 31:a6110950f385 114 static uint8_t buttonsRising;
AntonLS 31:a6110950f385 115
elmbed 17:d8b901d791fd 116 void post_color(uint32_t rgb);
elmbed 17:d8b901d791fd 117 void mask_color(uint32_t rgb);
elmbed 17:d8b901d791fd 118 void beep(uint16_t ms);
elmbed 17:d8b901d791fd 119 void beep_off(void);
elmbed 17:d8b901d791fd 120 void powerup(uint8_t);
elmbed 17:d8b901d791fd 121 void pulse(uint16_t on_time, uint16_t period, uint16_t ms, uint32_t rgb);
elmbed 17:d8b901d791fd 122 void pulse_off(void);
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 31:a6110950f385 130 void resetTouchIfStuck();
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 31:a6110950f385 146 EdgeDigIn( PinName pin, PinMode pull=PullNone, uint8_t btnMsk=1 ) : 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