Esempio n. 1
0
void game_end() {
    //turns off all communication with Node2
    timer_disable();
    //can_play_music();
    oled_clear_screen();

    //print GAME OVER
    oled_pos(3, 4);
    oled_printf("GAME OVER");
    _delay_ms(1500);
    oled_clear_screen();


    oled_pos(2, 2);
    oled_printf("Final score:");
    oled_pos(4, 7);
    oled_printf("%d", game_score);
    printf("Final score: %d\n", game_score);

    oled_pos(7, 0);
    oled_printf("press any button");
    while ((!button_read(2) && !button_read(1) && button_read(3)) ); //wait for button press
    _delay_ms(100);
    oled_clear_screen();
}
Esempio n. 2
0
void game_postGameMessage(int rank) {
    oled_set_write_position(1,8);
    oled_printf("NEW HIGHSCORE!");
    oled_set_write_position(2,0);
    oled_printf("Finished as");
    oled_set_write_position(3,0);
    oled_printf("number %d", rank);
}
Esempio n. 3
0
int accel_demo_start(int sleep) {
	// Disable deep sleep
	ts_core_deepsleep_hook_add(accel_demo_deepsleep_hook, NULL);

	oled_start_module();

	struct oled_tblock_s loc_1 = {.x=0, .y=00, .width=128, .height=22};
	struct oled_tblock_s loc_2 = {.x=0, .y=24, .width=128, .height=10};
	struct oled_tblock_s loc_3 = {.x=0, .y=34, .width=128, .height=10};
	oled_printf(&loc_1, FONTID_SANS17X22, "Acceleration display");
	oled_printf(&loc_2, FONTID_MONO5X8, "Tilt = -");
	oled_printf(&loc_3, FONTID_MONO5X8, "Impact = -");

	ts_accel_callback_register(ACCEL_EVENT_IMPACT | ACCEL_EVENT_TILT, accel_demo_callback, NULL);

	return OK;
}

void accel_demo_stop() {
	ts_accel_callback_unregister(accel_demo_callback);
	// Remove deep sleep hook
	ts_core_deepsleep_hook_remove(accel_demo_deepsleep_hook);
}

static bool accel_demo_deepsleep_hook(void * const priv) {
	return false;
}

