Le support aux utilisateurs et les demandes de création de comptes externes doivent être faites depuis les issues du projet GitLab HEFR (https://gitlab.forge.hefr.ch/forge-hefr/gitlab-hefr)

Commit 7347ce22 authored by Nicolas Maier's avatar Nicolas Maier
Browse files

Menu avec retour

parent 1f86ec11
Pipeline #7268 failed with stage
in 37 seconds
......@@ -109,5 +109,4 @@ int buttons_on_event(buttons_handler_t routine, void* param) {
return 0;
}
return -1;
}
......@@ -28,6 +28,7 @@
#include "communication.h"
#include "display.h"
#include "timer.h"
#include "menu.h"
#include "nrf24.h"
#include "kernel.h"
#include "thread.h"
......@@ -200,7 +201,7 @@ static void send_wait_ack(uint8_t* txdata) {
}
static void send_wait_hello() {
static bool send_wait_hello() {
uint8_t txdata[NRF_TX_SIZE];
txdata[0] = COMMUNICATION_HELLO;
int err_count = 0;
......@@ -237,16 +238,26 @@ static void send_wait_hello() {
if (received_hello) {
printf("Received answer hello\n");
break;
return true;
} else {
printf("Didn't receive answer hello\n");
}
if (menu_should_stop()) {
printf("Stop waiting answer hello, back to menu\n");
return false;
}
sleep_ms(COMMUNICATION_RETRY_DELAY_MS, false);
}
}
void communication_init(bool initIsJ1, msgqid_t msgq_game,
void communication_init() {
thread_create(thread_nrf_rx, 0, "nrf_rx", 0);
}
bool communication_start(bool initIsJ1, msgqid_t msgq_game,
msgqid_t msgq_game_pty) {
info = (struct communication_info) {
......@@ -257,12 +268,8 @@ void communication_init(bool initIsJ1, msgqid_t msgq_game,
.ack = 0,
.recv = 0,
};
communication_open();
send_wait_hello();
thread_create(thread_nrf_rx, 0, "nrf_rx", 0);
return send_wait_hello();
}
void communication_sendBar(uint8_t position) {
......
......@@ -38,7 +38,8 @@ enum communication_message {
COMMUNICATION_POINT,
};
void communication_init(bool isJ1, msgqid_t msgq_game, msgqid_t msgq_game_pty);
void communication_init();
bool communication_start(bool isJ1, msgqid_t msgq_game, msgqid_t msgq_game_pty);
void communication_sendBar(uint8_t position);
void communication_sendBall(uint8_t position_x, uint8_t position_y,
float dir_x, float dir_y);
......
......@@ -305,8 +305,6 @@ static void game_thread(void* param)
next_state.ball_dir.x = -next_state.ball_dir.x;
}
printf("------------- elapsed %zu\n", elapsed_time_2_us);
if (next_state.is_ally_playing) {
if (next_state.current_special == SPECIAL_RANDOMBALL) {
if (former_state.ball_pos.y < DISPLAY_GAME_AREA_SIZE/3
......@@ -448,7 +446,12 @@ static void game_buttons_handler(enum buttons_set btn, void* param) {
}
}
void game_init(bool initIsJ1, msgqid_t msgq_game, msgqid_t msgq_game_pty) {
void game_init() {
thread_create(game_thread, 0, "game_thread", 0);
}
void game_start(bool initIsJ1, msgqid_t msgq_game, msgqid_t msgq_game_pty) {
srand(timer_get_counter(TIMER_WAIT_END));
leds_init();
......@@ -463,6 +466,4 @@ void game_init(bool initIsJ1, msgqid_t msgq_game, msgqid_t msgq_game_pty) {
};
prepare_game();
thread_create(game_thread, 0, "game_thread", 0);
}
......@@ -27,7 +27,7 @@
#include "msgq.h"
#include "display.h"
void game_init(bool isJ1, msgqid_t msgq_game, msgqid_t msgq_game_pty);
void game_update_ennemy_bar(uint8_t pos);
extern void game_init();
extern void game_start(bool initIsJ1, msgqid_t msgq_game, msgqid_t msgq_game_pty);
#endif /* GAME_H */
......@@ -31,13 +31,14 @@
#include "communication.h"
#include "exception.h"
#include "intc.h"
#include "menu.h"
#include "wheel.h"
#include "leds.h"
#include "buttons.h"
#include "gpio.h"
#include "display.h"
#include "game.h"
#include "timer.h"
#include "buttons.h"
#include "kernel.h"
#include "thread.h"
......@@ -64,35 +65,13 @@ int main()
timer_init(DMTIMER_4);
timer_init(DMTIMER_5);
display_show_text(" Press ", 8, 23);
display_show_text(" 1 or 2 ", 4, 33);
display_show_text("to start", 4, 43);
bool isJ1 = false;
while (true) {
if (buttons_get_state(BUTTONS_1) == BUTTONS_CLOSED) {
isJ1 = true;
break;
}
if (buttons_get_state(BUTTONS_2) == BUTTONS_CLOSED) {
isJ1 = false;
break;
}
if (buttons_get_state(BUTTONS_4) == BUTTONS_CLOSED) {
display_clear_game_area();
}
}
display_clear_game_area();
display_show_text(" Waiting ", 0, 28);
display_show_text(isJ1 ? " for J2" : " for J1", 4, 38);
communication_init();
game_init();
msgqid_t msgq_game = msgq_create(50);
msgqid_t msgq_game_pty = msgq_create(50);
communication_init(isJ1, msgq_game, msgq_game_pty);
game_init(isJ1, msgq_game, msgq_game_pty);
menu_init(msgq_game, msgq_game_pty);
kernel_launch();
}
/**
* Copyright 2018 University of Applied Sciences Western Switzerland / Fribourg
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Project: HEIA-FR / Embedded Systems 2
*
* Author: Nicolas Maier - Jonathan Dias Vicente
* Date: 04.06.2019
*/
#include "stdint.h"
#include "stdbool.h"
#include "menu.h"
#include "communication.h"
#include "game.h"
#include "buttons.h"
#include "display.h"
void menu_init(msgqid_t msgq_game, msgqid_t msgq_game_pty) {
while (true) {
display_clear_game_area();
//display_reset_fields();
display_show_text(" Press ", 8, 23);
display_show_text(" 1 or 2 ", 4, 33);
display_show_text("to start", 4, 43);
bool isJ1 = false;
while (true) {
if (buttons_get_state(BUTTONS_1) == BUTTONS_CLOSED) {
isJ1 = true;
break;
}
if (buttons_get_state(BUTTONS_2) == BUTTONS_CLOSED) {
isJ1 = false;
break;
}
}
display_clear_game_area();
display_show_text(" Waiting ", 0, 28);
display_show_text(isJ1 ? " for J2" : " for J1", 4, 38);
if (communication_start(isJ1, msgq_game, msgq_game_pty)) {
game_start(isJ1, msgq_game, msgq_game_pty);
break;
}
}
}
bool menu_should_stop() {
return buttons_get_state(BUTTONS_4) == BUTTONS_CLOSED;
}
#pragma once
#ifndef MENU_H
#define MENU_H
/**
* Copyright 2018 University of Applied Sciences Western Switzerland / Fribourg
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Project: HEIA-FR / Embedded Systems 2
*
* Author: Nicolas Maier - Jonathan Dias Vicente
* Date: 04.06.2019
*/
#include "msgq.h"
extern void menu_init(msgqid_t msgq_game, msgqid_t msgq_game_pty);
extern bool menu_should_stop();
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment