import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.PointF;
-import android.os.Environment;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import net.osdn.gokigen.cameratest.fuji.Connection;
import net.osdn.gokigen.cameratest.fuji.ILiveViewImage;
import net.osdn.gokigen.cameratest.fuji.ReceivedDataHolder;
+import net.osdn.gokigen.cameratest.fuji.statuses.IFujiStatus;
+import net.osdn.gokigen.cameratest.fuji.statuses.IFujiStatusNotify;
import androidx.annotation.NonNull;
-import java.io.File;
-import java.io.FileInputStream;
-
-
-public class CamTest implements View.OnClickListener, View.OnTouchListener, ILiveViewImage
+public class CamTest implements View.OnClickListener, View.OnTouchListener, ILiveViewImage, IFujiStatusNotify
{
private String TAG = toString();
private final Activity activity;
private TextView textview;
private Connection connection;
//private FileOutputStream outputStream = null;
- private int offsetSize = 18; // 4byte: データサイズ、14byte: (謎の)ヘッダ
+ private static final int offsetSize = 18; // 4byte: データサイズ、14byte: (謎の)ヘッダ
public CamTest(@NonNull Activity activity)
{
this.activity = activity;
- this.connection = new Connection(this);
+ this.connection = new Connection(this, this);
}
public void connect()
}
}
- @Override
- public void updateImage(final Bitmap bitmap)
- {
- try
- {
- Log.v(TAG, "bitmap : " + bitmap.getByteCount() + " bytes.");
-
- ////// 画像を更新する
- activity.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try
- {
- // ビットマップイメージを表示する。
- ImageView view = activity.findViewById(R.id.imageView);
- view.setImageBitmap(bitmap);
- view.invalidate();
- }
- catch (Throwable e)
- {
- e.printStackTrace();
- }
- }
- });
- }
- catch (Throwable e)
- {
- e.printStackTrace();
- }
- }
-/*
- private void outputFile(ReceivedDataHolder receivedData)
- {
- try
- {
- if (outputStream != null)
- {
- final byte[] byteData = receivedData.getData();
- outputStream.write(byteData, 0, byteData.length);
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
-
- private void prepareFile()
- {
- try
- {
- final String directoryPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getPath() + "/AirA01a/";
- final String outputFileName = "camtest.bin";
- File filepath = new File(directoryPath.toLowerCase(), outputFileName.toLowerCase());
- outputStream = new FileOutputStream(filepath);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- outputStream = null;
- }
- }
-
- private void readImageFile(final String readFileName)
- {
- Thread thread = new Thread(new Runnable() {
- @Override
- public void run() {
- readImageFileImpl(readFileName);
- }
- });
- try
- {
- thread.start();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
-
- private void readImageFileImpl(final String readFileName)
- {
- try
- {
- Log.v(TAG, "readImageFileImpl() : " + readFileName);
- final String directoryPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getPath() + "/AirA01a/";
- File filepath = new File(directoryPath.toLowerCase(), readFileName.toLowerCase());
- FileInputStream istr = new FileInputStream(filepath);
- final Bitmap imageData = BitmapFactory.decodeStream(istr);
- istr.close();
- if (imageData == null)
- {
- Log.v(TAG, "readImageFileImpl() : bitmap is NULL.");
- }
- else
- {
- Log.v(TAG, "readImageFileImpl() : bitmap is " + imageData.getByteCount() + " bytes.");
- }
- ////// 画像表示を更新する //////
- activity.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try
- {
- // ビットマップイメージを表示する。
- ImageView view = activity.findViewById(R.id.information_view);
- view.setImageBitmap(imageData);
- view.invalidate();
- }
- catch (Throwable e)
- {
- e.printStackTrace();
- }
- }
- });
- }
- catch (Throwable e)
- {
- e.printStackTrace();
- }
- }
-*/
-
private Bitmap getBitmap(ReceivedDataHolder receivedData)
{
try
Log.v(TAG, "getBitmap() : NULL. (offset : " + offsetSize + ")");
return (null);
}
-/*
- else
- {
- Log.v(TAG, "getBitmap() : " + imageData.getByteCount() + "bytes. (offset : " + offsetSize + ")");
- }
-*/
return (imageData);
}
catch (Exception e)
}
return (null);
}
+
+ @Override
+ public void statusUpdated(final IFujiStatus cameraStatus)
+ {
+ try
+ {
+ Log.v(TAG, "statusUpdated()");
+
+ // 情報エリアの内容を更新する
+ final InformationView view = activity.findViewById(R.id.information_view);
+ if (view == null)
+ {
+ return;
+ }
+ view.drawInformation(cameraStatus);
+
+ ////// 画像を更新する
+ activity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ try
+ {
+ view.invalidate();
+ }
+ catch (Throwable e)
+ {
+ e.printStackTrace();
+ }
+ }
+ });
+ }
+ catch (Throwable e)
+ {
+ e.printStackTrace();
+ }
+
+ }
}
--- /dev/null
+package net.osdn.gokigen.cameratest.camtest;
+
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.util.AttributeSet;
+
+import androidx.appcompat.widget.AppCompatImageView;
+
+import net.osdn.gokigen.cameratest.fuji.statuses.IFujiStatus;
+
+public class InformationView extends AppCompatImageView
+{
+ String message = "AAAAA";
+
+ public InformationView(Context context) {
+ super(context);
+ initComponent(context);
+ }
+
+ public InformationView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ initComponent(context);
+ }
+
+ public InformationView(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ initComponent(context);
+ }
+
+ private void initComponent(Context context) {
+
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas)
+ {
+ super.onDraw(canvas);
+ drawCanvas(canvas);
+ }
+
+ private void drawCanvas(Canvas canvas)
+ {
+ // Clears the canvas.
+ canvas.drawARGB(255, 0, 0, 0);
+
+ // Rotates the image.
+ int centerX = canvas.getWidth() / 2;
+ int centerY = canvas.getHeight() / 2;
+
+ Paint framePaint = new Paint();
+ framePaint.setStyle(Paint.Style.STROKE);
+ framePaint.setColor(Color.WHITE);
+
+ canvas.drawText(message, centerX, centerY, framePaint);
+ }
+
+ /**
+ * 表示エリアの情報を更新する
+ *
+ *
+ */
+ public void drawInformation(IFujiStatus cameraStatus)
+ {
+
+
+ }
+
+}
import androidx.annotation.NonNull;
import net.osdn.gokigen.cameratest.fuji.statuses.FujiStatusChecker;
+import net.osdn.gokigen.cameratest.fuji.statuses.IFujiStatusNotify;
import net.osdn.gokigen.cameratest.fuji.statuses.IFujiStatusRequest;
public class Connection implements IFujiStatusRequest
private final Communication comm;
private final FujiStatusChecker statusChecker;
- public Connection(@NonNull ILiveViewImage imageViewer)
+ public Connection(@NonNull ILiveViewImage imageViewer, @NonNull IFujiStatusNotify notify)
{
this.comm = new Communication(imageViewer);
this.sequence = new MessageSequence();
- this.statusChecker = new FujiStatusChecker(this);
+ this.statusChecker = new FujiStatusChecker(this, notify);
}
public boolean start_connect()
try
{
comm.send_to_camera(sequence.status_request_message(), true);
- //Thread.sleep(30);// ちょっと待つ
ReceivedDataHolder rx_bytes = comm.receive_from_camera();
- if (rx_bytes.getData().length > 0) {
+ if (rx_bytes.getData().length > 0)
+ {
+ // 受信したステータス情報を渡す
statusChecker.statusReceived(rx_bytes);
}
- dump_bytes(12, rx_bytes);
-
- // なんで2回... でもやってみる
- rx_bytes = comm.receive_from_camera();
- dump_bytes(13, rx_bytes);
+ //dump_bytes(12, rx_bytes);
return (true);
}
ReceivedDataHolder rx_bytes = comm.receive_from_camera();
dump_bytes(14, rx_bytes);
-
- // なんで2回受信... でもやってみる
- rx_bytes = comm.receive_from_camera();
- dump_bytes(15, rx_bytes);
}
catch (Exception e)
{
package net.osdn.gokigen.cameratest.fuji;
-import android.graphics.Bitmap;
-
public interface ILiveViewImage
{
void updateImage(ReceivedDataHolder receivedData);
- void updateImage(Bitmap bitmap);
-
}
import android.util.Log;
+import androidx.annotation.NonNull;
+
import net.osdn.gokigen.cameratest.fuji.ReceivedDataHolder;
public class FujiStatusChecker implements IFujiStatusReceive
{
private final String TAG = toString();
private final IFujiStatusRequest comm;
+ private final IFujiStatusNotify notify;
+ private final FujiStatusHolder statusHolder;
private boolean threadIsRunning = false;
private final int WAIT_MS = 400;
- public FujiStatusChecker(IFujiStatusRequest comm)
+ public FujiStatusChecker(@NonNull IFujiStatusRequest comm, @NonNull IFujiStatusNotify notify)
{
this.comm = comm;
+ this.notify = notify;
+ this.statusHolder = new FujiStatusHolder();
}
@Override
}
@Override
- public void statusReceived2nd(ReceivedDataHolder data)
- {
- statusReceivedImpl(data.getData());
- }
-
- @Override
public void start()
{
Thread thread = new Thread(new Runnable() {
private void statusReceivedImpl(byte[] data)
{
+ boolean isStatusUpdated = false;
try
{
Log.v(TAG, "status Received. " + data.length + " bytes.");
+/*
+RX [00] 7a 00 00 00 02 00 15 10
+RX [01] b1 00 00 00 12 00 1b d2
+RX [02] 00 00 00 00 0c 50 02 00
+RX [03] 00 00 12 50 00 00 00 00
+RX [04] 29 d2 67 04 00 00 2a d2
+RX [05] a1 06 00 00 0e 50 03 00
+RX [06] 00 00 01 50 03 00 00 00
+RX [07] 7c d1 04 04 02 03 09 d2
+RX [08] 01 00 00 00 10 50 b3 fe
+RX [09] ff ff 05 50 02 00 00 00
+RX [10] 28 d0 00 00 00 00 0a 50
+RX [11] 01 80 00 00 41 d2 0a 00
+RX [12] 00 00 18 d0 04 00 00 00
+RX [13] 07 50 90 01 00 00 01 d0
+RX [14] 03 00 00 00 2a d0 40 06
+RX [15] 00 80 0c 00 00 00 03 00
+RX [16] 01 20 b1 00 00 00
+*/
+
+ if (isStatusUpdated)
+ {
+ notify.statusUpdated(statusHolder);
+ }
}
catch (Exception e)
{
--- /dev/null
+package net.osdn.gokigen.cameratest.fuji.statuses;
+
+class FujiStatusHolder implements IFujiStatus
+{
+ /**
+ * コンストラクタ
+ */
+ FujiStatusHolder()
+ {
+
+ }
+
+
+}
--- /dev/null
+package net.osdn.gokigen.cameratest.fuji.statuses;
+
+public interface IFujiStatus
+{
+
+
+}
--- /dev/null
+package net.osdn.gokigen.cameratest.fuji.statuses;
+
+public interface IFujiStatusNotify
+{
+ void statusUpdated(final IFujiStatus cameraStatus);
+
+}
void start();
void stop();
void statusReceived(ReceivedDataHolder data);
- void statusReceived2nd(ReceivedDataHolder data);
}
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/show_information" />
- <ImageView
+ <net.osdn.gokigen.cameratest.camtest.InformationView
android:id="@+id/information_view"
android:layout_width="300dp"
android:layout_height="150dp"