Skip to content

Commit

Permalink
Implement luna-sysmgr portability initiative
Browse files Browse the repository at this point in the history
*  Add concept of known and unknown devices
*  Remove general reliance on TARGET_DEVICE
*  Add explicit support for hidlib, libnapp, media-api, nyx and affinity
*  Change default configuration for unknown device to exclude unsupported libraries
*  Clean up names for DEFINES for HAS_LUNA_PREFS and HAS_QPA

Open-webOS-DCO-1.0-Signed-off-by: Roger Stringer <[email protected]>

Change-Id: I476638f29a287cf1e352fd4a57813a44819835c3
  • Loading branch information
Roger Stringer committed Oct 26, 2012
1 parent d78f4f0 commit c7149d8
Show file tree
Hide file tree
Showing 56 changed files with 323 additions and 1,040 deletions.
139 changes: 4 additions & 135 deletions Src/base/AmbientLightSensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

#include <cjson/json.h>
#include <glib.h>
#if defined (TARGET_DEVICE)
#if defined(HAS_LUNA_PREF)
#include <lunaprefs.h>
#endif
#include <lunaservice.h>
Expand Down Expand Up @@ -121,18 +121,6 @@ AmbientLightSensor::AmbientLightSensor ()
LSErrorFree (&lserror);
}


#if defined (MACHINE_CASTLE)

m_alsEnabled = true;

m_alsBorder[0] = 10 * ALS_SAMPLE_SIZE;
m_alsBorder[1] = 200 * ALS_SAMPLE_SIZE;

m_alsMargin[0] = 2 * ALS_SAMPLE_SIZE;
m_alsMargin[1] = (m_alsBorder[1] / 10) > (ALS_SAMPLE_SIZE * 2) ? m_alsBorder[1] / 10 : ALS_SAMPLE_SIZE * 2;

#else
if (Settings::LunaSettings()->enableAls) {
m_alsEnabled = true;

Expand All @@ -158,8 +146,6 @@ AmbientLightSensor::AmbientLightSensor ()

}

#endif

m_instance = this;

g_debug ("%s started", __PRETTY_FUNCTION__);
Expand Down Expand Up @@ -203,7 +189,7 @@ bool AmbientLightSensor::stop ()

