[ion/3ds] Cleaning, added support for battery and USB. Now can quit exam mode.

This commit is contained in:
M4x1m3
2020-04-21 10:36:16 +02:00
parent 1919933f8d
commit b169c3dc2d
9 changed files with 160 additions and 2 deletions

View File

@@ -4,15 +4,22 @@ ion_src += $(addprefix ion/src/simulator/3ds/, \
callback.cpp \
display.cpp \
framebuffer.cpp \
language.cpp \
telemetry_init.cpp \
keyboard.cpp \
events_keyboard.cpp \
driver/display.cpp \
driver/language.cpp \
driver/led.cpp \
driver/usb.cpp \
driver/battery.cpp \
driver/common.cpp \
)
sdl_simu_needs_to_be_removed += $(addprefix ion/src/simulator/shared/, \
dummy/display.cpp \
dummy/led.cpp \
dummy/usb.cpp \
dummy/battery.cpp \
display.cpp:-headless \
events_keyboard.cpp:-headless \
framebuffer_base.cpp \

View File

@@ -0,0 +1,15 @@
#include <ion/battery.h>
#include "common.h"
bool Ion::Battery::isCharging() {
return Ion::Simulator::CommonDriver::isCharging();
}
Ion::Battery::Charge Ion::Battery::level() {
return Ion::Simulator::CommonDriver::getLevel();
}
float Ion::Battery::voltage() {
return 0.0f;
}

View File

@@ -0,0 +1,57 @@
#include <3ds.h>
#include "common.h"
static bool plugged = false;
static bool battery_charging = false;
static Ion::Battery::Charge battery_level = Ion::Battery::Charge::FULL;
static time_t last_pull = 0;
bool Ion::Simulator::CommonDriver::isPlugged() {
pullData();
return plugged;
}
bool Ion::Simulator::CommonDriver::isCharging() {
pullData();
return battery_charging;
}
Ion::Battery::Charge Ion::Simulator::CommonDriver::getLevel() {
pullData();
return battery_level;
}
void Ion::Simulator::CommonDriver::pullData() {
time_t current = time(NULL);
if (difftime(current, last_pull) >= PULL_DELAY) {
PTMU_GetAdapterState(&plugged);
u8 bat_level = 0;
PTMU_GetBatteryLevel(&bat_level);
switch(bat_level) {
case 5:
battery_level = Ion::Battery::Charge::FULL;
break;
case 4:
case 3:
battery_level = Ion::Battery::Charge::SOMEWHERE_INBETWEEN;
break;
case 2:
case 1:
battery_level = Ion::Battery::Charge::LOW;
break;
case 0:
default:
battery_level = Ion::Battery::Charge::EMPTY;
break;
}
u8 bat_charging = 0;
PTMU_GetBatteryChargeState(&bat_charging);
battery_charging = (bool) bat_charging;
last_pull = time(NULL);
}
}

View File

@@ -0,0 +1,22 @@
#ifndef ION_DRIVER_COMMON_H
#define ION_DRIVER_COMMON_H
#include <ion/battery.h>
#include <time.h>
#define PULL_DELAY 1.0f
namespace Ion {
namespace Simulator {
namespace CommonDriver {
void pullData();
bool isPlugged();
bool isCharging();
Ion::Battery::Charge getLevel();
}
}
}
#endif

View File

@@ -1,4 +1,4 @@
#include "platform.h"
#include "../platform.h"
#include <3ds.h>

View File

@@ -0,0 +1,19 @@
#include <ion/led.h>
namespace Ion {
namespace LED {
KDColor getColor() {
return KDColorBlack;
}
void setColor(KDColor c) {}
void setBlinking(uint16_t period, float dutyCycle) {}
KDColor updateColorWithPlugAndCharge() {
return KDColorBlack;
}
}
}

View File

@@ -0,0 +1,23 @@
#include <ion/usb.h>
#include "common.h"
bool Ion::USB::isPlugged() {
return Ion::Simulator::CommonDriver::isPlugged();
}
bool Ion::USB::isEnumerated() {
return false;
}
void Ion::USB::clearEnumerationInterrupt() {
}
void Ion::USB::DFU() {
}
void Ion::USB::enable() {
}
void Ion::USB::disable() {
}

View File

@@ -1,5 +1,6 @@
#include "main.h"
#include "platform.h"
#include "driver/common.h"
#include <assert.h>
#include <ion/events.h>
@@ -7,6 +8,7 @@
#include <3ds.h>
static bool was_plugged = false;
namespace Ion {
namespace Events {
@@ -15,6 +17,15 @@ namespace Events {
Event getPlatformEvent() {
Event result = None;
if (Ion::Simulator::CommonDriver::isPlugged() && !was_plugged) {
was_plugged = true;
return USBPlug;
}
if (!Ion::Simulator::CommonDriver::isPlugged() && was_plugged) {
was_plugged = false;
}
if (!aptMainLoop()) {
result = Termination;

View File

@@ -43,6 +43,8 @@ static bool sNeedsRefresh = false;
void init() {
gfxInitDefault();
cfguInit();
// mcuHwcInit();
ptmuInit();
relayout();
}
@@ -83,6 +85,8 @@ void refresh() {
}
void quit() {
// mcuHwcExit();
ptmuExit();
cfguExit();
gfxExit();
}