forked from EkardNT/GymClock
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.h
More file actions
131 lines (113 loc) · 3.75 KB
/
Copy pathcommon.h
File metadata and controls
131 lines (113 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#ifndef GYMCLOCK_COMMON_H
#define GYMCLOCK_COMMON_H
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266WebServerSecure.h>
#include <DNSServer.h>
#include <EEPROM.h>
#include <ESP8266HTTPUpdateServer.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
#include <AceTime.h>
const char AP_SSID[] = "GymClockAdmin";
// Change this to the actual password before flashing the sign.
const char AP_PASSWORD[] = "password";
const IPAddress AP_LOCAL_IP(192, 168, 4, 22);
const IPAddress AP_GATEWAY(192, 168, 4, 9);
const IPAddress AP_SUBNET_MASK(255, 255, 255, 0);
const int MAX_SSID_SIZE = 32;
const int MAX_PASSWORD_SIZE = 32;
// EEPROM offsets.
// 1 byte for ssid field length
// MAX_SSID_SIZE for ssid field
// 1 byte for password field length
// MAX_PASSWORD_SIZE for password field
const int EEPROM_SIZE = 2 + MAX_SSID_SIZE + MAX_PASSWORD_SIZE;
const int SSID_LEN_EEPROM_ADDR = 0;
const int SSID_EEPROM_ADDR = 1 + SSID_LEN_EEPROM_ADDR;
const int PASSWORD_LEN_EEPROM_ADDR = SSID_EEPROM_ADDR + MAX_SSID_SIZE;
const int PASSWORD_EEPROM_ADDR = 1 + PASSWORD_LEN_EEPROM_ADDR;
// SER
const int srDataPin = D3;
// RCLK
const int srStorageClockPin = D2;
// SRCLK
const int srShiftClockPin = D1;
// The address pins
const int addrBitMap[4] = { D4, D5, D6, D7 };
// Controls Speakers
const int tonePin = D0;
// Indexed by 'char' - '0'
const byte segmentsForNumericChars[] = {
//_GFEDCBA
0b00111111, // '0'
0b00110000, // '1'
0b01101101, // '2'
0b01111001, // '3'
0b01110010, // '4'
0b01011011, // '5'
0b01011111, // '6'
0b00110001, // '7'
0b01111111, // '8'
0b01111011, // '9'
};
// Indexed by 'char' - 'a' or 'A'
const byte segmentsForAlphabeticChars[] = {
//_GFEDCBA
0b01110111, // 'a'
0b00000000, // 'b'
0b00000000, // 'c'
0b01111100, // 'd'
0b01001111, // 'e'
0b00000000, // 'f'
0b01011111, // 'g'
0b01110110, // 'h'
0b00000000, // 'i'
0b00000000, // 'j'
0b00000000, // 'k'
0b00001110, // 'l'
0b00000000, // 'm'
0b00110111, // 'n'
0b00111111, // 'o'
0b01110011, // 'p'
0b00000000, // 'q'
0b01000100, // 'r'
0b01011011, // 's'
0b00110001, // 't'
0b00000000, // 'u'
0b00000000, // 'v'
0b00000000, // 'w'
0b00000000, // 'x'
0b01110010, // 'y'
0b00000000, // 'z'
};
extern bool networkActive;
const int NUM_DIGITS = 10;
// 7 for the main segments in the digit, and the last bit for the colon/separator segment.
const int NUM_SEGMENTS_PER_DIGIT = 8;
const int NUM_SEGMENTS = NUM_DIGITS * NUM_SEGMENTS_PER_DIGIT;
// Holds the state for the entire display. The main loop constantly renders the display by lighting
// up digits in turn over and over. Human persistence of vision creates the illusion that the entire
// display is lit up at once.
// The main 6 digits are at indices 0-5. The left 2-digit cluster is at indices 6-7, and the right at 8-9.
extern byte displayState[NUM_DIGITS];
// The number of digits that will be lit at once. 10 would be ideal, but would take too much current (~1 amp per fully-lit digit).
const int LIT_RENDER_WINDOW = 3;
const int ZONE_MGR_CACHE_SIZE = 3;
extern ace_time::BasicZoneManager<ZONE_MGR_CACHE_SIZE> zoneManager;
const unsigned long MILLIS_PER_SECOND = 1000;
const unsigned long MILLIS_PER_MINUTE = 60 * MILLIS_PER_SECOND;
const unsigned long MILLIS_PER_HOUR = 60 * MILLIS_PER_MINUTE;
void waitForSerial();
void renderDisplay();
// Helper function used by the main renderDisplay function. Selects a certain
// digit by setting the address lines appropriately.
void selectDigitForRender(int digit);
void renderToDigit(byte digitState);
// Display an ASCII character on a given digit, optionally lighting up the colon light too.
void updateDigit(byte digit, unsigned char character);
void show2DigitNumber(int number, byte firstDigit);
void clearDisplay();
#endif