bool AmbientLightSensor::on ()
{
#if defined (TARGET_DEVICE)
#if defined(TARGET_DEVICE)
LSError lserror;
LSErrorInit(&lserror);
bool result;
Expand All @@ -230,9 +216,7 @@ bool AmbientLightSensor::on ()
m_alsCountInRegion = 0;
m_alsSamplesNeeded = ALS_INIT_SAMPLE_SIZE;
m_alsSampleList.clear();
#if !defined (MACHINE_CASTLE)
m_alsRegion = ALS_REGION_INDOOR;
#endif

/* fine-tuning support for NYX */
InputControl* ic = HostBase::instance()->getInputControlALS();
Expand Down Expand Up @@ -284,125 +268,10 @@ bool AmbientLightSensor::off ()

bool AmbientLightSensor::update (int intensity)
{
#if defined (MACHINE_CASTLE)
return updateAlsCastle (intensity);
#else
if (Settings::LunaSettings()->enableAls)
return updateAls (intensity);
else
return false;
#endif
}

// this function is called only on castle due to the sensor limitations
// the als region is calculated from a running average of the als values
// this causes the als region change to occur slowly
bool AmbientLightSensor::updateAlsCastle (int intensity)
{
#if defined (TARGET_DEVICE)
LSError lserror;
LSErrorInit(&lserror);
bool result = true;

int current = m_alsRegion;
int oldPtr = m_alsPointer;

if (m_alsSampleCount == 0)
{
// the first sample comes is, assume others will be close
int i = 0;
for ( ; i < m_alsSamplesNeeded ; i++)
m_alsValue[i] = intensity;
m_alsSum = intensity * m_alsSamplesNeeded;
}
else
{
m_alsSum -= m_alsValue[m_alsPointer];
m_alsValue[m_alsPointer] = intensity;
m_alsSum += intensity;
}

if (m_alsSampleCount < m_alsSamplesNeeded)
{
m_alsSampleCount++;
if (m_alsSampleCount == m_alsSamplesNeeded)
{
g_debug ("resetting ALS to sample at 1sec");

// switch to the slow mode
InputControl* ic = HostBase::instance()->getInputControlALS();
if (NULL != ic)
{
if (!ic->setRate(NYX_REPORT_RATE_LOW))
return false;
}
}
}

m_alsPointer = (m_alsPointer + 1) % m_alsSamplesNeeded;

if (m_alsDisabled > 0)
{
m_alsRegion = ALS_REGION_UNDEFINED;
g_debug ("%s: reported light level of %i (%i) [region set to default by subscription]", __PRETTY_FUNCTION__, intensity, m_alsSum / m_alsSamplesNeeded);

goto end;
}

if (!m_alsEnabled)
{
m_alsRegion = ALS_REGION_UNDEFINED;
g_debug ("%s: reported light level of %i (%i) [device not calibrated]", __PRETTY_FUNCTION__, intensity, m_alsSum / m_alsSamplesNeeded);

goto end;
}

if (m_alsSum < m_alsBorder[0])
{
if (current == ALS_REGION_INDOOR && m_alsSum >= m_alsBorder[0] - m_alsMargin[0])
m_alsRegion = ALS_REGION_INDOOR;
else
m_alsRegion = ALS_REGION_DARK;
}
else if (m_alsSum < m_alsBorder[1])
{
if (current == ALS_REGION_DARK && m_alsSum < m_alsBorder[0] + m_alsMargin[0])
m_alsRegion = ALS_REGION_DARK;
else if (current == ALS_REGION_OUTDOOR && m_alsSum >= m_alsBorder[1] - m_alsMargin[1])
m_alsRegion = ALS_REGION_OUTDOOR;
else
m_alsRegion = ALS_REGION_INDOOR;
}
else
{
if (current == ALS_REGION_INDOOR && m_alsSum < m_alsBorder[1] + m_alsMargin[1])
m_alsRegion = ALS_REGION_INDOOR;
else
m_alsRegion = ALS_REGION_OUTDOOR;
}

end:

if (m_alsSubscriptions > 0)
{
gchar *status = g_strdup_printf ("{\"returnValue\":true,\"current\":%i,\"average\":%i,\"region\":%i}",
m_alsValue[oldPtr], m_alsSum / m_alsSamplesNeeded, m_alsRegion);

if (NULL != status)
result = LSSubscriptionReply(m_service, "/control/status", status, &lserror);
if(!result)
{
LSErrorPrint (&lserror, stderr);
LSErrorFree (&lserror);
}
g_free(status);
}

// if there was no change return false, no need to update anything
return (m_alsRegion != current);
#else
return false;
#endif
}

bool sortIncr (int32_t alsVal1, int32_t alsVal2)
Expand All @@ -420,7 +289,7 @@ bool sortIncr (int32_t alsVal1, int32_t alsVal2)

bool AmbientLightSensor::updateAls(int intensity)
{
#if defined (TARGET_DEVICE)
#if defined(TARGET_DEVICE)
LSError lserror;
LSErrorInit(&lserror);
bool result = true;
Expand Down Expand Up @@ -646,7 +515,7 @@ Example status updates:
*/
bool AmbientLightSensor::controlStatus(LSHandle *sh, LSMessage *message, void *ctx)
{
#if defined (TARGET_DEVICE)
#if defined(TARGET_DEVICE)
LSError lserror;
LSErrorInit(&lserror);
bool result = true;
Expand Down
15 changes: 0 additions & 15 deletions Src/base/AmbientLightSensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,6 @@
#include "lunaservice.h"
#include <list>

#if defined (MACHINE_CASTLE)
// special case for castle
#define ALS_INIT_SAMPLE_SIZE 8
#define ALS_SAMPLE_SIZE 8
#define ALS_REGION_COUNT 5

#define ALS_REGION_UNDEFINED 0
#define ALS_REGION_DARK 1
#define ALS_REGION_INDOOR 3
#define ALS_REGION_OUTDOOR 5

#else
// for all devices after castle
#define ALS_INIT_SAMPLE_SIZE 10
#define ALS_SAMPLE_SIZE 10
#define ALS_REGION_COUNT 5
Expand All @@ -50,7 +37,6 @@
#define ALS_REGION_INDOOR 3
#define ALS_REGION_OUTDOOR 4

#endif

class AmbientLightSensor
{
Expand Down Expand Up @@ -99,7 +85,6 @@ class AmbientLightSensor
bool on();
bool off ();

bool updateAlsCastle (int intensity);
bool updateAls (int intensity);
};

Expand Down
2 changes: 1 addition & 1 deletion Src/base/BackupManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ Example response for a succesful call:
]
}
\endcode
/**
*
* Called by the backup service for all four of our callback functions: preBackup,
* postBackup, preRestore, postRestore.
*/
Expand Down
2 changes: 1 addition & 1 deletion Src/base/CoreNaviManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "Preferences.h"
#include "Settings.h"

#if defined (MACHINE_PIXIE) || defined(MACHINE_BROADWAY)
#if defined(MACHINE_BROADWAY)
#define MINIMUM_BRIGHTNESS 5
#define MAXIMUM_BRIGHTNESS 100
#else
Expand Down
6 changes: 3 additions & 3 deletions Src/base/CpuAffinity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
#include <glib.h>
#include <string.h>

#if defined(TARGET_DEVICE)
#if defined(HAS_AFFINITY)
#include <libaffinity.h>
#endif

#include "CpuAffinity.h"

void setCpuAffinity(int pid, int processor)
{
#if defined(TARGET_DEVICE)
#if defined(HAS_AFFINITY)
int ret = libaffinity_set_affinity(pid, processor);
if (ret)
g_warning("Failed to set cpu affinity for process %d to processor %d: retVal: %d, errno: %s",
Expand All @@ -46,7 +46,7 @@ void setCpuAffinity(int pid, int processor)

void resetCpuAffinity(int pid)
{
#if defined(TARGET_DEVICE)
#if defined(HAS_AFFINITY)
int ret = libaffinity_reset_affinity(pid);
if (ret)
g_warning("Failed to reset cpu affinity for process %d: retVal: %d, errno: %s",
Expand Down
Loading

0 comments on commit c7149d8

Please sign in to comment.