Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BufferedSerial FatFileSystemCpp mbed
Revision 85:0cc5931bb9ef, committed 2022-12-15
- Comitter:
- JamieB
- Date:
- Thu Dec 15 06:05:30 2022 +0000
- Parent:
- 79:1910ae03cb2e
- Parent:
- 81:aee60dcce61b
- Commit message:
- Push to somewhere else due to merge issue
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/FIZ_readers/FIZCanon.h Thu Dec 15 05:53:28 2022 +0000 +++ b/FIZ_readers/FIZCanon.h Thu Dec 15 06:05:30 2022 +0000 @@ -28,4 +28,4 @@ #define CANON_START 0x94 -#endif \ No newline at end of file +#endif
--- a/FIZ_readers/FIZDigiPowerActive.cpp Thu Dec 15 05:53:28 2022 +0000
+++ b/FIZ_readers/FIZDigiPowerActive.cpp Thu Dec 15 06:05:30 2022 +0000
@@ -199,14 +199,29 @@
return;
}
// pc.puts("FIZ good\r\n");
- uint16_t iris_Position = ((uint16_t)inputBuffer[2])<<8 | inputBuffer[3];
+ uint16_t iris_Position = ((uint16_t)inputBuffer[2])<<8 | inputBuffer[3];
uint16_t zoom_Position = ((uint16_t)inputBuffer[4])<<8 | inputBuffer[5];
- uint16_t focus_Position = ((uint16_t)inputBuffer[6])<<8 | inputBuffer[7];
+ uint32_t focus_Position = ((uint32_t)inputBuffer[6])<<8 | inputBuffer[7];
-// MAY NEED TO SCALE THESE
- _focus = (uint32_t)(focus_Position * UserSettings.focus_scale) + UserSettings.focus_offset;
- _iris = (uint16_t) (iris_Position * UserSettings.iris_scale) + UserSettings.iris_offset;
- _zoom = (uint16_t) (zoom_Position * UserSettings.zoom_scale) + UserSettings.zoom_offset;
+ if (UserSettings.absolute_focus) {
+ _focus = getAbsoluteFocus(focus_Position);
+ } else {
+ _focus = (uint32_t)(focus_Position * UserSettings.focus_scale) + UserSettings.focus_offset;
+ }
+ if (UserSettings.absolute_iris) {
+ _iris = getAbsoluteIris(iris_Position);
+ } else {
+ _iris = (uint16_t) (iris_Position * UserSettings.iris_scale) + UserSettings.iris_offset;
+ }
+ if (UserSettings.absolute_zoom) {
+ _zoom = getAbsoluteZoom(zoom_Position);
+ } else {
+ _zoom = (uint16_t) (zoom_Position * UserSettings.zoom_scale) + UserSettings.zoom_offset;
+ }
+// // MAY NEED TO SCALE THESE
+// _focus = (uint32_t)(focus_Position * UserSettings.focus_scale) + UserSettings.focus_offset;
+// _iris = (uint16_t) (iris_Position * UserSettings.iris_scale) + UserSettings.iris_offset;
+// _zoom = (uint16_t) (zoom_Position * UserSettings.zoom_scale) + UserSettings.zoom_offset;
newData = true;
}
--- a/FIZ_readers/FIZDigiPowerActive.h Thu Dec 15 05:53:28 2022 +0000 +++ b/FIZ_readers/FIZDigiPowerActive.h Thu Dec 15 06:05:30 2022 +0000 @@ -29,4 +29,4 @@ }; -#endif \ No newline at end of file +#endif
--- a/FIZ_readers/FIZReader.cpp Thu Dec 15 05:53:28 2022 +0000
+++ b/FIZ_readers/FIZReader.cpp Thu Dec 15 06:05:30 2022 +0000
@@ -1,6 +1,11 @@
#include "FIZReader.h"
#include "LTCApp.h"
+#include "cc.h"
#include "mbed.h"
+#include <cstdint>
+#include <vector>
+#include <algorithm>
+
FIZReader::FIZReader(const PinName Tx, const PinName Rx) : _port(Tx,Rx)
{
_focus = 0;
@@ -19,12 +24,72 @@
return wasNew;
}
- int FIZReader::hexValue(char ascii) {
- if (((ascii-'0') >= 0) && ((ascii-'0') <= 9))
- return ascii-'0';
- if (((ascii-'A') >= 0) && ((ascii-'A') <= 5))
- return ascii-'A'+10;
- if (((ascii-'a') >= 0) && ((ascii-'a') <= 5))
- return ascii-'a'+10;
- return 0;
- }
\ No newline at end of file
+int FIZReader::hexValue(char ascii) {
+ if (((ascii-'0') >= 0) && ((ascii-'0') <= 9))
+ return ascii-'0';
+ if (((ascii-'A') >= 0) && ((ascii-'A') <= 5))
+ return ascii-'A'+10;
+ if (((ascii-'a') >= 0) && ((ascii-'a') <= 5))
+ return ascii-'a'+10;
+ return 0;
+}
+
+unsigned int FIZReader::getAbsoluteValue(unsigned int encoder_pos, vector<unsigned int> &encoder_range, vector<unsigned int> &absolute_range) {
+ unsigned int result;
+ if( encoder_pos <= encoder_range.front() ) return absolute_range.front();
+ if( encoder_pos >= encoder_range.back()) return absolute_range.back();
+
+ int lower = encoder_range.size() -2;
+ int upper = encoder_range.size() -1;
+ for (int pos_pointer = 0; pos_pointer < encoder_range.size(); pos_pointer++) {
+ if (encoder_pos < encoder_range[pos_pointer]) {
+ lower = pos_pointer - 1;
+ upper = pos_pointer;
+ break;
+ }
+ }
+
+ // pos_upper = encoder_range[upper];
+ // pos_lower = encoder_range[lower];
+ // pos_value = encoder_pos;
+
+ result = absolute_range[lower]+(encoder_pos-encoder_range[lower])*(absolute_range[upper]-absolute_range[lower])/(encoder_range[upper]-encoder_range[lower]);
+
+ return result;
+
+}
+
+ // vector<int>::iterator lb = lower_bound(encoder_range.begin(), encoder_range.end(), encoder_pos);
+ // auto upper = lb++;
+
+ // if (lb == encoder_range.end())
+ // --upper; // extrapolating above
+ // else if (*lb == encoder_pos)
+ // return absolute_range[*lb];
+
+ // int lower = upper? upper - 1: 1; // if upper is not zero, get value below, else flip and get the one above
+
+ // if(encoder_range[upper]<encoder_range[lower])
+ // result = absolute_range[upper]+(encoder_pos-encoder_range[upper])*(absolute_range[lower]-absolute_range[upper])/(encoder_range[lower]-encoder_range[upper]);
+ // else
+uint32_t FIZReader::getAbsoluteFocus(uint32_t encoder_pos) {
+ if (UserSettings.focus_encoder_map.size())
+ return (uint32_t) getAbsoluteValue(encoder_pos, UserSettings.focus_encoder_map, UserSettings.focus_absolute_map);
+ else
+ return encoder_pos;
+}
+uint16_t FIZReader::getAbsoluteIris(uint16_t encoder_pos) {
+ if (UserSettings.iris_encoder_map.size())
+ return (uint16_t) getAbsoluteValue(encoder_pos, UserSettings.iris_encoder_map, UserSettings.iris_absolute_map);
+ else
+ return encoder_pos;
+}
+uint16_t FIZReader::getAbsoluteZoom(uint16_t encoder_pos) {
+ if (UserSettings.zoom_encoder_map.size()){
+ return (uint16_t) getAbsoluteValue(encoder_pos, UserSettings.zoom_encoder_map, UserSettings.zoom_absolute_map);
+ }
+ else
+ return encoder_pos;
+}
+
+
--- a/FIZ_readers/FIZReader.h Thu Dec 15 05:53:28 2022 +0000
+++ b/FIZ_readers/FIZReader.h Thu Dec 15 06:05:30 2022 +0000
@@ -1,6 +1,7 @@
#ifndef __FIZReader_H__
#define __FIZReader_H__
#include "BufferedSerial.h"
+#include <vector>
class FIZReader {
@@ -14,7 +15,10 @@
protected:
int hexValue(char ascii);
-
+ unsigned int getAbsoluteValue(unsigned int encoder_pos, vector<unsigned int> &encoder_range, vector<unsigned int> &absolute_range);
+ uint32_t getAbsoluteFocus(uint32_t encoder_pos);
+ uint16_t getAbsoluteIris(uint16_t encoder_pos);
+ uint16_t getAbsoluteZoom(uint16_t encoder_pos);
RawSerial _port;
uint32_t _focus; // in mm
--- a/FIZ_readers/FIZ_ArriCmotion.h Thu Dec 15 05:53:28 2022 +0000 +++ b/FIZ_readers/FIZ_ArriCmotion.h Thu Dec 15 06:05:30 2022 +0000 @@ -22,4 +22,4 @@ }; -#endif \ No newline at end of file +#endif
--- a/FIZ_readers/FIZ_DISNEY.h Thu Dec 15 05:53:28 2022 +0000 +++ b/FIZ_readers/FIZ_DISNEY.h Thu Dec 15 06:05:30 2022 +0000 @@ -21,4 +21,4 @@ }; -#endif \ No newline at end of file +#endif
--- a/FIZ_readers/FIZ_digiPower.h Thu Dec 15 05:53:28 2022 +0000 +++ b/FIZ_readers/FIZ_digiPower.h Thu Dec 15 06:05:30 2022 +0000 @@ -22,4 +22,4 @@ }; -#endif \ No newline at end of file +#endif
--- a/FreeD.h Thu Dec 15 05:53:28 2022 +0000 +++ b/FreeD.h Thu Dec 15 06:05:30 2022 +0000 @@ -41,4 +41,4 @@ } -#endif \ No newline at end of file +#endif
--- a/LTCApp.h Thu Dec 15 05:53:28 2022 +0000
+++ b/LTCApp.h Thu Dec 15 06:05:30 2022 +0000
@@ -70,14 +70,22 @@
float iris_offset;
float zoom_scale;
float zoom_offset;
- vector<int> focus_encoder_map;
- vector<float> focus_absolute_map;
- vector<int> iris_encoder_map;
- vector<float> iris_absolute_map;
- vector<int> zoom_encoder_map;
- vector<float> zoom_absolute_map;
+ bool low_zoom_precision;
+ bool absolute_focus;
+ bool absolute_iris;
+ bool absolute_zoom;
+ vector<unsigned int> focus_encoder_map;
+ vector<unsigned int> focus_absolute_map;
+ vector<unsigned int> iris_encoder_map;
+ vector<unsigned int> iris_absolute_map;
+ vector<unsigned int> zoom_encoder_map;
+ vector<unsigned int> zoom_absolute_map;
} UserSettings_t;
extern UserSettings_t UserSettings;
+// extern int pos_upper;
+// extern int pos_lower;
+// extern int pos_value;
+
#endif
--- a/main.cpp Thu Dec 15 05:53:28 2022 +0000
+++ b/main.cpp Thu Dec 15 06:05:30 2022 +0000
@@ -1,4 +1,4 @@
-#define APP_VERSION 0.302
+#define APP_VERSION 0.32
/*
Settings file options
@@ -189,6 +189,9 @@
bool TXFrame = true;
+// int pos_lower = 0;
+// int pos_upper = 0;
+// int pos_value = 0;
void filterOff(void)
{
@@ -674,8 +677,13 @@
size_t len = sizeof(chunk);
char *line = new char[len];
pc.printf("Opened File %s\r\n", filename);
+<<<<<<< working copy
vector<int> *encoder;
vector<float> *absolute;
+=======
+ vector<unsigned int> *encoder;
+ vector<unsigned int> *absolute;
+>>>>>>> merge rev
int focus_datapoints;
int iris_datapoints;
int zoom_datapoints;
@@ -693,6 +701,7 @@
strncpy(line + len_used, chunk, len - len_used);
len_used += chunk_used;
if(line[len_used - 1] == '\n') {
+<<<<<<< working copy
pc.printf("Retrieved line of length %u: ", len_used);
pc.printf("%s\n", line);
if (sscanf(line,"FOCUS:%d", &focus_datapoints) == 1) {
@@ -729,9 +738,61 @@
} else {
printf("\tNot Valid matching line\n");
}
+=======
+ // pc.printf("Retrieved line of length %u: ", len_used);
+ // pc.printf("%s", line);
+ // Thread::wait(10);
+ if (sscanf(line,"FOCUS:%d", &focus_datapoints) == 1) {
+ encoder = &UserSettings.focus_encoder_map;
+ absolute = &UserSettings.focus_absolute_map;
+ UserSettings.absolute_focus = true;
+ // pc.printf(" - Set Focus\r\n");
+ // Thread::wait(10);
+ } else if (sscanf(line,"IRIS:%d", &iris_datapoints) == 1) {
+ encoder = &UserSettings.iris_encoder_map;
+ absolute = &UserSettings.iris_absolute_map;
+ UserSettings.absolute_iris = true;
+ // pc.printf(" - Set Iris\r\n");
+ // Thread::wait(10);
+ } else if (sscanf(line,"ZOOM:%d", &zoom_datapoints) == 1) {
+ encoder = &UserSettings.zoom_encoder_map;
+ absolute = &UserSettings.zoom_absolute_map;
+ UserSettings.absolute_zoom = true;
+ // pc.printf(" - Set Zoom\r\n");
+ // Thread::wait(10);
+ } else if (strchr(line,',') != NULL) {
+ // pc.printf("\tProbably some data in this line\n");
+ unsigned int encoder_val;
+ unsigned int absolute_val;
+ if (sscanf(line, "%d,%d", &encoder_val, &absolute_val) == 2) {
+ encoder->push_back(encoder_val);
+ absolute->push_back(absolute_val);
+ // pc.printf(" - ADDED Datapoint\r\n");
+ // Thread::wait(10);
+ }
+ } // else { pc.printf(" - Not Valid matching line\r\n"); }
+>>>>>>> merge rev
line[0] = '\0';
}
}
+ pc.printf("FOCUS: ");
+ for(int i = 0; i < UserSettings.focus_encoder_map.size(); i++) {
+ pc.printf("(%d, ", UserSettings.focus_encoder_map[i]);
+ pc.printf("%d)", UserSettings.focus_absolute_map[i]);
+ }
+ pc.printf("\r\n");
+ pc.printf("IRIS: ");
+ for(int i = 0; i < UserSettings.iris_encoder_map.size(); i++) {
+ pc.printf("(%d, ", UserSettings.iris_encoder_map[i]);
+ pc.printf("%d)", UserSettings.iris_absolute_map[i]);
+ }
+ pc.printf("\r\n");
+ pc.printf("ZOOM: ");
+ for(int i = 0; i < UserSettings.zoom_encoder_map.size(); i++) {
+ pc.printf("(%d, ", UserSettings.zoom_encoder_map[i]);
+ pc.printf("%d)", UserSettings.zoom_absolute_map[i]);
+ }
+ pc.printf("\r\n");
fclose(LensFile);
free(line);
} else {
@@ -782,6 +843,10 @@
UserSettings.iris_offset = 0;
UserSettings.zoom_scale = 1;
UserSettings.zoom_offset= 0;
+ UserSettings.low_zoom_precision = false; //TODO: Get zoom range from lens file, if over 327mm, set this flag (and set top bit in zoom output)
+ UserSettings.absolute_focus = false;
+ UserSettings.absolute_iris = false;
+ UserSettings.absolute_zoom = false;
// LocalFileSystem localFS("local");
FILE *LSFile= fopen("/local/settings.txt","r");
@@ -1245,7 +1310,7 @@
int main()
{
pc.baud(115200);
- pc.printf("\r\n\r\nStartup - v%.2f\r\n", APP_VERSION); //Change via Line 1
+ pc.printf("\r\n\r\nStartup - v%.3f\r\n", APP_VERSION); //Change via Line 1
setRED();
readSettingsFile();
@@ -1405,6 +1470,11 @@
}
VIPS.sendQueued(); // should ideally be called on 100Hz PPS edge but we don't have that in this code...
+ // if (pos_value) {
+ // pc.printf("Z: %d - (%d, %d)\r\n", pos_value, pos_lower, pos_upper);
+ // pos_value = 0;
+ // }
+
if (logButtonLastState != logButton) {
logButtonLastState = logButton;
if (logButtonLastState) { // pressed