Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * UsbControllerActivity.java
- * This file is part of UsbController
- *
- * Copyright (C) 2012 - Manuel Di Cerbo
- *
- * UsbController 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; either version 2 of the License, or
- * (at your option) any later version.
- *
- * UsbController 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 for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with UsbController. If not, see <http://www.gnu.org/licenses/>.
- */
- package com.example.pokuspost;
- import android.app.Activity;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.widget.Button;
- import android.widget.SeekBar;
- /**
- * (c) Neuxs-Computing GmbH Switzerland
- * @author Manuel Di Cerbo, 02.02.2012
- *
- */
- public class MainActivity extends Activity {
- /** Called when the activity is first created. */
- private static final int VID = 0x2341;
- private static final int PID = 0x0001;//I believe it is 0x0000 for the Arduino Megas
- private static UsbController sUsbController;
- private static int light = 0;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- if(sUsbController == null){
- sUsbController = new UsbController(this, mConnectionHandler, VID, PID);
- }
- ((Button)findViewById(R.id.light)).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if(light == 0){
- light = 1;
- if(sUsbController != null){
- sUsbController.send((byte)(light&0xFF));
- }
- }
- else{
- light = 0;
- if(sUsbController != null){
- sUsbController.send((byte)(light&0xFF));
- }
- }
- }
- });
- ((Button)findViewById(R.id.start)).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Log.d("try", "start");
- if(sUsbController == null)
- sUsbController = new UsbController(MainActivity.this, mConnectionHandler, VID, PID);
- else{
- sUsbController.stop();
- sUsbController = new UsbController(MainActivity.this, mConnectionHandler, VID, PID);
- }
- }
- });
- }
- private final IUsbConnectionHandler mConnectionHandler = new IUsbConnectionHandler() {
- @Override
- public void onUsbStopped() {
- Log.d("try","Usb stopped!");
- }
- @Override
- public void onErrorLooperRunningAlready() {
- Log.d("try","Looper already running!");
- }
- @Override
- public void onDeviceNotFound() {
- Log.d("Try", "device not found");
- if(sUsbController != null){
- sUsbController.stop();
- sUsbController = null;
- }
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement