Исправления мелких багов

This commit is contained in:
VladislavOstapov 2023-01-11 15:38:22 +03:00
parent 31f3f258f6
commit 0fb2f3b007
3 changed files with 58 additions and 24 deletions

View File

@ -145,22 +145,13 @@ static void image_draw_borders() {
image_insert_sprite(0, (int)(COLS - strlen(tmp) - 2), tmp, false); image_insert_sprite(0, (int)(COLS - strlen(tmp) - 2), tmp, false);
} }
static void showAll() {
// 10 строк, 10*(\sb%1d\s) = 40
// барабан хочу показывать так
//
// # Bx | Bx | Bx
// #time|time|time
//
image_init(); static int barrels_count = 0, barrels_time = 0, max_time = 0;
image_draw_borders();
char tmp[64]; static void collectBarrelsStatistic() {
sprintf(tmp, "Lock1=%2d Lock2=%2d", robot1_lock_zone, robot2_lock_zone); barrels_time = 0;
image_insert_sprite(0, 2, tmp); barrels_count = 0;
int barrels_count = 0, barrels_time = 0;
static int max_time = 0;
for (int i = 0; i < BARRELS_COUNT; i++) { for (int i = 0; i < BARRELS_COUNT; i++) {
if (barrels[i].flags.is_exist) { if (barrels[i].flags.is_exist) {
barrels_count++; barrels_count++;
@ -177,7 +168,23 @@ static void showAll() {
if (max_time < barrels_time) { if (max_time < barrels_time) {
max_time = barrels_time; max_time = barrels_time;
} }
}
static void showAll() {
// 10 строк, 10*(\sb%1d\s) = 40
// барабан хочу показывать так
//
// # Bx | Bx | Bx
// #time|time|time
//
image_init();
image_draw_borders();
char tmp[64];
sprintf(tmp, "Lock1=%2d Lock2=%2d", robot1_lock_zone, robot2_lock_zone);
image_insert_sprite(0, 2, tmp);
collectBarrelsStatistic();
sprintf(tmp, "barrels=%2d time=%d max_time=%d", barrels_count, barrels_time, max_time); sprintf(tmp, "barrels=%2d time=%d max_time=%d", barrels_count, barrels_time, max_time);
image_insert_sprite(0, 25, tmp); image_insert_sprite(0, 25, tmp);
@ -188,11 +195,24 @@ static void showAll() {
for (int i = 0; i < BARRELS_COUNT; i++) { for (int i = 0; i < BARRELS_COUNT; i++) {
const auto& b = barrels[i]; const auto& b = barrels[i];
if (b.flags.is_exist) { if (b.flags.is_exist) {
char flag_r = ' ';
if (b.flags.is_night) {
flag_r = 'n';
}
if (b.flags.is_empty) {
flag_r = 'e';
}
char flag_l = ' ';
if (b.flags.robot) {
flag_l = '*';
}
if (b.flags.is_up) { if (b.flags.is_up) {
sprintf(tmp, " B%d", i); sprintf(tmp, "%cB%d%c", flag_l, i, flag_r);
image_insert_sprite(4, (b.zone * 5) + 1, tmp); image_insert_sprite(4, (b.zone * 5) + 1, tmp);
} else { } else {
sprintf(tmp, " B%d\n%04d", i, b.software_timer); sprintf(tmp, "%cB%d%c\n%04d", flag_l, i, flag_r, b.software_timer);
image_insert_sprite(5, (b.zone * 5) + 1, tmp); image_insert_sprite(5, (b.zone * 5) + 1, tmp);
} }
@ -202,15 +222,15 @@ static void showAll() {
// рисуем роботов // рисуем роботов
if (hla_robot1_en) { if (hla_robot1_en) {
sprintf(tmp, "R1"); sprintf(tmp, "R1");
image_insert_sprite(2 + (robot1.mz.is_up ? 0 : 2), image_insert_sprite(2 + (robot1.mz.is_up ? 0 : 2) - (robot1.mx.correct_sensor ? 1 : 0),
(robot1.dx.current_zone * 5) + 2 + (robot1_offset_pos * 2), (robot1.dx.current_zone * 5) + 2 + (robot1_offset_pos * 2) + (robot1.mx.correct_sensor ? 1 : 0),
tmp); tmp);
} }
if (hla_robot2_en) { if (hla_robot2_en) {
sprintf(tmp, "R2"); sprintf(tmp, "R2");
image_insert_sprite(2 + (robot2.mz.is_up ? 0 : 2), image_insert_sprite(2 + (robot2.mz.is_up ? 0 : 2),
(robot2.dx.current_zone * 5) + 2 + (robot2_offset_pos * 2), (robot2.dx.current_zone * 5) + 2 + (robot2_offset_pos * 2) - (robot2.mx.correct_sensor ? 1 : 0),
tmp); tmp);
} }
@ -262,7 +282,13 @@ int main() {
while (true) { while (true) {
_scheduler_software_timer = 1; _scheduler_software_timer = 1;
// подсчитаем статистику
collectBarrelsStatistic();
// грузим не больше 5 барабанов
if (barrels_count < 5) {
button_load = 1; button_load = 1;
}
robot_main(); robot_main();
scheduler_main(); scheduler_main();

View File

@ -128,9 +128,9 @@ void scheduler_main()
robot1_lock_zone = -1; robot1_lock_zone = -1;
robot2_lock_zone = -1; robot2_lock_zone = -1;
// ставим всем барабанам которые в промывках флаг ночного барабана // ставим всем барабанам которые в промывках флаг ночного барабана (кроме тех, что заняты роботами)
for (short i = 0; i < BARRELS_COUNT; i++) { for (short i = 0; i < BARRELS_COUNT; i++) {
if (barrels[i].flags.is_exist) { if (barrels[i].flags.is_exist && barrels[i].flags.robot == 0) {
const short zones[] = { const short zones[] = {
ZONE_LOAD_1, ZONE_LOAD_1,
ZONE_WASHING_1A, ZONE_WASHING_1B, ZONE_WASHING_1A, ZONE_WASHING_1B,

12
utils.c
View File

@ -445,10 +445,18 @@ void debug_print_robot_code(const struct robot_code *code, const short robot_id,
* опустить траверсу * опустить траверсу
* установить время ожидания барабана (для промывки 4а) * установить время ожидания барабана (для промывки 4а)
*/ */
void create_operation(struct robot_code *code, const short barrel_id, const short start_zone, const short dest_zone, void create_operation(struct robot_code *code, short barrel_id, const short start_zone, const short dest_zone,
const short current_zone, const short robot_id) { const short current_zone, const short robot_id) {
// создаем код транзакции, пока обычный // создаем код транзакции, пока обычный
if (barrel_id >= BARRELS_COUNT) {
barrel_id = -1;
}
code->barrel_id = barrel_id; code->barrel_id = barrel_id;
if (barrel_id >= 0) {
barrels[barrel_id].flags.robot = robot_id;
}
short cmd_index = 0; short cmd_index = 0;
if (!one_robot_mode && !hla_night_mode) { if (!one_robot_mode && !hla_night_mode) {
@ -474,7 +482,7 @@ void create_operation(struct robot_code *code, const short barrel_id, const shor
} }
// если ночной режим, то нужно сразу обновить флаг у барабана // если ночной режим, то нужно сразу обновить флаг у барабана
if (hla_night_mode && barrel_id >= 0 && barrel_id < BARRELS_COUNT) { if (hla_night_mode && barrel_id >= 0) {
barrels[barrel_id].flags.is_night = -1; barrels[barrel_id].flags.is_night = -1;
} }