Brightness auto adjusting to ambient light level

This is general talk area for things that NOT RELATED WITH TV! Instead, about internal works like web site, forum, wiki, or talking, etc...

User avatar
erdem_ua
SamyGO Admin
Posts: 3112
Joined: Thu Oct 01, 2009 6:02 am
Location: Istanbul, Turkey
Contact:

Re: Brightness auto adjusting to ambient light level

Post by erdem_ua »

I think it's not needed to be "real time". Also we don't needed to scan whole frame. Just little from corners. From each side, %10+%10 of each frame is enough to calculate those values.
But don't know if MPEG allows partial decompression of an image and if there is enough juice to do that...

And with little money, poormans could use external ARM chip to decode MPEG2/4 stream...
Diverting stream to USB port and decode with ARM CPU will give us also almost real time processing.
There is a $25 computer could handle this calculation job which has graphic accelerator, MPEG2/4 decoder inside :D
But that will be overkill for a job :)

sbav, Could I update brightness setting via external tool?
I don't want to dive into exeDSP assembly again.
I want to update brightness directly from a program
Do you have lucky (register) number for that job?

Integrating this into exeDSP also problematic because TV needed to check sensor continuously. For example for each second...
I needed to find such a function...etc.

sbav1
Official SamyGO Developer
Posts: 374
Joined: Fri Jan 15, 2010 10:20 am

Re: Brightness auto adjusting to ambient light level

Post by sbav1 »

erdem_ua wrote: sbav, Could I update brightness setting via external tool?
I don't want to dive into exeDSP assembly again.
I want to update brightness directly from a program
Do you have lucky (register) number for that job?
Hmm, low-level function used for brightness control in LCD B650 is probably ChelseaPictureShare::m_ChelseaPicture_SetBrightness().
I don't think it is just one register (a whole array of registers, more likely). Also it needs some factory/calibration settings from EEPROM.
IMO chances for "external tool" approach are pretty slim.

There are numerous higher-level methods in firmware for brightness setting:

Code: Select all

[0067097C] -> SsPictureBase::SetBrightness(unsigned char) ; _ZN13SsPictureBase13SetBrightnessEh
[006182E0] -> TPAScreen::SetBrightness(unsigned char) ; _ZN9TPAScreen13SetBrightnessEh
[0067097C] -> SsPictureBase::SetBrightness(unsigned char) ; _ZN13SsPictureBase13SetBrightnessEh
[00701424] -> TDaVideoEnhancer::SetBright(int) ; _ZN16TDaVideoEnhancer9SetBrightEi
[0077FCE0] -> TDsChelseaVideoEnhancer::SetBright(int) ; _ZN23TDsChelseaVideoEnhancer9SetBrightEi
[0079BEEC] -> TDsFRCQVideoEnhancer::SetBright(int) ; _ZN20TDsFRCQVideoEnhancer9SetBrightEi
[00706B00] -> TDiVideoEnhancer::SetBright(int) ; _ZN16TDiVideoEnhancer9SetBrightEi
[00A56F34] -> TCScreenInfoManager::SetBrightness(unsigned char) ; _ZN19TCScreenInfoManager13SetBrightnessEh
[00A5A854] -> TPCScreen::SetBrightness(unsigned char) ; _ZN9TPCScreen13SetBrightnessEh
SsPictureBase::SetBrightness() looks promising; AFAIRC, SsPicture::SsPicture object instance pointer is stored somewhere in SsObject::m_poObjectList table.

User avatar
erdem_ua
SamyGO Admin
Posts: 3112
Joined: Thu Oct 01, 2009 6:02 am
Location: Istanbul, Turkey
Contact:

Re: Brightness auto adjusting to ambient light level

Post by erdem_ua »

Himm. Okey, exeDSP hook/injection is a must again...
Do you know anywhere that I can hook IP that receive self updates while TV is on? I needed to re-read/check/set brightness in every x sec...

sbav1
Official SamyGO Developer
Posts: 374
Joined: Fri Jan 15, 2010 10:20 am

Re: Brightness auto adjusting to ambient light level

Post by sbav1 »

erdem_ua wrote:Himm. Okey, exeDSP hook/injection is a must again...
Do you know anywhere that I can hook IP that receive self updates while TV is on? I needed to re-read/check/set brightness in every x sec...
Perhaps you can simply create an additional thread inside exeDSP, like this:

loader.c

Code: Select all

