Andriy Makukha / Mbed 2 deprecated football_project_wo_output

Dependencies:   mbed

Fork of football_project by MZJ

Committer:
AntonLS
Date:
Tue Jan 05 13:05:48 2016 +0000
Revision:
31:a6110950f385
Parent:
30:c60b0d52b067
Child:
39:b1f864b71318
Touch sensor rising edge ISR for better response.; Overcharge alarm more conserv.  Slave touch pwr toggle. ; Shows 101%/102% batt on plug/unplug, later gives real batt level.; Incl mbed-src to change startup code to use 32k RAM when set to BLE Nano.;

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