Skip to content

Commit

Permalink
do not use the ir_sensor_pluguin library
Browse files Browse the repository at this point in the history
  • Loading branch information
TalkingPanda0 committed Jan 6, 2024
1 parent a34c2b5 commit 7e859ba
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,52 @@
package org.talkingpanda.osram_remote

import android.content.Context
import android.content.ContextWrapper
import android.content.Intent
import android.content.IntentFilter
import android.hardware.ConsumerIrManager
import android.os.BatteryManager
import android.os.Build.VERSION
import android.os.Build.VERSION_CODES
import androidx.annotation.NonNull
import androidx.annotation.RequiresApi
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
import kotlin.reflect.typeOf


class MainActivity: FlutterActivity() {
private val CHANNEL = "org.talkingpanda/irtransmitter"
private lateinit var irManager: ConsumerIrManager
private fun convertIntegers(integers: List<Int>): IntArray? {
val ret = IntArray(integers.size)
val iterator = integers.iterator()
for (i in ret.indices) {
ret[i] = iterator.next()
}
return ret
}
@RequiresApi(VERSION_CODES.O)
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
irManager = getSystemService(Context.CONSUMER_IR_SERVICE) as ConsumerIrManager;
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler {
call, result ->
if (call.method == "transmit") {
val list = call.argument<ArrayList<Int>>("list")
if(list == null) {
result.error( "NOPATTERN","No pattern given",null)
} else {
irManager.transmit(38028,list.toIntArray());
}
result.success(null);
} else
{
result.notImplemented()
}
}
}

}

2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import 'package:dynamic_color/dynamic_color.dart';
import 'package:flutter/material.dart';
import 'package:osram_controller/utils/irtransmitter.dart';
import 'package:osram_controller/utils/remote.dart';
import 'package:osram_controller/widgets/remote_view.dart';

List<Remote> remotes = [];
void main() async {
WidgetsFlutterBinding.ensureInitialized();

remotes = await readRemotes();

if (remotes.isEmpty) {
Expand Down
9 changes: 7 additions & 2 deletions lib/utils/ir.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import 'package:ir_sensor_plugin/ir_sensor_plugin.dart';
import 'package:flutter/services.dart';

import 'package:osram_controller/utils/irtransmitter.dart';

const platform = MethodChannel('org.talkingpanda/irtransmitter');

void transmit(int code) async {
await IrSensorPlugin.transmitListInt(list: convertNECtoList(code));
//Ir.transmit(carrierFrequency: 38028, pattern: convertNECtoList(code));
await platform.invokeMethod("transmit", {"list": convertNECtoList(code)});
}

// Converts a int code to timing list
Expand Down
12 changes: 12 additions & 0 deletions lib/utils/irtransmitter.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'dart:async';
import 'dart:ffi';
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class IRTransmitter {
static const platform = MethodChannel('org.talkingpanda/irtransmitter');
void transmit(List<int> list) async {
await platform.invokeMethod("transmit", {"list": list});
}
}
42 changes: 33 additions & 9 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,30 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.2.1+1"
ir_sensor_plugin:
dependency: "direct main"
leak_tracker:
dependency: transitive
description:
name: leak_tracker
sha256: e45c31f458d01fd9ef4a214feb2e153b72d5b1907435f4332b1637a2f348c021
url: "https://pub.dev"
source: hosted
version: "9.0.18"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: ir_sensor_plugin
sha256: "3c71a18cc72bc5e60a35e8ea0fff5d54852d47406fe9f32f33c912dec27fe449"
name: leak_tracker_flutter_testing
sha256: "54808cfcfa87dbc0d74c61ac063d624adf1bd5c0407301f32b06c783c60dc4ca"
url: "https://pub.dev"
source: hosted
version: "0.3.0"
version: "2.0.0"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: "7e71be3c161472f6c9158ac8875dd8de575060d60b5d159ebca3600ea32c9116"
url: "https://pub.dev"
source: hosted
version: "1.0.6"
lints:
dependency: transitive
description:
Expand All @@ -260,10 +276,10 @@ packages:
dependency: transitive
description:
name: material_color_utilities
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
url: "https://pub.dev"
source: hosted
version: "0.5.0"
version: "0.8.0"
meta:
dependency: transitive
description:
Expand Down Expand Up @@ -457,10 +473,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f"
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
url: "https://pub.dev"
source: hosted
version: "0.7.0"
version: "0.6.1"
typed_data:
dependency: transitive
description:
Expand All @@ -477,6 +493,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
vm_service:
dependency: transitive
description:
name: vm_service
sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957
url: "https://pub.dev"
source: hosted
version: "13.0.0"
web:
dependency: transitive
description:
Expand Down
1 change: 0 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ dependencies:
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
ir_sensor_plugin: ^0.3.0
dynamic_color: ^1.6.9
shared_preferences: ^2.2.2
path: ^1.8.3
Expand Down

0 comments on commit 7e859ba

Please sign in to comment.