#include <stdio.h>
#include <dlfcn.h>
#include <errno.h>
#include <sys/mman.h>
#include <pthread.h>
#include <string.h>

int Game_Main(const char  *path, const char *udn __attribute__ ((unused)))
{
   unsigned *handle=NULL;
   char filename[128];

   strcpy(filename, path);
   strcat(filename,"remote.so");
   if ((handle=dlopen(filename, RTLD_NOW | RTLD_LOCAL | RTLD_NODELETE)) == NULL) {
      fputs("Cannot open remote.so!\n", stderr);
      fputs (dlerror(), stderr);
      fputs("\n", stderr);
      return 1; }

   unsigned *remote_thread=dlsym(handle, "remote_thread");
   dlclose(handle);

   if (remote_thread) {
      pthread_t helper;
      pthread_create(&helper, NULL, (void *)remote_thread, NULL);
      return 0; }

   fputs("remote_thread NOT found..\n", stderr);
   return 1;
} 
remote.c

Code: Select all

#include <stdio.h>
#include <string.h>

extern unsigned int _ZN8SsObject14m_poObjectListE[];
extern int _ZN13SsPictureBase13GetBrightnessEPh(unsigned int, unsigned char *);
extern int _ZN13SsPictureBase13SetBrightnessEh(unsigned int, unsigned char);

static unsigned char _GetBrightness() {
   unsigned char bval=0;
   _ZN13SsPictureBase13GetBrightnessEPh(_ZN8SsObject14m_poObjectListE[15], &bval);
   return(bval);
}

static int _SetBrightness(unsigned char bval) {
   return(_ZN13SsPictureBase13SetBrightnessEh(_ZN8SsObject14m_poObjectListE[15], bval));
}

void remote_thread(void *v) {
   int step=1;
   
   while (1) {
      // 0..100
      unsigned char bv=_GetBrightness();
      bv+=step;
      if (bv < 1) { bv=0; step=1; }
      if (bv > 99) { bv=100; step=-1; }

      fprintf(stderr, "Brightness -> %u\n", bv);
      fflush(stderr);
      _SetBrightness(bv);
      usleep(500000);
   }
} 
make.sh:

Code: Select all

#!/bin/bash
arm-linux-gnueabi-gcc -O2 -c loader.c -o loader.o
arm-linux-gnueabi-gcc -shared -Wl -o loader.so loader.o
arm-linux-gnueabi-gcc -O2 -c remote.c -o remote.o
arm-linux-gnueabi-gcc -shared -Wl -o remote.so remote.o 
clmeta.dat:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<contentlibrary>
	<contentpack id="BrightSetTestv01">
		<category>Game</category>
		<title language_id="English">Brightness Test App</title>
		<startpoint language_id="English">./loader.so</startpoint>
		<thumbnailpath>./SamyGO.png</thumbnailpath>
		<totalsize>1</totalsize>
	</contentpack>
</contentlibrary>
It works, but I have to say this: picture with very low or very hight brightness really looks like crap :).
Adjusting backlight (or perhaps energy saving) setting instead will be probably much better idea.. problem is, we don't know how to do this (not in small steps, anyway).

User avatar
erdem_ua
SamyGO Admin
Posts: 3112
Joined: Thu Oct 01, 2009 6:02 am
Location: Istanbul, Turkey
Contact:

Re: Brightness auto adjusting to ambient light level

Post by erdem_ua »

Oh thanks :)
You looks like completed whole application.
I look at backlight vs brightness setting and we definitely need adjusting of backlight instead of brightness.
Thanks for codes :)

Problem is that, I don't have libUSB... I think needed to compile toolchain for TV.
Tried Open embedded bitbake externalboot-developer but trunk is broken due quilt package too.
Anyone knows a shortcut?

tom_van
Official SamyGO Developer
Posts: 146
Joined: Tue Jan 19, 2010 10:44 am

Re: Brightness auto adjusting to ambient light level

Post by tom_van »

