diff --git a/module/flash.c b/module/flash.c index a3e5933..fcdfdbb 100644 --- a/module/flash.c +++ b/module/flash.c @@ -61,7 +61,7 @@ void flash_prepare() { cal_data_t cal = { 0, 16383, 0, 16383 }; flashc_memcpy((void *)&f.cal, &cal, sizeof(cal), true); - device_config_t device_config = {.flip = 0 }; + device_config_t device_config = { .flip = 0 }; flashc_memcpy((void *)&f.device_config, &device_config, sizeof(device_config), true); flash_update_last_saved_scene(0); diff --git a/module/globals.h b/module/globals.h index d4c9bf7..69ab454 100644 --- a/module/globals.h +++ b/module/globals.h @@ -33,7 +33,9 @@ typedef enum { } tele_mode_t; // device config -typedef struct { uint8_t flip; } device_config_t; +typedef struct { + uint8_t flip; +} device_config_t; void set_mode(tele_mode_t mode); void set_last_mode(void); diff --git a/module/main.c b/module/main.c index 9b9ba1f..716a3d4 100644 --- a/module/main.c +++ b/module/main.c @@ -77,12 +77,14 @@ void tele_profile_delay(uint8_t d) { scene_state_t scene_state; char scene_text[SCENE_TEXT_LINES][SCENE_TEXT_CHARS]; uint8_t preset_select; -region line[8] = { - {.w = 128, .h = 8, .x = 0, .y = 0 }, {.w = 128, .h = 8, .x = 0, .y = 8 }, - {.w = 128, .h = 8, .x = 0, .y = 16 }, {.w = 128, .h = 8, .x = 0, .y = 24 }, - {.w = 128, .h = 8, .x = 0, .y = 32 }, {.w = 128, .h = 8, .x = 0, .y = 40 }, - {.w = 128, .h = 8, .x = 0, .y = 48 }, {.w = 128, .h = 8, .x = 0, .y = 56 } -}; +region line[8] = { { .w = 128, .h = 8, .x = 0, .y = 0 }, + { .w = 128, .h = 8, .x = 0, .y = 8 }, + { .w = 128, .h = 8, .x = 0, .y = 16 }, + { .w = 128, .h = 8, .x = 0, .y = 24 }, + { .w = 128, .h = 8, .x = 0, .y = 32 }, + { .w = 128, .h = 8, .x = 0, .y = 40 }, + { .w = 128, .h = 8, .x = 0, .y = 48 }, + { .w = 128, .h = 8, .x = 0, .y = 56 } }; char copy_buffer[SCENE_TEXT_LINES][SCENE_TEXT_CHARS]; uint8_t copy_buffer_len = 0; @@ -116,16 +118,16 @@ static uint8_t mod_key = 0, hold_key, hold_key_count = 0; static uint64_t last_adc_tick = 0; // timers -static softTimer_t clockTimer = {.next = NULL, .prev = NULL }; -static softTimer_t refreshTimer = {.next = NULL, .prev = NULL }; -static softTimer_t keyTimer = {.next = NULL, .prev = NULL }; -static softTimer_t cvTimer = {.next = NULL, .prev = NULL }; -static softTimer_t adcTimer = {.next = NULL, .prev = NULL }; -static softTimer_t hidTimer = {.next = NULL, .prev = NULL }; -static softTimer_t metroTimer = {.next = NULL, .prev = NULL }; -static softTimer_t monomePollTimer = {.next = NULL, .prev = NULL }; -static softTimer_t monomeRefreshTimer = {.next = NULL, .prev = NULL }; -static softTimer_t gridFaderTimer = {.next = NULL, .prev = NULL }; +static softTimer_t clockTimer = { .next = NULL, .prev = NULL }; +static softTimer_t refreshTimer = { .next = NULL, .prev = NULL }; +static softTimer_t keyTimer = { .next = NULL, .prev = NULL }; +static softTimer_t cvTimer = { .next = NULL, .prev = NULL }; +static softTimer_t adcTimer = { .next = NULL, .prev = NULL }; +static softTimer_t hidTimer = { .next = NULL, .prev = NULL }; +static softTimer_t metroTimer = { .next = NULL, .prev = NULL }; +static softTimer_t monomePollTimer = { .next = NULL, .prev = NULL }; +static softTimer_t monomeRefreshTimer = { .next = NULL, .prev = NULL }; +static softTimer_t gridFaderTimer = { .next = NULL, .prev = NULL }; //////////////////////////////////////////////////////////////////////////////// @@ -245,32 +247,32 @@ void cvTimer_callback(void* o) { } void clockTimer_callback(void* o) { - event_t e = {.type = kEventTimer, .data = 0 }; + event_t e = { .type = kEventTimer, .data = 0 }; event_post(&e); } void refreshTimer_callback(void* o) { - event_t e = {.type = kEventScreenRefresh, .data = 0 }; + event_t e = { .type = kEventScreenRefresh, .data = 0 }; event_post(&e); } void keyTimer_callback(void* o) { - event_t e = {.type = kEventKeyTimer, .data = 0 }; + event_t e = { .type = kEventKeyTimer, .data = 0 }; event_post(&e); } void adcTimer_callback(void* o) { - event_t e = {.type = kEventPollADC, .data = 0 }; + event_t e = { .type = kEventPollADC, .data = 0 }; event_post(&e); } void hidTimer_callback(void* o) { - event_t e = {.type = kEventHidTimer, .data = 0 }; + event_t e = { .type = kEventHidTimer, .data = 0 }; event_post(&e); } void metroTimer_callback(void* o) { - event_t e = {.type = kEventAppCustom, .data = 0 }; + event_t e = { .type = kEventAppCustom, .data = 0 }; event_post(&e); } diff --git a/src/chaos.c b/src/chaos.c index fd5dcee..11509c1 100644 --- a/src/chaos.c +++ b/src/chaos.c @@ -17,9 +17,9 @@ static const float chaos_henon_b = 0.3; static const int chaos_cell_count = 8; static const int chaos_cell_max = 0xff; -static chaos_state_t chaos_state = { - .ix = 5000, .ir = 5000, .alg = CHAOS_ALGO_LOGISTIC -}; +static chaos_state_t chaos_state = { .ix = 5000, + .ir = 5000, + .alg = CHAOS_ALGO_LOGISTIC }; void chaos_init() { chaos_scale_values(&chaos_state); diff --git a/src/ops/delay.c b/src/ops/delay.c index 7935e3d..cd9ddc5 100644 --- a/src/ops/delay.c +++ b/src/ops/delay.c @@ -4,9 +4,9 @@ #include "teletype.h" #include "teletype_io.h" -static void delay_common_add(scene_state_t *ss, exec_state_t *es, - int16_t i, int16_t delay_time, - const tele_command_t *post_command); +static void delay_common_add(scene_state_t *ss, exec_state_t *es, int16_t i, + int16_t delay_time, + const tele_command_t *post_command); static void mod_DEL_func(scene_state_t *ss, exec_state_t *es, command_state_t *cs, @@ -16,28 +16,30 @@ static void op_DEL_CLR_get(const void *data, scene_state_t *ss, exec_state_t *es, command_state_t *cs); static void mod_DEL_X_func(scene_state_t *ss, exec_state_t *es, - command_state_t *cs, - const tele_command_t *post_command); + command_state_t *cs, + const tele_command_t *post_command); static void mod_DEL_R_func(scene_state_t *ss, exec_state_t *es, - command_state_t *cs, - const tele_command_t *post_command); + command_state_t *cs, + const tele_command_t *post_command); const tele_mod_t mod_DEL = MAKE_MOD(DEL, mod_DEL_func, 1); const tele_op_t op_DEL_CLR = MAKE_GET_OP(DEL.CLR, op_DEL_CLR_get, 0, false); const tele_mod_t mod_DEL_X = MAKE_MOD(DEL.X, mod_DEL_X_func, 2); const tele_mod_t mod_DEL_R = MAKE_MOD(DEL.R, mod_DEL_R_func, 2); -//common code to queue a delay shared between all delay ops -//NOTE it is the responsibility of the callee to call tele_has_delays -static void delay_common_add(scene_state_t *ss, exec_state_t *es, - int16_t i, int16_t delay_time, - const tele_command_t *post_command) { +// common code to queue a delay shared between all delay ops +// NOTE it is the responsibility of the callee to call tele_has_delays +static void delay_common_add(scene_state_t *ss, exec_state_t *es, int16_t i, + int16_t delay_time, + const tele_command_t *post_command) { + if (i < DELAY_SIZE) { ss->delay.count++; ss->delay.time[i] = delay_time; ss->delay.origin_script[i] = es_variables(es)->script_number; ss->delay.origin_i[i] = es_variables(es)->i; copy_command(&ss->delay.commands[i], post_command); + } } static void mod_DEL_func(scene_state_t *ss, exec_state_t *es, @@ -64,65 +66,65 @@ static void op_DEL_CLR_get(const void *NOTUSED(data), scene_state_t *ss, clear_delays(ss); } -static void mod_DEL_X_func(scene_state_t *ss, exec_state_t *es, - command_state_t *cs, - const tele_command_t *post_command) { +static void mod_DEL_X_func(scene_state_t *ss, exec_state_t *es, + command_state_t *cs, + const tele_command_t *post_command) { int16_t i = 0; int16_t num_delays = cs_pop(cs); int16_t delay_time = cs_pop(cs); int16_t delay_time_next; - if (delay_time < 1) delay_time = 1; //minimum delay time = 1ms + if (delay_time < 1) delay_time = 1; // minimum delay time = 1ms - delay_time_next = delay_time; //set first delay time to delay time + delay_time_next = delay_time; // set first delay time to delay time // 0 is the magic number for an empty slot. // Be careful not to set delay.time[i] to 0 before calling this function. while (ss->delay.time[i] != 0 && i != DELAY_SIZE) i++; while (i < DELAY_SIZE && num_delays > 0) { - //queue the delay - delay_common_add(ss, es, i, delay_time_next, post_command); + // queue the delay + delay_common_add(ss, es, i, delay_time_next, post_command); - //increment delay time for next delay - //normalise incremented value to stop negative wrap from increment + // increment delay time for next delay + // normalise incremented value to stop negative wrap from increment delay_time_next += delay_time; - delay_time_next = normalise_value(1, 32767, 1, delay_time_next); + delay_time_next = normalise_value(1, 32767, 1, delay_time_next); - num_delays--; - i++; + num_delays--; + i++; } tele_has_delays(ss->delay.count > 0); } -static void mod_DEL_R_func(scene_state_t *ss, exec_state_t *es, - command_state_t *cs, - const tele_command_t *post_command) { +static void mod_DEL_R_func(scene_state_t *ss, exec_state_t *es, + command_state_t *cs, + const tele_command_t *post_command) { int16_t i = 0; - int16_t num_delays = cs_pop(cs); //number of chained delays - int16_t delay_time = cs_pop(cs); //delay time - int16_t delay_time_next; //incremented delay time + int16_t num_delays = cs_pop(cs); // number of chained delays + int16_t delay_time = cs_pop(cs); // delay time + int16_t delay_time_next; // incremented delay time - if (delay_time < 1) delay_time = 1; //minimum delay time = 1ms + if (delay_time < 1) delay_time = 1; // minimum delay time = 1ms - delay_time_next = 1; //set first delay time to 1ms to trigger immediately + delay_time_next = 1; // set first delay time to 1ms to trigger immediately // 0 is the magic number for an empty slot. // Be careful not to set delay.time[i] to 0 before calling this function. while (ss->delay.time[i] != 0 && i != DELAY_SIZE) i++; while (i < DELAY_SIZE && num_delays > 0) { - //queue the delay - delay_common_add(ss, es, i, delay_time_next, post_command); + // queue the delay + delay_common_add(ss, es, i, delay_time_next, post_command); - //increment delay time for next delay - //normalise incremented value to stop negative wrap from increment + // increment delay time for next delay + // normalise incremented value to stop negative wrap from increment delay_time_next += delay_time; - delay_time_next = normalise_value(1, 32767, 1, delay_time_next); + delay_time_next = normalise_value(1, 32767, 1, delay_time_next); - num_delays--; - i++; + num_delays--; + i++; } tele_has_delays(ss->delay.count > 0); diff --git a/src/state.h b/src/state.h index 94daa14..0ce148d 100644 --- a/src/state.h +++ b/src/state.h @@ -331,7 +331,9 @@ typedef struct { int16_t top; } command_state_stack_t; -typedef struct { command_state_stack_t stack; } command_state_t; +typedef struct { + command_state_stack_t stack; +} command_state_t; extern void cs_init(command_state_t *cs); extern int16_t cs_stack_size(command_state_t *cs); diff --git a/src/teletype.c b/src/teletype.c index d52ca3b..cb57757 100644 --- a/src/teletype.c +++ b/src/teletype.c @@ -147,7 +147,7 @@ process_result_t run_script_with_exec_state(scene_state_t *ss, exec_state_t *es, #ifdef TELETYPE_PROFILE tele_profile_script(script_no); #endif - process_result_t result = {.has_value = false, .value = 0 }; + process_result_t result = { .has_value = false, .value = 0 }; es_set_script_number(es, script_no); @@ -285,11 +285,11 @@ process_result_t process_command(scene_state_t *ss, exec_state_t *es, // --------- // sometimes we have single value left of the stack, if so return it if (cs_stack_size(&cs)) { - process_result_t o = {.has_value = true, .value = cs_pop(&cs) }; + process_result_t o = { .has_value = true, .value = cs_pop(&cs) }; return o; } else { - process_result_t o = {.has_value = false, .value = 0 }; + process_result_t o = { .has_value = false, .value = 0 }; return o; } } diff --git a/src/turtle.c b/src/turtle.c index 28c35d5..30c3a97 100644 --- a/src/turtle.c +++ b/src/turtle.c @@ -4,19 +4,21 @@ #define max(X, Y) ((X) > (Y) ? (X) : (Y)) void turtle_init(scene_turtle_t *st) { - scene_turtle_t t = {.fence = {.x1 = 0, .y1 = 0, .x2 = 3, .y2 = 63 }, - .mode = TURTLE_BUMP, - .heading = 180, - .speed = 100, - .stepped = false, - .script_number = TEMP_SCRIPT }; + scene_turtle_t t = { .fence = { .x1 = 0, .y1 = 0, .x2 = 3, .y2 = 63 }, + .mode = TURTLE_BUMP, + .heading = 180, + .speed = 100, + .stepped = false, + .script_number = TEMP_SCRIPT }; memcpy(st, &t, sizeof(t)); turtle_set_x(st, 0); turtle_set_y(st, 0); st->last = st->position; } -typedef struct { QT x1, y1, x2, y2; } Q_fence_t; +typedef struct { + QT x1, y1, x2, y2; +} Q_fence_t; static inline Q_fence_t normalize_fence(turtle_fence_t in, turtle_mode_t mode) { Q_fence_t out; diff --git a/tests/main.c b/tests/main.c index 9d8b03c..93269dc 100644 --- a/tests/main.c +++ b/tests/main.c @@ -31,7 +31,7 @@ void tele_kill() {} void tele_mute() {} void tele_vars_updated() {} void tele_profile_script(size_t s) {} -void tele_profile_delay(uint8_t d) {} +void tele_profile_delay(uint8_t d) {} bool tele_get_input_state(uint8_t n) { return false; } diff --git a/tests/op_mod_tests.c b/tests/op_mod_tests.c index fdf76f7..c69cb2a 100644 --- a/tests/op_mod_tests.c +++ b/tests/op_mod_tests.c @@ -109,10 +109,10 @@ TEST mod_stack_size() { for (int j = 0; j < mod->params + stack_extra; j++) cs_push(&cs, 0); // execute func - const tele_command_t sub_command = {.length = 1, - .separator = 0, - .data = { {.tag = OP, - .value = E_OP_A } } }; + const tele_command_t sub_command = { .length = 1, + .separator = 0, + .data = { { .tag = OP, + .value = E_OP_A } } }; mod->func(&ss, &es, &cs, &sub_command); // check that the stack has the correct number of items in it diff --git a/tests/process_tests.c b/tests/process_tests.c index 5f86210..3125aa8 100644 --- a/tests/process_tests.c +++ b/tests/process_tests.c @@ -11,7 +11,7 @@ // correct (allows contiuation of state) TEST process_helper_state(scene_state_t* ss, size_t n, char* lines[], int16_t answer) { - process_result_t result = {.has_value = false, .value = 0 }; + process_result_t result = { .has_value = false, .value = 0 }; exec_state_t es; es_init(&es); es_push(&es); diff --git a/tests/turtle_tests.c b/tests/turtle_tests.c index 088b046..1ee519d 100644 --- a/tests/turtle_tests.c +++ b/tests/turtle_tests.c @@ -34,7 +34,7 @@ static const char *error_message(error_t e) { TEST process_helper_state(scene_state_t *ss, size_t n, char *lines[], int16_t answer) { count++; - process_result_t result = {.has_value = false, .value = 0 }; + process_result_t result = { .has_value = false, .value = 0 }; exec_state_t es; memset(&es, 0, sizeof(es)); es_init(&es);