Revisions
-
pavi2410 revised this gist
Jul 5, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ // Copyright 2017-2018 Pavitra, All rights reserved // Released under the Apache License, Version 2.0 // http://www.apache.org/licenses/LICENSE-2.0 -
pavi2410 revised this gist
Jul 5, 2018 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,9 +5,7 @@ package com.pavitra; import android.content.Context; import android.util.Log; import com.physicaloid.lib.*; -
pavi2410 revised this gist
Jul 5, 2018 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -68,17 +68,19 @@ public void BaudRate(int baudRate) { public void Read() { byte[] buf = new byte[256]; boolean success = true; String data = ""; if (mPhysicaloid.read(buf) > 0) { try { data = new String(buf, "UTF-8"); } catch (UnsupportedEncodingException e) { success = false; Log.e(LOG_TAG, e.getMessage()); } } else { success = false; } AfterRead(success, data); } -
pavi2410 revised this gist
Jul 5, 2018 . 1 changed file with 8 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,7 +17,7 @@ import java.io.UnsupportedEncodingException; @DesignerComponent(version = 6, description = "Arduino USB Serial Extension by Pavitra.", category = ComponentCategory.EXTENSION, nonVisible = true, @@ -67,19 +67,19 @@ public void BaudRate(int baudRate) { @SimpleFunction(description = "Read from Serial") public void Read() { byte[] buf = new byte[256]; boolean success = true; String data; if (mPhysicaloid.read(buf) > 0) { try { data = new String(buf, "UTF-8"); } catch (UnsupportedEncodingException e) { success = false; data = ""; Log.e(LOG_TAG, e.getMessage()); } } AfterRead(success, data); } @SimpleFunction(description = "Write Data to Serial") -
pavi2410 revised this gist
Jul 5, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,7 +17,7 @@ import java.io.UnsupportedEncodingException; @DesignerComponent(version = 5, description = "Arduino USB Serial Extension by Pavitra.", category = ComponentCategory.EXTENSION, nonVisible = true, -
pavi2410 revised this gist
Jun 14, 2018 . 1 changed file with 14 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,11 +15,13 @@ import com.google.appinventor.components.runtime.*; import com.google.appinventor.components.common.*; import java.io.UnsupportedEncodingException; @DesignerComponent(version = 4, description = "Arduino USB Serial Extension by Pavitra.", category = ComponentCategory.EXTENSION, nonVisible = true, iconName = "images/extension.png") @SimpleObject(external = true) @UsesLibraries(libraries = "physicaloid.jar") public class Arduino extends AndroidNonvisibleComponent implements Component { @@ -50,7 +52,7 @@ public boolean Open() { } @SimpleFunction public boolean Close() { Log.d(LOG_TAG, "Closing connection"); return mPhysicaloid.close(); } @@ -70,10 +72,14 @@ public void Read() { readSize = mPhysicaloid.read(buf); if (readSize > 0) { try { AfterRead(true, new String(buf, "UTF-8")); return; } catch (UnsupportedEncodingException e) { Log.e(LOG_TAG, e.getMessage()); } } AfterRead(false, ""); } @SimpleFunction(description = "Write Data to Serial") -
pavi2410 revised this gist
Jun 14, 2018 . 1 changed file with 76 additions and 113 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,133 +1,96 @@ // Copyright 2017 Pavitra, All rights reserved // Released under the Apache License, Version 2.0 // http://www.apache.org/licenses/LICENSE-2.0 package com.pavitra; import android.content.Context; import android.app.Activity; import android.util.Log; import android.widget.Toast; import com.physicaloid.lib.*; import com.google.appinventor.components.annotations.*; import com.google.appinventor.components.runtime.*; import com.google.appinventor.components.common.*; @DesignerComponent(version = 4, description = "Arduino USB Serial Extension by Pavitra.", category = ComponentCategory.EXTENSION, nonVisible = true, iconName = "images/extension.png") @SimpleObject(external = true) @UsesLibraries(libraries = "physicaloid.jar") public class Arduino extends AndroidNonvisibleComponent implements Component { private static final String LOG_TAG = "Arduino USB Serial Extension"; private Context context; Physicaloid mPhysicaloid; private int baudRate = 9600; public Arduino(ComponentContainer container) { super(container.$form()); context = container.$context(); Log.d(LOG_TAG, "Created"); } @SimpleFunction public void Initialize() { mPhysicaloid = new Physicaloid(context); Log.d(LOG_TAG, "Initialized"); } @SimpleFunction public boolean Open() { Log.d(LOG_TAG, "Opening connection"); return mPhysicaloid.open(); } @SimpleFunction public void Close() { Log.d(LOG_TAG, "Closing connection"); return mPhysicaloid.close(); } @SimpleFunction(description = "Default baud rate is 9600 bps") public void BaudRate(int baudRate) { this.baudRate = baudRate; mPhysicaloid.setBaudrate(baudRate); Log.d(LOG_TAG, "Baud Rate: " + baudRate); } @SimpleFunction(description = "Read from Serial") public void Read() { byte[] buf = new byte[256]; int readSize = 0; readSize = mPhysicaloid.read(buf); if (readSize > 0) { AfterRead(true, new String(buf, "UTF-8")); } else { AfterRead(false, ""); } } @SimpleFunction(description = "Write Data to Serial") public void Write(String writeData) { if (!writeData.isEmpty()) { byte[] buf = writeData.getBytes(); mPhysicaloid.write(buf); } } @SimpleFunction public boolean IsOpened() { return mPhysicaloid.isOpened(); } @SimpleEvent public void AfterRead(boolean success, String data) { EventDispatcher.dispatchEvent(this, "AfterRead", success, data); } } -
pavi2410 created this gist
May 21, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,133 @@ /* Copyright 2017 Pavitra, All rights reserved Released under the Apache License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0 */ package com.pavitra; import android.content.Context; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.widget.Toast; //import java.io.UnsupportedEncodingException; import com.physicaloid.lib.*; import com.google.appinventor.components.annotations.*; import com.google.appinventor.components.runtime.*; import com.google.appinventor.components.common.*; @DesignerComponent(version = Arduino.VERSION, description = "Arduino USB Serial Extension by Pavitra.\nVersion: " + Arduino.VERSION, category = ComponentCategory.EXTENSION, nonVisible = true, iconName = "images/extension.png") @SimpleObject(external = true) @UsesLibraries(libraries = "physicaloid.jar") public class Arduino extends AndroidNonvisibleComponent implements Component { public static final int VERSION = 3; private ComponentContainer container; private Context context; private final Activity activity; private static final String LOG_TAG = "Arduino USB Serial Extension"; private boolean suppressToast = false; private String str; private int baudRate = 9600; Physicaloid mPhysicaloid; public Arduino(ComponentContainer container) { super(container.$form()); this.container = container; context = (Context) container.$context(); activity = (Activity) container.$context(); Log.d(LOG_TAG, "Arduino USB Serial Extension Created"); } @SimpleFunction(description="Initialize") public void Initialize() { mPhysicaloid = new Physicaloid(this.context); showToast("Arduino Initialised"); } @SimpleFunction(description="Open connection. Default baud rate is 9600 bps") public void Open() { mPhysicaloid.open(); showToast("Opened"); } @SimpleFunction(description="Close connection") public void Close() { mPhysicaloid.close(); showToast("Closed"); } @SimpleFunction(description="Baud Rate") public void BaudRate(int baudRate) { this.baudRate = baudRate; mPhysicaloid.setBaudrate(baudRate); showToast("Closed"); } @SimpleFunction(description="Read from Serial") public String Read() { byte[] buf = new byte[256]; int readSize=0; readSize = mPhysicaloid.read(buf, buf.length); if(readSize>0) { try { str = new String(buf); } catch (RuntimeException e) { showToast(e.toString()); } } /* mPhysicaloid.read(buf, buf.length); String str = new String(buf);*/ showToast("Reading: " + str); return str; } @SimpleFunction(description="Write Data to Serial") public void Write(String writeData) { String str = writeData; if(str.length()>0) { byte[] buf = str.getBytes(); mPhysicaloid.write(buf, buf.length); showToast("Writing: " + str); } } //Show Toast @DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_BOOLEAN, defaultValue = "false") @SimpleProperty public void SuppressToast(boolean suppressToast) { this.suppressToast = suppressToast; } @SimpleProperty(category = PropertyCategory.BEHAVIOR, description = "whether Toast should be suppressed") public boolean SuppressToast() { return suppressToast; } private void showToast(String message) { if (!suppressToast) { Toast.makeText(this.context, message, Toast.LENGTH_SHORT).show(); } } }