tom_van wrote:The code common for SH4 and ARM:
SsPictureBase::SetBrightness(unsigned char) / SsPictureBase::SetContrast(unsigned char)
in turn calls
SsPictureBase::SetPictureModeData(SS_PictureModeItem_k, unsigned char *)
This routine call low level setting and stores new value in SsStore
I'm afraid that storing updated value every second might impose a problem with eeprom lifetime
(SsStore implements some level of caching but don't know details).

I verified on A model that adjusting backlight with 128 steps is absolutely perfect.
Adjusting this way is not noticeable in normal conditions.
No need to adjust other values, like brightness or contrast.

I believe that finer backlight control is available in lower levels of chelsea fw too.
Try to trace ChelseaPictureShare::m_ChelseaPicture_SetEnergySavingBacklight()

User avatar
erdem_ua
SamyGO Admin
Posts: 3112
Joined: Thu Oct 01, 2009 6:02 am
Location: Istanbul, Turkey
Contact:

Re: Brightness auto adjusting to ambient light level

Post by erdem_ua »

After some sweating, at least, could compile libusb 0.1.2. Than ported my lib usb 1.0 code to it. Now could read sensor data...
But :( my super duper brightness sensor has a problem. It works when you plug, but doesn't if TV open while plugged.
Needed to change design slightly make new board and add some caps D+D- & power lines to solve that issue.

Than will look at some back light functions at exeDSP, is you don't found before me :D
Do you know any good PCB software for linux?

tom_van
Official SamyGO Developer
Posts: 146
Joined: Tue Jan 19, 2010 10:44 am

Re: Brightness auto adjusting to ambient light level

Post by tom_van »

I use Eagle http://www.cadsoft.de/ on both Win/Linux.

User avatar
erdem_ua
SamyGO Admin
Posts: 3112
Joined: Thu Oct 01, 2009 6:02 am
Location: Istanbul, Turkey
Contact:

Re: Brightness auto adjusting to ambient light level

Post by erdem_ua »

At least I open exeDSP with IDA.
Found some options.
Do some one checked SsPictureBase::SetPanelLightControl(int, int) function? What it is for? "panel light" is what we are try to change indeed.

Also ChelseaPictureShare::m_ChelseaPicture_SetDynamicContrast(Settings_t *) might looks helpful.
And any one know what the ChelseaPictureShare::m_ChelseaPicture_SetFactoryItem_PWM_MAX( uint, int ).

In B series there is 5 power saving settings, Off, Low, Medium, High, Dynamic... All of those modes adjust backlight indeed. From most bright one to worst bright one except the Dynamic mode...
Also you can choose one of the 1 to 10 backlight power at each modes...

This make me thinking power saving setting sets the Max PWM value and selection of backlight power via menu puts divider to it.

For first step I am happy if we could adjust just 1-10 backlight control...
Please don't let me setup and debug the process since my computer and TV is on different rooms. :)

sbav1
Official SamyGO Developer
Posts: 374
Joined: Fri Jan 15, 2010 10:20 am

Re: Brightness auto adjusting to ambient light level

Post by sbav1 »

tom_van wrote: I believe that finer backlight control is available in lower levels of chelsea fw too.
Try to trace ChelseaPictureShare::m_ChelseaPicture_SetEnergySavingBacklight()
tom_van is spot-on, as usual :). ChelseaPictureShare::m_ChelseaPicture_SetEnergySavingBacklight is indeed lowest-level function for backlight control (at least in B650/FRCQ B-series sets with T-CHL* firmware; it may be very much different in Chelsea based PDPs, and/or Chelsea LED TVs - especially in LED sets with local dimming).

Looks like there are 4 chelsea register ranges/arrays involved:
1) 0x30220684: nice one, I believe this is chelsea main PWR (digital) backlight setting register. Typical (?) values ( esaving == off): 0x33-0x100 (backilght "0" -> 0x33, "1" -> 0x42, "2" -> 0x51, ..., "10" -> 0x100). Pretty good candidate for fine-grained backlight control. Writable, I did some preliminary tests, seems to work like a charm.

2) 0x30220680: 0x100 for esaving == auto, 0x00 otherwise (from ChelseaPictureShare::m_SetDimmingReg())

3) 0x30220660: another interesting one (I don't know what it is exactly; perhaps it's main chelsea register for analog dimming ?). Usually it holds some fixed (?) values for different picture modes; writable; quite funny effects for low values (really dark backlight levels possible - but screen becomes not uniform for very low settings) and high values (very bright backlight, heavy screen flickering). I guess it may be a good one, too, especially if you want to set your TV on fire ;). Seriously, I think it may be a little dangerous (for your TV inverter, and perhaps for you as well); please, be cautious.

4) 0x30220630-0x0x3022063c, 0x0x30220618-0x3022062c, 0x30220640-0x30220650, 0x0x30220658: ???. Details in ChelseaPictureShare::m_SetDimmingShape(); looks like some predefined sets of values for esaving == auto mode; otherwise: no idea.

Post Reply

Return to “General”