UPDATE!!:
I apologize for replying to myself and double posting but I wanted to
update my progress in this since I have been working out some problems with
an IT student.
We realized the following things:
-making your own app does not work. Throwing your code into HelloIOIO
sample app is much more successful. I checked every setting and couldn't
find why a modified HelloIOIO trumps my own oackage.
-because of previous point, the looper and pin assignment only correctly
works as it should ONLY in the HelloIOIO app.
-also any attempt to Log.d("anything") inside the Looper class for some
reason does not work, giving me no feedback where the IOIO has problem with
my code. Is there any way to get feedback inside the loop?
-for some reason it's better to have the Looper class inside
MainActivity.java of the HelloIOIO app.
Can I get a confirmation if this is true? Would help me understand the
underlying functionality more.
Further more, since I managed to get my code mostly to work using the
observations above, I am however not getting the expected result.
My code is at the end of this post. For some reason this sets a constant
logic "1" to all 3 used pins and the YELLOW stat LED is constant on. I see
no reason why it should so I was hoping someone could help my understand
what I am doing wrong here...
Help is MUCH appreciated...
Oh and I highly doubt this is a Null Pointer Exception since the app
doesn't crash and I checked this already thoroughly. It is just the
IOIO-OTG that doesn't want to work with me :(
package ioio.examples.hello;
> (removed all Library calls to shorten post)
>
> public class MainActivity extends IOIOActivity{
> private Bitmap bitmapb;
>
> private Button rButton;
> private static int picw = 32;
> private static int pich = 32;
> public static String[] sig2bitR = new String[picw * pich * 8];
> public static String[] sig2bitG = new String[picw * pich * 8];
> public static String[] sig2bitB = new String[picw * pich * 8];
> private String[] Red = new String[pich * picw];
> private String[] Green = new String[pich * picw];
> private String[] Blue = new String[pich * picw];
>
> @Override
> protected void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
> setContentView(R.layout.main);
> rButton = (Button) findViewById(R.id.button3);
> rButton.setOnClickListener(new OnClickListener() {
> @Override
> public void onClick(View v) {
> if (v.getId() == rButton.getId()) {
> Intent intent = new Intent(Intent.ACTION_PICK,
> android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
> startActivityForResult(intent, 0);
> }
> }
> });
> }
> @Override
> protected void onActivityResult(int requestCode, int resultCode, Intent
> data) {
> super.onActivityResult(requestCode, resultCode, data);
> if (resultCode == RESULT_OK) {
> Uri targetUri = data.getData();
> // textTargetUri.setText(targetUri.toString());
> Bitmap bitmapa;
> try {
> bitmapa = BitmapFactory.decodeStream(getContentResolver()
> .openInputStream(targetUri));
> bitmapb = Bitmap.createScaledBitmap(bitmapa, 32, 32, false);
> //imagethingy.setImageBitmap(bitmapb);
> int[] pix = new int[picw * pich];
> bitmapb.getPixels(pix, 0, picw, 0, 0, picw, pich);
> for (int y = 0; y < pich; y++) {
> for (int x = 0; x < picw; x++) {
> int index = y * picw + x;
> Red[index] = Integer
> .toBinaryString((pix[index] >> 16) & 0xff); // bitwise
> // shifting
> Green[index] = Integer
> .toBinaryString((pix[index] >> 8) & 0xff);
> Blue[index] = Integer.toBinaryString(pix[index] & 0xff);
> if (Red[index].length() != 8) {
> Red[index] = String.format("%08d",
> Integer.parseInt(Red[index]));
> }
> if (Green[index].length() != 8) {
> Green[index] = String.format("%08d",
> Integer.parseInt(Green[index]));
> }
> if (Blue[index].length() != 8) {
> Blue[index] = String.format("%08d",
> Integer.parseInt(Blue[index]));
> }
> }
> }
> for (int i = 0; i < Red.length; i++) {
> String[] s2r = Red[i].split("");
> String[] s2g = Green[i].split("");
> String[] s2b = Blue[i].split("");
> System.arraycopy(s2r, 1, sig2bitR, 8 * i, 8);
> System.arraycopy(s2g, 1, sig2bitG, 8 * i, 8);
> System.arraycopy(s2b, 1, sig2bitB, 8 * i, 8);
> }
> } catch (FileNotFoundException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> }
> }
> class Looper extends BaseIOIOLooper {
> private DigitalOutput pin2;
> private DigitalOutput pin4;
> private DigitalOutput pin6;
> private String[] sig2bitR = MainActivity.sig2bitR;
> private String[] sig2bitG = MainActivity.sig2bitG;
> private String[] sig2bitB = MainActivity.sig2bitB;
>
>
> @Override
> protected void setup() throws ConnectionLostException {
> pin2 = ioio_.openDigitalOutput(2, false);
> pin4 = ioio_.openDigitalOutput(4, false);
> pin6 = ioio_.openDigitalOutput(6, false);
> }
>
> @Override
> public void loop() throws ConnectionLostException {
>
>
> for (int j = 0; j<sig2bitR.length;j++){
> if (sig2bitR[j]=="0"){
> pin2.write(false);
> }
> else{
> pin2.write(true);
> }
> if (sig2bitG[j]=="0"){
> pin4.write(false);
> }
> else{
> pin4.write(true);
> }
> if (sig2bitB[j]=="0"){
> pin6.write(false);
> }
> else{
> pin6.write(true);
> }
>
> try {
> Thread.sleep(1000);
> } catch (InterruptedException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> }
> // }
>
> }
> }
> protected IOIOLooper createIOIOLooper() {
> return new Looper();
> }
> }
On Thursday, May 1, 2014 5:34:18 PM UTC+2, Sidharta Prahladsingh wrote:
>
> Forgot to write a question. Obvious however, does anyone know why I get
> this error?
>
> On Thursday, May 1, 2014 5:31:55 PM UTC+2, Sidharta Prahladsingh wrote:
>>
>> Hello,
>>
>> I am busy with a Bachelor project on my University where we want to drive
>> a 32x32 LED screen. Normally this is easy to do with the IOIO-OTG but we
>> want to make our own system to drive the LEDs, but want to use the IOIO-OTG
>> to only stream the RGB data in bit streams to our own system.
>>
>> I am trying to write an app that takes a picture out of your phone,
>> changes it to 32x32 bit, analyses the Colors per pixel, converts the color
>> levels (256 possible levels) to 8 bits and then finally making a very long
>> array (length = 32*32*8bits) serving as a bitstream for R,G and B which I
>> want to send via 3 pins through the IOIO-OTG.
>>
>> I am having quite some problem with this though. The app itself work just
>> fine and I do get my 3 very long arrays without null entries. The only
>> problem is that the moment I want to initialize the pins using for example
>> pin2 = ioio_openDirectOutput(2,false);, I get a Null Pointer Exception for
>> some reason.
>>
>> Main code:
>>
>>> package com.example.imagetest2;
>>> import java.io.FileNotFoundException;
>>> import ioio.lib.spi.Log;
>>> import ioio.lib.util.BaseIOIOLooper;
>>> import ioio.lib.api.DigitalOutput;
>>> import ioio.lib.api.exception.ConnectionLostException;
>>> import ioio.lib.util.IOIOLooper;
>>> import ioio.lib.util.android.IOIOActivity;
>>> import android.view.Menu;
>>> import android.view.View;
>>> import android.view.View.OnClickListener;
>>> import android.content.Intent;
>>> import android.graphics.Bitmap;
>>> import android.graphics.BitmapFactory;
>>> import android.net.Uri;
>>> import android.os.Bundle;
>>> import android.widget.Button;
>>> import android.widget.ImageView;
>>> import android.widget.TextView;
>>>
>>> public class MainActivity extends IOIOActivity implements
>>> OnClickListener {
>>>
>>> private Button shareButton;
>>> private ImageView imagethingy;
>>> private Bitmap bitmapb;
>>> private TextView color;
>>> private TextView colorint;
>>> private TextView status;
>>> private static int picw = 32;
>>> private static int pich = 32;
>>> public static String[] sig2bitR = new String[picw * pich * 8];
>>> public static String[] sig2bitG = new String[picw * pich * 8];
>>> public static String[] sig2bitB = new String[picw * pich * 8];
>>> private String[] Red = new String[pich * picw];
>>> private String[] Green = new String[pich * picw];
>>> private String[] Blue = new String[pich * picw];
>>>
>>> @Override
>>> protected void onCreate(Bundle savedInstanceState) {
>>> super.onCreate(savedInstanceState);
>>> setContentView(R.layout.fragment_main);
>>> shareButton = (Button) findViewById(R.id.share_button);
>>> shareButton.setOnClickListener(this);
>>> imagethingy = (ImageView) findViewById(R.id.imageView1);
>>> color = (TextView) findViewById(R.id.textView2);
>>> colorint = (TextView) findViewById(R.id.textView3);
>>> status = (TextView) findViewById(R.id.textView1);
>>> }
>>> @Override
>>> public void onClick(View v) {
>>> Intent intent = new Intent(Intent.ACTION_PICK,
>>> android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
>>> startActivityForResult(intent, 0);
>>> }
>>> @Override
>>> protected void onActivityResult(int requestCode, int resultCode, Intent
>>> data) {
>>> super.onActivityResult(requestCode, resultCode, data);
>>> if (resultCode == RESULT_OK) {
>>> Uri targetUri = data.getData();
>>> // textTargetUri.setText(targetUri.toString());
>>> Bitmap bitmapa;
>>> try {
>>> bitmapa = BitmapFactory.decodeStream(getContentResolver()
>>> .openInputStream(targetUri));
>>> bitmapb = Bitmap.createScaledBitmap(bitmapa, 32, 32, false);
>>> imagethingy.setImageBitmap(bitmapb);
>>> int[] pix = new int[picw * pich];
>>> bitmapb.getPixels(pix, 0, picw, 0, 0, picw, pich);
>>> for (int y = 0; y < pich; y++) {
>>> for (int x = 0; x < picw; x++) {
>>> int index = y * picw + x;
>>> Red[index] = Integer
>>> .toBinaryString((pix[index] >> 16) & 0xff); // bitwise
>>> // shifting
>>> Green[index] = Integer
>>> .toBinaryString((pix[index] >> 8) & 0xff);
>>> Blue[index] = Integer.toBinaryString(pix[index] & 0xff);
>>> if (Red[index].length() != 8) {
>>> Red[index] = String.format("%08d",
>>> Integer.parseInt(Red[index]));
>>> }
>>> if (Green[index].length() != 8) {
>>> Green[index] = String.format("%08d",
>>> Integer.parseInt(Green[index]));
>>> }
>>> if (Blue[index].length() != 8) {
>>> Blue[index] = String.format("%08d",
>>> Integer.parseInt(Blue[index]));
>>> }
>>> }
>>> }
>>> for (int i = 0; i < Red.length; i++) {
>>> String[] s2r = Red[i].split("");
>>> String[] s2g = Green[i].split("");
>>> String[] s2b = Blue[i].split("");
>>> System.arraycopy(s2r, 1, sig2bitR, 8 * i, 8);
>>> System.arraycopy(s2g, 1, sig2bitG, 8 * i, 8);
>>> System.arraycopy(s2b, 1, sig2bitB, 8 * i, 8);
>>> }
>>> } catch (FileNotFoundException e) {
>>> // TODO Auto-generated catch block
>>> e.printStackTrace();
>>> }
>>> Looper looper = new Looper();
>>> try {
>>> looper.setup();
>>> looper.loop();
>>> } catch (ConnectionLostException e) {
>>> // TODO Auto-generated catch block
>>> e.printStackTrace();
>>> }
>>> }
>>> }
>>>
>>> protected IOIOLooper createIOIOLooper() {
>>> return new Looper();
>>> }
>>> }
>>
>>
>>
>> Looper code:
>>>
>>> package com.example.imagetest2;
>>> import ioio.lib.api.DigitalOutput;
>>> import ioio.lib.api.exception.ConnectionLostException;
>>> import ioio.lib.spi.Log;
>>> import ioio.lib.util.BaseIOIOLooper;
>>> import ioio.lib.util.IOIOLooper;
>>>
>>>
>>> class Looper extends BaseIOIOLooper {
>>> private DigitalOutput pin2;
>>> private DigitalOutput pin4;
>>> private DigitalOutput pin6;
>>> private DigitalOutput led_;
>>> private String[] sig2bitR = MainActivity.sig2bitR;
>>> private String[] sig2bitG = MainActivity.sig2bitG;
>>> private String[] sig2bitB = MainActivity.sig2bitB;
>>> private boolean check =false;
>>> private int counter;
>>>
>>> @Override
>>> protected void setup() throws ConnectionLostException {
>>> pin2 = ioio_.openDigitalOutput(2, false);
>>> pin4 = ioio_.openDigitalOutput(4, false);
>>> pin6 = ioio_.openDigitalOutput(6, false);
>>> }
>>> /**
>>> * Called repetitively while the IOIO is connected.
>>> *
>>> * @throws ConnectionLostException
>>> * When IOIO connection is lost.
>>> *
>>> * @see ioio.lib.util.AbstractIOIOActivity.IOIOThread#loop()
>>> */
>>> @Override
>>> public void loop() throws ConnectionLostException {
>>>
>>> for (int j = 0; j < sig2bitR.length; j++) {
>>> if (sig2bitR[j] == null | sig2bitG[j] == null
>>> | sig2bitB[j] == null) {
>>> counter = counter + 1;
>>> }
>>> }
>>> Log.d("ImageTest", Integer.toString(counter));
>>> Log.d("ImageTest", sig2bitR[1]);
>>> for (int j = 0; j<sig2bitR.length;j++){
>>>
>>>
>>> if (sig2bitR[j]=="0"){
>>> pin2.write(false);
>>> }
>>> else{
>>> pin2.write(true);
>>> }
>>> if (sig2bitG[j]=="0"){
>>> pin4.write(false);
>>> }
>>> else{
>>> pin4.write(true);
>>> }
>>> if (sig2bitB[j]=="0"){
>>> pin6.write(false);
>>> }
>>> else{
>>> pin6.write(true);
>>> }
>>>
>>> }
>>>
>>> }
>>>
>>>
>>> }
>>
>>
>> Full error log:
>>
>>> 05-01 17:13:23.350: E/AndroidRuntime(12620): FATAL EXCEPTION: main
>>> 05-01 17:13:23.350: E/AndroidRuntime(12620): Process:
>>> com.example.imagetest2, PID: 12620
>>> 05-01 17:13:23.350: E/AndroidRuntime(12620): java.lang.RuntimeException:
>>> Failure delivering result ResultInfo{who=null, request=0, result=-1,
>>> data=Intent { act=com.htc.HTCAlbum.action.ITEM_PICKER_FROM_COLLECTIONS
>>> dat=content: typ=image/jpeg (has extras) }} to activity
>>> {com.example.imagetest2/com.example.imagetest2.MainActivity}:
>>> java.lang.NullPointerException
>>> 05-01 17:13:23.350: E/AndroidRuntime(12620): at
>>> android.app.ActivityThread.deliverResults(ActivityThread.java:3942)
>>> 05-01 17:13:23.350: E/AndroidRuntime(12620): at
>>> android.app.ActivityThread.handleSendResult(ActivityThread.java:3992)
>>> 05-01 17:13:23.350: E/AndroidRuntime(12620): at
>>> android.app.ActivityThread.access$1300(ActivityThread.java:156)
>>> 05-01 17:13:23.350: E/AndroidRuntime(12620): at
>>> android.app.ActivityThread$H.handleMessage(ActivityThread.java:1403)
>>> 05-01 17:13:23.350: E/AndroidRuntime(12620): at
>>> android.os.Handler.dispatchMessage(Handler.java:102)
>>> 05-01 17:13:23.350: E/AndroidRuntime(12620): at
>>> android.os.Looper.loop(Looper.java:157)
>>> 05-01 17:13:23.350: E/AndroidRuntime(12620): at
>>> android.app.ActivityThread.main(ActivityThread.java:5872)
>>> 05-01 17:13:23.350: E/AndroidRuntime(12620): at
>>> java.lang.reflect.Method.invokeNative(Native Method)
>>> 05-01 17:13:23.350: E/AndroidRuntime(12620): at
>>> java.lang.reflect.Method.invoke(Method.java:515)
>>> 05-01 17:13:23.350: E/AndroidRuntime(12620): at
>>> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1069)
>>> 05-01 17:13:23.350: E/AndroidRuntime(12620): at
>>> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:885)
>>> 05-01 17:13:23.350: E/AndroidRuntime(12620): at
>>> dalvik.system.NativeStart.main(Native Method)
>>> 05-01 17:13:23.350: E/AndroidRuntime(12620): Caused by:
>>> java.lang.NullPointerException
>>> 05-01 17:13:23.350: E/AndroidRuntime(12620): at
>>> com.example.imagetest2.Looper.setup(Looper.java:34)
>>> 05-01 17:13:23.350: E/AndroidRuntime(12620): at
>>> com.example.imagetest2.MainActivity.onActivityResult(MainActivity.java:151)
>>> 05-01 17:13:23.350: E/AndroidRuntime(12620): at
>>> android.app.Activity.dispatchActivityResult(Activity.java:5535)
>>> 05-01 17:13:23.350: E/AndroidRuntime(12620): at
>>> android.app.ActivityThread.deliverResults(ActivityThread.java:3938)
>>> 05-01 17:13:23.350: E/AndroidRuntime(12620): ... 11 more
>>
>>
>>
--
You received this message because you are subscribed to the Google Groups
"ioio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/ioio-users.
For more options, visit https://groups.google.com/d/optout.