Skip to content

Commit

Permalink
Merge branch 'main' into fix-ntp-ui-freeze
Browse files Browse the repository at this point in the history
  • Loading branch information
Aemiii91 authored Jul 4, 2023
2 parents a1fae1f + 825d630 commit f0cf854
Show file tree
Hide file tree
Showing 11 changed files with 217 additions and 174 deletions.
16 changes: 16 additions & 0 deletions files/20230617/New-MiyooGameListXml.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[xml]$xml = Get-Content 'gamelist.xml'

$nodesToDelete = @('desc', 'rating', 'genre', 'players', 'releasedate', 'developer', 'publisher', 'hash', 'thumbnail', 'genreid')

foreach ($node in $nodesToDelete) {
$xml.SelectNodes("//$node") | ForEach-Object { $_.ParentNode.RemoveChild($_) }
}

$gamesWithoutImage = $xml.SelectNodes("//game[not(image)]")
foreach ($game in $gamesWithoutImage) {
$newImage = $xml.CreateElement('image')
$newImage.InnerText = 'no-img.png'
$game.AppendChild($newImage)
}

$xml.OuterXml | Set-Content 'miyoogamelist.xml'
27 changes: 27 additions & 0 deletions files/20230617/New-MiyooGameListXmlFormatted.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[xml]$xml = Get-Content 'gamelist.xml'

$nodesToDelete = @('desc', 'rating', 'genre', 'players', 'releasedate', 'developer', 'publisher', 'hash', 'thumbnail', 'genreid')

foreach ($node in $nodesToDelete) {
$xml.SelectNodes("//$node") | ForEach-Object { $_.ParentNode.RemoveChild($_) }
}

$gamesWithoutImage = $xml.SelectNodes("//game[not(image)]")
foreach ($game in $gamesWithoutImage) {
$newImage = $xml.CreateElement('image')
$newImage.InnerText = 'no-img.png'
$game.AppendChild($newImage)
}

# Create an XmlWriterSettings object with the proper settings
$settings = New-Object System.Xml.XmlWriterSettings
$settings.Indent = $true
$settings.IndentChars = " "
$settings.NewLineChars = "`r`n"
$settings.NewLineHandling = [System.Xml.NewLineHandling]::Replace

# Create an XmlWriter with the settings and write the XML to it
$writer = [System.Xml.XmlWriter]::Create('miyoogamelist.xml', $settings)
$xml.WriteTo($writer)
$writer.Flush()
$writer.Close()
28 changes: 19 additions & 9 deletions src/common/components/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <string.h>
#include <strings.h>

#include "utils/log.h"
#include "utils/str.h"

#define MAX_NUM_VALUES 100
Expand Down Expand Up @@ -133,14 +134,17 @@ ListItem *list_currentItem(List *list)
return &list->items[list->active_pos];
}

void list_scroll(List *list)
void _list_scroll(List *list, int pos)
{
pos = _list_modulo(pos, list->item_count);
printf_debug("scroll to active: %d\n", pos);

// Scroll up
if (list->active_pos < list->scroll_pos)
list->scroll_pos = list->active_pos;
if (pos < list->scroll_pos)
list->scroll_pos = pos;
// Scroll down
else if (list->active_pos >= list->scroll_pos + list->scroll_height)
list->scroll_pos = list->active_pos - list->scroll_height + 1;
else if (pos >= list->scroll_pos + list->scroll_height)
list->scroll_pos = pos - list->scroll_height + 1;

// No scrolling if not enough items
if (list->item_count <= list->scroll_height)
Expand All @@ -150,6 +154,11 @@ void list_scroll(List *list)
list->scroll_pos = list->item_count - list->scroll_height;
}

void list_scroll(List *list)
{
_list_scroll(list, list->active_pos);
}

