Skip to content

Commit 43bf05e

Browse files
committed
Rename to arduino-clock, v2.0.0 (if a bit buggy)!
1 parent 02de84a commit 43bf05e

28 files changed

+126
-125
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ Written to support [RLB Designs’](http://rlb-designs.com/) Universal Nixie Dri
3434
* Switch and pulse signals supported on UNDB v9+
3535
* Nano 33 IoT support coming on future versions
3636

37-
[The latest release can be downloaded here.](https://github.com/clockspot/arduino-clock/releases/latest)
37+
[The latest release can be downloaded here.](https://github.com/clockspot/arduino-clock/releases) Please note [known bugs and to-dos.](https://github.com/clockspot/arduino-clock/blob/master/TODO.md)
3838

3939
# Configuration, compilation, and upload
4040

41-
Various options, such as enabled functionality, RTC, display, I/O pins, timeouts, and control behaviors, are specified in a config file. This allows you to maintain configs for multiple clock hardware profiles, and simply include the relevant config at the top of `arduino-nixie.h` before compiling. Several [example configs](https://github.com/clockspot/arduino-clock/tree/master/arduino-clock/configs) are provided, and [`~sample.h`](https://github.com/clockspot/arduino-clock/blob/master/arduino-clock/configs/%7Esample.h) includes all possible options with detailed comments.
41+
Various options, such as enabled functionality, RTC, display, I/O pins, timeouts, and control behaviors, are specified in a config file. This allows you to maintain configs for multiple clock hardware profiles, and simply include the relevant config at the top of `arduino-clock.h` before compiling. Several [example configs](https://github.com/clockspot/arduino-clock/tree/master/arduino-clock/configs) are provided, and [`~sample.h`](https://github.com/clockspot/arduino-clock/blob/master/arduino-clock/configs/%7Esample.h) includes all possible options with detailed comments.
4242

43-
You may also wish to adjust the defaults for the clock’s user-configurable values to best suit its intended use, in case the user performs a hard reset. Some of these are specified in the config; others, for now, are hardcoded in `arduino-nixie.ino` (`optsDef[]` for [settings](https://github.com/clockspot/arduino-clock/blob/master/INSTRUCTIONS.md#settings-menu) and `initEEPROM()` for other values).
43+
You may also wish to adjust the defaults for the clock’s user-configurable values to best suit its intended use, in case the user performs a hard reset. Some of these are specified in the config; others, for now, are hardcoded in `arduino-clock.ino` (`optsDef[]` for [settings](https://github.com/clockspot/arduino-clock/blob/master/INSTRUCTIONS.md#settings-menu) and `initEEPROM()` for other values).
4444

4545
I use the Arduino IDE to compile and upload, due to the use of various Arduino and Arduino-oriented libraries. Make sure the relevant libraries are installed in the Library Manager, per the config in use.
4646

TODO.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
# To-dos
22

3-
* Rename project to arduino-clock with first push of v2+ - replace instances of arduino-nixie within
3+
* Startup SEL hold doesn't seem to work with IMU
44
* Reintroduce nixie clean and scroll
55
* Persistent storage on EEPROM - find a solution that writes to flash less often
66
* Network/NTP
7-
* Persistent storage for wi-fi credentials!
87
* Why does the page sometimes drop?
98
* wi-fi credential save fails if keys are part of the string?
109
* DST calc may behave unpredictably between 1–2am on fallback day
11-
* Redo NTP on startup if it failed (networkStartWifi())
10+
* Redo NTP if it failed (networkStartWifi()) - per bad response - how to make it wait a retry period
1211
* Make [2036-ready](https://en.wikipedia.org/wiki/Year_2038_problem#Network_Time_Protocol_timestamps)
1312
* Notice when a leap second is coming and handle it
1413
* When setting page is used to set day counter and date, and the month changes, set date max. For 2/29 it should just do 3/1 probably.

arduino-nixie/arduino-nixie.h renamed to arduino-clock/arduino-clock.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
////////// Hardware configuration //////////
55
//Include the config file that matches your hardware setup. If needed, duplicate an existing one.
66

7-
#include "configs/led-iot.h"
8-
//#include "configs/undb-v9-relay.h"
7+
#include "configs/undb-v9.h"
98

109
////////////////////////////////////////////
1110

arduino-nixie/arduino-nixie.ino renamed to arduino-clock/arduino-clock.ino

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
// Inspired by original sketch by Robin Birtles (rlb-designs.com) and Chris Gerekos
55

66
#include <arduino.h>
7-
#include "arduino-nixie.h";
7+
#include "arduino-clock.h";
88

99
////////// Software version //////////
10-
const byte vMajor = 1;
11-
const byte vMinor = 9;
10+
const byte vMajor = 2;
11+
const byte vMinor = 0;
1212
const byte vPatch = 0;
13-
const bool vDev = 1;
13+
const bool vDev = 0;
1414

1515
////////// Includes //////////
1616

@@ -155,10 +155,10 @@ unsigned int tempValDispLast = 0;
155155
////////// Main code control //////////
156156

157157
void setup(){
158-
Serial.begin(9600);
159-
#ifndef __AVR__ //SAMD only
160-
while(!Serial);
161-
#endif
158+
// Serial.begin(9600);
159+
// #ifndef __AVR__ //SAMD only
160+
// while(!Serial);
161+
// #endif
162162
rtcInit();
163163
initStorage(); //pulls persistent storage data into volatile vars - see storage.cpp
164164
byte changed = initEEPROM(false); //do a soft init to make sure vals in range
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

arduino-nixie/dispMAX7219.cpp renamed to arduino-clock/dispMAX7219.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <arduino.h>
2-
#include "arduino-nixie.h"
2+
#include "arduino-clock.h"
33

4-
#ifdef DISP_MAX7219 //see arduino-nixie.ino Includes section
4+
#ifdef DISP_MAX7219 //see arduino-clock.ino Includes section
55

66
#include "dispMAX7219.h"
77
#include <SPI.h> //Arduino - for SPI access to MAX7219
File renamed without changes.

arduino-nixie/dispNixie.cpp renamed to arduino-clock/dispNixie.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <arduino.h>
2-
#include "arduino-nixie.h"
2+
#include "arduino-clock.h"
33

4-
#ifdef DISP_NIXIE //see arduino-nixie.ino Includes section
4+
#ifdef DISP_NIXIE //see arduino-clock.ino Includes section
55

66
#include "dispNixie.h"
77

File renamed without changes.

arduino-nixie/input.cpp renamed to arduino-clock/input.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include <arduino.h>
2-
#include "arduino-nixie.h"
2+
#include "arduino-clock.h"
33

44
#include "input.h"
55

File renamed without changes.

arduino-nixie/network.cpp renamed to arduino-clock/network.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include <arduino.h>
2-
#include "arduino-nixie.h"
2+
#include "arduino-clock.h"
33

44
#ifndef __AVR__ //TODO better sensor
55
//do stuff for wifinina
@@ -41,7 +41,7 @@ WiFiServer server(80);
4141
bool networkSupported(){ return true; }
4242

4343
void initNetwork(){
44-
Serial.println(F("Hello world from network.cpp"));
44+
//Serial.println(F("Hello world from network.cpp"));
4545
//Check status of wifi module up front
4646
//if(WiFi.status()==WL_NO_MODULE){ Serial.println(F("Communication with WiFi module failed!")); while(true); }
4747
//else if(WiFi.firmwareVersion()<WIFI_FIRMWARE_LATEST_VERSION) Serial.println(F("Please upgrade the firmware"));
@@ -50,9 +50,9 @@ void initNetwork(){
5050
for(byte i=0; i<32; i++){ if(readEEPROM(55+i,false)=='\0') break; wssid.concat((char)(readEEPROM(55+i,false))); } //Read in the SSID
5151
for(byte i=0; i<64; i++){ if(readEEPROM(87+i,false)=='\0') break; wpass.concat((char)(readEEPROM(87+i,false))); } //Read in the pass
5252
wki = readEEPROM(151,false); //Read in the wki
53-
Serial.print(F("wssid=")); Serial.println(wssid);
54-
Serial.print(F("wpass=")); Serial.println(wpass);
55-
Serial.print(F("wki=")); Serial.println(wki);
53+
//Serial.print(F("wssid=")); Serial.println(wssid);
54+
//Serial.print(F("wpass=")); Serial.println(wpass);
55+
//Serial.print(F("wki=")); Serial.println(wki);
5656
networkStartWiFi();
5757
}
5858
void cycleNetwork(){
@@ -84,7 +84,7 @@ void checkForWiFiStatusChange(){
8484

8585
void networkStartWiFi(){
8686
WiFi.end(); //if AP is going, stop it
87-
if(wssid==F("")){ Serial.println(F("no start wifi")); return; } //don't try to connect if there's no creds
87+
if(wssid==F("")) return; //don't try to connect if there's no creds
8888
checkForWiFiStatusChange(); //just for serial logging
8989
//Serial.print(millis(),DEC); Serial.println(F("blank display per start wifi"));
9090
blankDisplay(0,5,false); //I'm guessing if it hangs, nixies won't be able to display anyway
@@ -401,9 +401,9 @@ void checkClients(){
401401
client.print(F("."));
402402
client.print(getVersionPart(2),DEC);
403403
if(getVersionPart(3)) //don't link directly to anything, just the project
404-
client.print(F("-dev (<a href='https://github.com/clockspot/arduino-nixie' target='_blank'>details</a>)"));
404+
client.print(F("-dev (<a href='https://github.com/clockspot/arduino-clock' target='_blank'>details</a>)"));
405405
else { //link directly to the release of this version
406-
client.print(F(" (<a href='https://github.com/clockspot/arduino-nixie/releases/tag/v")); //TODO needs fix after rename
406+
client.print(F(" (<a href='https://github.com/clockspot/arduino-clock/releases/tag/v")); //TODO needs fix after rename
407407
client.print(getVersionPart(0),DEC);
408408
client.print(F("."));
409409
client.print(getVersionPart(1),DEC);
@@ -791,8 +791,8 @@ void checkClients(){
791791
wki = currentLine.substring(startPos).toInt();
792792
//Persistent storage - see wssid/wpass definitions above
793793
for(byte i=0; i<97; i++) writeEEPROM(55+i,0,false,false); //Clear out the old values (32+64+1)
794-
for(byte i=0; i<wssid.length(); i++) writeEEPROM(55+i,wssid[i],false,false); //Write in the SSID
795-
for(byte i=0; i<wpass.length(); i++) writeEEPROM(87+i,wpass[i],false,false); //Write in the pass
794+
for(byte i=0; i<wssid.length(); i++) { if(i<55+32) writeEEPROM(55+i,wssid[i],false,false); } //Write in the SSID
795+
for(byte i=0; i<wpass.length(); i++) { if(i<87+64) writeEEPROM(87+i,wpass[i],false,false); } //Write in the pass
796796
writeEEPROM(151,wki,false,false); //Write in the wki
797797
commitEEPROM(); //commit all the above
798798
requestType = 3; //triggers an admin restart after the client is closed, below
File renamed without changes.

arduino-nixie/rtcDS3231.cpp renamed to arduino-clock/rtcDS3231.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <arduino.h>
2-
#include "arduino-nixie.h"
2+
#include "arduino-clock.h"
33

4-
#ifdef RTC_DS3231 //see arduino-nixie.ino Includes section
4+
#ifdef RTC_DS3231 //see arduino-clock.ino Includes section
55

66
#include "rtcDS3231.h"
77
#include <Wire.h> //Arduino - GNU LPGL - for I2C access to DS3231
File renamed without changes.

arduino-nixie/rtcMillis.cpp renamed to arduino-clock/rtcMillis.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <arduino.h>
2-
#include "arduino-nixie.h"
2+
#include "arduino-clock.h"
33

4-
#ifdef RTC_MILLIS //see arduino-nixie.ino Includes section
4+
#ifdef RTC_MILLIS //see arduino-clock.ino Includes section
55

66
#include "rtcMillis.h"
77

File renamed without changes.

arduino-clock/storage.cpp

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Persistent storage
2+
3+
// This project was originally written to use the AVR Arduino's EEPROM for persistent storage, and would frequently read it directly during runtime (not just at startup). I wanted to abstract that away, partly to add support for SAMD flash memory, and partly to protect against runtime errors due to EEPROM/flash failure.
4+
// This code serves those values out of a volatile array of bytes, which are backed by EEPROM/flash for the sole purpose of recovery after a power failure. It reads them from EEPROM/flash at startup, and sets them when changed.
5+
// Flash support is via cmaglie's FlashStorage library. It offers an EEPROM emulation mode, which I'm currently using, but I don't like that it writes the entire "EEPROM" data to flash (not just the value being updated) with every commit() – I think it will wear out unnecessarily. TODO address this.
6+
// Note that flash data is necessarily wiped out when the sketch is (re)uploaded.
7+
8+
#include <arduino.h>
9+
#include "arduino-clock.h"
10+
11+
#include "storage.h"
12+
13+
#ifdef __AVR__
14+
#include <EEPROM.h> //Arduino - GNU LPGL
15+
#else //SAMD - is there a better way to detect EEPROM availability? TODO
16+
#define FLASH_AS_EEPROM
17+
//cmaglie's FlashStorage library - https://github.com/cmaglie/FlashStorage/
18+
#include <FlashAsEEPROM.h> //EEPROM mode
19+
//#include <FlashStorage.h> //regular mode
20+
#endif
21+
22+
#define STORAGE_SPACE 152 //number of bytes
23+
byte storageBytes[STORAGE_SPACE]; //the volatile array of bytes
24+
#define COMMIT_TO_EEPROM 1 //1 for production
25+
26+
void initStorage(){
27+
//If this is SAMD, write starting values if unused
28+
#ifdef FLASH_AS_EEPROM
29+
//Serial.println(F("Hello world from storage.cpp"));
30+
//Serial.print(F("valid=")); Serial.println(EEPROM.isValid(),DEC);
31+
//Serial.print(F("16=")); Serial.println(EEPROM.read(16));
32+
if(!EEPROM.isValid() || EEPROM.read(16)==0 || EEPROM.read(16)==255){ //invalid eeprom, wipe it out
33+
for(byte i=0; i<STORAGE_SPACE; i++) EEPROM.update(i,0);
34+
if(COMMIT_TO_EEPROM){
35+
EEPROM.commit();
36+
//Serial.println(F("WARNING: FLASH EEPROM COMMIT per init"));
37+
}
38+
}
39+
#endif
40+
//Read from real persistent storage into storageBytes
41+
for(byte i=0; i<STORAGE_SPACE; i++) storageBytes[i] = EEPROM.read(i);
42+
}
43+
44+
int readEEPROM(int loc, bool isInt){
45+
//Read from the volatile array, either a byte or a signed int
46+
//Must read int as 16-bit, since on SAMD int is 32-bit and negatives aren't read correctly
47+
if(isInt) return (int16_t)(storageBytes[loc]<<8)+storageBytes[loc+1];
48+
else return storageBytes[loc];
49+
}
50+
51+
bool writeEEPROM(int loc, int val, bool isInt, bool commit){
52+
//Update the volatile array and the real persistent storage for posterity
53+
//Eiither a byte or a signed int
54+
//Serial.print(F("Set ")); Serial.print(loc); Serial.print(F("=")); Serial.print(val,DEC);
55+
if(readEEPROM(loc,isInt)==val){
56+
//Serial.println(F(": nothing doing"));
57+
return false;
58+
}
59+
//Serial.println(F(": ok (probably)"));
60+
if(isInt){
61+
storageBytes[loc] = highByte(val);
62+
storageBytes[loc+1] = lowByte(val);
63+
EEPROM.update(loc,highByte(val));
64+
EEPROM.update(loc+1,lowByte(val));
65+
} else {
66+
storageBytes[loc] = val;
67+
EEPROM.update(loc,val);
68+
}
69+
#ifdef FLASH_AS_EEPROM
70+
if(commit && COMMIT_TO_EEPROM){
71+
EEPROM.commit(); //bad!! See TODO in storage.h
72+
//Serial.println(F("WARNING: FLASH EEPROM COMMIT per write"));
73+
}
74+
#endif
75+
return true; //a value was changed
76+
}
77+
void commitEEPROM(){
78+
#ifdef FLASH_AS_EEPROM
79+
if(COMMIT_TO_EEPROM){
80+
EEPROM.commit(); //bad!! See TODO in storage.h
81+
//Serial.println(F("WARNING: FLASH EEPROM COMMIT by request"));
82+
}
83+
#endif
84+
}

arduino-clock/storage.h

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef STORAGE_H
2+
#define STORAGE_H
3+
4+
void initStorage(); //Read from real persistent storage into storageBytes
5+
int readEEPROM(int loc, bool isInt); //Read from the volatile array
6+
bool writeEEPROM(int loc, int val, bool isInt, bool commit=1); //Update the volatile array and the real persistent storage for posterity
7+
void commitEEPROM();
8+
9+
#endif //STORAGE_H

arduino-nixie/storage.cpp

-76
This file was deleted.

arduino-nixie/storage.h

-14
This file was deleted.

0 commit comments

Comments
 (0)