diff --git a/README.md b/README.md index 377c534..918e8ef 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ for f in */Makefile; do make -C ${f%/*} all; done * `hello_cpp_world`: A minimal hello world sample in C++. * `hello_world`: A minimal hello world sample. * `net_http`: A minimal HTTP download sample. +* `power`: A minimal power sample. * `pretty_livearea`: A minimal hello world sample with example livearea styling and features. * `rtc`: A minimal RTC sample. * `touch`: A minimal touch sample. diff --git a/power/Makefile b/power/Makefile new file mode 100644 index 0000000..84e37ab --- /dev/null +++ b/power/Makefile @@ -0,0 +1,55 @@ +PHONY := all package clean +rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d)) + +CC := arm-vita-eabi-gcc +CXX := arm-vita-eabi-g++ +STRIP := arm-vita-eabi-strip + +PROJECT_TITLE := Power Sample +PROJECT_TITLEID := VSDK00016 + +PROJECT := vita_sample +CXXFLAGS += -std=c++11 -I../common +CFLAGS += -I../common + +LIBS := -lSceCtrl_stub -lSceDisplay_stub -lSceKernel_stub -lScePower_stub + +SRC_C :=$(call rwildcard, src/, *.c) +SRC_CPP :=$(call rwildcard, src/, *.cpp) + +OBJ_DIRS := $(addprefix out/, $(dir $(SRC_C:src/%.c=%.o))) $(addprefix out/, $(dir $(SRC_CPP:src/%.cpp=%.o))) +OBJS := $(addprefix out/, $(SRC_C:src/%.c=%.o)) $(addprefix out/, $(SRC_CPP:src/%.cpp=%.o)) + + +all: package + +package: $(PROJECT).vpk + +$(PROJECT).vpk: eboot.bin param.sfo + vita-pack-vpk -s param.sfo -b eboot.bin $(PROJECT).vpk + +eboot.bin: $(PROJECT).velf + vita-make-fself $(PROJECT).velf eboot.bin + +param.sfo: + vita-mksfoex -s TITLE_ID="$(PROJECT_TITLEID)" "$(PROJECT_TITLE)" param.sfo + +$(PROJECT).velf: $(PROJECT).elf + $(STRIP) -g $< + vita-elf-create $< $@ + +$(PROJECT).elf: $(OBJS) + $(CXX) -Wl,-q $(CFLAGS) -o $@ $^ $(LIBS) + +$(OBJ_DIRS): + mkdir -p $@ + +out/%.o : src/%.cpp | $(OBJ_DIRS) + arm-vita-eabi-g++ -c $(CXXFLAGS) -o $@ $< + +out/%.o : src/%.c | $(OBJ_DIRS) + arm-vita-eabi-g++ -c $(CFLAGS) -o $@ $< + +clean: + rm -f $(PROJECT).velf $(PROJECT).elf $(PROJECT).vpk param.sfo eboot.bin $(OBJS) + rm -r $(abspath $(OBJ_DIRS)) diff --git a/power/src/main.c b/power/src/main.c new file mode 100644 index 0000000..26ac736 --- /dev/null +++ b/power/src/main.c @@ -0,0 +1,45 @@ +#include +#include +#include + +#include "debugScreen.h" + +/* Define printf, just to make typing easier */ +#define printf psvDebugScreenPrintf + +/* main routine */ +int main(int argc, char *argv[]) +{ + SceCtrlData pad; + int i = 0; + int batteryLifeTime = 0; + + psvDebugScreenInit(); + + printf("PS Vita Power Sample v0.1\n\n"); + + printf("External power: %s\n", scePowerIsPowerOnline()? "yes" : "no "); + printf("Low charge: %s\n", scePowerIsLowBattery()? "yes" : "no "); + printf("Charging: %s\n", scePowerIsBatteryCharging()? "yes" : "no "); + printf("Battery life percent: %d%%\n", scePowerGetBatteryLifePercent()); + batteryLifeTime = scePowerGetBatteryLifeTime(); + printf("Battery life time: (%02dh%02dm)\n", batteryLifeTime/60, batteryLifeTime-(batteryLifeTime/60*60)); + printf("Clock frequency of the ARM: %d mHz\n", scePowerGetArmClockFrequency()); + printf("Clock frequency of the BUS: %d mHz\n", scePowerGetBusClockFrequency()); + printf("Clock frequency of the GPU: %d mHz\n", scePowerGetGpuClockFrequency()); + + printf("\n\nPress start to exit\n"); + + while (1) + { + memset(&pad, 0, sizeof(pad)); + sceCtrlPeekBufferPositive(0, &pad, 1); + + if (pad.buttons & SCE_CTRL_START) + break; + } + + sceKernelExitProcess(0); + + return 0; +} \ No newline at end of file