bool list_scrollTo(List *list, int active_pos)
{
list->active_pos = _list_modulo(active_pos, list->item_count);
Expand All @@ -176,11 +185,11 @@ bool list_keyUp(List *list, bool key_repeat)

if (_list_did_wraparound(old_pos, list->active_pos, -1)) {
if (list->scroll_pos > 0) {
list->scroll_pos -= 1;
_list_scroll(list, list->scroll_pos - 1);
list->active_pos = old_pos;
}
else {
list->scroll_pos = list->item_count - list->scroll_height;
_list_scroll(list, list->item_count - 1);
}
}
else {
Expand All @@ -207,12 +216,13 @@ bool list_keyDown(List *list, bool key_repeat)
list_ensureVisible(list, 1);

if (_list_did_wraparound(old_pos, list->active_pos, 1)) {
printf_debug("scroll_pos: %d < item_count: %d - scroll_height: %d\n", list->scroll_pos, list->item_count, list->scroll_height);
if (list->scroll_pos < list->item_count - list->scroll_height) {
list->scroll_pos += 1;
_list_scroll(list, list->scroll_pos + list->scroll_height);
list->active_pos = old_pos;
}
else {
list->scroll_pos = 0;
_list_scroll(list, 0);
}
}
else {
Expand Down
2 changes: 1 addition & 1 deletion src/keymon/keymon.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ int main(void)
power_pressed = true;
if (!comboKey_menu && val == REPEAT) {
repeat_power++;
if (repeat_power == 7 && !settings.disable_standby) {
if (repeat_power == 7) {
deepsleep(); // 0.5sec deepsleep
}
else if (repeat_power >= REPEAT_SEC(5)) {
Expand Down
2 changes: 1 addition & 1 deletion src/tweaks/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void network_setSshAuthState(void *pt)

void network_wpsConnect(void *pt)
{
system("sh /mnt/SDCARD/.tmp_update/script/wpsclient.sh");
system("sh " NET_SCRIPT_PATH "/wpsclient.sh");
}

void network_setTzManualState(void *pt)
Expand Down
30 changes: 9 additions & 21 deletions static/build/.tmp_update/runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ main() {

# Auto launch
if [ ! -f $sysdir/config/.noAutoStart ]; then
state_change
check_game
state_change check_game
else
rm -f "$sysdir/cmd_to_run.sh" 2> /dev/null
fi
Expand All @@ -96,33 +95,24 @@ main() {
touch /tmp/run_advmenu
fi

state_change
check_switcher
state_change check_switcher
set_startup_tab

# Main runtime loop
while true; do
state_change
check_main_ui

check_networking

state_change
check_game_menu

state_change
check_game

check_networking

state_change
check_switcher
state_change check_main_ui
state_change check_game_menu
state_change check_game
state_change check_switcher
done
}

state_change() {
runifnecessary "keymon" keymon
check_networking
touch /tmp/state_changed
sync
eval "$1"
}

clear_logs() {
Expand Down Expand Up @@ -549,7 +539,6 @@ runifnecessary() {
done
}


start_networking() {
# Loop breaker for NTP
touch /tmp/ntp_run_once
Expand All @@ -558,7 +547,6 @@ start_networking() {

touch /tmp/network_changed
sync
check_networking
}

check_networking() {
Expand Down
138 changes: 138 additions & 0 deletions static/build/.tmp_update/script/network/wpsclient.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
sysdir=/mnt/SDCARD/.tmp_update
miyoodir=/mnt/SDCARD/miyoo
icondir=$sysdir/res
export LD_LIBRARY_PATH="/lib:/config/lib:$miyoodir/lib:$sysdir/lib:$sysdir/lib/parasyte"
export WPACLI=/customer/app/wpa_cli
export IMGPOP=$sysdir/bin/imgpop
# Syntax: ./imgpop duration delay image_path x_position y_position.

main() {
if ifconfig wlan0 &>/dev/null; then
if is_running wpa_supplicant && is_running udhcpc; then
wifiup
fi
sleep 1
log "WPS: Wi-Fi is up"
killall -9 imgpop
break
else
wifiquery
log "WPS: Wi-Fi disabled, trying to enable before connecting.."
/customer/app/axp_test wifion
sleep 2
ifconfig wlan0 up
sleep 1
wpa_supplicant -B -D nl80211 -iwlan0 -c /appconfigs/wpa_supplicant.conf
sleep 2
killall -9 imgpop
sed -i 's/"wifi":\s*0/"wifi": 1/' /appconfigs/system.json # tell mainui that wifi needs to be kept up once started

if is_running wpa_supplicant; then
wifiup
sleep 1
fi

touch /tmp/dont_restart_wifi
sync
fi

start_udhcpc
$WPACLI disable_network all > /dev/null 2>&1 &# disconnect any existing networks
log "WPS: Disconnecting from current network"
$WPACLI wps_pbc # start wps
log "WPS: Trying to connect to WPS host"

start_time=$(date +%s)

while true; do
IP=$(ip route get 1 2>/dev/null | awk '{print $NF;exit}')

if [ -z "$IP" ]; then
wpsflicker
sleep 5

current_time=$(date +%s)
elapsed_time=$((current_time - start_time))

if [ $elapsed_time -gt 30 ]; then
if [ -z "$IP" ]; then
wpsfail
log "WPS: Failed to connect.."
sleep 5
exit
else
wpsconnected
fi
fi
else
break
fi
done

killall -9 imgpop
log "WPS: Connected!"
wpsconnected
sleep 2
killall -9 imgpop
exit
}

start_udhcpc(){
udhcpc -i wlan0 -s /etc/init.d/udhcpc.script > /dev/null 2>&1 &
}

kill_udhcpc() {
if pgrep udhcpc > /dev/null; then
killall -9 udhcpc
fi
}

conn_cleanup() {
kill_udhcpc
start_udhcpc
}

is_running() {
process_name="$1"
pgrep "$process_name" > /dev/null
}

wifiquery(){
$IMGPOP 5 0 "$icondir/wifiquery.png" 84 428 > /dev/null 2>&1 &
}

wifiup(){
$IMGPOP 5 0 "$icondir/wifiup.png" 84 428 > /dev/null 2>&1 &
}

wpsfail() {
$IMGPOP 5 0 "$icondir/wpsfail.png" 84 428 > /dev/null 2>&1 &
}

wpstrying() {
$IMGPOP 1 0 "$icondir/wpstrying.png" 84 428 > /dev/null 2>&1 &
}

wpsconnected() {
$IMGPOP 10 0 "$icondir/wpsconnected.png" 84 428 > /dev/null 2>&1 &
}

wpsflicker() {
count=0
while [ $count -lt 4 ]; do
if [ $((count % 2)) -eq 0 ]; then
wpstrying
else
wpsfail
fi
sleep 1
count=$((count + 1))
killall -9 imgpop
done &
}

log() {
echo "$(date)" $* >> $sysdir/logs/network.log
}

main &
Loading

0 comments on commit f0cf854

Please sign in to comment.