Skip to content

Commit

Permalink
Add option -d, for USA date format
Browse files Browse the repository at this point in the history
  • Loading branch information
antiprism committed Feb 15, 2021
1 parent 311421b commit d2cd088
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
8 changes: 6 additions & 2 deletions display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,19 @@ void draw_time(ArduiPi_OLED &display, int start_x, int start_y, int sz,


// Draw date - DD-MM-YYYY
void draw_date(ArduiPi_OLED &display, int start_x, int start_y, int sz)
void draw_date(ArduiPi_OLED &display, int start_x, int start_y, int sz,
int date_format)
{
display.setTextColor(WHITE);

time_t t = time(0);
struct tm *now = localtime(&t);
const size_t STR_SZ = 32;
char str[STR_SZ];
strftime(str, STR_SZ, "%d-%m-%Y", now);
if(date_format == 1) // MM-DD-YYYY
strftime(str, STR_SZ, "%m-%d-%Y", now);
else // DD-MM-YYYY
strftime(str, STR_SZ, "%d-%m-%Y", now);

display.setCursor(start_x, start_y);
display.setTextSize(sz);
Expand Down
3 changes: 2 additions & 1 deletion display.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ void draw_time(ArduiPi_OLED &display, int start_x, int start_y, int sz,
int clock_format);

// Fraw date - DD-MM-YYYY
void draw_date(ArduiPi_OLED &display, int start_x, int start_y, int sz);
void draw_date(ArduiPi_OLED &display, int start_x, int start_y, int sz,
int date_format);

// Draw a connection indicator, 12x8
void draw_connection(ArduiPi_OLED &display, int x_start, int y_start,
Expand Down
1 change: 1 addition & 0 deletions display_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct display_info
Counter text_change;
std::vector<double> scroll;
int clock_format;
int date_format;
char pause_screen;
connection_info conn;
void conn_init() { conn.init(); }
Expand Down
12 changes: 10 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class OledOpts : public ProgramOpts {
int gap; // gap between bars, in pixels
vector<double> scroll; // rate (pixels per sec), start delay (secs)
int clock_format; // 0-3: 0,1 - 24h 2,3 - 12h 0,2 - leading 0
int date_format; // 0: DD-MM-YYYY, 1: MM-DD-YYYY
char pause_screen; // p - play, s - stop
string cava_method; // fifo, alsa or pulse
string cava_source; // Path to FIFO for audio-in, alsa device...
Expand All @@ -120,6 +121,7 @@ class OledOpts : public ProgramOpts {
bars(16),
gap(1),
clock_format(0),
date_format(0),
pause_screen('p'),
cava_method("fifo"),
cava_source("/tmp/mpd_oled_fifo"),
Expand Down Expand Up @@ -178,6 +180,7 @@ void OledOpts::usage()
" rate_title,delay_title,rate_artist,delay_artist\n"
" -C <fmt> clock format: 0 - 24h leading 0 (default), 1 - 24h no leading 0,\n"
" 2 - 24h leading 0, 3 - 24h no leading 0\n"
" -d use USA date format MM-DD-YYYY (default: DD-MM-YYYY)\n"
" -P <val> pause screen type: p - play (default), s - stop\n"
" -c cava input method and source (default: '%s,%s')\n"
" e.g. 'fifo,/tmp/my_fifo', 'alsa,hw:5,0', 'pulse'\n"
Expand Down Expand Up @@ -207,7 +210,7 @@ void OledOpts::process_command_line(int argc, char **argv)

handle_long_opts(argc, argv);

while ((c=getopt(argc, argv, ":ho:b:g:f:s:C:P:c:RI:a:B:r:D:S:")) != -1) {
while ((c=getopt(argc, argv, ":ho:b:g:f:s:C:dP:c:RI:a:B:r:D:S:")) != -1) {
if (common_opts(c, optopt))
continue;

Expand Down Expand Up @@ -267,6 +270,10 @@ void OledOpts::process_command_line(int argc, char **argv)
error("clock format number is not 0, 1, 2 or 3", c);
break;

case 'd':
date_format = 1;
break;

case 'P':
if (strcmp(optarg, "p") == 0)
pause_screen = 'p';
Expand Down Expand Up @@ -410,7 +417,7 @@ void draw_clock(ArduiPi_OLED &display, const display_info &disp_info)
draw_text(display, 22, 0, 16, disp_info.conn.get_ip_addr());
draw_connection(display, 128-2*W, 0, disp_info.conn);
draw_time(display, 4, 16, 4, disp_info.clock_format);
draw_date(display, 32, 56, 1);
draw_date(display, 32, 56, 1, disp_info.date_format);
}


Expand Down Expand Up @@ -493,6 +500,7 @@ int start_idle_loop(ArduiPi_OLED &display, FILE *fifo_file,
display_info disp_info;
disp_info.scroll = opts.scroll;
disp_info.clock_format = opts.clock_format;
disp_info.date_format = opts.date_format;
disp_info.pause_screen = opts.pause_screen;
disp_info.spect.init(opts.bars, opts.gap);
disp_info.status.set_source(opts.source);
Expand Down

0 comments on commit d2cd088

Please sign in to comment.