Fixed height / width values. Improved usage of height and width of the display. Fixed +/- info block position. The DELAY is now used.

This commit is contained in:
Kai Lauterbach 2024-02-04 19:51:03 +01:00
parent 3b6aa4e902
commit a76905bd62
3 changed files with 46 additions and 28 deletions

View file

@ -12,13 +12,13 @@
#include "esp_adc_cal.h"
#include "filters.h"
#define DEBUG_SERIAL
//#define DEBUG_SERIAL
#define DEBUG_BUFF
#define DELAY 250
#define DEBUG_DELAY 250
// Width and height of sprite
#define WIDTH 240
#define HEIGHT 320
#define DISPLAY_HEIGHT 240
#define DISPLAY_WIDTH 320
#define ADC_CHANNEL ADC1_CHANNEL_5 // GPIO33
#define NUM_SAMPLES 1000 // number of samples

View file

@ -2,7 +2,7 @@
void debug_buffer() {
ADC_Sampling();
i2s_adc_disable(I2S_NUM_0);
delay(1000);
delay(DEBUG_DELAY);
for (uint32_t i = 0; i < B_MULT * NUM_SAMPLES; i++) {
for (int j = 0; j < 1; j++) {
Serial.println(i2s_buff[i]);

View file

@ -7,15 +7,16 @@ void setup_screen() {
spr.setColorDepth(8);
// Create a sprite of defined size
spr.createSprite(HEIGHT, WIDTH);
spr.createSprite(DISPLAY_WIDTH, DISPLAY_HEIGHT);
// Clear the TFT screen to blue
tft.fillScreen(TFT_BLACK);
}
int data[HEIGHT] = {0};
int data[DISPLAY_WIDTH] = {0};
/*
float to_scale(float reading) {
float temp = WIDTH -
float temp = DISPLAY_HEIGHT -
(
(
(
@ -26,18 +27,33 @@ float to_scale(float reading) {
(v_div * 6)
)
)
* (WIDTH - 1)
* (DISPLAY_HEIGHT - 1)
- 1;
return temp;
}
*/
float to_scale(float reading) {
float temp = DISPLAY_HEIGHT - (((reading / 4095.0) + (offset / 3.3)) * 3300 / (v_div * 6)) * (DISPLAY_HEIGHT - 1) - 1;
return temp;
}
/*
float to_voltage(float reading) {
return (reading - 20480.0) / 4095.0 * 3.3;
}
*/
float to_voltage(float reading) {
return reading / 4095.0 * 3.3;
}
/*
uint32_t from_voltage(float voltage) {
return uint32_t(voltage / 3.3 * 4095 + 20480.0);
}
*/
uint32_t from_voltage(float voltage) {
return ((uint32_t)(voltage / 3.3 * 4095));
}
void update_screen(uint16_t *i2s_buff, float sample_rate) {
@ -149,11 +165,11 @@ void draw_sprite(float freq,
draw_channel1(trigger, 0, i2s_buff, sample_rate);
}
int shift = HEIGHT - 110;
int shift = DISPLAY_WIDTH - 110;
if (menu) {
spr.drawLine( 0, WIDTH/2, HEIGHT, WIDTH/2, TFT_WHITE); //center line
spr.fillRect(shift, 0, (WIDTH/2)-18, (WIDTH/2)+15, TFT_BLACK);
spr.drawRect(shift, 0, (WIDTH/2)-18, (WIDTH/2)+15, TFT_WHITE);
spr.drawLine( 0, DISPLAY_HEIGHT/2, DISPLAY_WIDTH, DISPLAY_HEIGHT/2, TFT_WHITE); //center line
spr.fillRect(shift, 0, (DISPLAY_HEIGHT/2)-18, (DISPLAY_HEIGHT/2)+15, TFT_BLACK);
spr.drawRect(shift, 0, (DISPLAY_HEIGHT/2)-18, (DISPLAY_HEIGHT/2)+15, TFT_WHITE);
spr.fillRect(shift + 1, 3 + 10 * (opt - 1), 100, 11, TFT_RED);
spr.drawString("AUTOSCALE", shift + 5, 5);
@ -183,27 +199,29 @@ void draw_sprite(float freq,
spr.drawString(offset_line, shift + 25, 59);
if (set_value) {
spr.fillRect(229, 0, 11, 11, TFT_BLUE);
spr.drawRect(229, 0, 11, 11, TFT_WHITE);
spr.drawLine(231, 5, 238 , 5, TFT_WHITE);
spr.drawLine(234, 2, 234, 8, TFT_WHITE);
uint16_t t_left = shift+161;
// Plus symbols while setting a value
spr.fillRect(t_left, 0, 11, 11, TFT_BLUE);
spr.drawRect(t_left, 0, 11, 11, TFT_WHITE);
spr.drawLine(t_left+2, 5, t_left+9, 5, TFT_WHITE);
spr.drawLine(t_left+5, 2, t_left+5, 8, TFT_WHITE);
spr.fillRect(229, 124, 11, 11, TFT_BLUE);
spr.drawRect(229, 124, 11, 11, TFT_WHITE);
spr.drawLine(231, 129, 238, 129, TFT_WHITE);
// Minus symbols while setting a value
spr.fillRect(t_left, 124, 11, 11, TFT_BLUE);
spr.drawRect(t_left, 124, 11, 11, TFT_WHITE);
spr.drawLine(t_left+2, 129, t_left+9, 129, TFT_WHITE);
}
}
else if (info) {
spr.drawLine( 0, 120, HEIGHT, 120, TFT_WHITE); //center line
//spr.drawRect(shift + 10, 0, HEIGHT - shift - 20, 30, TFT_WHITE);
spr.drawLine( 0, 120, DISPLAY_WIDTH, 120, TFT_WHITE); //center line
//spr.drawRect(shift + 10, 0, DISPLAY_WIDTH - shift - 20, 30, TFT_WHITE);
spr.drawString("P-P: " + String(max_v - min_v) + "V", shift + 15, 5);
spr.drawString(frequency, shift + 15, 15);
spr.drawString(String(int(v_div)) + "mV/div", shift - 100, 5);
spr.drawString(String(int(s_div)) + "uS/div", shift - 100, 15);
//String offset_line = String((2.0 * v_div) / 1000.0 - offset) + "V";
String offset_line = String((3.0 * v_div) / 1000.0 - offset) + "V";
spr.drawString(offset_line, shift + 75, 112);
spr.drawString(offset_line, shift + 75, (DISPLAY_HEIGHT/2) -8);
}
@ -215,15 +233,15 @@ void draw_sprite(float freq,
void draw_grid() {
for (int i = 0; i < (HEIGHT/10); i++) {
for (int i = 0; i < (DISPLAY_WIDTH/10); i++) {
spr.drawPixel(i * 10, 40, TFT_WHITE);
spr.drawPixel(i * 10, 80, TFT_WHITE);
spr.drawPixel(i * 10, 120, TFT_WHITE);
spr.drawPixel(i * 10, 160, TFT_WHITE);
spr.drawPixel(i * 10, 200, TFT_WHITE);
}
for (int i = 0; i < WIDTH; i += 10) {
for (int j = 0; j < HEIGHT; j += 40) {
for (int i = 0; i < DISPLAY_HEIGHT; i += 10) {
for (int j = 0; j < DISPLAY_WIDTH; j += 40) {
spr.drawPixel(j, i, TFT_WHITE);
}
}
@ -245,7 +263,7 @@ void draw_channel1(uint32_t trigger0, uint32_t trigger1, uint16_t *i2s_buff, flo
trigger0 += index_offset;
uint32_t old_index = trigger0;
float n_data = 0, o_data = to_scale(i2s_buff[trigger0]);
for (uint32_t i = 1; i < HEIGHT; i++) {
for (uint32_t i = 1; i < DISPLAY_WIDTH; i++) {
uint32_t index = trigger0 + (uint32_t)((i + 1) * data_per_pixel);
if (index < BUFF_SIZE) {
if (full_pix && s_div > 40 && current_filter == 0) {