Skip to content

Commit

Permalink
Merge branch 'jb48562_initial_battery_level' into 'master'
Browse files Browse the repository at this point in the history
Fix initial battery level reporting

See merge request mer-core/mce!133
  • Loading branch information
spiiroin committed Feb 4, 2020
2 parents c34d8cd + 3e41f3d commit acf7357
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 38 deletions.
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -262,6 +262,7 @@ CFLAGS += -Wstack-protector
#CFLAGS += -Werror (OBS build might have different compiler)
CFLAGS += -Wno-declaration-after-statement
CFLAGS += -Wno-missing-field-initializers
CFLAGS += -Wimplicit-fallthrough=2

# Linker
LDLIBS += -Wl,--as-needed
Expand Down
8 changes: 4 additions & 4 deletions datapipe.c
Expand Up @@ -3,9 +3,9 @@
* This file implements the sinmple datapipe framework;
* this can be used to filter data and to setup data triggers
* <p>
* Copyright © 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (C) 2014-2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
* Copyright (c) 2007 - 2008 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (c) 2014 - 2020 Jolla Ltd.
* Copyright (c) 2019 - 2020 Open Mobile Platform LLC.
* <p>
* @author David Weinehall <david.weinehall@nokia.com>
* @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
Expand Down Expand Up @@ -744,7 +744,7 @@ datapipe_t battery_status_pipe = DATAPIPE_INIT(battery_status,
datapipe_t battery_state_pipe = DATAPIPE_INIT(battery_state, battery_state, BATTERY_STATE_UNKNOWN, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);

/** Battery charge level; read only */
datapipe_t battery_level_pipe = DATAPIPE_INIT(battery_level, int, BATTERY_LEVEL_INITIAL, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
datapipe_t battery_level_pipe = DATAPIPE_INIT(battery_level, int, MCE_BATTERY_LEVEL_UNKNOWN, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);

/** Topmost window PID; read only */
datapipe_t topmost_window_pid_pipe = DATAPIPE_INIT(topmost_window_pid, int, -1, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
Expand Down
10 changes: 6 additions & 4 deletions evdev.c
Expand Up @@ -2,7 +2,8 @@
* @file evdev.c
* Mode Control Entity - evdev input device handling
* <p>
* Copyright (C) 2012-2019 Jolla Ltd.
* Copyright (c) 2012 - 2020 Jolla Ltd.
* Copyright (c) 2020 Open Mobile Platform LLC.
* <p>
* @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
*
Expand Down Expand Up @@ -262,16 +263,17 @@ int evdev_identify_device(int fd)
unsigned long bmap_type[BMAP_SIZE(EV_CNT)];
unsigned long bmap_code[BMAP_SIZE(KEY_CNT)];
unsigned long bmap_stat[BMAP_SIZE(KEY_CNT)];
char path[256];
char linkpath[PATH_MAX];
char path[PATH_MAX];
int n;

if( fd < 0 )
{
goto cleanup;
}

snprintf(path, sizeof path, "/proc/self/fd/%d", fd);
if( (n = readlink(path, path, sizeof path - 1)) <= 0 )
snprintf(linkpath, sizeof linkpath, "/proc/self/fd/%d", fd);
if( (n = readlink(linkpath, path, sizeof path - 1)) <= 0 )
{
strcpy(path, "unknown");
}
Expand Down
6 changes: 4 additions & 2 deletions event-input.c
Expand Up @@ -2,8 +2,9 @@
* @file event-input.c
* /dev/input event provider for the Mode Control Entity
* <p>
* Copyright © 2004-2011 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (C) 2013-2019 Jolla Ltd.
* Copyright (c) 2004 - 2011 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (c) 2013 - 2020 Jolla Ltd.
* Copyright (c) 2020 Open Mobile Platform LLC.
* <p>
* @author David Weinehall <david.weinehall@nokia.com>
* @author Ismo Laitinen <ismo.laitinen@nokia.com>
Expand Down Expand Up @@ -3542,6 +3543,7 @@ evin_datapipe_display_state_curr_cb(gconstpointer data)
evin_input_grab_set_touching(&evin_ts_grab_state, true);
evin_input_grab_set_touching(&evin_ts_grab_state, false);
}
/* Fall through */

case MCE_DISPLAY_ON:
case MCE_DISPLAY_DIM:
Expand Down
8 changes: 4 additions & 4 deletions mce-common.c
Expand Up @@ -2,8 +2,8 @@
* @file mce-common.c
* Common state logic for Mode Control Entity
* <p>
* Copyright (C) 2017-2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
* Copyright (c) 2017 - 2020 Jolla Ltd.
* Copyright (c) 2019 - 2020 Open Mobile Platform LLC.
* <p>
* @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
*
Expand Down Expand Up @@ -133,8 +133,8 @@ static battery_status_t battery_status = BATTERY_STATUS_UNDEF;
/** Battery state; assume unknown */
static battery_state_t battery_state = BATTERY_STATE_UNKNOWN;

/** Battery charge level: assume 100% */
static gint battery_level = BATTERY_LEVEL_INITIAL;
/** Battery charge level: assume unknown */
static gint battery_level = MCE_BATTERY_LEVEL_UNKNOWN;

/** Cached (raw) proximity sensor state */
static cover_state_t proximity_sensor_actual = COVER_UNDEF;
Expand Down
9 changes: 3 additions & 6 deletions mce.h
Expand Up @@ -2,9 +2,9 @@
* @file mce.h
* Generic headers for Mode Control Entity
* <p>
* Copyright © 2004-2011 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (C) 2012-2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
* Copyright (c) 2004 - 2011 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (c) 2012 - 2020 Jolla Ltd.
* Copyright (c) 2019 - 2020 Open Mobile Platform LLC.
* <p>
* @author David Weinehall <david.weinehall@nokia.com>
* @author Irina Bezruk <ext-irina.bezruk@nokia.com>
Expand Down Expand Up @@ -310,9 +310,6 @@ const char *tklock_request_repr(tklock_request_t state);

const char *tklock_status_repr(int status);

/** Assumed initial battery level */
#define BATTERY_LEVEL_INITIAL 100

/** Raw udev battery status */
typedef enum
{
Expand Down
8 changes: 4 additions & 4 deletions modules/battery-udev.c
Expand Up @@ -2,8 +2,8 @@
* @file battery-udev.c
* Battery module -- this implements battery and charger logic for MCE
* <p>
* Copyright (C) 2018-2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
* Copyright (c) 2018 - 2020 Jolla Ltd.
* Copyright (c) 2019 - 2020 Open Mobile Platform LLC.
* <p>
* @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
* <p>
Expand Down Expand Up @@ -296,7 +296,7 @@ G_MODULE_EXPORT module_info_struct module_info =
* sync with default values held in the relevant datapipes.
*/
static mcebat_t mcebat_datapipe = {
.battery_level = BATTERY_LEVEL_INITIAL,
.battery_level = MCE_BATTERY_LEVEL_UNKNOWN,
.battery_status = BATTERY_STATUS_UNDEF,
.battery_state = BATTERY_STATE_UNKNOWN,
.charger_state = CHARGER_STATE_UNDEF,
Expand All @@ -306,7 +306,7 @@ static mcebat_t mcebat_datapipe = {
/** Cached battery state as derived from udev
*/
static mcebat_t mcebat_actual = {
.battery_level = BATTERY_LEVEL_INITIAL,
.battery_level = MCE_BATTERY_LEVEL_UNKNOWN,
.battery_status = BATTERY_STATUS_UNDEF,
.battery_state = BATTERY_STATE_UNKNOWN,
.charger_state = CHARGER_STATE_UNDEF,
Expand Down
10 changes: 6 additions & 4 deletions modules/led.c
Expand Up @@ -2,8 +2,9 @@
* @file led.c
* LED module -- this handles the LED logic for MCE
* <p>
* Copyright © 2006-2011 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (C) 2012-2019 Jolla Ltd.
* Copyright (c) 2006 - 2011 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (c) 2012 - 2020 Jolla Ltd.
* Copyright (c) 2020 Open Mobile Platform LLC.
* <p>
* @author David Weinehall <david.weinehall@nokia.com>
* @author Tapio Rantala <ext-tapio.rantala@nokia.com>
Expand Down Expand Up @@ -57,6 +58,7 @@
#include <fcntl.h>

#include <mce/dbus-names.h>
#include <mce/mode-names.h>

#include <gmodule.h>

Expand Down Expand Up @@ -2888,8 +2890,8 @@ static gboolean init_patterns(void)
/** Flag for: charger connected */
static charger_state_t charger_state = CHARGER_STATE_UNDEF;

/** Current battery percent level */
static int battery_level = 0;
/** Current battery percent level: assume unknown */
static int battery_level = MCE_BATTERY_LEVEL_UNKNOWN;

/** Setting: sw breathing allowed */
static gboolean sw_breathing_enabled = MCE_DEFAULT_LED_SW_BREATH_ENABLED;
Expand Down
16 changes: 11 additions & 5 deletions modules/powersavemode.c
Expand Up @@ -3,8 +3,9 @@
* Power saving mode module -- this handles the power saving mode
* for MCE
* <p>
* Copyright © 2010-2011 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (C) 2014-2019 Jolla Ltd.
* Copyright (c) 2010 - 2011 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (c) 2014 - 2020 Jolla Ltd.
* Copyright (c) 2020 Open Mobile Platform LLC.
* <p>
* @author David Weinehall <david.weinehall@nokia.com>
* @author Tapio Rantala <ext-tapio.rantala@nokia.com>
Expand Down Expand Up @@ -32,6 +33,7 @@
#include "../mce-dbus.h"

#include <mce/dbus-names.h>
#include <mce/mode-names.h>

#include <gmodule.h>

Expand All @@ -51,8 +53,9 @@ G_MODULE_EXPORT module_info_struct module_info = {
.priority = 250
};

/** Battery charge level */
static gint battery_level = 100;
/** Battery charge level: assume unknown == -1 */
static gint battery_level = MCE_BATTERY_LEVEL_UNKNOWN;

/** Charger state */
static charger_state_t charger_state = CHARGER_STATE_UNDEF;

Expand Down Expand Up @@ -138,9 +141,12 @@ static void update_power_saving_mode(void)
* of other settings and states. */
activate = true;
}
else if ( battery_level <= MCE_BATTERY_LEVEL_UNKNOWN ) {
/* Ignore triggers based on charger and battery
* info until battery level becomes known. */
}
else if( charger_state == CHARGER_STATE_ON ) {
/* If charger is connected, PSM should be deactivated. */
activate = false;
}
else if( force_psm ) {
/* Forced PSM is triggered when no charger is connected. */
Expand Down
12 changes: 7 additions & 5 deletions tools/mcetool.c
@@ -1,9 +1,9 @@
/** @file mcetool.c
* Tool to test and remote control the Mode Control Entity
* <p>
* Copyright © 2005-2011 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (C) 2012-2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
* Copyright (c) 2005 - 2011 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (c) 2012 - 2020 Jolla Ltd.
* Copyright (c) 2019 - 2020 Open Mobile Platform LLC.
* <p>
* @author David Weinehall <david.weinehall@nokia.com>
* @author Santtu Lakkala <ext-santtu.1.lakkala@nokia.com>
Expand Down Expand Up @@ -2727,7 +2727,7 @@ static bool mcetool_do_set_charger_state(const char *arg)
static bool mcetool_do_set_battery_level(const char *arg)
{
int level = xmce_parse_integer(arg);
if( level < 0 || level > 100 ) {
if( level < -1 || level > 100 ) {
errorf("%s: invalid battery level\n", arg);
return false;
}
Expand Down Expand Up @@ -7999,7 +7999,9 @@ static const char version_text[] =
PROG_NAME" v"G_STRINGIFY(PRG_VERSION)"\n"
"Written by David Weinehall.\n"
"\n"
"Copyright (C) 2005-2011 Nokia Corporation. All rights reserved.\n"
"Copyright (c) 2005 - 2011 Nokia Corporation. All rights reserved.\n"
"Copyright (c) 2012 - 2020 Jolla Ltd.\n"
"Copyright (c) 2019 - 2020 Open Mobile Platform LLC.\n"
;

static __attribute__((__noreturn__)) bool mcetool_do_version(const char *arg)
Expand Down

0 comments on commit acf7357

Please sign in to comment.