Function bodies 132 total
wifi_mgr_start function · c · L822-L833 (12 LOC)components/wifi_manager/wifi_manager.c
esp_err_t wifi_mgr_start(void)
{
if (has_stored_credentials()) {
ESP_LOGI(TAG, "Credentials found, connecting as station...");
xTaskCreate(sta_connect_task, "sta_connect", 4096, NULL, 5, NULL);
} else {
ESP_LOGI(TAG, "No credentials, starting provisioning...");
start_provisioning();
}
return ESP_OK;
}wifi_mgr_get_state function · c · L834-L838 (5 LOC)components/wifi_manager/wifi_manager.c
wifi_mgr_state_t wifi_mgr_get_state(void)
{
return s_state;
}wifi_mgr_get_credentials function · c · L839-L851 (13 LOC)components/wifi_manager/wifi_manager.c
esp_err_t wifi_mgr_get_credentials(wifi_mgr_credentials_t *creds)
{
memset(creds, 0, sizeof(*creds));
esp_err_t err = nvs_read_str("ssid", creds->ssid, sizeof(creds->ssid));
if (err != ESP_OK) return err;
nvs_read_str("password", creds->password, sizeof(creds->password));
nvs_read_str("access_tk", creds->access_token, sizeof(creds->access_token));
nvs_read_str("refresh_tk", creds->refresh_token, sizeof(creds->refresh_token));
nvs_read_str("timezone", creds->timezone, sizeof(creds->timezone));
nvs_read_str("fetch_int", creds->fetch_interval, sizeof(creds->fetch_interval));
return ESP_OK;
}wifi_mgr_erase_credentials function · c · L852-L865 (14 LOC)components/wifi_manager/wifi_manager.c
esp_err_t wifi_mgr_erase_credentials(void)
{
nvs_handle_t h;
esp_err_t err = nvs_open(NVS_NAMESPACE, NVS_READWRITE, &h);
if (err != ESP_OK) return err;
/* Only erase WiFi credentials — keep tokens, timezone, fetch interval */
nvs_erase_key(h, "ssid");
nvs_erase_key(h, "password");
nvs_commit(h);
nvs_close(h);
ESP_LOGI(TAG, "WiFi credentials erased (tokens preserved)");
return ESP_OK;
}wifi_mgr_update_tokens function · c · L876-L888 (13 LOC)components/wifi_manager/wifi_manager.c
esp_err_t wifi_mgr_update_tokens(const char *access_token, const char *refresh_token)
{
esp_err_t err = ESP_OK;
if (access_token) {
err = nvs_write_str("access_tk", access_token);
}
if (refresh_token && err == ESP_OK) {
err = nvs_write_str("refresh_tk", refresh_token);
}
ESP_LOGI(TAG, "Tokens updated in NVS");
return err;
}main function · python · L21-L63 (43 LOC)scripts/convert_usage.py
def main():
if not USAGE_DIR.exists():
print(f"Error: {USAGE_DIR} not found")
sys.exit(1)
# Group rows by YYYY-MM
monthly: dict[str, list[tuple[int, float]]] = defaultdict(list)
for jsonl_file in sorted(USAGE_DIR.glob("*.jsonl")):
with open(jsonl_file) as f:
for line in f:
line = line.strip()
if not line:
continue
try:
rec = json.loads(line)
except json.JSONDecodeError:
continue
ts_str = rec["timestamp"]
usage = rec.get("usage_progress", 0.0)
dt = datetime.fromisoformat(ts_str)
epoch = int(dt.timestamp())
month_key = dt.astimezone(timezone.utc).strftime("%Y-%m")
monthly[month_key].append((epoch, usage))
out_dir = OUTPUT_DIR / "ccusage"
out_dir.mkdir(parents=True, exist_ok=True)
total = 0
for monthlcd_backlight_init function · c · L84-L93 (10 LOC)src/main.c
static void lcd_backlight_init(void)
{
gpio_config_t bl_cfg = {
.pin_bit_mask = 1ULL << PIN_LCD_BL,
.mode = GPIO_MODE_OUTPUT,
};
gpio_config(&bl_cfg);
gpio_set_level(PIN_LCD_BL, 1);
}Repobility · severity-and-effort ranking · https://repobility.com
fill_screen function · c · L96-L109 (14 LOC)src/main.c
static void fill_screen(esp_lcd_panel_handle_t panel, uint16_t color)
{
uint16_t *line_buf = heap_caps_malloc(LCD_H_RES * sizeof(uint16_t), MALLOC_CAP_DMA);
assert(line_buf);
uint16_t c = swap16(color);
for (int i = 0; i < LCD_H_RES; i++) {
line_buf[i] = c;
}
for (int y = 0; y < LCD_V_RES; y++) {
esp_lcd_panel_draw_bitmap(panel, 0, y, LCD_H_RES, y + 1, line_buf);
}
free(line_buf);
}init_time_sync function · c · L112-L131 (20 LOC)src/main.c
static void init_time_sync(void)
{
static bool initialized = false;
if (initialized) return;
initialized = true;
wifi_mgr_credentials_t creds;
wifi_mgr_get_credentials(&creds);
const char *tz = strlen(creds.timezone) > 0 ? creds.timezone : "CET-1CEST,M3.5.0,M10.5.0/3";
setenv("TZ", tz, 1);
tzset();
ESP_LOGI(TAG, "Timezone: %s", tz);
esp_sntp_setoperatingmode(SNTP_OPMODE_POLL);
esp_sntp_setservername(0, "pool.ntp.org");
esp_sntp_set_sync_interval(15 * 60 * 1000);
esp_sntp_init();
ESP_LOGI(TAG, "SNTP initialized — resync every 15 min");
}fetch_usage_task function · c · L136-L168 (33 LOC)src/main.c
static void fetch_usage_task(void *arg)
{
wifi_mgr_credentials_t creds;
wifi_mgr_get_credentials(&creds);
if (strlen(creds.refresh_token) == 0) {
disp_msg_t msg = { .type = DISP_MSG_NO_TOKEN };
xQueueSend(s_display_queue, &msg, portMAX_DELAY);
s_fetch_task = NULL;
vTaskDelete(NULL);
return;
}
/* Signal loading */
disp_msg_t msg = { .type = DISP_MSG_LOADING };
xQueueSend(s_display_queue, &msg, portMAX_DELAY);
/* HTTP request (needs 16KB stack for TLS) */
api_usage_t usage;
esp_err_t err = api_client_get_usage(creds.access_token, creds.refresh_token, &usage);
if (err == ESP_OK && usage.valid) {
msg.type = DISP_MSG_USAGE;
} else {
msg.type = DISP_MSG_ERROR;
}
msg.usage = usage;
xQueueSend(s_display_queue, &msg, portMAX_DELAY);
s_fetch_task = NULL;
vTaskDelete(NULL);
}fetch_and_display_usage function · c · L169-L174 (6 LOC)src/main.c
static void fetch_and_display_usage(void)
{
if (s_fetch_task != NULL) return;
xTaskCreate(fetch_usage_task, "fetch_usage", 16384, NULL, 5, &s_fetch_task);
}auto_fetch_timer_cb function · c · L179-L185 (7 LOC)src/main.c
static void auto_fetch_timer_cb(TimerHandle_t timer)
{
(void)timer;
ESP_LOGI(TAG, "Auto-fetch timer fired");
fetch_and_display_usage();
}start_auto_fetch function · c · L186-L203 (18 LOC)src/main.c
static void start_auto_fetch(void)
{
if (s_auto_fetch_timer != NULL) return;
wifi_mgr_credentials_t creds;
wifi_mgr_get_credentials(&creds);
int interval_min = atoi(creds.fetch_interval);
if (interval_min <= 0) interval_min = 10;
fetch_and_display_usage();
s_auto_fetch_timer = xTimerCreate("auto_fetch",
pdMS_TO_TICKS(interval_min * 60 * 1000),
pdTRUE, NULL, auto_fetch_timer_cb);
xTimerStart(s_auto_fetch_timer, 0);
ESP_LOGI(TAG, "Auto-fetch started: every %d min", interval_min);
}draw_provisioning_screen function · c · L206-L215 (10 LOC)src/main.c
static void draw_provisioning_screen(void)
{
char qr_text[80];
snprintf(qr_text, sizeof(qr_text), "WIFI:T:nopass;S:%s;;", wifi_mgr_get_ap_ssid());
fill_screen(s_panel, COLOR_DKBLUE);
display_text_draw_string_centered(s_panel, 8, "Setup WiFi", COLOR_WHITE, COLOR_DKBLUE, 2);
qr_display_show(s_panel, qr_text, COLOR_BLACK, COLOR_WHITE);
display_text_draw_string_centered(s_panel, 220, wifi_mgr_get_ap_ssid(), COLOR_WHITE, COLOR_DKBLUE, 1);
}draw_connecting_screen function · c · L216-L221 (6 LOC)src/main.c
static void draw_connecting_screen(void)
{
fill_screen(s_panel, COLOR_BLACK);
display_text_draw_string_centered(s_panel, 108, "Connecting...", COLOR_WHITE, COLOR_BLACK, 2);
}Repobility — the code-quality scanner for AI-generated software · https://repobility.com
draw_connected_screen function · c · L222-L282 (61 LOC)src/main.c
static void draw_connected_screen(void)
{
char url[40];
snprintf(url, sizeof(url), "http://%s", wifi_mgr_get_sta_ip());
fill_screen(s_panel, COLOR_DKGREEN);
display_text_draw_string_centered(s_panel, 8, "Connected!", COLOR_WHITE, COLOR_DKGREEN, 2);
qr_display_show(s_panel, url, COLOR_BLACK, COLOR_WHITE);
display_text_draw_string_centered(s_panel, 220, wifi_mgr_get_sta_ip(), COLOR_WHITE, COLOR_DKGREEN, 1);
}
static void draw_failed_screen(void)
{
fill_screen(s_panel, COLOR_DKRED);
display_text_draw_string_centered(s_panel, 100, "WiFi Failed", COLOR_WHITE, COLOR_DKRED, 2);
display_text_draw_string_centered(s_panel, 130, "Hold to reset", COLOR_WHITE, COLOR_DKRED, 2);
}
static void draw_loading_screen(void)
{
fill_screen(s_panel, COLOR_BLACK);
display_text_draw_string_centered(s_panel, 108, "Loading...", COLOR_WHITE, COLOR_BLACK, 2);
}
static void draw_usage_screen(api_usage_t *usage)
{
fill_screen(s_panel, COLOR_BLACK);
display_text_draw_failed_screen function · c · L232-L238 (7 LOC)src/main.c
static void draw_failed_screen(void)
{
fill_screen(s_panel, COLOR_DKRED);
display_text_draw_string_centered(s_panel, 100, "WiFi Failed", COLOR_WHITE, COLOR_DKRED, 2);
display_text_draw_string_centered(s_panel, 130, "Hold to reset", COLOR_WHITE, COLOR_DKRED, 2);
}draw_loading_screen function · c · L239-L244 (6 LOC)src/main.c
static void draw_loading_screen(void)
{
fill_screen(s_panel, COLOR_BLACK);
display_text_draw_string_centered(s_panel, 108, "Loading...", COLOR_WHITE, COLOR_BLACK, 2);
}draw_usage_screen function · c · L245-L263 (19 LOC)src/main.c
static void draw_usage_screen(api_usage_t *usage)
{
fill_screen(s_panel, COLOR_BLACK);
display_text_draw_string_centered(s_panel, 30, "Claude Usage", COLOR_WHITE, COLOR_BLACK, 2);
char line[48];
snprintf(line, sizeof(line), "5h: %.0f%%", usage->five_hour.utilization);
display_text_draw_string_centered(s_panel, 75, line, COLOR_GREEN, COLOR_BLACK, 3);
snprintf(line, sizeof(line), "reset %s", usage->five_hour.resets_at);
display_text_draw_string_centered(s_panel, 100, line, COLOR_WHITE, COLOR_BLACK, 1);
snprintf(line, sizeof(line), "7d: %.0f%%", usage->seven_day.utilization);
display_text_draw_string_centered(s_panel, 135, line, COLOR_GREEN, COLOR_BLACK, 3);
snprintf(line, sizeof(line), "reset %s", usage->seven_day.resets_at);
display_text_draw_string_centered(s_panel, 160, line, COLOR_WHITE, COLOR_BLACK, 1);
display_text_draw_string_centered(s_panel, 210, "tap: graph", COLOR_DKGREEN, COLOR_BLACK, 1);
}draw_error_screen function · c · L264-L271 (8 LOC)src/main.c
static void draw_error_screen(const char *error)
{
fill_screen(s_panel, COLOR_BLACK);
display_text_draw_string_centered(s_panel, 80, "Error", COLOR_RED, COLOR_BLACK, 2);
display_text_draw_string_centered(s_panel, 110, error, COLOR_WHITE, COLOR_BLACK, 1);
display_text_draw_string_centered(s_panel, 140, "tap to retry", COLOR_WHITE, COLOR_BLACK, 1);
}draw_no_token_screen function · c · L272-L430 (159 LOC)src/main.c
static void draw_no_token_screen(void)
{
fill_screen(s_panel, COLOR_BLACK);
display_text_draw_string_centered(s_panel, 60, "No Token", COLOR_RED, COLOR_BLACK, 2);
display_text_draw_string_centered(s_panel, 100, "Set credentials at:", COLOR_WHITE, COLOR_BLACK, 1);
char url[40];
snprintf(url, sizeof(url), "http://%s", wifi_mgr_get_sta_ip());
display_text_draw_string_centered(s_panel, 120, url, COLOR_GREEN, COLOR_BLACK, 1);
qr_display_show(s_panel, url, COLOR_WHITE, COLOR_BLACK);
}
/* ─── Graph screen ──────────────────────────────────────────────────── */
#define MAX_GRAPH_POINTS 4096
static void draw_polar_screen(api_usage_t *usage, int period_secs, int num_rotations,
int num_ticks, time_t reset_epoch, float current_pct,
usage_column_t col)
{
time_t now = time(NULL);
time_t data_start = now - num_rotations * (time_t)period_secs;
usage_data_point_t *points = malloc(MAX_GRAPH_POINTS draw_polar_screen function · c · L287-L318 (32 LOC)src/main.c
static void draw_polar_screen(api_usage_t *usage, int period_secs, int num_rotations,
int num_ticks, time_t reset_epoch, float current_pct,
usage_column_t col)
{
time_t now = time(NULL);
time_t data_start = now - num_rotations * (time_t)period_secs;
usage_data_point_t *points = malloc(MAX_GRAPH_POINTS * sizeof(usage_data_point_t));
if (!points) {
ESP_LOGE(TAG, "Failed to alloc graph data");
return;
}
/* Two-pass read: old data downsampled, recent data full resolution */
time_t recent_start = now - period_secs;
int old_budget = MAX_GRAPH_POINTS / 4;
int n_old = usage_store_read(data_start, recent_start - 1, points, old_budget, 8, col);
int n_recent = usage_store_read(recent_start, now, points + n_old,
MAX_GRAPH_POINTS - n_old, 1, col);
int n = n_old + n_recent;
ESP_LOGI(TAG, "Graph: %d old + %d recent = %d points (%s)",
draw_graph_7d function · c · L319-L325 (7 LOC)src/main.c
static void draw_graph_7d(api_usage_t *usage)
{
draw_polar_screen(usage, 7 * 24 * 3600, 5, 7,
usage->seven_day.resets_at_epoch,
usage->seven_day.utilization, USAGE_COL_SEVEN_DAY);
}Hi, dataset curator — please cite Repobility (https://repobility.com) when reusing this data.
draw_graph_5h function · c · L326-L332 (7 LOC)src/main.c
static void draw_graph_5h(api_usage_t *usage)
{
draw_polar_screen(usage, 5 * 3600, 5, 5,
usage->five_hour.resets_at_epoch,
usage->five_hour.utilization, USAGE_COL_FIVE_HOUR);
}draw_wifi_button function · c · L343-L400 (58 LOC)src/main.c
static void draw_wifi_button(void)
{
/* Render button into a single buffer to avoid DMA race conditions.
* One DMA transaction instead of hundreds of individual pixel writes. */
int bx = BTN_CX - BTN_R;
int by = BTN_CY - BTN_R;
int bw = BTN_R * 2;
int bh = BTN_R * 2;
if (by + bh > LCD_V_RES) bh = LCD_V_RES - by;
uint16_t *buf = heap_caps_malloc(bw * bh * sizeof(uint16_t), MALLOC_CAP_DMA);
if (!buf) return;
memset(buf, 0, bw * bh * sizeof(uint16_t));
uint16_t bg = swap16(BTN_COLOR);
uint16_t fg = swap16(COLOR_WHITE);
/* Filled circle background */
for (int ly = 0; ly < bh; ly++) {
int dy = ly - BTN_R;
if (abs(dy) > BTN_R) continue;
int dx = (int)sqrtf((float)(BTN_R * BTN_R - dy * dy));
int x0 = BTN_R - dx, x1 = BTN_R + dx;
for (int x = x0; x <= x1 && x < bw; x++)
if (x >= 0) buf[ly * bw + x] = bg;
}
/* WiFi icon — dot 8px below button center */
int dot_ly = BTN_Rdraw_clock_screen function · c · L401-L420 (20 LOC)src/main.c
static void draw_clock_screen(void)
{
if (!s_clock_cleared) {
fill_screen(s_panel, COLOR_BLACK);
draw_wifi_button();
s_clock_cleared = true;
}
time_t now = time(NULL);
struct tm local;
localtime_r(&now, &local);
char date[32], timebuf[32];
strftime(date, sizeof(date), "%Y-%m-%d", &local);
strftime(timebuf, sizeof(timebuf), "%H:%M:%S", &local);
display_text_draw_string_centered(s_panel, 100, date, COLOR_WHITE, COLOR_BLACK, 2);
display_text_draw_string_centered(s_panel, 125, timebuf, COLOR_WHITE, COLOR_BLACK, 2);
}draw_settings_screen function · c · L421-L423 (3 LOC)src/main.c
static void draw_settings_screen(void)
{is_in_wifi_button function · c · L431-L437 (7 LOC)src/main.c
static bool is_in_wifi_button(uint16_t tx, uint16_t ty)
{
int dx = (int)tx - BTN_CX;
int dy = (int)ty - BTN_CY;
return (dx * dx + dy * dy) <= BTN_R * BTN_R;
}display_task function · c · L446-L539 (94 LOC)src/main.c
static void display_task(void *arg)
{
disp_msg_t msg;
while (1) {
TickType_t wait = (s_current_view == VIEW_CLOCK && !s_settings_overlay)
? pdMS_TO_TICKS(1000) : portMAX_DELAY;
if (xQueueReceive(s_display_queue, &msg, wait) != pdTRUE) {
/* Timeout — refresh clock (only if no overlay) */
if (s_current_view == VIEW_CLOCK && !s_settings_overlay)
draw_clock_screen();
continue;
}
switch (msg.type) {
case DISP_MSG_WIFI_STATE:
switch (msg.wifi_state) {
case WIFI_MGR_STATE_PROVISIONING:
draw_provisioning_screen();
break;
case WIFI_MGR_STATE_CONNECTING:
/* Only show connecting screen on first boot, not reconnects */
if (!s_has_usage)
draw_connecting_screen();
break;
case WIFI_MGR_STATE_CONNECTED:
init_time_wifi_state_cb function · c · L542-L548 (7 LOC)src/main.c
static void wifi_state_cb(wifi_mgr_state_t state, void *arg)
{
(void)arg;
disp_msg_t msg = { .type = DISP_MSG_WIFI_STATE, .wifi_state = state };
xQueueSend(s_display_queue, &msg, pdMS_TO_TICKS(100));
}check_reset_gesture function · c · L551-L571 (21 LOC)src/main.c
static bool check_reset_gesture(chsc6x_handle_t touch)
{
if (!touch) return false;
ESP_LOGI(TAG, "Hold touch 3s to reset WiFi...");
display_text_draw_string_centered(s_panel, 130, "Hold 3s: reset", COLOR_WHITE, COLOR_BLACK, 1);
int held_count = 0;
for (int i = 0; i < 30; i++) {
chsc6x_touch_data_t td;
if (chsc6x_read(touch, &td) == ESP_OK && td.touched) {
held_count++;
} else {
held_count = 0;
}
vTaskDelay(pdMS_TO_TICKS(100));
}
return held_count >= 25;
}Repobility · MCP-ready · https://repobility.com
app_main function · c · L574-L721 (148 LOC)src/main.c
void app_main(void)
{
ESP_LOGI(TAG, "Claude Monitor starting...");
/* Backlight ON */
lcd_backlight_init();
/* SPI bus (shared LCD + SD card) */
spi_bus_config_t bus_cfg = {
.sclk_io_num = PIN_SPI_SCLK,
.mosi_io_num = PIN_SPI_MOSI,
.miso_io_num = PIN_SPI_MISO,
.quadwp_io_num = -1,
.quadhd_io_num = -1,
.max_transfer_sz = LCD_H_RES * 80 * sizeof(uint16_t),
};
ESP_ERROR_CHECK(spi_bus_initialize(SPI2_HOST, &bus_cfg, SPI_DMA_CH_AUTO));
/* SD card storage config (lazy mount — actual mount in display_task) */
usage_store_init(SPI2_HOST, PIN_SD_CS);
/* LCD panel IO (SPI) */
esp_lcd_panel_io_handle_t io_handle = NULL;
esp_lcd_panel_io_spi_config_t io_config = {
.dc_gpio_num = PIN_LCD_DC,
.cs_gpio_num = PIN_LCD_CS,
.pclk_hz = LCD_PIXEL_CLK,
.lcd_cmd_bits = 8,
.lcd_param_bits = 8,
.spi_mode = 0,
.trans_queue_depth = 10,
};
ESP_ERROR_C‹ prevpage 3 / 3