import 'package:dart_periphery/dart_periphery.dart';
import 'package:flutter/foundation.dart';

// linux_spidev was tried out here beforehand,
// but it didn't work and was replaced by dart_periphery
// import 'package:linux_spidev/linux_spidev.dart';

class MatrixService {
  final spi = SPI(0, 0, SPImode.mode0, 35000);
  // final spidev = Spidev.fromBusDevNrs(0, 0);

  void setLedsOn(List<int> pixels) async {
    // final handle = spidev.open();
    try {
      int refresh = 1;
      while (refresh != 0) {
        spi.transfer(pixels, false);
        await Future.delayed(const Duration(milliseconds: 100));
        refresh--;
      }
    } catch (e) {
      debugPrint(e.toString());
    } finally {
      // clean up the resource
      spi.dispose();
    }
  }
}
