Beispiel #1
0
  @Override
  public void onCreate() {
    LOG.info("Created car service");

    notificationManager = (NotificationManager) this.getSystemService(Service.NOTIFICATION_SERVICE);

    // TODO: config
    final CarConfig config = new CarConfig();

    final Settings settings = Settings.builder().setNeverSuspend(true).build();

    // Connect to the servo controller
    final Product product = config.getServos().getProduct();
    AndroidDriverBinding.bindToDevice(
        this,
        product,
        new AsyncBindingListener<AndroidDriverBinding>() {
          @Override
          public void onBind(int vendorId, int productId, AndroidDriverBinding driver) {
            try {
              final SensorController sensors = new SensorController(CarService.this);
              final MaestroServoController servos = new MaestroServoController(driver, settings);
              final WebController web = new WebController(getAssets(), config.getWeb());

              engine = new CarEngine(CarService.this, sensors, servos, web, config);
            } catch (Exception e) {
              this.onException(e);
            }
          }

          @Override
          public void onException(Throwable throwable) {
            LOG.error("Unknown error occurred", throwable);
          }
        });
  }