Compare commits
No commits in common. "1a54d4bc59eb0bd38bba0f9fc673129e9a97d299" and "100650edb21f2788f03ce85b8644dc14462f6280" have entirely different histories.
1a54d4bc59
...
100650edb2
6 changed files with 263 additions and 361 deletions
|
@ -1,39 +1,36 @@
|
|||
/* Add https://dl.espressif.com/dl/package_esp32_index.json to your arduino IDE to get ESP32 support
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <driver/i2s.h>
|
||||
#include <driver/adc.h>
|
||||
#include <soc/syscon_reg.h>
|
||||
|
||||
#include <TFT_eSPI.h>
|
||||
|
||||
#include <SPI.h>
|
||||
#include "esp_adc_cal.h"
|
||||
#include "filters.h"
|
||||
|
||||
//#define DEBUG_SERIAL
|
||||
#define DEBUG_BUFF
|
||||
#define DEBUG_DELAY 250
|
||||
//#define DEBUG_BUFF
|
||||
#define DELAY 1000
|
||||
|
||||
// Width and height of sprite
|
||||
#define DISPLAY_HEIGHT 240
|
||||
#define DISPLAY_WIDTH 320
|
||||
#define WIDTH 240
|
||||
#define HEIGHT 280
|
||||
|
||||
#define ADC_CHANNEL ADC1_CHANNEL_5 // GPIO33
|
||||
#define NUM_SAMPLES 1000 // number of samples
|
||||
#define I2S_NUM (0)
|
||||
#define BUFF_SIZE 50000
|
||||
#define B_MULT BUFF_SIZE/NUM_SAMPLES
|
||||
|
||||
#define BUTTON_Ok 32
|
||||
#define BUTTON_Plus 15
|
||||
#define BUTTON_Minus 35
|
||||
#define BUTTON_Back 34
|
||||
|
||||
TFT_eSPI tft = TFT_eSPI(); // Declare object "tft"
|
||||
|
||||
TFT_eSprite spr = TFT_eSprite(&tft); // Declare Sprite object "spr" with pointer to "tft" object
|
||||
|
||||
|
||||
|
||||
esp_adc_cal_characteristics_t adc_chars;
|
||||
|
||||
TaskHandle_t task_menu;
|
||||
|
@ -167,7 +164,7 @@ void core0_task( void * pvParameters ) {
|
|||
update_screen(i2s_buff, RATE);
|
||||
updating_screen = false;
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
//Serial.println("CORE0");
|
||||
Serial.println("CORE0");
|
||||
}
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
|
@ -175,46 +172,36 @@ void core0_task( void * pvParameters ) {
|
|||
|
||||
}
|
||||
|
||||
void core1_task(void *pvParameters)
|
||||
{
|
||||
void core1_task( void * pvParameters ) {
|
||||
|
||||
(void) pvParameters;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (!single_trigger)
|
||||
{
|
||||
while (updating_screen)
|
||||
{
|
||||
for (;;) {
|
||||
if (!single_trigger) {
|
||||
while (updating_screen) {
|
||||
vTaskDelay(pdMS_TO_TICKS(1));
|
||||
}
|
||||
if (!stop)
|
||||
{
|
||||
if (stop_change)
|
||||
{
|
||||
if (!stop) {
|
||||
if (stop_change) {
|
||||
i2s_adc_enable(I2S_NUM_0);
|
||||
stop_change = false;
|
||||
}
|
||||
ADC_Sampling(i2s_buff);
|
||||
new_data = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!stop_change)
|
||||
{
|
||||
else {
|
||||
if (!stop_change) {
|
||||
i2s_adc_disable(I2S_NUM_0);
|
||||
i2s_zero_dma_buffer(I2S_NUM_0);
|
||||
stop_change = true;
|
||||
}
|
||||
}
|
||||
// Serial.println("CORE1");
|
||||
Serial.println("CORE1");
|
||||
vTaskDelay(pdMS_TO_TICKS(300));
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
float old_mean = 0;
|
||||
while (single_trigger)
|
||||
{
|
||||
while (single_trigger) {
|
||||
stop = true;
|
||||
ADC_Sampling(i2s_buff);
|
||||
float mean = 0;
|
||||
|
@ -222,8 +209,7 @@ void core1_task(void *pvParameters)
|
|||
peak_mean(i2s_buff, BUFF_SIZE, &max_v, &min_v, &mean);
|
||||
|
||||
//signal captured (pp > 0.4V || changing mean > 0.2V) -> DATA ANALYSIS
|
||||
if ((old_mean != 0 && fabs(mean - old_mean) > 0.2) || to_voltage(max_v) - to_voltage(min_v) > 0.05)
|
||||
{
|
||||
if ((old_mean != 0 && fabs(mean - old_mean) > 0.2) || to_voltage(max_v) - to_voltage(min_v) > 0.05) {
|
||||
float freq = 0;
|
||||
float period = 0;
|
||||
uint32_t trigger0 = 0;
|
||||
|
@ -231,24 +217,19 @@ void core1_task(void *pvParameters)
|
|||
|
||||
//if analog mode OR auto mode and wave recognized as analog
|
||||
bool digital_data = !false;
|
||||
if (digital_wave_option == 1)
|
||||
{
|
||||
if (digital_wave_option == 1) {
|
||||
trigger_freq_analog(i2s_buff, RATE, mean, max_v, min_v, &freq, &period, &trigger0, &trigger1);
|
||||
}
|
||||
else if (digital_wave_option == 0)
|
||||
{
|
||||
else if (digital_wave_option == 0) {
|
||||
digital_data = digital_analog(i2s_buff, max_v, min_v);
|
||||
if (!digital_data)
|
||||
{
|
||||
if (!digital_data) {
|
||||
trigger_freq_analog(i2s_buff, RATE, mean, max_v, min_v, &freq, &period, &trigger0, &trigger1);
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
trigger_freq_digital(i2s_buff, RATE, mean, max_v, min_v, &freq, &period, &trigger0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
trigger_freq_digital(i2s_buff, RATE, mean, max_v, min_v, &freq, &period, &trigger0);
|
||||
}
|
||||
|
||||
|
@ -259,6 +240,7 @@ void core1_task(void *pvParameters)
|
|||
}
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(1)); //time for the other task to start (low priorit)
|
||||
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(300));
|
||||
}
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
|
||||
void peak_mean(uint16_t *i2s_buffer, uint32_t len, float *max_value, float *min_value, float *pt_mean)
|
||||
{
|
||||
void peak_mean(uint16_t *i2s_buffer, uint32_t len, float * max_value, float * min_value, float *pt_mean) {
|
||||
max_value[0] = i2s_buffer[0];
|
||||
min_value[0] = i2s_buffer[0];
|
||||
mean_filter filter(5);
|
||||
filter.init(i2s_buffer[0]);
|
||||
|
||||
float mean = 0;
|
||||
for (uint32_t i = 1; i < len; i++)
|
||||
{
|
||||
for (uint32_t i = 1; i < len; i++) {
|
||||
|
||||
float value = filter.filter((float)i2s_buffer[i]);
|
||||
if (value > max_value[0])
|
||||
|
@ -23,30 +20,25 @@ void peak_mean(uint16_t *i2s_buffer, uint32_t len, float *max_value, float *min_
|
|||
pt_mean[0] = mean;
|
||||
}
|
||||
|
||||
|
||||
//true if digital/ false if analog
|
||||
bool digital_analog(uint16_t *i2s_buffer, uint32_t max_v, uint32_t min_v)
|
||||
{
|
||||
bool digital_analog(uint16_t *i2s_buffer, uint32_t max_v, uint32_t min_v) {
|
||||
uint32_t upper_threshold = max_v - 0.05 * (max_v - min_v);
|
||||
uint32_t lower_threshold = min_v + 0.05 * (max_v - min_v);
|
||||
uint32_t digital_data = 0;
|
||||
uint32_t analog_data = 0;
|
||||
for (uint32_t i = 0; i < BUFF_SIZE; i++)
|
||||
{
|
||||
if (i2s_buffer[i] > lower_threshold)
|
||||
{
|
||||
if (i2s_buffer[i] > upper_threshold)
|
||||
{
|
||||
for (uint32_t i = 0; i < BUFF_SIZE; i++) {
|
||||
if (i2s_buffer[i] > lower_threshold) {
|
||||
if (i2s_buffer[i] > upper_threshold) {
|
||||
//HIGH DIGITAL
|
||||
digital_data++;
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
//ANALOG/TRANSITION
|
||||
analog_data++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
//LOW DIGITAL
|
||||
digital_data++;
|
||||
}
|
||||
|
@ -67,8 +59,7 @@ void trigger_freq_analog(uint16_t *i2s_buffer,
|
|||
float *pt_freq,
|
||||
float *pt_period,
|
||||
uint32_t *pt_trigger0,
|
||||
uint32_t *pt_trigger1)
|
||||
{
|
||||
uint32_t *pt_trigger1) {
|
||||
float freq = 0;
|
||||
float period = 0;
|
||||
bool signal_side = false;
|
||||
|
@ -78,24 +69,20 @@ void trigger_freq_analog(uint16_t *i2s_buffer,
|
|||
uint32_t trigger_index = 0;
|
||||
|
||||
//get initial signal relative to the mean
|
||||
if (to_voltage(i2s_buffer[0]) > mean)
|
||||
{
|
||||
if (to_voltage(i2s_buffer[0]) > mean) {
|
||||
signal_side = true;
|
||||
}
|
||||
|
||||
|
||||
//waveform repetitions calculation + get triggers time
|
||||
uint32_t wave_center = (max_v + min_v) / 2;
|
||||
for (uint32_t i = 1; i < BUFF_SIZE; i++)
|
||||
{
|
||||
if (signal_side && i2s_buffer[i] < wave_center - (wave_center - min_v) * 0.2)
|
||||
{
|
||||
for (uint32_t i = 1 ; i < BUFF_SIZE; i++) {
|
||||
if (signal_side && i2s_buffer[i] < wave_center - (wave_center - min_v) * 0.2) {
|
||||
signal_side = false;
|
||||
}
|
||||
else if (!signal_side && i2s_buffer[i] > wave_center + (max_v - wave_center) * 0.2)
|
||||
{
|
||||
else if (!signal_side && i2s_buffer[i] > wave_center + (max_v - wave_center) * 0.2) {
|
||||
freq++;
|
||||
if (trigger_count < trigger_num)
|
||||
{
|
||||
if (trigger_count < trigger_num) {
|
||||
trigger_temp[trigger_count] = i;
|
||||
trigger_count++;
|
||||
}
|
||||
|
@ -104,26 +91,22 @@ void trigger_freq_analog(uint16_t *i2s_buffer,
|
|||
}
|
||||
|
||||
//frequency calculation
|
||||
if (trigger_count < 2)
|
||||
{
|
||||
if (trigger_count < 2) {
|
||||
trigger_temp[0] = 0;
|
||||
trigger_index = 0;
|
||||
freq = 0;
|
||||
period = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
|
||||
//simple frequency calculation fair enough for frequencies over 2khz (20hz resolution)
|
||||
freq = freq * 1000 / 50;
|
||||
period = (float)(sample_rate * 1000.0) / freq; //us
|
||||
|
||||
//from 2000 to 80 hz -> uses mean of the periods for precision
|
||||
if (freq < 2000 && freq > 80)
|
||||
{
|
||||
if (freq < 2000 && freq > 80) {
|
||||
period = 0;
|
||||
for (uint32_t i = 1; i < trigger_count; i++)
|
||||
{
|
||||
for (uint32_t i = 1; i < trigger_count; i++) {
|
||||
period += trigger_temp[i] - trigger_temp[i - 1];
|
||||
}
|
||||
period /= (trigger_count - 1);
|
||||
|
@ -131,8 +114,7 @@ void trigger_freq_analog(uint16_t *i2s_buffer,
|
|||
}
|
||||
|
||||
//under 80hz, single period for frequency calculation
|
||||
else if (trigger_count > 1 && freq <= 80)
|
||||
{
|
||||
else if (trigger_count > 1 && freq <= 80) {
|
||||
period = trigger_temp[1] - trigger_temp[0];
|
||||
freq = sample_rate * 1000 / period;
|
||||
}
|
||||
|
@ -145,24 +127,25 @@ void trigger_freq_analog(uint16_t *i2s_buffer,
|
|||
The resulting trigger gets a negative offset of 5% of the calculated period
|
||||
*/
|
||||
uint32_t trigger2 = 0;
|
||||
if (trigger_temp[0] - period * 0.05 > 0 && trigger_count > 1)
|
||||
{
|
||||
if (trigger_temp[0] - period * 0.05 > 0 && trigger_count > 1) {
|
||||
trigger_index = trigger_temp[0] - period * 0.05;
|
||||
trigger2 = trigger_temp[1] - period * 0.05;
|
||||
}
|
||||
else if (trigger_count > 2)
|
||||
{
|
||||
else if (trigger_count > 2) {
|
||||
trigger_index = trigger_temp[1] - period * 0.05;
|
||||
if (trigger_count > 2)
|
||||
trigger2 = trigger_temp[2] - period * 0.05;
|
||||
}
|
||||
|
||||
|
||||
pt_trigger0[0] = trigger_index;
|
||||
pt_trigger1[0] = trigger2;
|
||||
pt_freq[0] = freq;
|
||||
pt_period[0] = period;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void trigger_freq_digital(uint16_t *i2s_buffer,
|
||||
float sample_rate,
|
||||
float mean,
|
||||
|
@ -170,8 +153,7 @@ void trigger_freq_digital(uint16_t *i2s_buffer,
|
|||
uint32_t min_v,
|
||||
float *pt_freq,
|
||||
float *pt_period,
|
||||
uint32_t *pt_trigger0)
|
||||
{
|
||||
uint32_t *pt_trigger0) {
|
||||
|
||||
float freq = 0;
|
||||
float period = 0;
|
||||
|
@ -182,37 +164,31 @@ void trigger_freq_digital(uint16_t *i2s_buffer,
|
|||
uint32_t trigger_index = 0;
|
||||
|
||||
//get initial signal relative to the mean
|
||||
if (to_voltage(i2s_buffer[0]) > mean)
|
||||
{
|
||||
if (to_voltage(i2s_buffer[0]) > mean) {
|
||||
signal_side = true;
|
||||
}
|
||||
|
||||
//waveform repetitions calculation + get triggers time
|
||||
uint32_t wave_center = (max_v + min_v) / 2;
|
||||
bool normal_high = (mean > to_voltage(wave_center)) ? true : false;
|
||||
if (max_v - min_v > 4095 * (0.4 / 3.3))
|
||||
{
|
||||
for (uint32_t i = 1; i < BUFF_SIZE; i++)
|
||||
{
|
||||
if (signal_side && i2s_buffer[i] < wave_center - (wave_center - min_v) * 0.2)
|
||||
{
|
||||
if (max_v - min_v > 4095 * (0.4 / 3.3)) {
|
||||
for (uint32_t i = 1 ; i < BUFF_SIZE; i++) {
|
||||
if (signal_side && i2s_buffer[i] < wave_center - (wave_center - min_v) * 0.2) {
|
||||
|
||||
//signal was high, fell -> trigger if normal high
|
||||
if (trigger_count < trigger_num && normal_high)
|
||||
{
|
||||
if (trigger_count < trigger_num && normal_high) {
|
||||
trigger_temp[trigger_count] = i;
|
||||
trigger_count++;
|
||||
}
|
||||
|
||||
signal_side = false;
|
||||
|
||||
}
|
||||
else if (!signal_side && i2s_buffer[i] > wave_center + (max_v - wave_center) * 0.2)
|
||||
{
|
||||
else if (!signal_side && i2s_buffer[i] > wave_center + (max_v - wave_center) * 0.2) {
|
||||
freq++;
|
||||
|
||||
//signal was low, rose -> trigger if normal low
|
||||
if (trigger_count < trigger_num && !normal_high)
|
||||
{
|
||||
if (trigger_count < trigger_num && !normal_high) {
|
||||
trigger_temp[trigger_count] = i;
|
||||
trigger_count++;
|
||||
}
|
||||
|
@ -224,14 +200,11 @@ void trigger_freq_digital(uint16_t *i2s_buffer,
|
|||
freq = freq * 1000 / 50;
|
||||
period = (float)(sample_rate * 1000.0) / freq; //us
|
||||
|
||||
if (trigger_count > 1)
|
||||
{
|
||||
if (trigger_count > 1) {
|
||||
//from 2000 to 80 hz -> uses mean of the periods for precision
|
||||
if (freq < 2000 && freq > 80)
|
||||
{
|
||||
if (freq < 2000 && freq > 80) {
|
||||
period = 0;
|
||||
for (uint32_t i = 1; i < trigger_count; i++)
|
||||
{
|
||||
for (uint32_t i = 1; i < trigger_count; i++) {
|
||||
period += trigger_temp[i] - trigger_temp[i - 1];
|
||||
}
|
||||
period /= (trigger_count - 1);
|
||||
|
@ -239,8 +212,7 @@ void trigger_freq_digital(uint16_t *i2s_buffer,
|
|||
}
|
||||
|
||||
//under 80hz, single period for frequency calculation
|
||||
else if (trigger_count > 1 && freq <= 80)
|
||||
{
|
||||
else if (trigger_count > 1 && freq <= 80) {
|
||||
period = trigger_temp[1] - trigger_temp[0];
|
||||
freq = sample_rate * 1000 / period;
|
||||
}
|
||||
|
@ -254,7 +226,11 @@ void trigger_freq_digital(uint16_t *i2s_buffer,
|
|||
trigger_index = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
pt_trigger0[0] = trigger_index;
|
||||
pt_freq[0] = freq;
|
||||
pt_period[0] = period;
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
void debug_buffer() {
|
||||
ADC_Sampling();
|
||||
i2s_adc_disable(I2S_NUM_0);
|
||||
delay(DEBUG_DELAY);
|
||||
delay(1000);
|
||||
for (uint32_t i = 0; i < B_MULT * NUM_SAMPLES; i++) {
|
||||
for (int j = 0; j < 1; j++) {
|
||||
Serial.println(i2s_buff[i]);
|
||||
|
|
|
@ -23,20 +23,12 @@ void configure_i2s(int rate) {
|
|||
i2s_adc_enable(I2S_NUM_0);
|
||||
}
|
||||
|
||||
/*
|
||||
void ADC_Sampling(uint16_t *i2s_buff){
|
||||
for (int i = 0; i < B_MULT; i++) {
|
||||
//TODO i2s_read_bytes is deprecated, replace with new function
|
||||
i2s_read_bytes(I2S_NUM_0, (char*)&i2s_buff[i * NUM_SAMPLES], NUM_SAMPLES * sizeof(uint16_t), portMAX_DELAY);
|
||||
}
|
||||
}
|
||||
*/
|
||||
void ADC_Sampling(uint16_t *i2s_buff){
|
||||
size_t bytes_read; for (int i = 0; i < B_MULT; i++) {
|
||||
i2s_read(I2S_NUM_0, (void*)&i2s_buff[i * NUM_SAMPLES], NUM_SAMPLES * sizeof(uint16_t), &bytes_read, portMAX_DELAY);
|
||||
for(size_t ix = 0; ix < bytes_read/2; ix++) i2s_buff[(i * NUM_SAMPLES) + ix] &= 0x0FFF; // 16bit to 12bit conversion
|
||||
}
|
||||
}
|
||||
|
||||
void set_sample_rate(uint32_t rate) {
|
||||
i2s_driver_uninstall(I2S_NUM_0);
|
||||
|
|
|
@ -12,7 +12,7 @@ int voltage_division[6] = { //screen has 4 divisions, 31 pixels each (125 pixels
|
|||
thus, the time division is the number
|
||||
of samples per screen division
|
||||
*/
|
||||
float time_division[9] = { //screen has 4 divisions, 60 pixel each (WIDTH pixel of width)
|
||||
float time_division[9] = { //screen has 4 divisions, 60 pixel each (240 pixel of width)
|
||||
10,
|
||||
25,
|
||||
50,
|
||||
|
@ -34,33 +34,26 @@ void menu_handler() {
|
|||
button();
|
||||
}
|
||||
|
||||
void button()
|
||||
{
|
||||
void button() {
|
||||
if ( btnok == 1 || btnbk == 1 || btnpl == 1 || btnmn == 1)
|
||||
{
|
||||
menu_action = true;
|
||||
}
|
||||
if (menu == true)
|
||||
{
|
||||
if (set_value)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
if (set_value) {
|
||||
switch (opt) {
|
||||
case Vdiv:
|
||||
if (btnpl == 1)
|
||||
{
|
||||
if (btnpl == 1) {
|
||||
volts_index++;
|
||||
if (volts_index >= sizeof(voltage_division) / sizeof(*voltage_division))
|
||||
{
|
||||
if (volts_index >= sizeof(voltage_division) / sizeof(*voltage_division)) {
|
||||
volts_index = 0;
|
||||
}
|
||||
btnpl = 0;
|
||||
}
|
||||
else if (btnmn == 1)
|
||||
{
|
||||
else if (btnmn == 1) {
|
||||
volts_index--;
|
||||
if (volts_index < 0)
|
||||
{
|
||||
if (volts_index < 0) {
|
||||
volts_index = sizeof(voltage_division) / sizeof(*voltage_division) - 1;
|
||||
}
|
||||
btnmn = 0;
|
||||
|
@ -70,20 +63,16 @@ void button()
|
|||
break;
|
||||
|
||||
case Sdiv:
|
||||
if (btnmn == 1)
|
||||
{
|
||||
if (btnmn == 1) {
|
||||
tscale_index++;
|
||||
if (tscale_index >= sizeof(time_division) / sizeof(*time_division))
|
||||
{
|
||||
if (tscale_index >= sizeof(time_division) / sizeof(*time_division)) {
|
||||
tscale_index = 0;
|
||||
}
|
||||
btnmn = 0;
|
||||
}
|
||||
else if (btnpl == 1)
|
||||
{
|
||||
else if (btnpl == 1) {
|
||||
tscale_index--;
|
||||
if (tscale_index < 0)
|
||||
{
|
||||
if (tscale_index < 0) {
|
||||
tscale_index = sizeof(time_division) / sizeof(*time_division) - 1;
|
||||
}
|
||||
btnpl = 0;
|
||||
|
@ -93,13 +82,11 @@ void button()
|
|||
break;
|
||||
|
||||
case Offset:
|
||||
if (btnmn == 1)
|
||||
{
|
||||
if (btnmn == 1) {
|
||||
offset += 0.1 * (v_div * 4) / 3300;
|
||||
btnmn = 0;
|
||||
}
|
||||
else if (btnpl == 1)
|
||||
{
|
||||
else if (btnpl == 1) {
|
||||
offset -= 0.1 * (v_div * 4) / 3300;
|
||||
btnpl = 0;
|
||||
}
|
||||
|
@ -127,6 +114,7 @@ void button()
|
|||
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
if (btnbk == 1)
|
||||
{
|
||||
|
@ -163,10 +151,8 @@ void button()
|
|||
hide_menu();
|
||||
btnbk = 0;
|
||||
}
|
||||
if (btnok == 1)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
if (btnok == 1) {
|
||||
switch (opt) {
|
||||
case Autoscale:
|
||||
auto_scale = !auto_scale;
|
||||
break;
|
||||
|
@ -185,8 +171,8 @@ void button()
|
|||
|
||||
case Stop:
|
||||
stop = !stop;
|
||||
Serial.print("Stop : ");
|
||||
Serial.println(stop);
|
||||
//Serial.print("Stop : ");
|
||||
//Serial.println(stop);
|
||||
set_value = false;
|
||||
break;
|
||||
|
||||
|
@ -225,6 +211,7 @@ void button()
|
|||
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
btnok = 0;
|
||||
|
@ -251,86 +238,71 @@ void button()
|
|||
}
|
||||
btnbk = 0;
|
||||
}
|
||||
if (btnpl == 1)
|
||||
{
|
||||
if (btnpl == 1) {
|
||||
volts_index++;
|
||||
if (volts_index >= sizeof(voltage_division) / sizeof(*voltage_division))
|
||||
{
|
||||
if (volts_index >= sizeof(voltage_division) / sizeof(*voltage_division)) {
|
||||
volts_index = 0;
|
||||
}
|
||||
btnpl = 0;
|
||||
v_div = voltage_division[volts_index];
|
||||
}
|
||||
if (btnmn == 1)
|
||||
{
|
||||
if (btnmn == 1) {
|
||||
tscale_index++;
|
||||
if (tscale_index >= sizeof(time_division) / sizeof(*time_division))
|
||||
{
|
||||
if (tscale_index >= sizeof(time_division) / sizeof(*time_division)) {
|
||||
tscale_index = 0;
|
||||
}
|
||||
btnmn = 0;
|
||||
s_div = time_division[tscale_index];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void hide_menu()
|
||||
{
|
||||
void hide_menu() {
|
||||
menu = false;
|
||||
}
|
||||
|
||||
void hide_all()
|
||||
{
|
||||
void hide_all() {
|
||||
menu = false;
|
||||
info = false;
|
||||
}
|
||||
|
||||
void show_menu()
|
||||
{
|
||||
void show_menu() {
|
||||
menu = true;
|
||||
}
|
||||
|
||||
String strings_vdiv()
|
||||
{
|
||||
String strings_vdiv() {
|
||||
return "";
|
||||
}
|
||||
|
||||
String strings_sdiv()
|
||||
{
|
||||
String strings_sdiv() {
|
||||
return "";
|
||||
}
|
||||
|
||||
String strings_offset()
|
||||
{
|
||||
String strings_offset() {
|
||||
return "";
|
||||
}
|
||||
|
||||
String strings_toffset()
|
||||
{
|
||||
String strings_toffset() {
|
||||
return "";
|
||||
}
|
||||
|
||||
String strings_freq()
|
||||
{
|
||||
String strings_freq() {
|
||||
return "";
|
||||
}
|
||||
|
||||
String strings_peak()
|
||||
{
|
||||
String strings_peak() {
|
||||
return "";
|
||||
}
|
||||
|
||||
String strings_vmax()
|
||||
{
|
||||
String strings_vmax() {
|
||||
return "";
|
||||
}
|
||||
|
||||
String strings_vmin()
|
||||
{
|
||||
String strings_vmin() {
|
||||
return "";
|
||||
}
|
||||
|
||||
String strings_filter()
|
||||
{
|
||||
String strings_filter() {
|
||||
return "";
|
||||
}
|
||||
|
|
|
@ -1,22 +1,21 @@
|
|||
void setup_screen() {
|
||||
// Initialise the TFT registers
|
||||
tft.init();
|
||||
tft.setRotation(3);
|
||||
tft.setRotation(1);
|
||||
|
||||
// Optionally set colour depth to 8 or 16 bits, default is 16 if not spedified
|
||||
spr.setColorDepth(8);
|
||||
|
||||
// Create a sprite of defined size
|
||||
spr.createSprite(DISPLAY_WIDTH, DISPLAY_HEIGHT);
|
||||
spr.createSprite(HEIGHT, WIDTH);
|
||||
// Clear the TFT screen to blue
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
}
|
||||
|
||||
int data[DISPLAY_WIDTH] = {0};
|
||||
int data[280] = {0};
|
||||
|
||||
/*
|
||||
float to_scale(float reading) {
|
||||
float temp = DISPLAY_HEIGHT -
|
||||
float temp = WIDTH -
|
||||
(
|
||||
(
|
||||
(
|
||||
|
@ -27,33 +26,18 @@ float to_scale(float reading) {
|
|||
(v_div * 6)
|
||||
)
|
||||
)
|
||||
* (DISPLAY_HEIGHT - 1)
|
||||
* (WIDTH - 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) {
|
||||
|
||||
|
@ -165,11 +149,11 @@ void draw_sprite(float freq,
|
|||
draw_channel1(trigger, 0, i2s_buff, sample_rate);
|
||||
}
|
||||
|
||||
int shift = DISPLAY_WIDTH - 110;
|
||||
int shift = 150;
|
||||
if (menu) {
|
||||
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.drawLine( 0, 120, 280, 120, TFT_WHITE); //center line
|
||||
spr.fillRect(shift, 0, 102, 135, TFT_BLACK);
|
||||
spr.drawRect(shift, 0, 102, 135, TFT_WHITE);
|
||||
spr.fillRect(shift + 1, 3 + 10 * (opt - 1), 100, 11, TFT_RED);
|
||||
|
||||
spr.drawString("AUTOSCALE", shift + 5, 5);
|
||||
|
@ -194,34 +178,30 @@ void draw_sprite(float freq,
|
|||
spr.drawRect(shift, 0, 70, 30, TFT_WHITE);
|
||||
spr.drawString("P-P: " + String(max_v - min_v) + "V", shift + 5, 5);
|
||||
spr.drawString(frequency, shift + 5, 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 + 25, (DISPLAY_HEIGHT/2)-8);
|
||||
String offset_line = String((2.0 * v_div) / 1000.0 - offset) + "V";
|
||||
spr.drawString(offset_line, shift + 40, 59);
|
||||
|
||||
if (set_value) {
|
||||
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, 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);
|
||||
|
||||
// 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);
|
||||
|
||||
spr.fillRect(229, 124, 11, 11, TFT_BLUE);
|
||||
spr.drawRect(229, 124, 11, 11, TFT_WHITE);
|
||||
spr.drawLine(231, 129, 238, 129, TFT_WHITE);
|
||||
}
|
||||
}
|
||||
else if (info) {
|
||||
spr.drawLine( 0, 120, DISPLAY_WIDTH, 120, TFT_WHITE); //center line
|
||||
//spr.drawRect(shift + 10, 0, DISPLAY_WIDTH - shift - 20, 30, TFT_WHITE);
|
||||
spr.drawLine( 0, 120, 280, 120, TFT_WHITE); //center line
|
||||
//spr.drawRect(shift + 10, 0, 280 - 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, (DISPLAY_HEIGHT/2)-8);
|
||||
String offset_line = String((2.0 * v_div) / 1000.0 - offset) + "V";
|
||||
spr.drawString(offset_line, shift + 100, 112);
|
||||
}
|
||||
|
||||
|
||||
|
@ -233,15 +213,15 @@ void draw_sprite(float freq,
|
|||
|
||||
void draw_grid() {
|
||||
|
||||
for (int i = 0; i < (DISPLAY_WIDTH/10); i++) {
|
||||
for (int i = 0; i < 28; 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 < DISPLAY_HEIGHT; i += 10) {
|
||||
for (int j = 0; j < DISPLAY_WIDTH; j += 40) {
|
||||
for (int i = 0; i < 240; i += 10) {
|
||||
for (int j = 0; j < 280; j += 40) {
|
||||
spr.drawPixel(j, i, TFT_WHITE);
|
||||
}
|
||||
}
|
||||
|
@ -263,7 +243,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 < DISPLAY_WIDTH; i++) {
|
||||
for (uint32_t i = 1; i < 280; 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) {
|
||||
|
|
Loading…
Reference in a new issue