3333#define MAX_STR_LEN 500
3434
3535// If you would like to read DBs created with this repo
36- // with page size more than 512 , change here,
36+ // with page size more than 4096 , change here,
3737// but ensure as much SRAM can be allocated.
38- // Please Arduino Uno cannot support page size > 512.
3938#define BUF_SIZE 4096
4039byte buf[BUF_SIZE];
4140char filename[MAX_FILE_NAME_LEN];
@@ -69,11 +68,11 @@ int32_t write_fn(struct dblog_write_context *ctx, void *buf, uint32_t pos, size_
6968 return DBLOG_RES_ERR;
7069 if (fflush (myFile))
7170 return DBLOG_RES_FLUSH_ERR;
71+ fsync (fileno (myFile));
7272 return ret;
7373}
7474
7575int flush_fn (struct dblog_write_context *ctx) {
76- fsync (fileno (myFile));
7776 return DBLOG_RES_OK;
7877}
7978
@@ -345,7 +344,7 @@ void display_row(struct dblog_read_context *ctx) {
345344}
346345
347346void input_db_name () {
348- Serial. print ( F ( " DB name (prefix /) : " ));
347+ displayPrompt ( " DB name: " ));
349348 input_string (filename, sizeof (filename));
350349}
351350
@@ -358,9 +357,14 @@ void log_analog_data() {
358357 int num_entries;
359358 int dly;
360359 input_db_name ();
361- Serial.print (F (" \n Record count (1 to 32767 on UNO) : " ));
360+ Serial.print (F (" \n Record count: " ));
362361 num_entries = input_num ();
363- Serial.print (F (" \n Number of analog pins (from A0): " ));
362+ // A0 = 36; A3 = 39; A4 = 32; A5 = 33; A6 = 34; A7 = 35; A10 = 4;
363+ // A11 = 0; A12 = 2; A13 = 15; A14 = 13; A15 = 12; A16 = 14;
364+ // A17 = 27; A18 = 25; A19 = 26;
365+ Serial.print (F (" \n Starting analog pin (32): " ));
366+ int8_t analog_pin_start = input_num ();
367+ Serial.print (F (" \n No. of pins (5): " ));
364368 int8_t analog_pin_count = input_num ();
365369 char ts[24 ];
366370 if (input_ts (ts) < 23 ) {
@@ -380,7 +384,7 @@ void log_analog_data() {
380384 ctx.buf = buf;
381385 ctx.col_count = analog_pin_count + 1 ;
382386 ctx.page_resv_bytes = 0 ;
383- ctx.page_size_exp = 9 ;
387+ ctx.page_size_exp = 12 ;
384388 ctx.max_pages_exp = 0 ;
385389 ctx.read_fn = read_fn_wctx;
386390 ctx.flush_fn = flush_fn;
@@ -394,7 +398,7 @@ void log_analog_data() {
394398 update_ts (ts, (int ) (millis () - last_ms));
395399 last_ms = millis ();
396400 for (int8_t i = 0 ; i < analog_pin_count; i++) {
397- int val = analogRead (A0 + i);
401+ int val = analogRead (analog_pin_start + i);
398402 res = dblog_set_col_val (&ctx, i + 1 , DBLOG_TYPE_INT, &val, sizeof (int ));
399403 if (res)
400404 break ;
@@ -407,6 +411,7 @@ void log_analog_data() {
407411 }
408412 }
409413 }
414+ Serial.print (F (" \n Logging completed. Finalizing...\n " ));
410415 if (!res)
411416 res = dblog_finalize (&ctx);
412417 fclose (myFile);
@@ -460,7 +465,7 @@ void locate_records(int8_t choice) {
460465 char srch_datetime[24 ]; // YYYY-MM-DD HH:MM:SS.SSS
461466 int8_t dt_len;
462467 if (choice == 2 ) {
463- Serial.print (F (" \n Enter RowID (1 to 32767 on UNO) : " ));
468+ Serial.print (F (" \n Enter RowID: " ));
464469 rowid = input_num ();
465470 } else
466471 dt_len = input_ts (srch_datetime);
@@ -592,4 +597,4 @@ void loop() {
592597 Serial.println (F (" Invalid choice. Try again." ));
593598 }
594599
595- }
600+ }
0 commit comments