void accel_demo_callback(void const * const e, void * const priv) {
	struct accel_event_s const * const event = e;
	struct oled_tblock_s loc_2 = {.x=0, .y=24, .width=128, .height=10};
	struct oled_tblock_s loc_3 = {.x=0, .y=34, .width=128, .height=10};

	switch (event->id) {
		default:
			return;

		case ACCEL_EVENT_TILT: {
			struct accel_event_tilt const * const tilt_e = e;
			oled_printf(&loc_2, FONTID_MONO5X8, "Tilt = %d", tilt_e->tilt_value);
			}
			break;

		case ACCEL_EVENT_IMPACT: {
			struct accel_event_impact const * const imp_e = e;
			oled_printf(&loc_3, FONTID_MONO5X8, "Impact = %.2f g", ((float)imp_e->impact_value)/1000.0f);
			}
			break;
	}
}
Esempio n. 4
0
void game_track_score() {
    game_score_counter++;

    //Using 70 Hz clock
    if(game_score_counter > counting_speed) {
        game_score++;
        game_score_counter = 0;
        oled_set_write_position(4, 16);
        oled_printf("Score: %d", game_score);
    }
}
Esempio n. 5
0
void game_main(void) {
    game_introMessage();
    while(!joy_read_right_button()) {
        _delay_us(10);
    }
    game_start();
    while(!game_lost) {
        _delay_us(10);
    }
    oled_printf("Game lost!");
    game_end();
}
Esempio n. 6
0
void game_keep_score() {
    if (ball_rolling)  {
        game_score_counter++;
    }

    if (game_score_counter > 7) {
        game_score++;
        game_score_counter = 0;
        oled_pos(3, 11);
        oled_printf("%d", game_score);
    }
}
Esempio n. 7
0
void game_introMessage(void) {
    oled_clear_screen();
    oled_set_write_position(0, 0);
    oled_printf("Welcome to this");
    oled_set_write_position(1, 0);
    oled_printf("interactive ball");
    oled_set_write_position(2, 0);
    oled_printf("bump experience.");
    oled_set_write_position(4, 0);
    oled_printf("Put your balls");
    oled_set_write_position(5, 0);
    oled_printf("on the solenoid");
    oled_set_write_position(6, 0);
    oled_printf("to begin..");
    oled_set_write_position(7, 0);
    oled_printf("  ..good luck");
}
Esempio n. 8
0
void game_start() {
    game_reset_score();
    game_not_lost = 1;
    /*
    	oled_clear_screen();
    	oled_pos(3,2);
    	oled_printf("remove ball");
    	_delay_ms(1500);*/
    oled_clear_screen();
    oled_pos(3, 2);
    oled_printf("Score: ");

    //flush pending game_lost messages
    can_data_receive();
    can_data_receive();
    timer_enable();

    ball_rolling = 0;
}
Esempio n. 9
0
const bool wifi(const struct ip_info *info) {
	uint8_t mac_address[6] ALIGNED;
	char *ap_password = NULL;
	struct ip_info ip_config;

	oled_info_t oled_info = { OLED_128x64_I2C_DEFAULT };
	const bool oled_connected =  oled_start(&oled_info);


	if (!wifi_detect()){
		(void) console_status(CONSOLE_YELLOW, WIFI_NOT_CONNECTED);
		OLED_CONNECTED(oled_connected, oled_puts(&oled_info, WIFI_NOT_CONNECTED));
		return false;
	}

	(void) ap_params_init();
	ap_password = (char *) ap_params_get_password();

	(void) console_status(CONSOLE_YELLOW, STARTING_WIFI);
	OLED_CONNECTED(oled_connected, oled_status(&oled_info, STARTING_WIFI));

	wifi_ap_init(ap_password);

	printf("ESP8266 information\n");
	printf(" SDK      : %s\n", system_get_sdk_version());
	printf(" Firmware : %s\n\n", wifi_get_firmware_version());

	if (network_params_init()) {
		(void) console_status(CONSOLE_YELLOW, CHANGING_TO_STATION_MODE);
		OLED_CONNECTED(oled_connected, oled_status(&oled_info, CHANGING_TO_STATION_MODE));

		ssid = network_params_get_ssid();
		if (network_params_is_use_dhcp()) {
			wifi_station(ssid, network_params_get_password());
		} else {
			ip_config.ip.addr = network_params_get_ip_address();
			ip_config.netmask.addr = network_params_get_net_mask();
			ip_config.gw.addr = network_params_get_default_gateway();
			wifi_station_ip(ssid, network_params_get_password(), &ip_config);
		}
	}

	opmode = wifi_get_opmode();

	if (opmode == WIFI_STA) {
		printf("WiFi mode : Station (AP: %s)\n", network_params_get_ssid());
	} else {
		printf("WiFi mode : Access Point (authenticate mode: %s)\n", *ap_password == '\0' ? "Open" : "WPA_WPA2_PSK");
	}

	if (wifi_get_macaddr(mac_address)) {
		printf(" MAC address : "MACSTR "\n", MAC2STR(mac_address));
	} else {
		(void) console_error("wifi_get_macaddr");
		OLED_CONNECTED(oled_connected, oled_status(&oled_info, "E: wifi_get_macaddr"));
	}

	printf(" Hostname    : %s\n", wifi_get_hostname());

	if (wifi_get_ip_info(&ip_config)) {
		printf(" IP-address  : " IPSTR "\n", IP2STR(ip_config.ip.addr));
		printf(" Netmask     : " IPSTR "\n", IP2STR(ip_config.netmask.addr));
		printf(" Gateway     : " IPSTR "\n", IP2STR(ip_config.gw.addr));

		if (opmode == WIFI_STA) {
			const _wifi_station_status status = wifi_station_get_connect_status();
			printf("      Status : %s\n", wifi_station_status(status));

			if (status != WIFI_STATION_GOT_IP) {
				(void) console_error("Not connected!");

				if (oled_connected) {
					oled_set_cursor(&oled_info, 2, 0);
					(void) oled_puts(&oled_info, wifi_station_status(status));
					oled_set_cursor(&oled_info, 5, 0);
					(void) oled_printf(&oled_info, "SSID : %s\n", network_params_get_ssid());
					oled_status(&oled_info, "E: Not connected!");
				}

				for (;;)
					;
			}
		}
	} else {
		(void) console_error("wifi_get_ip_info");
		OLED_CONNECTED(oled_connected, oled_status(&oled_info, "E: wifi_get_ip_info"));
	}

	if (fota_params_init()) {
		OLED_CONNECTED(oled_connected, oled_status(&oled_info, "FOTA mode"));
		console_newline();
		fota(fota_params_get_server());
		for (;;)
			;
	}

	(void) console_status(CONSOLE_GREEN, WIFI_STARTED);
	OLED_CONNECTED(oled_connected, oled_status(&oled_info, WIFI_STARTED));

	memcpy((void *)info, (const void *)&ip_config, sizeof(struct ip_info));

	return true;
}