sceDisplaySetBrightness and sceDisplayDisable sample

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
sakya
Posts: 190
Joined: Fri Apr 28, 2006 5:48 pm
Contact:

sceDisplaySetBrightness and sceDisplayDisable sample

Post by sakya »

Hi! :)

Since it seems I wasn't the only one to have problems with these functions, here's a simple program that uses sceDisplaySetBrightness/sceDisplayGetBrightness and sceDisplayDisable/sceDisplayEnable

Code: Select all

#include <pspkernel.h>
#include <pspctrl.h>
#include <pspdebug.h>
#include <psppower.h>
#include <pspdisplay.h>

PSP_MODULE_INFO&#40;"Brightness Test ", 0x1000, 1, 1&#41;;
PSP_MAIN_THREAD_ATTR&#40;0&#41;;

void sceDisplay_driver_9E3C6DC6&#40;int a0,int a1&#41;;//a0 0-100,a1 = 0/1 &#40;set to 0&#41;
#define sceDisplaySetBrightness sceDisplay_driver_9E3C6DC6
void sceDisplay_driver_31C4BAA8&#40;int *a0,int *a1&#41;;
#define sceDisplayGetBrightness sceDisplay_driver_31C4BAA8
int sceDisplayEnable&#40;void&#41;;
int sceDisplayDisable&#40;void&#41;; 

//Flag for exit from loop when user exits with HOME&#58;
static int runningFlag = 1;

// TWILIGHT ZONE! <do doo do doo>
/* Exit callback */
int exit_callback&#40;int arg1, int arg2, void *common&#41; &#123;
          runningFlag = 0;
          sceKernelExitGame&#40;&#41;;
          return 0;
&#125;

/* Callback thread */
int CallbackThread&#40;SceSize args, void *argp&#41; &#123;
          int cbid;

          cbid = sceKernelCreateCallback&#40;"Exit Callback", exit_callback, NULL&#41;;
          sceKernelRegisterExitCallback&#40;cbid&#41;;

          sceKernelSleepThreadCB&#40;&#41;;

          return 0;
&#125;

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks&#40;void&#41; &#123;
          int thid = 0;

          thid = sceKernelCreateThread&#40;"update_thread", CallbackThread, 0x11, 0xFA0, PSP_THREAD_ATTR_USER, 0&#41;;
          if&#40;thid >= 0&#41; &#123;
                    sceKernelStartThread&#40;thid, 0, 0&#41;;
          &#125;

          return thid;
&#125;
// END OF TWILIGHT ZONE! <do doo do do>

int main&#40;&#41; &#123;
		  scePowerSetClockFrequency&#40;222, 222, 111&#41;;

          SetupCallbacks&#40;&#41;;

		  sceDisplaySetFrameBuf&#40;NULL,0,PSP_DISPLAY_PIXEL_FORMAT_4444, PSP_DISPLAY_SETBUF_IMMEDIATE&#41;;

          pspDebugScreenInit&#40;&#41;;
		  pspDebugScreenSetTextColor&#40;0xffffff&#41;;
		  pspDebugScreenSetBackColor&#40;0x000000&#41;;
		  pspDebugScreenSetXY&#40;0, 0&#41;;
		  pspDebugScreenPrintf&#40;"Brightness test"&#41;;

		  static int curBrightness = 0;
		  static int displayStatus = 1;

		  SceCtrlData pad;
		  sceCtrlSetSamplingMode&#40;PSP_CTRL_MODE_ANALOG&#41;;

		  sceDisplayGetBrightness&#40;&curBrightness, 0&#41;;

		  pspDebugScreenSetXY&#40;0, 22&#41;;
		  pspDebugScreenPrintf&#40;"Press START to turn display on/off"&#41;;
		  pspDebugScreenSetXY&#40;0, 23&#41;;
		  pspDebugScreenPrintf&#40;"Press L or R to change brightness"&#41;;
		  pspDebugScreenSetXY&#40;0, 24&#41;;
		  pspDebugScreenPrintf&#40;"Press TRIANGLE to exit"&#41;;

		  while&#40;runningFlag&#41; &#123;
			pspDebugScreenSetXY&#40;0, 15&#41;;
			pspDebugScreenPrintf&#40;"Current brightness&#58; %3.3i", curBrightness&#41;;				

			sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
			if&#40;pad.Buttons & PSP_CTRL_LTRIGGER&#41; &#123;
				if &#40;curBrightness > 0&#41;&#123;
					sceDisplaySetBrightness&#40;--curBrightness, 0&#41;;
					sceKernelDelayThread&#40;100000&#41;;
				&#125;
			&#125;else if&#40;pad.Buttons & PSP_CTRL_RTRIGGER&#41; &#123;
				if &#40;curBrightness < 100&#41;&#123;
					sceDisplaySetBrightness&#40;++curBrightness, 0&#41;;
					sceKernelDelayThread&#40;100000&#41;;
				&#125;
			&#125;else if&#40;pad.Buttons & PSP_CTRL_START&#41; &#123;
				if &#40;displayStatus == 1&#41;&#123;
					sceDisplayDisable&#40;&#41;;
					displayStatus = 0;
				&#125;else&#123;
					sceDisplayEnable&#40;&#41;;
					displayStatus = 1;
				&#125;
				sceKernelDelayThread&#40;400000&#41;;
			&#125;else if&#40;pad.Buttons & PSP_CTRL_TRIANGLE&#41; &#123;
				break;
			&#125;
		  &#125;
		  sceKernelExitGame&#40;&#41;;
		  return&#40;0&#41;;
&#125;
Makefile:

Code: Select all

TARGET = bright
OBJS = main.o
CFLAGS = -O3 -G0 -Wall
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;
LIBDIR =

LIBS = -lpspgu -lpspdisplay_driver -lpsppower
LDFLAGS =
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Brightness Test 
PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak
Maybe it's usefull for someone else. :)
Thanks to Art for his help.

Just a question: the program works fine, but compiling it I get an "implicit declaration of function 'sceDisplayDisable'" but cannot find any header file with sceDisplayDisable declared in my sdk...

EDIT: fixed code, no more "implicit declaration..." warning. ;)

Ciaooo
Sakya
Last edited by sakya on Wed Aug 01, 2007 9:49 pm, edited 2 times in total.
Art
Posts: 642
Joined: Wed Nov 09, 2005 8:01 am

Post by Art »

Add this:

Code: Select all

int sceDisplayEnable&#40;void&#41;;
int sceDisplayDisable&#40;void&#41;;
after

Code: Select all

void sceDisplay_driver_9E3C6DC6&#40;int a0,int a1&#41;;//a0 0-100,a1 = 0/1 &#40;set to 0&#41;
#define sceDisplaySetBrightness sceDisplay_driver_9E3C6DC6
void sceDisplay_driver_31C4BAA8&#40;int *a0,int *a1&#41;;
#define sceDisplayGetBrightness sceDisplay_driver_31C4BAA8 
Art.
sakya
Posts: 190
Joined: Fri Apr 28, 2006 5:48 pm
Contact:

Post by sakya »

Hi! :)

Many thanks (again). :)
Edited the first message.

Ciaooo
Sakya
Post Reply