Example #1
0
static int systemGetPowerInfo(lua_State *L){
	
	u8 batteryPercent;
	
	PTMU_GetBatteryLevel(&batteryPercent);
	
	u8 batteryStateBool;
	PTMU_GetBatteryChargeState(&batteryStateBool);
	
	if (batteryStateBool == 0) {
		
		lua_pushstring(L, "battery");
		
	} else if (batteryStateBool == 1) {
		
		if (batteryPercent == 5) {
			
			lua_pushstring(L, "charged");
			
		} else {
			
			lua_pushstring(L, "charging");
			
		}
		
	}
	
	lua_pushnumber(L, batteryPercent * 20); //PTMU_GetBatteryLevel returns a number between 0 and 5, so I multiply it for 20 to match LÖVE, which gives 0-100
	lua_pushnil(L);
	
	return 3;
	
}
Example #2
0
bool ctr::battery::charging() {
    if(!initialized) {
        ctr::err::set(initError);
        return false;
    }

    u8 charging;
    ctr::err::parse(ctr::err::SOURCE_BATTERY_GET_CHARGE_STATE, (u32) PTMU_GetBatteryChargeState(&charging));
    if(ctr::err::has()) {
        return false;
    }

    return charging != 0;
}
Example #3
0
void GUI_StatusBar(char* title)
{
	ACU_GetWifiStatus(NULL, &wifiStatus);
	PTMU_GetBatteryLevel(NULL, &batteryLevel);
	PTMU_GetBatteryChargeState(NULL, &charging);

	//Wifi icon
	if (wifiStatus) gfxDrawSprite(GFX_TOP, GFX_LEFT, (u8*)Wifi_bin, 20, 40, 0, 220);

	//Battery icon
	if (charging)
	{
		gfxDrawSprite(GFX_TOP, GFX_LEFT, batteryLevels[charging_animation/9], 19, 17, 0, 221);
		if(charging_animation!=49)charging_animation++;
		else charging_animation = 1;
	}
	else gfxDrawSprite(GFX_TOP, GFX_LEFT, batteryLevels[batteryLevel], 19, 17, 0, 221);

	//Clock
    GUI_Clock();

	//Title
    gfxDrawText(GFX_TOP, GFX_LEFT, &fontBlack, title, 80, 238 - fontBlack.height * 1);
}
Example #4
0
File: ui.c Project: XeQMuK3K4/FBI
static void ui_draw_top(ui_view* ui) {
    u32 topScreenBgWidth = 0;
    u32 topScreenBgHeight = 0;
    screen_get_texture_size(&topScreenBgWidth, &topScreenBgHeight, TEXTURE_TOP_SCREEN_BG);

    u32 topScreenTopBarWidth = 0;
    u32 topScreenTopBarHeight = 0;
    screen_get_texture_size(&topScreenTopBarWidth, &topScreenTopBarHeight, TEXTURE_TOP_SCREEN_TOP_BAR);

    u32 topScreenTopBarShadowWidth = 0;
    u32 topScreenTopBarShadowHeight = 0;
    screen_get_texture_size(&topScreenTopBarShadowWidth, &topScreenTopBarShadowHeight, TEXTURE_TOP_SCREEN_TOP_BAR_SHADOW);

    u32 topScreenBottomBarWidth = 0;
    u32 topScreenBottomBarHeight = 0;
    screen_get_texture_size(&topScreenBottomBarWidth, &topScreenBottomBarHeight, TEXTURE_TOP_SCREEN_BOTTOM_BAR);

    u32 topScreenBottomBarShadowWidth = 0;
    u32 topScreenBottomBarShadowHeight = 0;
    screen_get_texture_size(&topScreenBottomBarShadowWidth, &topScreenBottomBarShadowHeight, TEXTURE_TOP_SCREEN_BOTTOM_BAR_SHADOW);

    screen_select(GFX_TOP);
    screen_draw_texture(TEXTURE_TOP_SCREEN_BG, (TOP_SCREEN_WIDTH - topScreenBgWidth) / 2, (TOP_SCREEN_HEIGHT - topScreenBgHeight) / 2, topScreenBgWidth, topScreenBgHeight);

    if(ui->drawTop != NULL) {
        ui->drawTop(ui, ui->data, 0, topScreenTopBarHeight, TOP_SCREEN_WIDTH, TOP_SCREEN_HEIGHT - topScreenBottomBarHeight);
    }

    float topScreenTopBarX = (TOP_SCREEN_WIDTH - topScreenTopBarWidth) / 2;
    float topScreenTopBarY = 0;
    screen_draw_texture(TEXTURE_TOP_SCREEN_TOP_BAR, topScreenTopBarX, topScreenTopBarY, topScreenTopBarWidth, topScreenTopBarHeight);
    screen_draw_texture(TEXTURE_TOP_SCREEN_TOP_BAR_SHADOW, topScreenTopBarX, topScreenTopBarY + topScreenTopBarHeight, topScreenTopBarShadowWidth, topScreenTopBarShadowHeight);

    float topScreenBottomBarX = (TOP_SCREEN_WIDTH - topScreenBottomBarWidth) / 2;
    float topScreenBottomBarY = TOP_SCREEN_HEIGHT - topScreenBottomBarHeight;
    screen_draw_texture(TEXTURE_TOP_SCREEN_BOTTOM_BAR, topScreenBottomBarX, topScreenBottomBarY, topScreenBottomBarWidth, topScreenBottomBarHeight);
    screen_draw_texture(TEXTURE_TOP_SCREEN_BOTTOM_BAR_SHADOW, topScreenBottomBarX, topScreenBottomBarY - topScreenBottomBarShadowHeight, topScreenBottomBarShadowWidth, topScreenBottomBarShadowHeight);

    time_t t = time(NULL);
    char* timeText = ctime(&t);

    float timeTextWidth;
    float timeTextHeight;
    screen_get_string_size(&timeTextWidth, &timeTextHeight, timeText, 0.5f, 0.5f);
    screen_draw_string(timeText, topScreenTopBarX + (topScreenTopBarWidth - timeTextWidth) / 2, topScreenTopBarY + (topScreenTopBarHeight - timeTextHeight) / 2, 0.5f, 0.5f, COLOR_TEXT, false);

    u32 batteryIcon = 0;
    u8 batteryChargeState = 0;
    u8 batteryLevel = 0;
    if(R_SUCCEEDED(PTMU_GetBatteryChargeState(&batteryChargeState)) && batteryChargeState) {
        batteryIcon = TEXTURE_BATTERY_CHARGING;
    } else if(R_SUCCEEDED(PTMU_GetBatteryLevel(&batteryLevel))) {
        batteryIcon = TEXTURE_BATTERY_0 + batteryLevel;
    } else {
        batteryIcon = TEXTURE_BATTERY_0;
    }

    u32 batteryWidth;
    u32 batteryHeight;
    screen_get_texture_size(&batteryWidth, &batteryHeight, batteryIcon);

    float batteryX = topScreenTopBarX + topScreenTopBarWidth - 2 - batteryWidth;
    float batteryY = topScreenTopBarY + (topScreenTopBarHeight - batteryHeight) / 2;
    screen_draw_texture(batteryIcon, batteryX, batteryY, batteryWidth, batteryHeight);

    u32 wifiIcon = 0;
    u32 wifiStatus = 0;
    if(R_SUCCEEDED(ACU_GetWifiStatus(&wifiStatus)) && wifiStatus) {
        wifiIcon = TEXTURE_WIFI_0 + osGetWifiStrength();
    } else {
        wifiIcon = TEXTURE_WIFI_DISCONNECTED;
    }

    u32 wifiWidth;
    u32 wifiHeight;
    screen_get_texture_size(&wifiWidth, &wifiHeight, wifiIcon);

    float wifiX = topScreenTopBarX + topScreenTopBarWidth - 2 - batteryWidth - 4 - wifiWidth;
    float wifiY = topScreenTopBarY + (topScreenTopBarHeight - wifiHeight) / 2;
    screen_draw_texture(wifiIcon, wifiX, wifiY, wifiWidth, wifiHeight);

    FS_ArchiveResource sd;
    FSUSER_GetSdmcArchiveResource(&sd);

    FS_ArchiveResource nand;
    FSUSER_GetNandArchiveResource(&nand);

    char buffer[64];
    snprintf(buffer, 64, "SD: %.1f MiB, NAND: %.1f MiB", ((u64) sd.freeClusters * (u64) sd.clusterSize) / 1024.0 / 1024.0, ((u64) nand.freeClusters * (u64) nand.clusterSize) / 1024.0 / 1024.0);

    float freeSpaceHeight;
    screen_get_string_size(NULL, &freeSpaceHeight, buffer, 0.5f, 0.5f);

    screen_draw_string(buffer, topScreenBottomBarX + 2, topScreenBottomBarY + (topScreenBottomBarHeight - freeSpaceHeight) / 2, 0.5f, 0.5f, COLOR_TEXT, false);
}
Example #5
0
int main()
{
   // Initialize services
   srvInit();
   aptInit();
   hidInit(NULL);
   ptmInit();
   gfxInitDefault();
   // consoleInit(GFX_TOP, NULL);
   csndInit();
   // fsInit();
   // sdmcInit();

   chdir("sdmc:/");

   void *device = gfxCreateDevice(240, 320);
   gfxMakeCurrent(device);

   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glOrtho(0.0, 1.0, 1.0, 0.0, -1.0, 1.0);

   glTranslatef(0.5f, 0.5f, 0.0f);
   glRotatef(90.0f, 0.0f, 0.0f, 1.0f);
   glTranslatef(-0.5f, -0.5f, 0.0f);

   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();

   glGenTextures(1, &play_button);
   glGenTextures(1, &pause_button);
   glGenTextures(1, &loop_button);
   glGenTextures(1, &loop_disable_button);
   glGenTextures(1, &power_icon);

   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

   int x, y, n;
   u8* image_data = stbi_load_from_memory(play_3_png, play_3_png_size, &x, &y, &n, 4);
   glBindTexture(GL_TEXTURE_2D, play_button);
   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_data);
   stbi_image_free(image_data);

   image_data = stbi_load_from_memory(pause_2_png, pause_2_png_size, &x, &y, &n, 4);
   glBindTexture(GL_TEXTURE_2D, pause_button);
   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_data);
   stbi_image_free(image_data);

   image_data = stbi_load_from_memory(loop_png, loop_png_size, &x, &y, &n, 4);
   glBindTexture(GL_TEXTURE_2D, loop_button);
   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_data);
   stbi_image_free(image_data);

   image_data = stbi_load_from_memory(loop_disable_png, loop_disable_png_size, &x, &y, &n, 4);
   glBindTexture(GL_TEXTURE_2D, loop_disable_button);
   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_data);
   stbi_image_free(image_data);

   image_data = stbi_load_from_memory(power_png, power_png_size, &x, &y, &n, 4);
   glBindTexture(GL_TEXTURE_2D, power_icon);
   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_data);
   stbi_image_free(image_data);

   glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

   void *top_device = gfxCreateDevice(240, 400);
   gfxMakeCurrent(top_device);
   initfont_goth();
   initfont_anita();
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glOrtho(0.0, 1.0, 1.0, 0.0, -1.0, 1.0);

   glTranslatef(0.5f, 0.5f, 0.0f);
   glRotatef(90.0f, 0.0f, 0.0f, 1.0f);
   glTranslatef(-0.5f, -0.5f, 0.0f);

   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
   glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   glEnable(GL_BLEND);
   glEnable(GL_TEXTURE_2D);

   int frames = 0;
   int channel = 0x8;


   while (aptMainLoop())
   {
      gspWaitForVBlank();
      hidScanInput();
      gfxMakeCurrent(top_device);
      glClear(GL_COLOR_BUFFER_BIT);
      glLoadIdentity();
      glScalef(1.0/400.0, 1.0/240.0, 1.0);
      state_man();
      gfxFlush(gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL));
      u8 plevel;
      u8 charge;
      PTMU_GetBatteryLevel(NULL, &plevel);
      PTMU_GetBatteryChargeState(NULL, &charge);
      if (plevel != power_level) {
         power_level = plevel;
         // draw_ui = true;
      }
      if (charge != is_charging) {
         is_charging = charge;
         //draw_ui = true;
      }

      gfxMakeCurrent(device);
      u8* fb = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL);
      render();
      gfxFlush(fb);
      // Your code goes here

      u32 kDown = hidKeysDown();
      if (kDown & KEY_START)
         break; // break in order to return to hbmenu

      // Flush and swap framebuffers
      if (audiobuf && !paused) {
         if(frames >= 50) {
            frames = 0;
            int n = 0;
            if (decode_mode == AUDIO_MODE_VORBIS) {
               n = stb_vorbis_get_samples_short_interleaved(v, 2, audiobuf, Samples * 2);
            } else {
               while (audiobuf_index < Samples * 2) {
                  n = FLAC__stream_decoder_process_single(FLAC_decoder);
                  if (FLAC__stream_decoder_get_state(FLAC_decoder) == FLAC__STREAM_DECODER_END_OF_STREAM) break;
               }
               audiobuf_index = 0;
            }

            if(n == 0) {
               if (decode_mode == AUDIO_MODE_VORBIS) {
                  stb_vorbis_close(v);
               } else {
                  FLAC__stream_decoder_delete(FLAC_decoder);
               }
               linearFree(audiobuf);
               audiobuf = NULL;
               v = NULL;
               FLAC_decoder = NULL;
               if (loop_flag) play_file_from_filename(currently_playing);
            }

            GSPGPU_FlushDataCache(NULL, (u8*)audiobuf, audiobuf_size);
            if (channel == 0x8) channel = 0x6;
            if (channel == 0x6) channel = 0x8;
            csndPlaySound(SOUND_CHANNEL(channel), SOUND_ONE_SHOT | SOUND_LINEAR_INTERP | SOUND_FORMAT_16BIT, Samples * 2, 10.0, 0.0, (u32*)audiobuf, (u32*)audiobuf, audiobuf_size);

         }
         frames++;
      }

      gfxFlushBuffers();
      gfxSwapBuffersGpu();
   }

   // Exit services
   if (FLAC_decoder) {
      FLAC__stream_decoder_delete(FLAC_decoder);
   }
   csndExit();
   gfxExit();
   ptmExit();
   hidExit();
   aptExit();
   srvExit();
   return 0;
}