OLED powertutor code

https://github.com/msg555/PowerTutor/blob/master/src/edu/umich/PowerTutor/components/OLED.java

OLED component java file in powertutor source code.

Brightness read from
“/sys/class/leds/lcd-backlight/brightness”,
“/sys/devices/virtual/leds/lcd-backlight/brightness”,
“/sys/devices/platform/trout-backlight.0/leds/lcd-backlight/brightness”,

Pixel info read from “/dev/fb0” or “/dev/graphics/fb0”

Get N random samples

 Random r = new Random();
    samples = new int[NUMBER_OF_SAMPLES];
    for(int i = 0; i < NUMBER_OF_SAMPLES; i++) {
      int a = screenWidth * screenHeight * i / NUMBER_OF_SAMPLES;
      int b = screenWidth * screenHeight * (i + 1) / NUMBER_OF_SAMPLES;
      samples[i] = a + r.nextInt(b – a);
    }

Get coefficient, the power file is stored in constant.

double[] channel = constants.oledChannelPower();
    rcoef = channel[0] / 255 / 255;
    gcoef = channel[1] / 255 / 255;
    bcoef = channel[2] / 255 / 255;
    modul_coef = constants.oledModulation() / 255 / 255 / 3 / 3;

Calculate the pixel power and get the average value

if(screen && frameBufferFile.exists()) {
      if(NativeLoader.jniLoaded()) {
        pixPower = getScreenPixPower(rcoef, gcoef, bcoef, modul_coef);
      } else try {
        RandomAccessFile fin = new RandomAccessFile(frameBufferFile, “r”);
        for(int x : samples) {
          fin.seek(x * 4);
          int px = fin.readInt();
          int b = px >> 8 & 0xFF;
          int g = px >> 16 & 0xFF;
          int r = px >> 24 & 0xFF;
          /* Calculate the power usage of this one pixel if it were at full
* brightness. Linearly scale by brightness to get true power
* consumption. To calculate whole screen compute average of sampled
* region and multiply by number of pixels.
*/
          int modul_val = r + g + b;
          pixPower += rcoef * (r * r) + gcoef * (g * g) + bcoef * (b * b) –
                      modul_coef * (modul_val * modul_val);
        }
        fin.close();
      } catch(FileNotFoundException e) {
        pixPower = -1;
      } catch(IOException e) {
        pixPower = -1;
        e.printStackTrace();
      }
      if(pixPower >= 0) {
        pixPower *= 1.0 * screenWidth * screenHeight / NUMBER_OF_SAMPLES;
      }
    }

JNI file is similar like this one: https://github.com/msg555/PowerTutor/blob/master/jni/bindings.cpp

———————————————————————————————-

it actually reads from framebuffer fb0, example: http://www.pocketmagic.net/2010/11/android-native-screen-capture-application-using-the-framebuffer/#.Uu_NN2RdXRo

while when I want to directly open it from RootExplore, it only show me black screen.

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s