Example #1
0
void mzd_nightmode_start()
{
    if (navi_client != NULL)
        return;

    try
    {
        DBus::Connection service_bus(SERVICE_BUS_ADDRESS, false);
        service_bus.register_bus();
        navi_client = new Navi2NNGClient(service_bus, "/com/jci/navi2NNG", "com.jci.navi2NNG");
    }
    catch(DBus::Error& error)
    {
        loge("DBUS: Failed to connect to SERVICE bus %s: %s", error.name(), error.message());
        mzd_nightmode_stop();
        return;
    }

    printf("Nightmode service connection established.\n");
}
Example #2
0
static void nightmode_thread_func(std::condition_variable& quitcv, std::mutex& quitmutex)
{
    int nightmode = NM_NO_VALUE;
    mzd_nightmode_start();
    //Offset so the GPS and NM thread are not perfectly in sync testing each second
    std::this_thread::sleep_for(std::chrono::milliseconds(500));

    while (true)
    {
        int nightmodenow = mzd_is_night_mode_set();

        // We send nightmode status periodically, otherwise Google Maps
        // doesn't switch to nightmode if it's started late. Even if the
        // other AA UI is already in nightmode.
        if (nightmodenow != NM_NO_VALUE) {
            nightmode = nightmodenow;

            g_hu->hu_queue_command([nightmodenow](IHUConnectionThreadInterface& s)
            {
                HU::SensorEvent sensorEvent;
                sensorEvent.add_night_mode()->set_is_night(nightmodenow);

                s.hu_aap_enc_send_message(0, AA_CH_SEN, HU_SENSOR_CHANNEL_MESSAGE::SensorEvent, sensorEvent);
            });
        }

        {
            std::unique_lock<std::mutex> lk(quitmutex);
            if (quitcv.wait_for(lk, std::chrono::milliseconds(1000)) == std::cv_status::no_timeout)
            {
                break;
            }
        }
    }

    mzd_nightmode_stop();
}