Пример #1
0
int
main(int argc, char *argv[]) {

        GOOGLE_PROTOBUF_VERIFY_VERSION;

        hu_log_library_versions();
        hu_install_crash_handler();
#if defined GDK_VERSION_3_10
        printf("GTK VERSION 3.10.0 or higher\n");
        //Assuming we are on Gnome, what's the DPI scale factor?
        gdk_init(&argc, &argv);

        GdkScreen * primaryDisplay = gdk_screen_get_default();
        if (primaryDisplay) {
                g_dpi_scalefactor = (float) gdk_screen_get_monitor_scale_factor(primaryDisplay, 0);
                printf("Got gdk_screen_get_monitor_scale_factor() == %f\n", g_dpi_scalefactor);
        }
#else
        printf("Using hard coded scalefactor\n");
        g_dpi_scalefactor = 1;
#endif
        gst_app_t *app = &gst_app;
        int ret = 0;
        errno = 0;

        gst_init(NULL, NULL);
        struct sigaction action;
        sigaction(SIGINT, NULL, &action);
        if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
            SDL_Log("Unable to initialize SDL: %s", SDL_GetError());
            return 1;
        }

        sigaction(SIGINT, &action, NULL);

        DesktopCommandServerCallbacks commandCallbacks;
        CommandServer commandServer(commandCallbacks);
        if (!commandServer.Start())
        {
            loge("Command server failed to start");
        }

        //loop to emulate the caar
        while(true)
        {
            DesktopEventCallbacks callbacks;
            HUServer headunit(callbacks);

            /* Start AA processing */
            ret = headunit.hu_aap_start(HU_TRANSPORT_TYPE::USB, true);
            if (ret < 0) {
                    printf("Phone is not connected. Connect a supported phone and restart.\n");
                    return 0;
            }

            callbacks.connected = true;

            g_hu = &headunit.GetAnyThreadInterface();
            commandCallbacks.eventCallbacks = &callbacks;

              /* Start gstreamer pipeline and main loop */
            ret = gst_loop(app);
            if (ret < 0) {
                    printf("STATUS:gst_loop() ret: %d\n", ret);
            }

            callbacks.connected = false;
            commandCallbacks.eventCallbacks = nullptr;

            /* Stop AA processing */
            ret = headunit.hu_aap_shutdown();
            if (ret < 0) {
                    printf("STATUS:hu_aap_stop() ret: %d\n", ret);
                    SDL_Quit();
                    return (ret);
            }

            g_hu = nullptr;
        }

        SDL_Quit();

        return (ret);
}
Пример #2
0
int main (int argc, char *argv[])
{	
	signal (SIGTERM, signals_handler);

	gst_app_t *app = &gst_app;
	int ret = 0;
	errno = 0;
	byte ep_in_addr  = -2;
	byte ep_out_addr = -2;

	/* Init gstreamer pipeline */
	ret = gst_pipeline_init(app);
	if (ret < 0) {
		printf("gst_pipeline_init() ret: %d\n", ret);
		return (-4);
	}

	/* Start AA processing */
	ret = hu_aap_start (ep_in_addr, ep_out_addr);
	if (ret == -1)
	{
		printf("Phone switched to accessory mode. Attempting once more.\n");
		sleep(1);
		ret = hu_aap_start (ep_in_addr, ep_out_addr);
	}

	if (ret < 0) {
		if (ret == -2)
			printf("Phone is not connected. Connect a supported phone and restart.\n");
		else if (ret == -1)
			printf("Phone switched to accessory mode. Restart to enter AA mode.\n");
		else
			printf("hu_app_start() ret: %d\n", ret);
		return (ret);
	}

	printf("Starting Android Auto...\n");

	/* Open Touchscreen Device */
	mTouch.fd = open(EVENT_DEVICE_TS, O_RDONLY);

	if (mTouch.fd == -1) {
		fprintf(stderr, "%s is not a vaild device\n", EVENT_DEVICE_TS);
		return -3;
	}

	/* Open Commander Device */
	mCommander.fd = open(EVENT_DEVICE_CMD, O_RDONLY);

	if (mCommander.fd == -1) {
		fprintf(stderr, "%s is not a vaild device\n", EVENT_DEVICE_CMD);
		return -3;
	}


	sendqueue = g_async_queue_new();

	pthread_t iput_thread;

	pthread_create(&iput_thread, NULL, &input_thread, (void *)app);

	pthread_t nm_thread;

	pthread_create(&nm_thread, NULL, &nightmode_thread, (void *)app);


	pthread_t mn_thread;

	pthread_create(&mn_thread, NULL, &main_thread, (void *)app);

	/* Start gstreamer pipeline and main loop */
	ret = gst_loop(app);
	if (ret < 0) {
		printf("gst_loop() ret: %d\n", ret);
		ret = -5;
	}

	/* Stop AA processing */
	ret = hu_aap_stop ();
	if (ret < 0) {
		printf("hu_aap_stop() ret: %d\n", ret);
		ret = -6;
	}

	close(mTouch.fd);
	close(mCommander.fd);

	pthread_cancel(nm_thread);
	pthread_cancel(mn_thread);
	pthread_cancel(iput_thread);

	printf("END \n");

	return (ret);
}