1 package net.osdn.gokigen.gr2control.camera.ricohgr2.wrapper;
3 import android.util.Log;
5 import net.osdn.gokigen.gr2control.camera.ICameraStatus;
6 import net.osdn.gokigen.gr2control.camera.ICameraStatusWatcher;
7 import net.osdn.gokigen.gr2control.camera.utils.SimpleHttpClient;
8 import net.osdn.gokigen.gr2control.liveview.ICameraStatusUpdateNotify;
10 import java.util.ArrayList;
11 import java.util.List;
13 import androidx.annotation.NonNull;
19 public class RicohGr2StatusChecker implements ICameraStatusWatcher, ICameraStatus
21 private final String TAG = toString();
22 private final String statusCheckUrl = "http://192.168.0.1/v1/props";
23 private final String statusSetUrl = "http://192.168.0.1/v1/params/camera";
24 private final String grCommandUrl = "http://192.168.0.1/_gr";
25 private final int sleepMs;
27 private int timeoutMs = 5000;
28 private boolean whileFetching = false;
29 private RicohGr2StatusHolder statusHolder;
30 private boolean useGR2command = false;
36 RicohGr2StatusChecker(int sleepMs)
38 this.sleepMs = sleepMs;
41 public void setUseGR2Command(boolean useGR2command)
43 this.useGR2command = useGR2command;
51 public void startStatusWatch(@NonNull ICameraStatusUpdateNotify notifier)
53 Log.v(TAG, "startStatusWatch()");
56 this.statusHolder = new RicohGr2StatusHolder(notifier);
57 Thread thread = new Thread(new Runnable()
64 start(statusCheckUrl);
85 public void stopStatusWatch()
87 Log.v(TAG, "stoptStatusWatch()");
88 whileFetching = false;
95 private void start(@NonNull final String watchUrl)
99 Log.v(TAG, "start() already starting.");
105 whileFetching = true;
106 Thread thread = new Thread(new Runnable()
111 Log.d(TAG, "Start status watch.");
112 while (whileFetching)
116 statusHolder.updateStatus(SimpleHttpClient.httpGet(watchUrl, timeoutMs));
117 Thread.sleep(sleepMs);
124 Log.v(TAG, "STATUS WATCH STOPPED.");
136 public @NonNull List<String> getStatusList(@NonNull final String key)
140 if (statusHolder == null)
142 return (new ArrayList<>());
144 String listKey = key + "List";
145 return (statusHolder.getAvailableItemList(listKey));
151 return (new ArrayList<>());
155 public String getStatus(@NonNull String key)
159 if (statusHolder == null)
163 return (statusHolder.getItemStatus(key));
173 public void setStatus(@NonNull final String key, @NonNull final String value)
175 Thread thread = new Thread(new Runnable() {
181 String postData = key + "=" + value;
182 if ((useGR2command)&&(key.equals("exposureMode")))
184 // 撮影モードを変更するときは、GR専用コマンドを送ることにする。
185 postData = "cmd=" + decideButtonCode(value);
186 response = SimpleHttpClient.httpPost(grCommandUrl, postData, timeoutMs);
187 Log.v(TAG, "CHANGE MODE : " + postData + " resp. (" + response.length() + "bytes.)");
190 response = SimpleHttpClient.httpPut(statusSetUrl, postData, timeoutMs);
191 Log.v(TAG, "SET PROPERTY : " + postData + " resp. (" + response.length() + "bytes.)");
195 // GR専用コマンドで、画面表示をリフレッシュ
196 response = SimpleHttpClient.httpPost(grCommandUrl, "cmd=mode refresh", timeoutMs);
197 Log.v(TAG, "refresh resp. (" + response.length() + "bytes.)");
217 * 撮影モードをGRのダイアルコマンドに変更する
220 private String decideButtonCode(String exposureMode)
222 String buttonCode = "bdial AUTO";
223 if (exposureMode == null)
227 switch (exposureMode)
230 buttonCode = "bdial MOVIE";
233 buttonCode = "bdial M";
236 buttonCode = "bdial TAV";
239 buttonCode = "bdial AV";
242 buttonCode = "bdial TV";
245 buttonCode = "bdial P";
248 buttonCode = "bdial AUTO";