|
14 | 14 | ## Flash with default settings and |
15 | 15 | ## Flash Size: "4MB (Sketch: 1MB, FS: 3MB)" |
16 | 16 | |
17 | | -
|
| 17 | + |
18 | 18 | TODO: Add cps line trend to geiger mode |
19 | 19 | TODO: Add custom display font |
20 | 20 |
|
|
47 | 47 | #define SCREEN_HEIGHT 64 // OLED display height, in pixels |
48 | 48 | #define SCREEN_ADDRESS 0x3C // See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32 |
49 | 49 | #define EVENT_BUFFER 50000 // Buffer this many events for Serial.print |
50 | | -#define TRNG_BITS 8 // Number of bits for each random number, max 8 |
51 | 50 | #define BASELINE_NUM 101 // Number of measurements taken to determine the DC baseline |
52 | 51 | #define CONFIG_FILE "/config.json" // File to store the settings |
53 | 52 | #define DEBUG_FILE "/debug.json" // File to store some misc debug info |
@@ -82,7 +81,7 @@ struct Config { |
82 | 81 | ================= |
83 | 82 | */ |
84 | 83 |
|
85 | | -const String FW_VERSION = "4.3.1"; // Firmware Version Code |
| 84 | +const String FW_VERSION = "4.3.2"; // Firmware Version Code |
86 | 85 |
|
87 | 86 | const uint8_t GND_PIN = A2; // GND meas pin |
88 | 87 | const uint8_t VSYS_MEAS = A3; // VSYS/3 |
@@ -116,12 +115,13 @@ volatile unsigned long start_time = 0; // Time in ms when the spectrum collect |
116 | 115 | volatile unsigned long last_time = 0; // Last time the display has been refreshed |
117 | 116 | volatile uint32_t last_total = 0; // Last total pulse count for display |
118 | 117 |
|
119 | | -volatile unsigned long trng_stamps[3]; // Timestamps for True Random Number Generator |
120 | | -volatile uint8_t random_num = 0b00000000; // Generated random bits that form a byte together |
121 | | -volatile uint8_t bit_index = 0; // Bit index for the generated number |
122 | | -volatile uint32_t trng_nums[1000]; // TRNG number output array |
123 | | -volatile uint16_t number_index = 0; // Amount of saved numbers to the TRNG array |
124 | | -volatile uint32_t total_events = 0; // Total number of all registered pulses |
| 118 | +const uint16_t TRNG_STORAGE_SIZE = 1024; // Number of trng bytes stored in memory |
| 119 | +volatile unsigned long trng_stamps[3]; // Timestamps for True Random Number Generator |
| 120 | +volatile uint8_t random_num = 0b00000000; // Generated random bits that form a byte together |
| 121 | +volatile uint8_t bit_index = 0; // Bit index for the generated number |
| 122 | +volatile uint8_t trng_nums[TRNG_STORAGE_SIZE]; // TRNG number output array |
| 123 | +volatile uint16_t number_index = 0; // Amount of saved numbers to the TRNG array |
| 124 | +volatile size_t total_events = 0; // Total number of all registered pulses |
125 | 125 |
|
126 | 126 | RunningMedian baseline(BASELINE_NUM); // Array of a number of baseline (DC bias) measurements at the SiPM input |
127 | 127 | uint16_t current_baseline = 0; // Median value of the input baseline voltage |
@@ -820,7 +820,7 @@ void writeDebugFileTime() { |
820 | 820 |
|
821 | 821 | debugFile.close(); |
822 | 822 |
|
823 | | - const uint32_t temp = doc.containsKey("power_on_hours") ? doc["power_on_hours"] : 0; |
| 823 | + const uint32_t temp = doc["power_on_hours"].is<uint32_t>() ? doc["power_on_hours"] : 0; |
824 | 824 | doc["power_on_hours"] = temp + 1; |
825 | 825 |
|
826 | 826 | debugFile = LittleFS.open(DEBUG_FILE, "w"); // Open read and write |
@@ -848,7 +848,7 @@ void writeDebugFileBoot() { |
848 | 848 |
|
849 | 849 | debugFile.close(); |
850 | 850 |
|
851 | | - const uint32_t temp = doc.containsKey("power_cycle_count") ? doc["power_cycle_count"] : 0; |
| 851 | + const uint32_t temp = doc["power_cycle_count"].is<uint32_t>() ? doc["power_cycle_count"] : 0; |
852 | 852 | doc["power_cycle_count"] = temp + 1; |
853 | 853 |
|
854 | 854 | debugFile = LittleFS.open(DEBUG_FILE, "w"); // Open read and write |
@@ -881,31 +881,31 @@ Config loadSettings(bool msg = true) { |
881 | 881 | return new_conf; |
882 | 882 | } |
883 | 883 |
|
884 | | - if (doc.containsKey("ser_output")) { |
| 884 | + if (doc["ser_output"].is<bool>()) { |
885 | 885 | new_conf.ser_output = doc["ser_output"]; |
886 | 886 | } |
887 | | - if (doc.containsKey("geiger_mode")) { |
| 887 | + if (doc["geiger_mode"].is<bool>()) { |
888 | 888 | new_conf.geiger_mode = doc["geiger_mode"]; |
889 | 889 | } |
890 | | - if (doc.containsKey("print_spectrum")) { |
| 890 | + if (doc["print_spectrum"].is<bool>()) { |
891 | 891 | new_conf.print_spectrum = doc["print_spectrum"]; |
892 | 892 | } |
893 | | - if (doc.containsKey("meas_avg")) { |
| 893 | + if (doc["meas_avg"].is<size_t>()) { |
894 | 894 | new_conf.meas_avg = doc["meas_avg"]; |
895 | 895 | } |
896 | | - if (doc.containsKey("enable_display")) { |
| 896 | + if (doc["enable_display"].is<bool>()) { |
897 | 897 | new_conf.enable_display = doc["enable_display"]; |
898 | 898 | } |
899 | | - if (doc.containsKey("enable_trng")) { |
| 899 | + if (doc["enable_trng"].is<bool>()) { |
900 | 900 | new_conf.enable_trng = doc["enable_trng"]; |
901 | 901 | } |
902 | | - if (doc.containsKey("subtract_baseline")) { |
| 902 | + if (doc["subtract_baseline"].is<bool>()) { |
903 | 903 | new_conf.subtract_baseline = doc["subtract_baseline"]; |
904 | 904 | } |
905 | | - if (doc.containsKey("enable_ticker")) { |
| 905 | + if (doc["enable_ticker"].is<bool>()) { |
906 | 906 | new_conf.enable_ticker = doc["enable_ticker"]; |
907 | 907 | } |
908 | | - if (doc.containsKey("tick_rate")) { |
| 908 | + if (doc["tick_rate"].is<size_t>()) { |
909 | 909 | new_conf.tick_rate = doc["tick_rate"]; |
910 | 910 | } |
911 | 911 |
|
@@ -1242,12 +1242,12 @@ void eventInt() { |
1242 | 1242 |
|
1243 | 1243 | bitWrite(random_num, bit_index, (delta0 < delta1)); |
1244 | 1244 |
|
1245 | | - if (bit_index < TRNG_BITS - 1) { |
| 1245 | + if (bit_index < 7) { // Check if still less than a byte |
1246 | 1246 | bit_index++; |
1247 | 1247 | } else { |
1248 | 1248 | trng_nums[number_index] = random_num; |
1249 | 1249 |
|
1250 | | - if (number_index < 999) { |
| 1250 | + if (number_index < TRNG_STORAGE_SIZE - 1) { // Check if TRNG byte storage array is full |
1251 | 1251 | number_index++; |
1252 | 1252 | } else { |
1253 | 1253 | number_index = 0; // Catch overflow |
@@ -1367,6 +1367,8 @@ void setup1() { |
1367 | 1367 | saveSettings(); // Create settings file if none is present |
1368 | 1368 | writeDebugFileBoot(); // Update power cycle count |
1369 | 1369 |
|
| 1370 | + // Disable unused UART0 |
| 1371 | + Serial1.end(); |
1370 | 1372 | // Set the correct SPI pins |
1371 | 1373 | SPI.setRX(4); |
1372 | 1374 | SPI.setTX(3); |
|
0 commit comments