main/files.c

Sat, 20 Oct 2018 13:23:15 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 20 Oct 2018 13:23:15 +0200
changeset 0
b74b0e4902c3
child 1
ad2c8b13eb88
permissions
-rw-r--r--

Initial checkin brewboard

/**
 * @file files.c
 * @brief Files management.
 */

#include "config.h"


extern sButton                  Buttons[MAXBUTTONS];
extern int                      Main_Screen;

bool				Refresh = false;



void Files_Dir(char *path)
{
    char		filename[256], tmp[42];
    uint16_t		y = 28;
    DIR			*dir;
    struct dirent	*de;
    struct stat		st;

    _bg = TFT_BLACK;
    TFT_fillScreen(_bg);
    TopMessage(path);
    _fg = TFT_WHITE;
    TFT_setFont(DEFAULT_FONT, NULL);

    if ((dir = opendir(path))) {
	de = readdir(dir);
	while (de) {
	    TFT_print(de->d_name, 2, y);
	    sprintf(filename, "%s/%s", path, de->d_name);
	    if (stat(filename, &st) == 0) {
		sprintf(tmp, "%ld", st.st_size);
		TFT_print(tmp, RIGHT, y);
	    }
	    de = readdir(dir);
	    y += 16;
	}
	closedir(dir);
    }

    Buttons_Add(130, 200, 60, 40, "Ok", 0);
    Buttons[0].dark = true;
    Buttons_Show();

    while (true) {
	if (Buttons_Scan() == 0) {
	    Buttons_Clear();
	    return;
	}
	vTaskDelay(50 / portTICK_PERIOD_MS);
    }
}



/*
 * Files init function, only runs once a new screen is entered.
 */
void Files_Init(void)
{
    switch (Main_Screen) {
	case MAIN_TOOLS_FILES:
			break;

	default:	break;
    }
}



/*
 * Recipes management loop, non-blocking.
 */
void Files_Loop(void)
{
    switch (Main_Screen) {

	case MAIN_TOOLS_FILES:
			Files_Dir("/sdcard/recipe");
			Files_Dir("/sdcard/w/log");
			Main_Screen = MAIN_TOOLS;
			break;

	default:	break;
    }
}

mercurial