1
0
mirror of https://github.com/whowechina/aic_pico.git synced 2024-09-24 02:58:21 +02:00

Better debug handling

This commit is contained in:
whowechina 2024-04-29 17:44:18 +08:00
parent dee5521ce8
commit 8a7751de84
8 changed files with 87 additions and 100 deletions

View File

@ -13,7 +13,6 @@
typedef void (*aime_putc_func)(uint8_t byte);
void aime_init(aime_putc_func putc_func);
void aime_debug(bool enable);
void aime_virtual_aic(bool enable);
void aime_set_mode(int mode);

View File

@ -13,7 +13,6 @@
typedef void (*bana_putc_func)(uint8_t byte);
void bana_init(bana_putc_func putc_func);
void bana_debug(bool enable);
bool bana_feed(int c);

View File

@ -200,11 +200,8 @@ static void handle_level(int argc, char *argv[])
static void handle_debug()
{
static bool debug = true;
printf("Debug: %s\n", debug ? "ON" : "OFF");
aime_debug(debug);
bana_debug(debug);
debug = !debug;
aic_runtime.debug = !aic_runtime.debug;
printf("Debug: %s\n", aic_runtime.debug ? "ON" : "OFF");
}
void commands_init()

View File

@ -1,44 +1,44 @@
/*
* Controller Config and Runtime Data
* WHowe <github.com/whowechina>
*
* Config is a global data structure that stores all the configuration
* Runtime is something to share between files.
*/
#include "config.h"
#include "save.h"
aic_cfg_t *aic_cfg;
static aic_cfg_t default_cfg = {
.light = { .min = 24, .max = 128, .rgb = true, .led = true },
.virtual_aic = true,
.mode = 0,
};
aic_runtime_t *aic_runtime;
static void config_loaded()
{
if (aic_cfg->light.min > aic_cfg->light.max) {
aic_cfg->light = default_cfg.light;
config_changed();
}
}
void config_changed()
{
save_request(false);
}
void config_factory_reset()
{
*aic_cfg = default_cfg;
save_request(true);
}
void config_init()
{
aic_cfg = (aic_cfg_t *)save_alloc(sizeof(*aic_cfg), &default_cfg, config_loaded);
}
/*
* Controller Config and Runtime Data
* WHowe <github.com/whowechina>
*
* Config is a global data structure that stores all the configuration
* Runtime is something to share between files.
*/
#include "config.h"
#include "save.h"
aic_cfg_t *aic_cfg;
static aic_cfg_t default_cfg = {
.light = { .min = 24, .max = 128, .rgb = true, .led = true },
.virtual_aic = true,
.mode = 0,
};
aic_runtime_t aic_runtime;
static void config_loaded()
{
if (aic_cfg->light.min > aic_cfg->light.max) {
aic_cfg->light = default_cfg.light;
config_changed();
}
}
void config_changed()
{
save_request(false);
}
void config_factory_reset()
{
*aic_cfg = default_cfg;
save_request(true);
}
void config_init()
{
aic_cfg = (aic_cfg_t *)save_alloc(sizeof(*aic_cfg), &default_cfg, config_loaded);
}

View File

@ -1,35 +1,35 @@
/*
* Controller Config
* WHowe <github.com/whowechina>
*/
#ifndef CONFIG_H
#define CONFIG_H
#include <stdint.h>
#include <stdbool.h>
typedef struct __attribute__((packed)) {
struct {
uint8_t min;
uint8_t max;
bool rgb;
bool led;
} light;
bool virtual_aic;
uint8_t mode;
uint32_t reserved;
} aic_cfg_t;
typedef struct {
uint16_t fps[2];
} aic_runtime_t;
extern aic_cfg_t *aic_cfg;
extern aic_runtime_t *aic_runtime;
void config_init();
void config_changed(); // Notify the config has changed
void config_factory_reset(); // Reset the config to factory default
#endif
/*
* Controller Config
* WHowe <github.com/whowechina>
*/
#ifndef CONFIG_H
#define CONFIG_H
#include <stdint.h>
#include <stdbool.h>
typedef struct __attribute__((packed)) {
struct {
uint8_t min;
uint8_t max;
bool rgb;
bool led;
} light;
bool virtual_aic;
uint8_t mode;
uint32_t reserved;
} aic_cfg_t;
typedef volatile struct {
bool debug;
} aic_runtime_t;
extern aic_cfg_t *aic_cfg;
extern aic_runtime_t aic_runtime;
void config_init();
void config_changed(); // Notify the config has changed
void config_factory_reset(); // Reset the config to factory default
#endif

View File

@ -14,11 +14,12 @@
#include "hardware/gpio.h"
#include "hardware/i2c.h"
#include "config.h"
#include "nfc.h"
#include "aime.h"
static bool debug = false;
#define DEBUG(...) if (debug) printf(__VA_ARGS__)
#define DEBUG(...) if (aic_runtime.debug) printf(__VA_ARGS__)
#define AIME_EXPIRE_TIME 10000000ULL
@ -98,11 +99,6 @@ void aime_init(aime_putc_func putc_func)
aime_putc = putc_func;
}
void aime_debug(bool enable)
{
debug = enable;
}
void aime_virtual_aic(bool enable)
{
virtual_aic.enabled = enable;
@ -184,7 +180,7 @@ static void send_response()
aime_putc(checksum);
DEBUG("\n\033[33mResp %2d:%02x >>", response.payload_len, response.cmd);
DEBUG("\n\033[33m%6ld<< %02x:", time_us_32() / 1000, response.cmd);
for (int i = 0; i < response.payload_len; i++) {
DEBUG(" %02x", response.payload[i]);
}

View File

@ -14,11 +14,12 @@
#include "hardware/gpio.h"
#include "hardware/i2c.h"
#include "config.h"
#include "nfc.h"
#include "bana.h"
static bool debug = false;
#define DEBUG(...) if (debug) printf(__VA_ARGS__)
#define DEBUG(...) if (aic_runtime.debug) printf(__VA_ARGS__)
#define BANA_EXPIRE_TIME 10000000ULL
@ -40,11 +41,6 @@ void bana_init(bana_putc_func putc_func)
bana_putc = putc_func;
}
void bana_debug(bool enable)
{
debug = enable;
}
typedef union __attribute__((packed)) {
struct {
struct {

View File

@ -35,7 +35,7 @@
#include "aime.h"
#include "bana.h"
#define DEBUG(...) { if (0) printf(__VA_ARGS__); }
#define DEBUG(...) if (aic_runtime.debug) printf(__VA_ARGS__)
static struct {
uint8_t current[9];