forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

sceDisplaySetBrightness and sceDisplayDisable sample

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
sakya



Joined: 28 Apr 2006
Posts: 190

PostPosted: Mon Jul 09, 2007 7:32 pm    Post subject: sceDisplaySetBrightness and sceDisplayDisable sample Reply with quote

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:
#include <pspkernel.h>
#include <pspctrl.h>
#include <pspdebug.h>
#include <psppower.h>
#include <pspdisplay.h>

PSP_MODULE_INFO("Brightness Test ", 0x1000, 1, 1);
PSP_MAIN_THREAD_ATTR(0);

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

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

// TWILIGHT ZONE! <do doo do doo>
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common) {
          runningFlag = 0;
          sceKernelExitGame();
          return 0;
}

/* Callback thread */
int CallbackThread(SceSize args, void *argp) {
          int cbid;

          cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
          sceKernelRegisterExitCallback(cbid);

          sceKernelSleepThreadCB();

          return 0;
}

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void) {
          int thid = 0;

          thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, PSP_THREAD_ATTR_USER, 0);
          if(thid >= 0) {
                    sceKernelStartThread(thid, 0, 0);
          }

          return thid;
}
// END OF TWILIGHT ZONE! <do doo do do>

int main() {
        scePowerSetClockFrequency(222, 222, 111);

          SetupCallbacks();

        sceDisplaySetFrameBuf(NULL,0,PSP_DISPLAY_PIXEL_FORMAT_4444, PSP_DISPLAY_SETBUF_IMMEDIATE);

          pspDebugScreenInit();
        pspDebugScreenSetTextColor(0xffffff);
        pspDebugScreenSetBackColor(0x000000);
        pspDebugScreenSetXY(0, 0);
        pspDebugScreenPrintf("Brightness test");

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

        SceCtrlData pad;
        sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);

        sceDisplayGetBrightness(&curBrightness, 0);

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

        while(runningFlag) {
         pspDebugScreenSetXY(0, 15);
         pspDebugScreenPrintf("Current brightness: %3.3i", curBrightness);            

         sceCtrlReadBufferPositive(&pad, 1);
         if(pad.Buttons & PSP_CTRL_LTRIGGER) {
            if (curBrightness > 0){
               sceDisplaySetBrightness(--curBrightness, 0);
               sceKernelDelayThread(100000);
            }
         }else if(pad.Buttons & PSP_CTRL_RTRIGGER) {
            if (curBrightness < 100){
               sceDisplaySetBrightness(++curBrightness, 0);
               sceKernelDelayThread(100000);
            }
         }else if(pad.Buttons & PSP_CTRL_START) {
            if (displayStatus == 1){
               sceDisplayDisable();
               displayStatus = 0;
            }else{
               sceDisplayEnable();
               displayStatus = 1;
            }
            sceKernelDelayThread(400000);
         }else if(pad.Buttons & PSP_CTRL_TRIANGLE) {
            break;
         }
        }
        sceKernelExitGame();
        return(0);
}


Makefile:
Code:
TARGET = bright
OBJS = main.o
CFLAGS = -O3 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =

LIBS = -lpspgu -lpspdisplay_driver -lpsppower
LDFLAGS =
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Brightness Test
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/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
Back to top
View user's profile Send private message Visit poster's website
Art



Joined: 09 Nov 2005
Posts: 647

PostPosted: Tue Jul 10, 2007 12:57 am    Post subject: Reply with quote

Add this:
Code:

int sceDisplayEnable(void);
int sceDisplayDisable(void);


after

Code:

void sceDisplay_driver_9E3C6DC6(int a0,int a1);//a0 0-100,a1 = 0/1 (set to 0)
#define sceDisplaySetBrightness sceDisplay_driver_9E3C6DC6
void sceDisplay_driver_31C4BAA8(int *a0,int *a1);
#define sceDisplayGetBrightness sceDisplay_driver_31C4BAA8

Art.
Back to top
View user's profile Send private message
sakya



Joined: 28 Apr 2006
Posts: 190

PostPosted: Tue Jul 10, 2007 1:06 am    Post subject: Reply with quote

Hi! :)

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

Ciaooo
Sakya
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group