~phablet-team/powerd/trunk

« back to all changes in this revision

Viewing changes to src/powerd-sensors.cpp

  • Committer: CI Train Bot
  • Author(s): Alexandros Frantzis
  • Date: 2015-09-30 12:29:37 UTC
  • mfrom: (178.1.4 unity-screen-reason-call)
  • Revision ID: ci-train-bot@canonical.com-20150930122937-n2wpyvcsx5ga37t4
Turn the screen on using reason call/call_done when a voice call is received/finishes respectively Fixes: #1291455
Approved by: PS Jenkins bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include <ubuntu/application/sensors/light.h>
28
28
#include <ubuntu/application/sensors/proximity.h>
29
29
 
 
30
namespace
 
31
{
 
32
 
30
33
UASensorsProximity* prox_sensor;
31
34
UASensorsLight* light_sensor;
32
35
GMainLoop* main_loop = NULL;
33
36
std::atomic<bool> allow_synthetic{false};
 
37
enum class Proximity { unknown, near, far };
 
38
std::atomic<Proximity> current_proximity{Proximity::unknown};
 
39
 
 
40
void update_and_emit_proximity(Proximity proximity)
 
41
{
 
42
    current_proximity = proximity;
 
43
    if (proximity == Proximity::near)
 
44
        powerd_proximity_event(TRUE);
 
45
    else if (proximity == Proximity::far)
 
46
        powerd_proximity_event(FALSE);
 
47
}
34
48
 
35
49
gboolean emit_synthetic_proximity_far(void *context)
36
50
{
37
51
    if (allow_synthetic)
38
 
        powerd_proximity_event(FALSE);
 
52
        update_and_emit_proximity(Proximity::far);
39
53
 
40
54
    return FALSE;
41
55
}
47
61
    {
48
62
        case U_PROXIMITY_NEAR:
49
63
        {
50
 
            powerd_proximity_event(TRUE);
 
64
            update_and_emit_proximity(Proximity::near);
51
65
            break;
52
66
        }
53
67
        case U_PROXIMITY_FAR:
54
68
        {
55
 
            powerd_proximity_event(FALSE);
 
69
            update_and_emit_proximity(Proximity::far);
56
70
            break;
57
71
        }
58
72
    }
59
73
}
60
74
 
 
75
}
 
76
 
61
77
void powerd_sensors_proximity_enable(void)
62
78
{
63
79
    //FIXME: Some proximity sensors do not
66
82
    //far event in case no event has been emitted 500ms
67
83
    //after enabling the proximity sensor
68
84
    allow_synthetic = true;
 
85
    current_proximity = Proximity::unknown;
69
86
    g_timeout_add(500, emit_synthetic_proximity_far, NULL);
70
87
 
71
88
    ua_sensors_proximity_enable(prox_sensor);
75
92
{
76
93
    allow_synthetic = false;
77
94
    ua_sensors_proximity_disable(prox_sensor);
 
95
    current_proximity = Proximity::unknown;
 
96
}
 
97
 
 
98
void powerd_sensors_proximity_emit(void)
 
99
{
 
100
    update_and_emit_proximity(current_proximity);
78
101
}
79
102
 
80
103
void on_new_als_event(UASLightEvent *event, void *context)