Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of football_project by
TA.h@46:28c29ef61276, 2016-01-11 (annotated)
- Committer:
- AntonLS
- Date:
- Mon Jan 11 16:34:46 2016 +0000
- Revision:
- 46:28c29ef61276
- Parent:
- 45:1eb335c00cb2
- Child:
- 50:efe0f3017848
Freeform improvements, etc.
Who changed what in which revision?
| User | Revision | Line number | New 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 | 46:28c29ef61276 | 15 | #define TOUCHLIGHTS 0x7 /* We'll use bit 2 for the power button */ |
| AntonLS | 30:c60b0d52b067 | 16 | #define DEFTOUCHMASK (TOUCHLIGHTS & (5 | 2 /* test/bott */)) /* Note: No longer using "bottom" touch sensor/lights */ |
| AntonLS | 46:28c29ef61276 | 17 | #define DIS_ON_DARK 0x40 /* Used for disabling touch sensor(s) when in dark mode */ |
| AntonLS | 30:c60b0d52b067 | 18 | |
| elmbed | 17:d8b901d791fd | 19 | struct Message |
| elmbed | 17:d8b901d791fd | 20 | { |
| elmbed | 17:d8b901d791fd | 21 | char command; |
| elmbed | 17:d8b901d791fd | 22 | uint32_t value; |
| elmbed | 17:d8b901d791fd | 23 | uint8_t cone; |
| elmbed | 17:d8b901d791fd | 24 | }; |
| elmbed | 17:d8b901d791fd | 25 | |
| elmbed | 17:d8b901d791fd | 26 | class TA |
| elmbed | 17:d8b901d791fd | 27 | { |
| elmbed | 17:d8b901d791fd | 28 | private: |
| elmbed | 17:d8b901d791fd | 29 | // You will need to initialize the radio by telling it what ID it has and what network it's on |
| elmbed | 17:d8b901d791fd | 30 | // The NodeID takes values from 1-127, 0 is reserved for sending broadcast messages (send to all nodes) |
| elmbed | 17:d8b901d791fd | 31 | // The Network ID takes values from 0-255 |
| elmbed | 17:d8b901d791fd | 32 | // 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 | 33 | static uint8_t node_id; // 1 //network ID used for this unit |
| elmbed | 17:d8b901d791fd | 34 | static uint8_t network_id;// 99 //network ID used for this network |
| elmbed | 17:d8b901d791fd | 35 | static uint8_t gateway_id;// 1 //the ID of the network controller |
| elmbed | 17:d8b901d791fd | 36 | static uint8_t ack_time;// 50 // # of ms to wait for an ack |
| elmbed | 17:d8b901d791fd | 37 | |
| elmbed | 17:d8b901d791fd | 38 | static ByteBuffer send_buffer; |
| elmbed | 17:d8b901d791fd | 39 | static ByteBuffer receive_buffer; |
| elmbed | 17:d8b901d791fd | 40 | |
| elmbed | 17:d8b901d791fd | 41 | //encryption is OPTIONAL |
| elmbed | 17:d8b901d791fd | 42 | //to enable encryption you will need to: |
| elmbed | 17:d8b901d791fd | 43 | // - provide a 16-byte encryption KEY (same on all nodes that talk encrypted) |
| elmbed | 17:d8b901d791fd | 44 | // - to call .Encrypt(KEY) to start encrypting |
| elmbed | 17:d8b901d791fd | 45 | // - to stop encrypting call .Encrypt(NULL) |
| elmbed | 17:d8b901d791fd | 46 | static uint8_t KEY[];// = "ABCDABCDABCDABCD"; |
| elmbed | 17:d8b901d791fd | 47 | static uint16_t interPacketDelay;// = 1000; //wait this many ms between sending packets |
| elmbed | 17:d8b901d791fd | 48 | |
| elmbed | 17:d8b901d791fd | 49 | // Need an instance of the Radio Module |
| elmbed | 17:d8b901d791fd | 50 | unsigned char sendSize;//=0; |
| elmbed | 17:d8b901d791fd | 51 | char payload[];// = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
| elmbed | 17:d8b901d791fd | 52 | bool requestACK;//=true; |
| elmbed | 17:d8b901d791fd | 53 | |
| elmbed | 17:d8b901d791fd | 54 | //static neopixels_spi neopixels; |
| elmbed | 17:d8b901d791fd | 55 | |
| elmbed | 17:d8b901d791fd | 56 | // LED controller |
| elmbed | 17:d8b901d791fd | 57 | static DigitalOut SDI; |
| elmbed | 17:d8b901d791fd | 58 | static DigitalOut CKI; |
| elmbed | 17:d8b901d791fd | 59 | |
| elmbed | 17:d8b901d791fd | 60 | //static uint32_t last_rgb; |
| elmbed | 17:d8b901d791fd | 61 | |
| elmbed | 17:d8b901d791fd | 62 | // outputs |
| elmbed | 17:d8b901d791fd | 63 | //static uint8_t buzzPin; |
| elmbed | 17:d8b901d791fd | 64 | //static uint8_t capPin; |
| elmbed | 17:d8b901d791fd | 65 | static uint8_t red; |
| elmbed | 17:d8b901d791fd | 66 | static uint8_t green; |
| elmbed | 17:d8b901d791fd | 67 | static uint8_t blue; |
| elmbed | 17:d8b901d791fd | 68 | |
| elmbed | 17:d8b901d791fd | 69 | static DigitalOut enable_1; |
| elmbed | 17:d8b901d791fd | 70 | static DigitalOut enable_2; |
| elmbed | 17:d8b901d791fd | 71 | static DigitalOut enable_3; |
| elmbed | 17:d8b901d791fd | 72 | |
| elmbed | 17:d8b901d791fd | 73 | static DigitalOut cap_enable; |
| elmbed | 17:d8b901d791fd | 74 | static DigitalOut buzzPin; |
| elmbed | 17:d8b901d791fd | 75 | |
| AntonLS | 31:a6110950f385 | 76 | static class EdgeDigIn touch_1; |
| AntonLS | 31:a6110950f385 | 77 | // static DigitalIn touch_1; |
| elmbed | 17:d8b901d791fd | 78 | static DigitalIn touch_2; |
| elmbed | 17:d8b901d791fd | 79 | static DigitalIn touch_3; |
| elmbed | 17:d8b901d791fd | 80 | |
| elmbed | 17:d8b901d791fd | 81 | |
| elmbed | 17:d8b901d791fd | 82 | // lights |
| elmbed | 17:d8b901d791fd | 83 | static uint8_t mask; |
| elmbed | 17:d8b901d791fd | 84 | |
| elmbed | 17:d8b901d791fd | 85 | // beeping |
| elmbed | 17:d8b901d791fd | 86 | bool beeping; |
| elmbed | 17:d8b901d791fd | 87 | unsigned long beep_start; |
| elmbed | 17:d8b901d791fd | 88 | unsigned long beep_duration; |
| elmbed | 17:d8b901d791fd | 89 | |
| elmbed | 17:d8b901d791fd | 90 | // pulsing |
| elmbed | 17:d8b901d791fd | 91 | uint32_t current_color; |
| elmbed | 17:d8b901d791fd | 92 | bool pulsing; |
| elmbed | 17:d8b901d791fd | 93 | unsigned long pulse_start; |
| elmbed | 17:d8b901d791fd | 94 | unsigned long pulse_period; |
| elmbed | 17:d8b901d791fd | 95 | unsigned long pulse_on; |
| elmbed | 17:d8b901d791fd | 96 | unsigned long pulse_duration; |
| elmbed | 17:d8b901d791fd | 97 | |
| elmbed | 17:d8b901d791fd | 98 | bool powering_up1; |
| elmbed | 17:d8b901d791fd | 99 | bool powering_up2; |
| elmbed | 17:d8b901d791fd | 100 | unsigned long powerup_start; |
| elmbed | 17:d8b901d791fd | 101 | unsigned long powerup_toggle; |
| elmbed | 17:d8b901d791fd | 102 | |
| elmbed | 17:d8b901d791fd | 103 | // private functions |
| elmbed | 17:d8b901d791fd | 104 | bool waitForAck(int cone); |
| elmbed | 17:d8b901d791fd | 105 | void ledSetup(void); |
| elmbed | 17:d8b901d791fd | 106 | bool _send(char *message, uint8_t cone); |
| elmbed | 17:d8b901d791fd | 107 | bool _recieve(void); |
| elmbed | 17:d8b901d791fd | 108 | public: |
| elmbed | 17:d8b901d791fd | 109 | //constructor |
| elmbed | 17:d8b901d791fd | 110 | TA(); |
| elmbed | 17:d8b901d791fd | 111 | |
| elmbed | 17:d8b901d791fd | 112 | char data[DATA_SIZE]; |
| elmbed | 17:d8b901d791fd | 113 | //static uint8_t networkID; // network group |
| elmbed | 17:d8b901d791fd | 114 | |
| AntonLS | 31:a6110950f385 | 115 | static uint8_t buttonsRising; |
| AntonLS | 31:a6110950f385 | 116 | |
| elmbed | 17:d8b901d791fd | 117 | void post_color(uint32_t rgb); |
| elmbed | 17:d8b901d791fd | 118 | void mask_color(uint32_t rgb); |
| elmbed | 17:d8b901d791fd | 119 | void beep(uint16_t ms); |
| elmbed | 17:d8b901d791fd | 120 | void beep_off(void); |
| elmbed | 17:d8b901d791fd | 121 | void powerup(uint8_t); |
| elmbed | 17:d8b901d791fd | 122 | void pulse(uint16_t on_time, uint16_t period, uint16_t ms, uint32_t rgb); |
| elmbed | 17:d8b901d791fd | 123 | void pulse_off(void); |
| elmbed | 17:d8b901d791fd | 124 | int get_buffer_size(void); |
| elmbed | 17:d8b901d791fd | 125 | bool send(Message *m); |
| elmbed | 17:d8b901d791fd | 126 | void send_immediate(Message *m); |
| elmbed | 17:d8b901d791fd | 127 | bool sendRaw(uint8_t *message, uint8_t len, uint8_t cone); |
| elmbed | 17:d8b901d791fd | 128 | bool recieve(Message *m); |
| elmbed | 17:d8b901d791fd | 129 | void spin(void); |
| elmbed | 17:d8b901d791fd | 130 | bool activated(void); |
| AntonLS | 46:28c29ef61276 | 131 | void resetTouch(); |
| elmbed | 17:d8b901d791fd | 132 | bool tripped(void); |
| elmbed | 17:d8b901d791fd | 133 | uint8_t buttons(void); |
| elmbed | 17:d8b901d791fd | 134 | void setMask(uint8_t the_mask); |
| elmbed | 17:d8b901d791fd | 135 | void initialize(uint8_t address); |
| elmbed | 17:d8b901d791fd | 136 | |
| elmbed | 17:d8b901d791fd | 137 | void Ram_TableDisplay(void); |
| elmbed | 17:d8b901d791fd | 138 | void get_free_memory(void); |
| elmbed | 17:d8b901d791fd | 139 | void check_mem(void); |
| elmbed | 17:d8b901d791fd | 140 | |
| elmbed | 17:d8b901d791fd | 141 | }; |
| elmbed | 17:d8b901d791fd | 142 | |
| AntonLS | 31:a6110950f385 | 143 | class EdgeDigIn : public InterruptIn |
| AntonLS | 31:a6110950f385 | 144 | { |
| AntonLS | 31:a6110950f385 | 145 | public: |
| AntonLS | 31:a6110950f385 | 146 | uint8_t btnMsk; |
| AntonLS | 31:a6110950f385 | 147 | EdgeDigIn( PinName pin, PinMode pull=PullNone, uint8_t btnMsk=1 ) : InterruptIn( pin ), btnMsk( btnMsk ) |
| AntonLS | 31:a6110950f385 | 148 | { |
| AntonLS | 31:a6110950f385 | 149 | mode( pull ); // Set pull mode |
| AntonLS | 31:a6110950f385 | 150 | rise( this, &EdgeDigIn::risen ); // Attach ISR for rise |
| AntonLS | 31:a6110950f385 | 151 | } |
| AntonLS | 31:a6110950f385 | 152 | void risen() |
| AntonLS | 31:a6110950f385 | 153 | { |
| AntonLS | 39:b1f864b71318 | 154 | TA::buttonsRising |= btnMsk; |
| AntonLS | 31:a6110950f385 | 155 | } |
| AntonLS | 31:a6110950f385 | 156 | }; |
| elmbed | 17:d8b901d791fd | 157 | |
| elmbed | 17:d8b901d791fd | 158 | #endif |
