-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18684 from Florin9doi/infrared
sceSircs/Infrared support on Android
- Loading branch information
Showing
16 changed files
with
215 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (c) 2012- PPSSPP Project. | ||
|
||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, version 2.0 or later versions. | ||
|
||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License 2.0 for more details. | ||
|
||
// A copy of the GPL 2.0 should have been included with the program. | ||
// If not, see http://www.gnu.org/licenses/ | ||
|
||
// Official git repository and contact information can be found at | ||
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. | ||
|
||
#ifdef __MINGW32__ | ||
#include <unistd.h> | ||
#endif | ||
#include <ctime> | ||
|
||
#include "Common/System/System.h" | ||
#include "Common/System/Request.h" | ||
#include "Common/Serialize/Serializer.h" | ||
#include "Common/Serialize/SerializeFuncs.h" | ||
#include "Core/HLE/HLE.h" | ||
#include "Core/HLE/sceSircs.h" | ||
#include "Core/HLE/FunctionWrappers.h" | ||
#include "Core/MemMapHelpers.h" | ||
|
||
int sceSircsSend(u32 dataAddr, int count) { | ||
auto data = PSPPointer<SircsData>::Create(dataAddr); | ||
if (data.IsValid()) { | ||
INFO_LOG(HLE, "%s (version=0x%x, command=0x%x, address=0x%x, count=%d)", | ||
__FUNCTION__, data->version, data->command, data->address, count); | ||
#if PPSSPP_PLATFORM(ANDROID) | ||
char command[40] = {0}; | ||
snprintf(command, sizeof(command), "sircs_%d_%d_%d_%d", | ||
data->version, data->command, data->address, count); | ||
System_InfraredCommand(command); | ||
#endif | ||
data.NotifyRead("sceSircsSend"); | ||
} | ||
return 0; | ||
} | ||
|
||
const HLEFunction sceSircs[] = | ||
{ | ||
{0X62411801, nullptr, "sceSircsInit", '?', "" }, | ||
{0X19155A2F, nullptr, "sceSircsEnd", '?', "" }, | ||
{0X71EEF62D, &WrapI_UI<sceSircsSend>, "sceSircsSend", 'i', "xi" }, | ||
{0x83381633, nullptr, "sceSircsReceive", '?', "" }, | ||
}; | ||
|
||
void Register_sceSircs() | ||
{ | ||
RegisterModule("sceSircs", ARRAY_SIZE(sceSircs), sceSircs); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) 2012- PPSSPP Project. | ||
|
||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, version 2.0 or later versions. | ||
|
||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License 2.0 for more details. | ||
|
||
// A copy of the GPL 2.0 should have been included with the program. | ||
// If not, see http://www.gnu.org/licenses/ | ||
|
||
// Official git repository and contact information can be found at | ||
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. | ||
|
||
#pragma once | ||
|
||
#include "Core/HLE/FunctionWrappers.h" | ||
|
||
void Register_sceSircs(); | ||
|
||
typedef struct { | ||
u8 version; | ||
u8 command; | ||
u16 address; | ||
} SircsData; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package org.ppsspp.ppsspp; | ||
|
||
import android.content.Context; | ||
import android.hardware.ConsumerIrManager; | ||
import android.hardware.ConsumerIrManager.CarrierFrequencyRange; | ||
import android.os.Build; | ||
import android.util.Log; | ||
|
||
import androidx.annotation.RequiresApi; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
@RequiresApi(api = Build.VERSION_CODES.KITKAT) | ||
class InfraredHelper { | ||
private static final String TAG = InfraredHelper.class.getSimpleName(); | ||
private static final int SIRC_FREQ = 40000; | ||
private ConsumerIrManager mConsumerIrManager; | ||
|
||
InfraredHelper(Context context) throws Exception { | ||
mConsumerIrManager = (ConsumerIrManager) context.getSystemService(Context.CONSUMER_IR_SERVICE); | ||
Log.d(TAG, "HasIrEmitter: " + mConsumerIrManager.hasIrEmitter()); | ||
if (!mConsumerIrManager.hasIrEmitter()) { | ||
throw new Exception("No Ir Emitter"); | ||
} | ||
boolean sirc_freq_supported = false; | ||
CarrierFrequencyRange[] carrierFrequencies = mConsumerIrManager.getCarrierFrequencies(); | ||
for (CarrierFrequencyRange freq : carrierFrequencies) { | ||
Log.d(TAG, "CarrierFrequencies: " + freq.getMinFrequency() + " -> " + freq.getMaxFrequency()); | ||
if (freq.getMinFrequency() <= SIRC_FREQ && SIRC_FREQ <= freq.getMaxFrequency()) { | ||
sirc_freq_supported = true; | ||
} | ||
} | ||
if (!sirc_freq_supported) { | ||
throw new Exception("Sirc Frequency unsupported"); | ||
} | ||
} | ||
|
||
void sendSircCommand(int version, int command, int address, int count) { | ||
final List<Integer> start = Arrays.asList(2400, 600); | ||
final List<Integer> one = Arrays.asList(1200, 600); | ||
final List<Integer> zero = Arrays.asList( 600, 600); | ||
|
||
List<Integer> iterList = new ArrayList<>(); | ||
iterList.addAll(start); | ||
|
||
for (int i = 0; i < version; i++) { | ||
List<Integer> val = i < 7 | ||
? ((command >> i ) & 1) == 1 ? one : zero | ||
: ((address >> i - 7) & 1) == 1 ? one : zero; | ||
iterList.addAll(val); | ||
} | ||
|
||
int iterSum = 0; | ||
for (int i = 0; i < iterList.size() - 1; i++) { | ||
iterSum += iterList.get(i); | ||
} | ||
int lastVal = 52000 - iterSum; // SIRC cicle = 52ms | ||
iterList.set(iterList.size() - 1, lastVal); | ||
|
||
List<Integer> patternList = new ArrayList<>(); | ||
// Android is limited to 2 seconds => max 38 loops of 52ms each | ||
// Limit even further to 4 loops for now | ||
for (int i = 0; i < count && i < 4; i++) { | ||
patternList.addAll(iterList); | ||
} | ||
|
||
int[] pattern = new int[patternList.size()]; | ||
for (int i = 0; i < patternList.size(); i++) { | ||
pattern[i] = patternList.get(i); | ||
} | ||
mConsumerIrManager.transmit(SIRC_FREQ, pattern); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters