[chronojump/michrolab] Erasing each bar individualy to optimize redrawing. TODO: Some bars are wrongly erased
- From: Xavier Padullés <xpadulles src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump/michrolab] Erasing each bar individualy to optimize redrawing. TODO: Some bars are wrongly erased
- Date: Fri, 26 Aug 2022 22:30:53 +0000 (UTC)
commit 029c2abd0fa248d6a48d226031c4ddd5a750b157
Author: Xavier Padullés <testing chronojump org>
Date: Sat Aug 27 00:29:20 2022 +0200
Erasing each bar individualy to optimize redrawing. TODO: Some bars are wrongly erased
arduino/michrolab/graphs.ino | 42 +++++++++++++++++++++++++++++++++++++----
arduino/michrolab/michrolab.ino | 29 ++++++++++++++++++++--------
2 files changed, 59 insertions(+), 12 deletions(-)
---
diff --git a/arduino/michrolab/graphs.ino b/arduino/michrolab/graphs.ino
index aa9550c00..ca3b67b10 100644
--- a/arduino/michrolab/graphs.ino
+++ b/arduino/michrolab/graphs.ino
@@ -80,13 +80,15 @@ void redrawAxes(ILI9341_t3 & d, double gx, double gy, double w, double h, double
d.drawLine(gx, yAxis, gx + w, yAxis, BLACK);
}
- if (resize) tft.drawRect(0, 0, gx, gy, BLACK);
+ if (resize){
+ tft.drawRect(0, 0, gx, gy, BLACK);
+ //Vertical line
+ //d.drawLine(gx, gy, gx, gy - h, acolor);
+ }
d.setTextSize(1);
d.setTextColor(tcolor, bcolor);
- //Vertical line
- d.drawLine(gx, gy, gx, gy - h, acolor);
// draw y scale
for (double i = ylo; i <= yhi; i += yinc)
@@ -94,7 +96,7 @@ void redrawAxes(ILI9341_t3 & d, double gx, double gy, double w, double h, double
// compute the transform
yAxis = (i - ylo) * (-h) / (yhi - ylo) + gy;
- d.drawLine(gx, yAxis, gx + w, yAxis, acolor);
+ //d.drawLine(gx, yAxis, gx + w, yAxis, acolor);
//If the scale has changed the numbers must be redrawn
if (resize)
{
@@ -146,8 +148,39 @@ void barPlot (float gx, float gy, float w, float h, float yhi, int numBars, int
float localX = w - b;
float barValue = 0;
float barPixHeight = 0;
+
+ for(int i = currentIndex + 1; i <= currentIndex + 10; i++)
+ {
+ Serial.print(i % 10);
+ Serial.print("\t");
+ }
+
+ Serial.println();
+
+ for(int i = currentIndex + 1; i <= currentIndex + 10; i++)
+ {
+ Serial.print(bars[ i % 10]);
+ Serial.print("\t");
+ }
+
+ Serial.println();
//the first bar to plot corresponds to the last updated slot of the array
+
+ //Deleting the previous bars (The older bar are not in the buffer)
+ for (int i = 1; i<10; i++)
+ {
+ localX -= a;
+ barValue = bars[ (currentIndex - i -1 + 10) % 10];
+ barPixHeight = barValue * h / yhi;
+ tft.fillRect(gx+localX, gy - barPixHeight , b, barPixHeight, BLACK);
+ localX -= b;
+ }
+
+ localX -= a;
+ tft.fillRect(gx+localX, gy - h , b, h, BLACK);
+ localX = w - b;
+
for (int i = 0; i<10; i++)
{
localX -= a;
@@ -161,4 +194,5 @@ void barPlot (float gx, float gy, float w, float h, float yhi, int numBars, int
}
localX -= b;
}
+ Serial.println("-----");
}
diff --git a/arduino/michrolab/michrolab.ino b/arduino/michrolab/michrolab.ino
index 04cabebc8..888c93d2a 100644
--- a/arduino/michrolab/michrolab.ino
+++ b/arduino/michrolab/michrolab.ino
@@ -347,7 +347,8 @@ IntervalTimer rcaTimer;
String fullFileName;
File dataFile;
int sampleNum = 0;
-String fileBuffer;
+//String fileBuffer;
+char fileBuffer[100];
void setup() {
//Attention: some SD cards fails to initalize after uploading the firmware
@@ -1151,7 +1152,7 @@ void captureBars()
{
index = (numRepetitions - 1) % 10;
redrawBars = false;
- tft.fillRect(30, 0, 290, 200, BLACK);
+ //tft.fillRect(30, 0, 290, 200, BLACK);
if (bars[(numRepetitions - 1) % 10] > graphRange)
{
redrawAxes(tft, 30, 200, 290, 200, 290, 200, 0, graphRange, graphRange / 10, "", "", "", WHITE,
GREY, WHITE, WHITE, BLACK, RED, true);
@@ -1168,16 +1169,28 @@ void captureBars()
}
}
+//void saveEncoderSpeed()
+//{
+// long position = encoder.read();
+// fileBuffer = fileBuffer + String(position - lastSamplePosition) + ",";
+// sampleNum++;
+// lastSamplePosition = position;
+// if (sampleNum >= 5){
+// dataFile.print(fileBuffer);
+// fileBuffer = "";
+// sampleNum = 1;
+// }
+//}
+
void saveEncoderSpeed()
{
long position = encoder.read();
- fileBuffer = fileBuffer + String(position - lastSamplePosition) + ",";
+ fileBuffer[sampleNum] =(char)(position - lastSamplePosition);
sampleNum++;
lastSamplePosition = position;
- if (sampleNum >= 100){
- dataFile.print(fileBuffer);
- fileBuffer = "";
- sampleNum = 1;
+ if (sampleNum >= 99){
+ //dataFile.write(fileBuffer, 100);
+ sampleNum = 0;
}
}
@@ -1285,7 +1298,7 @@ void startEncoderCapture(void)
selectExerciseType(gravitatory);
selectValueDialog("Select the load you are\ngoing to move", "0,5,20,200", "0.5,1,5", 1);
//captureRaw();
- encoderTimer.begin(saveEncoderSpeed,1000);
+ encoderTimer.begin(saveEncoderSpeed,1000000);
captureBars();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]