Permalink
Browse files

Add power sample (#10)

  • Loading branch information...
1 parent 03c4ecf commit d15a8bf1264ed4705f69297825de448d39a1565c @joel16 joel16 committed with xyzz Aug 26, 2016
Showing with 101 additions and 0 deletions.
  1. +1 −0 README.md
  2. +55 −0 power/Makefile
  3. +45 −0 power/src/main.c
View
@@ -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.
View
@@ -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))
View
@@ -0,0 +1,45 @@
+#include <psp2/ctrl.h>
+#include <psp2/kernel/processmgr.h>
+#include <psp2/power.h>
+
+#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;
+}

0 comments on commit d15a8bf

Please sign in to comment.