1
0
Fork 0
mirror of https://github.com/DarkMatterCore/nxdumptool.git synced 2024-11-22 18:26:39 +00:00

Added StatusInfoTask.

This commit is contained in:
Pablo Curiel 2021-06-18 03:02:23 -04:00
parent ee17ffca5d
commit 063d8e9b3f
5 changed files with 120 additions and 2 deletions

View file

@ -31,6 +31,9 @@ namespace nxdt::views
class RootView: public brls::TabFrame
{
private:
bool applet_mode = false;
nxdt::tasks::StatusInfoTask *status_info_task = nullptr;
nxdt::tasks::GameCardTask *gc_status_task = nullptr;
nxdt::tasks::TitleTask *title_task = nullptr;
nxdt::tasks::UmsTask *ums_task = nullptr;

View file

@ -44,6 +44,43 @@ namespace nxdt::tasks
/* Custom vector type used to hold UMS devices. */
typedef std::vector<UsbHsFsDevice> UmsDeviceVector;
/* Status info task. */
class StatusInfoTask: public brls::RepeatingTask
{
private:
VoidEvent status_info_event;
std::string cur_time = "";
u32 charge_percentage = 0;
PsmChargerType charger_type = PsmChargerType_Unconnected;
NifmInternetConnectionType connection_type = (NifmInternetConnectionType)0;
u32 signal_strength = 0;
NifmInternetConnectionStatus connection_status = (NifmInternetConnectionStatus)0;
protected:
void run(retro_time_t current_time) override;
public:
StatusInfoTask(void);
~StatusInfoTask(void);
std::string GetCurrentTimeString(void);
void GetBatteryStats(u32 *out_charge_percentage, PsmChargerType *out_charger_type);
void GetNetworkStats(NifmInternetConnectionType *out_connection_type, u32 *out_signal_strength, NifmInternetConnectionStatus *out_connection_status);
ALWAYS_INLINE VoidEvent::Subscription RegisterListener(VoidEvent::Callback cb)
{
return this->status_info_event.subscribe(cb);
}
ALWAYS_INLINE void UnregisterListener(VoidEvent::Subscription subscription)
{
this->status_info_event.unsubscribe(subscription);
}
};
/* Gamecard task. */
class GameCardTask: public brls::RepeatingTask
{

View file

@ -23,7 +23,7 @@
"dump_options": "Dump options",
"dump_card_image": {
"label": "Dump gamecard image",
"label": "Dump gamecard image (XCI)",
"description": "Generates a raw gamecard image. This is the option most people will want to use."
},

View file

@ -19,7 +19,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <nxdt_includes.h>
#include <nxdt_utils.h>
#include <root_view.hpp>
#include <gamecard_tab.hpp>
//#include <user_titles_tab.hpp>
@ -33,7 +33,11 @@ namespace nxdt::views
{
RootView::RootView(void) : brls::TabFrame()
{
/* Check if we're running under applet mode. */
this->applet_mode = utilsAppletModeCheck();
/* Start background tasks. */
this->status_info_task = new nxdt::tasks::StatusInfoTask();
this->gc_status_task = new nxdt::tasks::GameCardTask();
this->title_task = new nxdt::tasks::TitleTask();
this->ums_task = new nxdt::tasks::UmsTask();

View file

@ -26,6 +26,80 @@
namespace nxdt::tasks
{
/* Status info task. */
StatusInfoTask::StatusInfoTask(void) : brls::RepeatingTask(NXDT_TASK_INTERVAL * 10)
{
brls::RepeatingTask::start();
brls::Logger::debug("Status info task started.");
}
StatusInfoTask::~StatusInfoTask(void)
{
/* Clear current time string. */
this->cur_time.clear();
brls::Logger::debug("Status info task stopped.");
}
void StatusInfoTask::run(retro_time_t current_time)
{
brls::RepeatingTask::run(current_time);
/* Get current time. */
bool is_am = true;
time_t unix_time = time(NULL);
struct tm *timeinfo = localtime(&unix_time);
if (timeinfo->tm_hour > 12)
{
timeinfo->tm_hour -= 12;
is_am = false;
} else
if (!timeinfo->tm_hour)
{
timeinfo->tm_hour = 12;
}
this->cur_time.clear();
fmt::format_to(std::back_inserter(this->cur_time), "{:02d}:{:02d}:{:02d} {}", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, is_am ? "AM" : "PM");
/* Get battery stats. */
psmGetBatteryChargePercentage(&(this->charge_percentage));
psmGetChargerType(&(this->charger_type));
/* Get network connection status. */
Result rc = nifmGetInternetConnectionStatus(&(this->connection_type), &(this->signal_strength), &(this->connection_status));
if (R_FAILED(rc))
{
this->connection_type = (NifmInternetConnectionType)0;
this->signal_strength = 0;
this->connection_status = (NifmInternetConnectionStatus)0;
}
this->status_info_event.fire();
}
std::string StatusInfoTask::GetCurrentTimeString(void)
{
return this->cur_time;
}
void StatusInfoTask::GetBatteryStats(u32 *out_charge_percentage, PsmChargerType *out_charger_type)
{
if (!out_charge_percentage || !out_charger_type) return;
*out_charge_percentage = this->charge_percentage;
*out_charger_type = this->charger_type;
}
void StatusInfoTask::GetNetworkStats(NifmInternetConnectionType *out_connection_type, u32 *out_signal_strength, NifmInternetConnectionStatus *out_connection_status)
{
if (!out_connection_type || !out_signal_strength || !out_connection_status) return;
*out_connection_type = this->connection_type;
*out_signal_strength = this->signal_strength;
*out_connection_status = this->connection_status;
}
/* Gamecard task. */
GameCardTask::GameCardTask(void) : brls::RepeatingTask(NXDT_TASK_INTERVAL)