Skip to content

Instantly share code, notes, and snippets.

@YumNumm
Last active January 30, 2022 16:18
Show Gist options
  • Save YumNumm/e420ffc332f93422c62505101c6d864b to your computer and use it in GitHub Desktop.
Save YumNumm/e420ffc332f93422c62505101c6d864b to your computer and use it in GitHub Desktop.
部屋のライトコントローラ(NECだったかな)
import 'dart:io';
final Map<String, String> light_map = {
"on":
"0x01,0x58,0x00,0xab,0x00,0x16,0x00,0x17,0x00,0x15,0x00,0x42,0x00,0x16,0x00,0x17,0x00,0x15,0x00,0x17,0x00,0x16,0x00,0x17,0x00,0x16,0x00,0x17,0x00,0x15,0x00,0x17,0x00,0x16,0x00,0x42,0x00,0x15,0x00,0x42,0x00,0x16,0x00,0x16,0x00,0x16,0x00,0x42,0x00,0x15,0x00,0x42,0x00,0x16,0x00,0x17,0x00,0x15,0x00,0x42,0x00,0x16,0x00,0x41,0x00,0x16,0x00,0x17,0x00,0x16,0x00,0x41,0x00,0x16,0x00,0x41,0x00,0x16,0x00,0x17,0x00,0x16,0x00,0x41,0x00,0x16,0x00,0x17,0x00,0x16,0x00,0x41,0x00,0x16,0x00,0x17,0x00,0x16,0x00,0x41,0x00,0x16,0x00,0x17,0x00,0x16,0x00,0x16,0x00,0x16,0x00,0x42,0x00,0x15,0x00,0x17,0x00,0x16,0x00,0x42,0x00,0x15,0x00,0x17,0x00,0x16,0x00,0x41,0x00,0x16,0x00,0x17,0x00,0x16,0x06,0x1c",
"off":
"0x01,0x58,0x00,0xab,0x00,0x16,0x00,0x17,0x00,0x15,0x00,0x42,0x00,0x16,0x00,0x17,0x00,0x15,0x00,0x17,0x00,0x16,0x00,0x17,0x00,0x16,0x00,0x17,0x00,0x15,0x00,0x17,0x00,0x16,0x00,0x42,0x00,0x15,0x00,0x42,0x00,0x16,0x00,0x16,0x00,0x16,0x00,0x42,0x00,0x15,0x00,0x42,0x00,0x16,0x00,0x17,0x00,0x15,0x00,0x42,0x00,0x16,0x00,0x41,0x00,0x16,0x00,0x17,0x00,0x16,0x00,0x41,0x00,0x16,0x00,0x41,0x00,0x16,0x00,0x17,0x00,0x16,0x00,0x41,0x00,0x16,0x00,0x17,0x00,0x16,0x00,0x41,0x00,0x16,0x00,0x17,0x00,0x16,0x00,0x41,0x00,0x16,0x00,0x17,0x00,0x16,0x00,0x16,0x00,0x16,0x00,0x42,0x00,0x15,0x00,0x17,0x00,0x16,0x00,0x42,0x00,0x15,0x00,0x17,0x00,0x16,0x00,0x41,0x00,0x16,0x00,0x17,0x00,0x16,0x06,0x1c",
"night":
"0x01,0x56,0x00,0xad,0x00,0x15,0x00,0x17,0x00,0x17,0x00,0x41,0x00,0x17,0x00,0x15,0x00,0x17,0x00,0x16,0x00,0x17,0x00,0x16,0x00,0x16,0x00,0x16,0x00,0x18,0x00,0x15,0x00,0x17,0x00,0x40,0x00,0x16,0x00,0x41,0x00,0x16,0x00,0x17,0x00,0x17,0x00,0x40,0x00,0x15,0x00,0x43,0x00,0x15,0x00,0x17,0x00,0x18,0x00,0x3f,0x00,0x17,0x00,0x41,0x00,0x15,0x00,0x17,0x00,0x18,0x00,0x15,0x00,0x17,0x00,0x16,0x00,0x17,0x00,0x40,0x00,0x16,0x00,0x41,0x00,0x17,0x00,0x40,0x00,0x17,0x00,0x41,0x00,0x17,0x00,0x15,0x00,0x18,0x00,0x40,0x00,0x15,0x00,0x42,0x00,0x16,0x00,0x41,0x00,0x16,0x00,0x17,0x00,0x17,0x00,0x15,0x00,0x18,0x00,0x15,0x00,0x17,0x00,0x16,0x00,0x17,0x00,0x40,0x00,0x16,0x00,0x17,0x00,0x17,0x06,0x1a",
"full":
"0x01,0x58,0x00,0xab,0x00,0x16,0x00,0x17,0x00,0x17,0x00,0x40,0x00,0x16,0x00,0x17,0x00,0x17,0x00,0x15,0x00,0x18,0x00,0x15,0x00,0x17,0x00,0x16,0x00,0x17,0x00,0x15,0x00,0x17,0x00,0x41,0x00,0x15,0x00,0x42,0x00,0x16,0x00,0x17,0x00,0x17,0x00,0x40,0x00,0x16,0x00,0x41,0x00,0x16,0x00,0x17,0x00,0x17,0x00,0x40,0x00,0x16,0x00,0x41,0x00,0x16,0x00,0x17,0x00,0x17,0x00,0x16,0x00,0x17,0x00,0x40,0x00,0x16,0x00,0x41,0x00,0x16,0x00,0x17,0x00,0x17,0x00,0x15,0x00,0x18,0x00,0x40,0x00,0x15,0x00,0x17,0x00,0x18,0x00,0x40,0x00,0x17,0x00,0x40,0x00,0x16,0x00,0x16,0x00,0x18,0x00,0x15,0x00,0x17,0x00,0x40,0x00,0x16,0x00,0x42,0x00,0x17,0x00,0x15,0x00,0x18,0x00,0x3f,0x00,0x16,0x00,0x17,0x00,0x17,0x06,0x1b",
"down":
"0x01,0x56,0x00,0xad,0x00,0x16,0x00,0x16,0x00,0x18,0x00,0x40,0x00,0x16,0x00,0x16,0x00,0x18,0x00,0x15,0x00,0x17,0x00,0x16,0x00,0x16,0x00,0x16,0x00,0x17,0x00,0x16,0x00,0x17,0x00,0x40,0x00,0x17,0x00,0x40,0x00,0x16,0x00,0x17,0x00,0x17,0x00,0x40,0x00,0x15,0x00,0x42,0x00,0x15,0x00,0x18,0x00,0x17,0x00,0x40,0x00,0x16,0x00,0x41,0x00,0x18,0x00,0x15,0x00,0x17,0x00,0x40,0x00,0x18,0x00,0x40,0x00,0x15,0x00,0x17,0x00,0x17,0x00,0x40,0x00,0x16,0x00,0x42,0x00,0x16,0x00,0x41,0x00,0x15,0x00,0x17,0x00,0x18,0x00,0x40,0x00,0x16,0x00,0x16,0x00,0x17,0x00,0x16,0x00,0x16,0x00,0x41,0x00,0x16,0x00,0x17,0x00,0x17,0x00,0x16,0x00,0x17,0x00,0x15,0x00,0x17,0x00,0x40,0x00,0x18,0x00,0x15,0x00,0x16,0x06,0x1b",
"up":
"0x01,0x57,0x00,0xac,0x00,0x16,0x00,0x17,0x00,0x16,0x00,0x41,0x00,0x17,0x00,0x16,0x00,0x16,0x00,0x17,0x00,0x15,0x00,0x17,0x00,0x16,0x00,0x17,0x00,0x16,0x00,0x17,0x00,0x16,0x00,0x41,0x00,0x16,0x00,0x41,0x00,0x16,0x00,0x17,0x00,0x16,0x00,0x41,0x00,0x16,0x00,0x41,0x00,0x16,0x00,0x17,0x00,0x17,0x00,0x40,0x00,0x16,0x00,0x41,0x00,0x16,0x00,0x17,0x00,0x17,0x00,0x16,0x00,0x16,0x00,0x41,0x00,0x16,0x00,0x17,0x00,0x15,0x00,0x42,0x00,0x16,0x00,0x41,0x00,0x15,0x00,0x42,0x00,0x16,0x00,0x17,0x00,0x16,0x00,0x41,0x00,0x16,0x00,0x41,0x00,0x16,0x00,0x17,0x00,0x15,0x00,0x42,0x00,0x16,0x00,0x17,0x00,0x15,0x00,0x18,0x00,0x15,0x00,0x17,0x00,0x15,0x00,0x43,0x00,0x15,0x00,0x17,0x00,0x16,0x06,0x1c",
};
Future<void> main(List<String> args) async {
final File file = File("/tmp/light");
//final File file = File("./log");
if (args[0] == "status") {
print((await file.readAsLines())[0].toString());
} else {
final int light_value_tmp = int.parse(args[0]);
final int light_value = getValue(light_value_tmp);
final int read = int.parse(await file.readAsString());
bool needresent = true;
if (getValue(read) == light_value) needresent = false;
if (read != light_value_tmp) needresent = true;
if (needresent) {
file.writeAsString(light_value_tmp.toString());
bool is_light_on = true;
if (light_value_tmp == 0) is_light_on = false;
//print(light_value);
final String code = sender(light_value, is_light_on);
final ProcessResult result =
await Process.run("/usr/local/bin/bto_usbir", ["-d", code]);
if (result.exitCode != 0) {
print(result.stderr);
}
}
print(light_value_tmp);
}
}
String sender([int lightValue = 2, bool isLightOn = true]) {
String Data = "";
//もし、ライトをオフにするなら問答無用でオフ実行(全灯,ON/OFF)
if (!isLightOn) {
Data = light_map["full"]! + "," + light_map["off"]!;
} else {
//ふつ~~のライト(全灯にして回数分下げる)
Data = light_map["full"]!;
int _temp = 5 - lightValue;
for (int j = 0; j < _temp; j++) {
Data += "," + light_map["down"]!;
}
}
return Data.toString();
}
int getValue(int s) => s ~/ 20 + ((s == 100) ? 0 : 1);
/*else if (isNightLight) {
//常夜灯(常夜灯にして5回下げて上げる)
Data = light_map["night"]!;
for (int j = 0; j < 5; j++) {
Data += "," + light_map["down"]!;
}
for (int j = 0; j < lightValue - 1; j++) {
Data += "," + light_map["up"]!;
}
}*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment