+ int gtl = GraphTraceLen;
+ memset(GraphBuffer, 0x00, GraphTraceLen);
+ GraphTraceLen = 0;
+ if (redraw)
+ RepaintGraphWindow();
+ return gtl;
+}
+// option '1' to save GraphBuffer any other to restore
+void save_restoreGB(uint8_t saveOpt)
+{
+ static int SavedGB[MAX_GRAPH_TRACE_LEN];
+ static int SavedGBlen;
+ static bool GB_Saved = false;
+
+ if (saveOpt==1) { //save
+ memcpy(SavedGB, GraphBuffer, sizeof(GraphBuffer));
+ SavedGBlen = GraphTraceLen;
+ GB_Saved=true;
+ } else if (GB_Saved){ //restore
+ memcpy(GraphBuffer, SavedGB, sizeof(GraphBuffer));
+ GraphTraceLen = SavedGBlen;
+ RepaintGraphWindow();
+ }
+ return;
+}
+
+// DETECT CLOCK NOW IN LFDEMOD.C
+void setGraphBuf(uint8_t *buff, size_t size)
+{
+ if ( buff == NULL ) return;
+
+ ClearGraph(0);
+
+ if ( size > MAX_GRAPH_TRACE_LEN )
+ size = MAX_GRAPH_TRACE_LEN;
+
+ for (uint16_t i = 0; i < size; ++i)
+ GraphBuffer[i] = buff[i] - 128;
+
+ GraphTraceLen = size;
+ RepaintGraphWindow();
+ return;
+}
+size_t getFromGraphBuf(uint8_t *buff)
+{
+ if (buff == NULL ) return 0;
+ uint32_t i;
+ for (i=0; i < GraphTraceLen; ++i){
+ if (GraphBuffer[i] > 127) GraphBuffer[i] = 127; //trim
+ if (GraphBuffer[i] < -127) GraphBuffer[i] = -127; //trim
+ buff[i] = (uint8_t)(GraphBuffer[i]+128);
+ }
+ return i;
+}
+
+// A simple test to see if there is any data inside Graphbuffer.
+bool HasGraphData(){
+
+ if ( GraphTraceLen <= 0) {
+ PrintAndLog("No data available, try reading something first");
+ return false;
+ }
+ return true;
+}
+
+// Detect high and lows in Grapbuffer.
+// Only loops the first 256 values.
+void DetectHighLowInGraph(int *high, int *low, bool addFuzz) {
+
+ uint8_t loopMax = 255;
+ if ( loopMax > GraphTraceLen)
+ loopMax = GraphTraceLen;
+
+ for (uint8_t i = 0; i < loopMax; ++i) {
+ if (GraphBuffer[i] > *high)
+ *high = GraphBuffer[i];
+ else if (GraphBuffer[i] < *low)
+ *low = GraphBuffer[i];
+ }
+
+ //12% fuzz in case highs and lows aren't clipped
+ if (addFuzz) {
+ *high = (int)(*high * .88);
+ *low = (int)(*low * .88);
+ }
+}
+
+// Get or auto-detect ask clock rate
+int GetAskClock(const char str[], bool printAns, bool verbose)
+{
+ int clock;
+ sscanf(str, "%i", &clock);
+ if (!strcmp(str, ""))
+ clock = 0;