This commit is contained in:
furrtek
2016-05-09 21:05:11 +02:00
parent 8523bd860e
commit 569f299f42
57 changed files with 1155 additions and 772 deletions
+3 -1
View File
@@ -175,6 +175,7 @@ CPPSRC = main.cpp \
ui_sd_card_debug.cpp \
ui_console.cpp \
ui_receiver.cpp \
ui_record_view.cpp \
ui_spectrum.cpp \
ui_loadmodule.cpp \
ui_afskrx.cpp \
@@ -196,10 +197,11 @@ CPPSRC = main.cpp \
../common/ert_packet.cpp \
capture_app.cpp \
sd_card.cpp \
time.cpp \
file.cpp \
log_file.cpp \
png_writer.cpp \
audio_thread.cpp \
capture_thread.cpp \
manchester.cpp \
string_format.cpp \
temperature_logger.cpp \
+1 -1
View File
@@ -136,7 +136,7 @@ AISLogger::AISLogger(
void AISLogger::on_packet(const ais::Packet& packet) {
// TODO: Unstuff here, not in baseband!
if( log_file.is_ready() ) {
if( log_file.is_open() ) {
std::string entry;
entry.reserve((packet.length() + 3) / 4);
+34 -26
View File
@@ -30,6 +30,8 @@ using namespace portapack;
#include "utility.hpp"
#include "string_format.hpp"
namespace ui {
/* AMOptionsView *********************************************************/
@@ -84,6 +86,7 @@ AnalogAudioView::AnalogAudioView(
&field_vga,
&options_modulation,
&field_volume,
&record_view,
&waterfall,
} });
@@ -208,6 +211,8 @@ void AnalogAudioView::remove_options_widget() {
}
void AnalogAudioView::set_options_widget(std::unique_ptr<Widget> new_widget) {
remove_options_widget();
if( new_widget ) {
options_widget = std::move(new_widget);
add_child(options_widget.get());
@@ -215,11 +220,6 @@ void AnalogAudioView::set_options_widget(std::unique_ptr<Widget> new_widget) {
}
void AnalogAudioView::on_show_options_frequency() {
// TODO: This approach of managing options views is error-prone and unsustainable!
remove_options_widget();
field_frequency.set_style(&style_options_group);
auto widget = std::make_unique<FrequencyOptionsView>(options_view_rect, &style_options_group);
widget->set_step(receiver_model.frequency_step());
@@ -232,14 +232,10 @@ void AnalogAudioView::on_show_options_frequency() {
};
set_options_widget(std::move(widget));
field_frequency.set_style(&style_options_group);
}
void AnalogAudioView::on_show_options_rf_gain() {
// TODO: This approach of managing options views is error-prone and unsustainable!
remove_options_widget();
field_lna.set_style(&style_options_group);
auto widget = std::make_unique<RadioGainOptionsView>(options_view_rect, &style_options_group);
widget->set_rf_amp(receiver_model.rf_amp());
@@ -248,23 +244,28 @@ void AnalogAudioView::on_show_options_rf_gain() {
};
set_options_widget(std::move(widget));
field_lna.set_style(&style_options_group);
}
void AnalogAudioView::on_show_options_modulation() {
// TODO: This approach of managing options views is error-prone and unsustainable!
remove_options_widget();
std::unique_ptr<Widget> widget;
const auto modulation = static_cast<ReceiverModel::Mode>(receiver_model.modulation());
if( modulation == ReceiverModel::Mode::AMAudio ) {
options_modulation.set_style(&style_options_group);
auto widget = std::make_unique<AMOptionsView>(options_view_rect, &style_options_group);
set_options_widget(std::move(widget));
}
if( modulation == ReceiverModel::Mode::NarrowbandFMAudio ) {
options_modulation.set_style(&style_options_group);
auto widget = std::make_unique<NBFMOptionsView>(options_view_rect, &style_options_group);
set_options_widget(std::move(widget));
switch(modulation) {
case ReceiverModel::Mode::AMAudio:
widget = std::make_unique<AMOptionsView>(options_view_rect, &style_options_group);
break;
case ReceiverModel::Mode::NarrowbandFMAudio:
widget = std::make_unique<NBFMOptionsView>(options_view_rect, &style_options_group);
break;
default:
break;
}
set_options_widget(std::move(widget));
options_modulation.set_style(&style_options_group);
}
void AnalogAudioView::on_frequency_step_changed(rf::Frequency f) {
@@ -283,7 +284,7 @@ void AnalogAudioView::on_headphone_volume_changed(int32_t v) {
void AnalogAudioView::update_modulation(const ReceiverModel::Mode modulation) {
audio::output::mute();
audio_thread.reset();
record_view.stop();
const auto is_wideband_spectrum_mode = (modulation == ReceiverModel::Mode::SpectrumAnalysis);
receiver_model.set_baseband_configuration({
@@ -294,11 +295,18 @@ void AnalogAudioView::update_modulation(const ReceiverModel::Mode modulation) {
receiver_model.set_baseband_bandwidth(is_wideband_spectrum_mode ? 12000000 : 1750000);
receiver_model.enable();
// TODO: This doesn't belong here! There's a better way.
size_t sampling_rate = 0;
switch(modulation) {
case ReceiverModel::Mode::AMAudio: sampling_rate = 12000; break;
case ReceiverModel::Mode::NarrowbandFMAudio: sampling_rate = 24000; break;
case ReceiverModel::Mode::WidebandFMAudio: sampling_rate = 48000; break;
default:
break;
}
record_view.set_sampling_rate(sampling_rate);
if( !is_wideband_spectrum_mode ) {
const auto filename = next_filename_matching_pattern("AUD_????.S16");
if( !filename.empty() ) {
audio_thread = std::make_unique<AudioThread>(filename);
}
audio::output::unmute();
}
}
+7 -5
View File
@@ -26,8 +26,7 @@
#include "ui_receiver.hpp"
#include "ui_spectrum.hpp"
#include "audio_thread.hpp"
#include "ui_record_view.hpp"
#include "ui_font_fixed_8x16.hpp"
@@ -93,7 +92,7 @@ public:
void focus() override;
private:
static constexpr ui::Dim header_height = 2 * 16;
static constexpr ui::Dim header_height = 3 * 16;
const Rect options_view_rect { 0 * 8, 1 * 16, 30 * 8, 1 * 16 };
@@ -142,9 +141,12 @@ private:
std::unique_ptr<Widget> options_widget;
spectrum::WaterfallWidget waterfall;
RecordView record_view {
{ 0 * 8, 2 * 16, 30 * 8, 1 * 16 },
"AUD_????", RecordView::FileType::WAV, 12, 2,
};
std::unique_ptr<AudioThread> audio_thread;
spectrum::WaterfallWidget waterfall;
void on_tuning_frequency_changed(rf::Frequency f);
void on_baseband_bandwidth_changed(uint32_t bandwidth_hz);
-145
View File
@@ -1,145 +0,0 @@
/*
* Copyright (C) 2016 Jared Boone, ShareBrained Technology, Inc.
*
* This file is part of PortaPack.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#ifndef __AUDIO_THREAD_H__
#define __AUDIO_THREAD_H__
#include "ch.h"
#include "file.hpp"
#include "event_m0.hpp"
#include "portapack_shared_memory.hpp"
#include "hackrf_gpio.hpp"
using namespace hackrf::one;
#include <cstring>
class StreamOutput {
public:
StreamOutput(
FIFO<uint8_t>* const fifo
) : fifo { fifo }
{
}
size_t available() {
return fifo->len();
}
size_t read(void* const data, const size_t length) {
return fifo->out(reinterpret_cast<uint8_t*>(data), length);
}
private:
FIFO<uint8_t>* const fifo;
};
class AudioThread {
public:
AudioThread(
std::string file_path
) : file_path { std::move(file_path) },
write_buffer { std::make_unique<std::array<uint8_t, write_size>>() }
{
// Need significant stack for FATFS
thread = chThdCreateFromHeap(NULL, 1024, NORMALPRIO + 10, AudioThread::static_fn, this);
}
~AudioThread() {
chThdTerminate(thread);
chEvtSignal(thread, EVT_FIFO_HIGHWATER);
const auto success = chThdWait(thread);
if( !success ) {
led_tx.on();
}
}
static void check_fifo_isr() {
if( (shared_memory.FIFO_HACK != nullptr) && (thread != nullptr) ) {
auto fifo = reinterpret_cast<FIFO<uint8_t>*>(shared_memory.FIFO_HACK);
if( fifo->len() >= write_size ) {
chEvtSignalI(thread, EVT_FIFO_HIGHWATER);
}
}
}
private:
static constexpr size_t write_size = 16384;
static constexpr eventmask_t EVT_FIFO_HIGHWATER = 1;
const std::string file_path;
std::unique_ptr<std::array<uint8_t, write_size>> write_buffer;
File file;
static Thread* thread;
static msg_t static_fn(void* arg) {
auto obj = static_cast<AudioThread*>(arg);
return obj->run();
}
msg_t run() {
if( !file.open_for_writing(file_path) ) {
return false;
}
auto fifo = reinterpret_cast<FIFO<uint8_t>*>(shared_memory.FIFO_HACK);
if( !fifo ) {
return false;
}
StreamOutput stream { fifo };
while( !chThdShouldTerminate() ) {
chEvtWaitAny(EVT_FIFO_HIGHWATER);
while( stream.available() >= write_buffer->size() ) {
if( !transfer(stream, write_buffer.get()) ) {
return false;
}
}
}
return true;
}
bool transfer(StreamOutput& stream, std::array<uint8_t, write_size>* const write_buffer) {
bool success = false;
led_usb.on();
const auto bytes_to_write = stream.read(write_buffer->data(), write_buffer->size());
if( bytes_to_write == write_buffer->size() ) {
if( file.write(write_buffer->data(), write_buffer->size()) ) {
success = true;
}
}
led_usb.off();
return success;
}
};
#endif/*__AUDIO_THREAD_H__*/
+156
View File
@@ -0,0 +1,156 @@
/*
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
*
* This file is part of PortaPack.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#ifndef __BITMAP_HPP__
#define __BITMAP_HPP__
#include "ui.hpp"
namespace ui {
static constexpr uint8_t bitmap_record_data[] = {
0x00, 0x00,
0x00, 0x00,
0xc0, 0x03,
0xf0, 0x0f,
0xf8, 0x1f,
0xf8, 0x1f,
0xfc, 0x3f,
0xfc, 0x3f,
0xfc, 0x3f,
0xfc, 0x3f,
0xf8, 0x1f,
0xf8, 0x1f,
0xf0, 0x0f,
0xc0, 0x03,
0x00, 0x00,
0x00, 0x00,
};
static constexpr Bitmap bitmap_record {
{ 16, 16 }, bitmap_record_data
};
static constexpr uint8_t bitmap_stop_data[] = {
0x00, 0x00,
0x00, 0x00,
0xfc, 0x3f,
0xfc, 0x3f,
0xfc, 0x3f,
0xfc, 0x3f,
0xfc, 0x3f,
0xfc, 0x3f,
0xfc, 0x3f,
0xfc, 0x3f,
0xfc, 0x3f,
0xfc, 0x3f,
0xfc, 0x3f,
0xfc, 0x3f,
0x00, 0x00,
0x00, 0x00,
};
static constexpr Bitmap bitmap_stop {
{ 16, 16 }, bitmap_stop_data
};
static constexpr uint8_t bitmap_sleep_data[] = {
0x00, 0x00,
0x00, 0x00,
0x00, 0x04,
0x00, 0x08,
0x00, 0x18,
0x00, 0x18,
0x00, 0x38,
0x00, 0x3c,
0x00, 0x3c,
0x00, 0x3e,
0x84, 0x1f,
0xf8, 0x1f,
0xf0, 0x0f,
0xc0, 0x03,
0x00, 0x00,
0x00, 0x00,
};
static constexpr Bitmap bitmap_sleep {
{ 16, 16 }, bitmap_sleep_data
};
static constexpr uint8_t bitmap_camera_data[] = {
0x00, 0x00,
0x00, 0x00,
0x00, 0x00,
0xcc, 0x03,
0xe8, 0x07,
0xfc, 0x3f,
0x3c, 0x3c,
0x9c, 0x39,
0xdc, 0x3b,
0xdc, 0x3b,
0x9c, 0x39,
0x3c, 0x3c,
0xfc, 0x3f,
0x00, 0x00,
0x00, 0x00,
0x00, 0x00,
};
static constexpr Bitmap bitmap_camera {
{ 16, 16 }, bitmap_camera_data
};
static constexpr uint8_t bitmap_sd_card_ok_data[] = {
0x00, 0x00, 0x00, 0x00, 0xe0, 0x1f, 0xf0, 0x1f,
0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f,
0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f,
0xf8, 0x1f, 0xf8, 0x1f, 0x00, 0x00, 0x00, 0x00,
};
static constexpr Bitmap bitmap_sd_card_ok {
{ 16, 16 }, bitmap_sd_card_ok_data
};
static constexpr uint8_t bitmap_sd_card_unknown_data[] = {
0x00, 0x00, 0x00, 0x00, 0xe0, 0x1f, 0xf0, 0x1f,
0x38, 0x1c, 0x98, 0x19, 0xf8, 0x19, 0xf8, 0x1c,
0x78, 0x1e, 0x78, 0x1e, 0xf8, 0x1f, 0x78, 0x1e,
0xf8, 0x1f, 0xf8, 0x1f, 0x00, 0x00, 0x00, 0x00,
};
static constexpr Bitmap bitmap_sd_card_unknown {
{ 16, 16 }, bitmap_sd_card_unknown_data
};
static constexpr uint8_t bitmap_sd_card_error_data[] = {
0x00, 0x00, 0x00, 0x00, 0xe0, 0x1f, 0xf0, 0x1f,
0xf8, 0x1f, 0xd8, 0x1b, 0x98, 0x19, 0x38, 0x1c,
0x78, 0x1e, 0x38, 0x1c, 0x98, 0x19, 0xd8, 0x1b,
0xf8, 0x1f, 0xf8, 0x1f, 0x00, 0x00, 0x00, 0x00,
};
static constexpr Bitmap bitmap_sd_card_error {
{ 16, 16 }, bitmap_sd_card_error_data
};
} /* namespace ui */
#endif/*__BITMAP_HPP__*/
+4 -25
View File
@@ -24,20 +24,16 @@
#include "portapack.hpp"
using namespace portapack;
#include "file.hpp"
#include "utility.hpp"
namespace ui {
CaptureAppView::CaptureAppView(NavigationView& nav) {
add_children({ {
&button_start_stop,
&rssi,
&channel,
&field_frequency,
&field_lna,
&field_vga,
&record_view,
&waterfall,
} });
@@ -65,10 +61,6 @@ CaptureAppView::CaptureAppView(NavigationView& nav) {
this->on_vga_changed(v_db);
};
button_start_stop.on_select = [this](ImageButton&) {
this->on_start_stop();
};
receiver_model.set_baseband_configuration({
.mode = toUType(ReceiverModel::Mode::Capture),
.sampling_rate = sampling_rate,
@@ -76,6 +68,8 @@ CaptureAppView::CaptureAppView(NavigationView& nav) {
});
receiver_model.set_baseband_bandwidth(baseband_bandwidth);
receiver_model.enable();
record_view.set_sampling_rate(sampling_rate / 8);
}
CaptureAppView::~CaptureAppView() {
@@ -97,22 +91,7 @@ void CaptureAppView::set_parent_rect(const Rect new_parent_rect) {
}
void CaptureAppView::focus() {
button_start_stop.focus();
}
void CaptureAppView::on_start_stop() {
if( capture_thread ) {
capture_thread.reset();
button_start_stop.set_bitmap(&bitmap_record);
} else {
const auto filename = next_filename_matching_pattern("BBD_????.C16");
if( filename.empty() ) {
return;
}
capture_thread = std::make_unique<AudioThread>(filename);
button_start_stop.set_bitmap(&bitmap_stop);
}
record_view.focus();
}
void CaptureAppView::on_tuning_frequency_changed(rf::Frequency f) {
+7 -60
View File
@@ -25,61 +25,14 @@
#include "ui_widget.hpp"
#include "ui_navigation.hpp"
#include "ui_receiver.hpp"
#include "ui_record_view.hpp"
#include "ui_spectrum.hpp"
#include "audio_thread.hpp"
#include <string>
#include <memory>
namespace ui {
static constexpr uint8_t bitmap_record_data[] = {
0x00, 0x00,
0x00, 0x00,
0xc0, 0x03,
0xf0, 0x0f,
0xf8, 0x1f,
0xf8, 0x1f,
0xfc, 0x3f,
0xfc, 0x3f,
0xfc, 0x3f,
0xfc, 0x3f,
0xf8, 0x1f,
0xf8, 0x1f,
0xf0, 0x0f,
0xc0, 0x03,
0x00, 0x00,
0x00, 0x00,
};
static constexpr Bitmap bitmap_record {
{ 16, 16 }, bitmap_record_data
};
static constexpr uint8_t bitmap_stop_data[] = {
0x00, 0x00,
0x00, 0x00,
0xfc, 0x3f,
0xfc, 0x3f,
0xfc, 0x3f,
0xfc, 0x3f,
0xfc, 0x3f,
0xfc, 0x3f,
0xfc, 0x3f,
0xfc, 0x3f,
0xfc, 0x3f,
0xfc, 0x3f,
0xfc, 0x3f,
0xfc, 0x3f,
0x00, 0x00,
0x00, 0x00,
};
static constexpr Bitmap bitmap_stop {
{ 16, 16 }, bitmap_stop_data
};
class CaptureAppView : public View {
public:
CaptureAppView(NavigationView& nav);
@@ -94,26 +47,15 @@ public:
std::string title() const override { return "Capture"; };
private:
static constexpr ui::Dim header_height = 2 * 16;
static constexpr ui::Dim header_height = 3 * 16;
static constexpr uint32_t sampling_rate = 4000000;
static constexpr uint32_t baseband_bandwidth = 2500000;
std::unique_ptr<AudioThread> capture_thread;
void on_start_stop();
void on_tuning_frequency_changed(rf::Frequency f);
void on_lna_changed(int32_t v_db);
void on_vga_changed(int32_t v_db);
ImageButton button_start_stop {
{ 0 * 8, 0, 2 * 8, 1 * 16 },
&bitmap_record,
Color::red(),
Color::black()
};
RSSI rssi {
{ 21 * 8, 0, 6 * 8, 4 },
};
@@ -134,6 +76,11 @@ private:
{ 18 * 8, 0 * 16 }
};
RecordView record_view {
{ 0 * 8, 2 * 16, 30 * 8, 1 * 16 },
"BBD_????", RecordView::FileType::RawS16, 14, 1,
};
spectrum::WaterfallWidget waterfall;
};
+122
View File
@@ -0,0 +1,122 @@
/*
* Copyright (C) 2016 Jared Boone, ShareBrained Technology, Inc.
*
* This file is part of PortaPack.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#include "capture_thread.hpp"
#include "portapack_shared_memory.hpp"
// StreamOutput ///////////////////////////////////////////////////////////
class StreamOutput {
public:
StreamOutput(CaptureConfig* const config);
~StreamOutput();
size_t available() {
return fifo->len();
}
size_t read(void* const data, const size_t length) {
return fifo->out(reinterpret_cast<uint8_t*>(data), length);
}
static FIFO<uint8_t>* fifo;
private:
CaptureConfig* const config;
};
FIFO<uint8_t>* StreamOutput::fifo = nullptr;
StreamOutput::StreamOutput(
CaptureConfig* const config
) : config { config }
{
shared_memory.baseband_queue.push_and_wait(
CaptureConfigMessage { config }
);
fifo = config->fifo;
}
StreamOutput::~StreamOutput() {
fifo = nullptr;
shared_memory.baseband_queue.push_and_wait(
CaptureConfigMessage { nullptr }
);
}
// CaptureThread //////////////////////////////////////////////////////////
Thread* CaptureThread::thread = nullptr;
CaptureThread::CaptureThread(
std::unique_ptr<Writer> writer,
size_t write_size_log2,
size_t buffer_count_log2
) : config { write_size_log2, buffer_count_log2 },
writer { std::move(writer) }
{
// Need significant stack for FATFS
thread = chThdCreateFromHeap(NULL, 1024, NORMALPRIO + 10, CaptureThread::static_fn, this);
}
CaptureThread::~CaptureThread() {
if( thread ) {
chThdTerminate(thread);
chEvtSignal(thread, EVT_MASK_CAPTURE_THREAD);
chThdWait(thread);
thread = nullptr;
}
}
void CaptureThread::check_fifo_isr() {
// TODO: Prevent over-signalling by transmitting a set of
// flags from the baseband core.
const auto fifo = StreamOutput::fifo;
if( fifo ) {
chEvtSignalI(thread, EVT_MASK_CAPTURE_THREAD);
}
}
msg_t CaptureThread::run() {
const size_t write_size = 1U << config.write_size_log2;
const auto write_buffer = std::make_unique<uint8_t[]>(write_size);
if( !write_buffer ) {
return false;
}
StreamOutput stream { &config };
while( !chThdShouldTerminate() ) {
if( stream.available() >= write_size ) {
if( stream.read(write_buffer.get(), write_size) != write_size ) {
return false;
}
if( !writer->write(write_buffer.get(), write_size) ) {
return false;
}
} else {
chEvtWaitAny(EVT_MASK_CAPTURE_THREAD);
}
}
return true;
}
+67
View File
@@ -0,0 +1,67 @@
/*
* Copyright (C) 2016 Jared Boone, ShareBrained Technology, Inc.
*
* This file is part of PortaPack.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#ifndef __CAPTURE_THREAD_H__
#define __CAPTURE_THREAD_H__
#include "ch.h"
#include "event_m0.hpp"
#include <cstdint>
#include <cstddef>
#include <utility>
class Writer {
public:
virtual bool write(const void* const buffer, const size_t bytes) = 0;
virtual ~Writer() = default;
};
class CaptureThread {
public:
CaptureThread(
std::unique_ptr<Writer> writer,
size_t write_size_log2,
size_t buffer_count_log2
);
~CaptureThread();
const CaptureConfig& state() const {
return config;
}
static void check_fifo_isr();
private:
CaptureConfig config;
std::unique_ptr<Writer> writer;
static Thread* thread;
static msg_t static_fn(void* arg) {
auto obj = static_cast<CaptureThread*>(arg);
return obj->run();
}
msg_t run();
};
#endif/*__CAPTURE_THREAD_H__*/
+1 -1
View File
@@ -66,7 +66,7 @@ ERTLogger::ERTLogger(
}
void ERTLogger::on_packet(const ert::Packet& packet) {
if( log_file.is_ready() ) {
if( log_file.is_open() ) {
const auto formatted = packet.symbols_formatted();
log_file.write_entry(packet.received_at(), formatted.data + "/" + formatted.errors);
}
+11 -6
View File
@@ -22,16 +22,17 @@
#include "event_m0.hpp"
#include "portapack.hpp"
#include "portapack_persistent_memory.hpp"
#include "portapack_shared_memory.hpp"
#include "sd_card.hpp"
#include "time.hpp"
#include "message.hpp"
#include "message_queue.hpp"
#include "irq_controls.hpp"
#include "audio_thread.hpp"
#include "capture_thread.hpp"
#include "ch.h"
@@ -46,8 +47,8 @@ CH_IRQ_HANDLER(M4Core_IRQHandler) {
CH_IRQ_PROLOGUE();
chSysLockFromIsr();
AudioThread::check_fifo_isr();
EventDispatcher::events_flag_isr(EVT_MASK_APPLICATION);
CaptureThread::check_fifo_isr();
EventDispatcher::check_fifo_isr();
chSysUnlockFromIsr();
creg::m4txevent::clear();
@@ -132,6 +133,10 @@ void EventDispatcher::dispatch(const eventmask_t events) {
handle_lcd_frame_sync();
}
if( events & EVT_MASK_ENCODER ) {
handle_encoder();
}
if( events & EVT_MASK_TOUCH ) {
handle_touch();
}
@@ -158,6 +163,8 @@ void EventDispatcher::handle_rtc_tick() {
else
portapack::bl_tick_counter++;
}
time::on_tick_second();
}
ui::Widget* EventDispatcher::touch_widget(ui::Widget* const w, ui::TouchEvent event) {
@@ -278,6 +285,4 @@ void EventDispatcher::init_message_queues() {
new (&shared_memory.application_queue) MessageQueue(
shared_memory.application_queue_data, SharedMemory::application_queue_k
);
shared_memory.FIFO_HACK = nullptr;
}
+8 -2
View File
@@ -28,6 +28,7 @@
#include "ui_painter.hpp"
#include "portapack.hpp"
#include "portapack_shared_memory.hpp"
#include "message.hpp"
@@ -43,6 +44,7 @@ constexpr auto EVT_MASK_SWITCHES = EVENT_MASK(3);
constexpr auto EVT_MASK_ENCODER = EVENT_MASK(4);
constexpr auto EVT_MASK_TOUCH = EVENT_MASK(5);
constexpr auto EVT_MASK_APPLICATION = EVENT_MASK(6);
constexpr auto EVT_MASK_CAPTURE_THREAD = EVENT_MASK(7);
class EventDispatcher {
public:
@@ -57,6 +59,12 @@ public:
void set_display_sleep(const bool sleep);
static inline void check_fifo_isr() {
if( !shared_memory.application_queue.is_empty() ) {
events_flag_isr(EVT_MASK_APPLICATION);
}
}
static inline void events_flag(const eventmask_t events) {
if( thread_event_loop ) {
chEvtSignal(thread_event_loop, events);
@@ -73,8 +81,6 @@ public:
return message_map_;
}
static Thread* thread_record;
private:
static MessageHandlerMap message_map_;
static Thread* thread_event_loop;
+47 -49
View File
@@ -23,40 +23,32 @@
#include <algorithm>
File::~File() {
close();
}
bool File::open_for_writing(const std::string& file_path) {
const auto open_result = f_open(&f, file_path.c_str(), FA_WRITE | FA_OPEN_ALWAYS);
return (open_result == FR_OK);
}
bool File::open_for_reading(const std::string& file_path) {
const auto open_result = f_open(&f, file_path.c_str(), FA_READ | FA_OPEN_EXISTING);
return (open_result == FR_OK);
}
bool File::open_for_append(const std::string& file_path) {
if( open_for_writing(file_path) ) {
const auto seek_result = f_lseek(&f, f_size(&f));
if( seek_result == FR_OK ) {
return true;
} else {
close();
}
File::File(const std::string& filename, openmode mode) {
BYTE fatfs_mode = 0;
if( mode & openmode::in ) {
fatfs_mode |= FA_READ;
}
if( mode & openmode::out ) {
fatfs_mode |= FA_WRITE;
}
if( mode & openmode::trunc ) {
fatfs_mode |= FA_CREATE_ALWAYS;
}
if( mode & openmode::ate ) {
fatfs_mode |= FA_OPEN_ALWAYS;
}
return false;
if( f_open(&f, filename.c_str(), fatfs_mode) == FR_OK ) {
if( mode & openmode::ate ) {
if( f_lseek(&f, f_size(&f)) != FR_OK ) {
f_close(&f);
}
}
}
}
bool File::close() {
File::~File() {
f_close(&f);
return true;
}
bool File::is_ready() {
return f_error(&f) == 0;
}
bool File::read(void* const data, const size_t bytes_to_read) {
@@ -71,6 +63,17 @@ bool File::write(const void* const data, const size_t bytes_to_write) {
return (result == FR_OK) && (bytes_written == bytes_to_write);
}
uint64_t File::seek(const uint64_t new_position) {
const auto old_position = f_tell(&f);
if( f_lseek(&f, new_position) != FR_OK ) {
f_close(&f);
}
if( f_tell(&f) != new_position ) {
f_close(&f);
}
return old_position;
}
bool File::puts(const std::string& string) {
const auto result = f_puts(string.c_str(), &f);
return (result >= 0);
@@ -94,22 +97,16 @@ static std::string find_last_file_matching_pattern(const std::string& pattern) {
return last_match;
}
static std::string increment_filename_ordinal(const std::string& filename) {
std::string result { filename };
static std::string remove_filename_extension(const std::string& filename) {
const auto extension_index = filename.find_last_of('.');
return filename.substr(0, extension_index);
}
static std::string increment_filename_stem_ordinal(const std::string& filename_stem) {
std::string result { filename_stem };
auto it = result.rbegin();
// Back up past extension.
for(; it != result.rend(); ++it) {
if( *it == '.' ) {
++it;
break;
}
}
if( it == result.rend() ) {
return { };
}
// Increment decimal number before the extension.
for(; it != result.rend(); ++it) {
const auto c = *it;
@@ -128,15 +125,16 @@ static std::string increment_filename_ordinal(const std::string& filename) {
return result;
}
std::string next_filename_matching_pattern(const std::string& filename_pattern) {
auto filename = find_last_file_matching_pattern(filename_pattern);
if( filename.empty() ) {
filename = filename_pattern;
std::replace(std::begin(filename), std::end(filename), '?', '0');
std::string next_filename_stem_matching_pattern(const std::string& filename_stem_pattern) {
const auto filename = find_last_file_matching_pattern(filename_stem_pattern + ".*");
auto filename_stem = remove_filename_extension(filename);
if( filename_stem.empty() ) {
filename_stem = filename_stem_pattern;
std::replace(std::begin(filename_stem), std::end(filename_stem), '?', '0');
} else {
filename = increment_filename_ordinal(filename);
filename_stem = increment_filename_stem_ordinal(filename_stem);
}
return filename;
return filename_stem;
}
namespace std {
+20 -7
View File
@@ -32,18 +32,27 @@
class File {
public:
enum openmode {
app = 0x100,
binary = 0x200,
in = FA_READ,
out = FA_WRITE,
trunc = FA_CREATE_ALWAYS,
ate = FA_OPEN_ALWAYS,
};
File(const std::string& filename, openmode mode);
~File();
bool open_for_writing(const std::string& file_path);
bool open_for_reading(const std::string& file_path);
bool open_for_append(const std::string& file_path);
bool close();
bool is_ready();
bool is_open() const {
return f_error(&f) == 0;
}
bool read(void* const data, const size_t bytes_to_read);
bool write(const void* const data, const size_t bytes_to_write);
uint64_t seek(const uint64_t new_position);
template<size_t N>
bool write(const std::array<uint8_t, N>& data) {
return write(data.data(), N);
@@ -57,7 +66,11 @@ private:
FIL f;
};
std::string next_filename_matching_pattern(const std::string& filename_pattern);
inline constexpr File::openmode operator|(File::openmode a, File::openmode b) {
return File::openmode(static_cast<int>(a) | static_cast<int>(b));
}
std::string next_filename_stem_matching_pattern(const std::string& filename_stem_pattern);
namespace std {
namespace filesystem {
+3 -25
View File
@@ -23,28 +23,14 @@
#include "string_format.hpp"
#include "lpc43xx_cpp.hpp"
using namespace lpc43xx;
LogFile::LogFile(
const std::string& file_path
) : file_path { file_path }
) : file { file_path, File::openmode::out | File::openmode::ate }
{
file.open_for_append(file_path);
sd_card_status_signal_token = sd_card::status_signal += [this](const sd_card::Status status) {
this->on_sd_card_status(status);
};
}
LogFile::~LogFile() {
sd_card::status_signal -= sd_card_status_signal_token;
file.close();
}
bool LogFile::is_ready() {
return file.is_ready();
bool LogFile::is_open() const {
return file.is_open();
}
bool LogFile::write_entry(const rtc::RTC& datetime, const std::string& entry) {
@@ -55,11 +41,3 @@ bool LogFile::write_entry(const rtc::RTC& datetime, const std::string& entry) {
bool LogFile::write(const std::string& message) {
return file.puts(message) && file.sync();
}
void LogFile::on_sd_card_status(const sd_card::Status status) {
if( status == sd_card::Status::Mounted ) {
file.open_for_append(file_path);
} else {
file.close();
}
}
+1 -9
View File
@@ -25,7 +25,6 @@
#include <string>
#include "file.hpp"
#include "sd_card.hpp"
#include "lpc43xx_cpp.hpp"
using namespace lpc43xx;
@@ -33,22 +32,15 @@ using namespace lpc43xx;
class LogFile {
public:
LogFile(const std::string& file_path);
~LogFile();
bool is_ready();
bool is_open() const;
bool write_entry(const rtc::RTC& datetime, const std::string& entry);
private:
const std::string file_path;
File file;
SignalToken sd_card_status_signal_token;
bool write(const std::string& message);
void on_sd_card_status(const sd_card::Status status);
};
#endif/*__LOG_FILE_H__*/
+16 -2
View File
@@ -110,9 +110,23 @@ void init() {
}
/* Configure other pins */
/* Glitch filter operates at 3ns instead of 50ns due to the WM8731
* returning an ACK very fast (170ns) and confusing the I2C state
* machine into thinking there was a bus error. It looks like the
* MCU sees SDA fall before SCL falls, indicating a START at the
* point an ACK is expected. With the glitch filter off or set to
* 3ns, it's probably still a bit tight timing-wise, but improves
* reliability on some problem units.
*/
LPC_SCU->SFSI2C0 =
(1U << 3)
| (1U << 11)
(1U << 0) // SCL: 3ns glitch
| (0U << 2) // SCL: Standard/Fast mode
| (1U << 3) // SCL: Input enabled
| (0U << 7) // SCL: Enable input glitch filter
| (1U << 8) // SDA: 3ns glitch
| (0U << 10) // SDA: Standard/Fast mode
| (1U << 11) // SDA: Input enabled
| (0U << 15) // SDA: Enable input glitch filter
;
power.init();
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2016 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
*
* This file is part of PortaPack.
*
@@ -19,6 +19,14 @@
* Boston, MA 02110-1301, USA.
*/
#include "audio_thread.hpp"
#include "time.hpp"
Thread* AudioThread::thread = nullptr;
namespace time {
Signal<> signal_tick_second;
void on_tick_second() {
signal_tick_second.emit();
}
} /* namespace time */
+35
View File
@@ -0,0 +1,35 @@
/*
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
*
* This file is part of PortaPack.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#ifndef __TIME_H__
#define __TIME_H__
#include "signal.hpp"
namespace time {
extern Signal<> signal_tick_second;
void on_tick_second();
} /* namespace time */
#endif/*__TIME_H__*/
+1 -1
View File
@@ -62,7 +62,7 @@ TPMSLogger::TPMSLogger(
void TPMSLogger::on_packet(const tpms::Packet& packet, const uint32_t target_frequency) {
const auto hex_formatted = packet.symbols_formatted();
if( log_file.is_ready() ) {
if( log_file.is_open() ) {
// TODO: function doesn't take uint64_t, so when >= 1<<32, weirdness will ensue!
const auto tuning_frequency_str = to_string_dec_uint(target_frequency, 10);
+1 -1
View File
@@ -34,7 +34,7 @@ namespace ui {
class Audio : public Widget {
public:
constexpr Audio(
Audio(
const Rect parent_rect
) : Widget { parent_rect },
rms_db_ { -120 },
+1 -1
View File
@@ -34,7 +34,7 @@ namespace ui {
class Channel : public Widget {
public:
constexpr Channel(
Channel(
const Rect parent_rect
) : Widget { parent_rect },
max_db_ { -120 }
+1 -1
View File
@@ -84,7 +84,7 @@ private:
class TemperatureWidget : public Widget {
public:
explicit constexpr TemperatureWidget(
explicit TemperatureWidget(
Rect parent_rect
) : Widget { parent_rect }
{
+3 -3
View File
@@ -90,12 +90,12 @@ void SystemStatusView::set_title(const std::string new_value) {
}
void SystemStatusView::on_camera() {
const auto filename = next_filename_matching_pattern("SCR_????.PNG");
if( filename.empty() ) {
const auto filename_stem = next_filename_stem_matching_pattern("SCR_????");
if( filename_stem.empty() ) {
return;
}
PNGWriter png { filename };
PNGWriter png { filename_stem + ".PNG" };
for(int i=0; i<320; i++) {
std::array<ColorRGB888, 240> row;
+2 -46
View File
@@ -32,57 +32,13 @@
#include "ui_audio.hpp"
#include "ui_sd_card_status_view.hpp"
#include "bitmap.hpp"
#include <vector>
#include <utility>
namespace ui {
static constexpr uint8_t bitmap_sleep_data[] = {
0x00, 0x00,
0x00, 0x00,
0x00, 0x04,
0x00, 0x08,
0x00, 0x18,
0x00, 0x18,
0x00, 0x38,
0x00, 0x3c,
0x00, 0x3c,
0x00, 0x3e,
0x84, 0x1f,
0xf8, 0x1f,
0xf0, 0x0f,
0xc0, 0x03,
0x00, 0x00,
0x00, 0x00,
};
static constexpr Bitmap bitmap_sleep {
{ 16, 16 }, bitmap_sleep_data
};
static constexpr uint8_t bitmap_camera_data[] = {
0x00, 0x00,
0x00, 0x00,
0x00, 0x00,
0xcc, 0x03,
0xe8, 0x07,
0xfc, 0x3f,
0x3c, 0x3c,
0x9c, 0x39,
0xdc, 0x3b,
0xdc, 0x3b,
0x9c, 0x39,
0x3c, 0x3c,
0xfc, 0x3f,
0x00, 0x00,
0x00, 0x00,
0x00, 0x00,
};
static constexpr Bitmap bitmap_camera {
{ 16, 16 }, bitmap_camera_data
};
class SystemStatusView : public View {
public:
std::function<void(void)> on_back;
+251
View File
@@ -0,0 +1,251 @@
/*
* Copyright (C) 2016 Jared Boone, ShareBrained Technology, Inc.
*
* This file is part of PortaPack.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#include "ui_record_view.hpp"
#include "portapack.hpp"
using namespace portapack;
#include "file.hpp"
#include "time.hpp"
#include "string_format.hpp"
#include "utility.hpp"
#include <cstdint>
class RawFileWriter : public Writer {
public:
RawFileWriter(
const std::string& filename
) : file { filename, File::openmode::out | File::openmode::binary | File::openmode::trunc }
{
}
bool write(const void* const buffer, const size_t bytes) override {
return file.write(buffer, bytes);
}
private:
File file;
};
class WAVFileWriter : public Writer {
public:
WAVFileWriter(
const std::string& filename,
size_t sampling_rate
) : file { filename, File::openmode::out | File::openmode::binary | File::openmode::trunc },
header { sampling_rate }
{
update_header();
}
~WAVFileWriter() {
update_header();
}
bool write(const void* const buffer, const size_t bytes) override {
const auto success = file.write(buffer, bytes) ;
if( success ) {
bytes_written += bytes;
}
return success;
}
private:
struct fmt_pcm_t {
constexpr fmt_pcm_t(
const uint32_t sampling_rate
) : nSamplesPerSec { sampling_rate },
nAvgBytesPerSec { nSamplesPerSec * nBlockAlign }
{
}
private:
const uint8_t ckID[4] { 'f', 'm', 't', ' ' };
const uint32_t cksize { 16 };
const uint16_t wFormatTag { 0x0001 };
const uint16_t nChannels { 1 };
const uint32_t nSamplesPerSec;
const uint32_t nAvgBytesPerSec;
const uint16_t nBlockAlign { 2 };
const uint16_t wBitsPerSample { 16 };
};
struct data_t {
void set_size(const uint32_t value) {
cksize = value;
}
private:
const uint8_t ckID[4] { 'd', 'a', 't', 'a' };
uint32_t cksize { 0 };
};
struct header_t {
constexpr header_t(
const uint32_t sampling_rate
) : fmt { sampling_rate }
{
}
void set_data_size(const uint32_t value) {
data.set_size(value);
cksize = sizeof(header_t) + value - 8;
}
private:
const uint8_t riff_id[4] { 'R', 'I', 'F', 'F' };
uint32_t cksize { 0 };
const uint8_t wave_id[4] { 'W', 'A', 'V', 'E' };
fmt_pcm_t fmt;
data_t data;
};
File file;
header_t header;
uint64_t bytes_written { 0 };
void update_header() {
header.set_data_size(bytes_written);
const auto old_position = file.seek(0);
file.write(&header, sizeof(header));
file.seek(old_position);
}
};
namespace ui {
RecordView::RecordView(
const Rect parent_rect,
std::string filename_stem_pattern,
const FileType file_type,
const size_t buffer_size_k,
const size_t buffer_count_k
) : View { parent_rect },
filename_stem_pattern { filename_stem_pattern },
file_type { file_type },
buffer_size_k { buffer_size_k },
buffer_count_k { buffer_count_k }
{
add_children({ {
&button_record,
&text_record_filename,
&text_record_dropped,
} });
button_record.on_select = [this](ImageButton&) {
this->toggle();
};
signal_token_tick_second = time::signal_tick_second += [this]() {
this->on_tick_second();
};
}
RecordView::~RecordView() {
time::signal_tick_second -= signal_token_tick_second;
}
void RecordView::focus() {
button_record.focus();
}
bool RecordView::is_active() const {
return (bool)capture_thread;
}
void RecordView::toggle() {
if( is_active() ) {
stop();
} else {
start();
}
}
void RecordView::start() {
stop();
text_record_filename.set("");
text_record_dropped.set("");
if( sampling_rate == 0 ) {
return;
}
const auto filename_stem = next_filename_stem_matching_pattern(filename_stem_pattern);
if( filename_stem.empty() ) {
return;
}
std::unique_ptr<Writer> writer;
switch(file_type) {
case FileType::WAV:
writer = std::make_unique<WAVFileWriter>(
filename_stem + ".WAV",
sampling_rate
);
break;
case FileType::RawS16:
write_metadata_file(filename_stem + ".TXT");
writer = std::make_unique<RawFileWriter>(
filename_stem + ".C16"
);
break;
default:
break;
};
if( writer ) {
text_record_filename.set(filename_stem);
button_record.set_bitmap(&bitmap_stop);
capture_thread = std::make_unique<CaptureThread>(
std::move(writer),
buffer_size_k, buffer_count_k
);
}
}
void RecordView::stop() {
if( is_active() ) {
capture_thread.reset();
button_record.set_bitmap(&bitmap_record);
}
}
void RecordView::write_metadata_file(const std::string& filename) {
File file { filename, File::openmode::out | File::openmode::trunc };
file.puts("sample_rate=" + to_string_dec_uint(sampling_rate) + "\n");
file.puts("center_frequency=" + to_string_dec_uint(receiver_model.tuning_frequency()) + "\n");
}
void RecordView::on_tick_second() {
if( is_active() ) {
const auto dropped_percent = std::min(99U, capture_thread->state().dropped_percent());
const auto s = to_string_dec_uint(dropped_percent, 2, ' ') + "\%";
text_record_dropped.set(s);
}
}
} /* namespace ui */
+103
View File
@@ -0,0 +1,103 @@
/*
* Copyright (C) 2016 Jared Boone, ShareBrained Technology, Inc.
*
* This file is part of PortaPack.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#ifndef __UI_RECORD_VIEW_H__
#define __UI_RECORD_VIEW_H__
#include "ui_widget.hpp"
#include "capture_thread.hpp"
#include "signal.hpp"
#include "bitmap.hpp"
#include <cstddef>
#include <string>
#include <memory>
namespace ui {
class RecordView : public View {
public:
enum FileType {
RawS16 = 2,
WAV = 3,
};
RecordView(
const Rect parent_rect,
std::string filename_stem_pattern,
FileType file_type,
const size_t buffer_size_k,
const size_t buffer_count_k
);
~RecordView();
void focus() override;
void set_sampling_rate(const size_t new_sampling_rate) {
if( new_sampling_rate != sampling_rate ) {
stop();
sampling_rate = new_sampling_rate;
}
}
void start();
void stop();
bool is_active() const;
private:
void toggle();
void write_metadata_file(const std::string& filename);
void on_tick_second();
const std::string filename_stem_pattern;
const FileType file_type;
const size_t buffer_size_k;
const size_t buffer_count_k;
size_t sampling_rate { 0 };
SignalToken signal_token_tick_second;
ImageButton button_record {
{ 0 * 8, 0 * 16, 2 * 8, 1 * 16 },
&bitmap_record,
Color::red(),
Color::black()
};
Text text_record_filename {
{ 3 * 8, 0 * 16, 8 * 8, 16 },
"",
};
Text text_record_dropped {
{ 16 * 8, 0 * 16, 3 * 8, 16 },
"",
};
std::unique_ptr<CaptureThread> capture_thread;
};
} /* namespace ui */
#endif/*__UI_RECORD_VIEW_H__*/
+1 -1
View File
@@ -34,7 +34,7 @@ namespace ui {
class RSSI : public Widget {
public:
constexpr RSSI(
RSSI(
const Rect parent_rect
) : Widget { parent_rect },
min_ { 0 },
+8 -8
View File
@@ -133,15 +133,15 @@ private:
return Result::FailHeap;
}
File file;
if( !file.open_for_writing(filename) ) {
File file { filename, File::openmode::out | File::openmode::binary | File::openmode::trunc };
if( !file.is_open() ) {
return Result::FailFileOpenWrite;
}
lfsr_word_t v = 1;
const halrtcnt_t test_start = halGetCounterValue();
while( !chThdShouldTerminate() && file.is_ready() && (_stats.write_bytes < bytes_to_write) ) {
while( !chThdShouldTerminate() && file.is_open() && (_stats.write_bytes < bytes_to_write) ) {
lfsr_fill(v,
reinterpret_cast<lfsr_word_t*>(buffer->data()),
sizeof(*buffer.get()) / sizeof(lfsr_word_t)
@@ -164,7 +164,7 @@ private:
}
}
file.close();
file.sync();
const halrtcnt_t test_end = halGetCounterValue();
_stats.write_test_duration = test_end - test_start;
@@ -178,15 +178,15 @@ private:
return Result::FailHeap;
}
File file;
if( !file.open_for_reading(filename) ) {
File file { filename, File::openmode::in | File::openmode::binary };
if( !file.is_open() ) {
return Result::FailFileOpenRead;
}
lfsr_word_t v = 1;
const halrtcnt_t test_start = halGetCounterValue();
while( !chThdShouldTerminate() && file.is_ready() && (_stats.read_bytes < bytes_to_read) ) {
while( !chThdShouldTerminate() && file.is_open() && (_stats.read_bytes < bytes_to_read) ) {
const halrtcnt_t read_start = halGetCounterValue();
if( !file.read(buffer->data(), buffer->size()) ) {
break;
@@ -211,7 +211,7 @@ private:
}
}
file.close();
file.sync();
const halrtcnt_t test_end = halGetCounterValue();
_stats.read_test_duration = test_end - test_start;
@@ -24,45 +24,14 @@
#include <string>
#include <algorithm>
#include "bitmap.hpp"
namespace ui {
/* SDCardStatusView *****************************************************/
namespace detail {
static constexpr uint8_t bitmap_sd_card_ok_data[] = {
0x00, 0x00, 0x00, 0x00, 0xe0, 0x1f, 0xf0, 0x1f,
0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f,
0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f,
0xf8, 0x1f, 0xf8, 0x1f, 0x00, 0x00, 0x00, 0x00,
};
static constexpr Bitmap bitmap_sd_card_ok {
{ 16, 16 }, bitmap_sd_card_ok_data
};
static constexpr uint8_t bitmap_sd_card_unknown_data[] = {
0x00, 0x00, 0x00, 0x00, 0xe0, 0x1f, 0xf0, 0x1f,
0x38, 0x1c, 0x98, 0x19, 0xf8, 0x19, 0xf8, 0x1c,
0x78, 0x1e, 0x78, 0x1e, 0xf8, 0x1f, 0x78, 0x1e,
0xf8, 0x1f, 0xf8, 0x1f, 0x00, 0x00, 0x00, 0x00,
};
static constexpr Bitmap bitmap_sd_card_unknown {
{ 16, 16 }, bitmap_sd_card_unknown_data
};
static constexpr uint8_t bitmap_sd_card_error_data[] = {
0x00, 0x00, 0x00, 0x00, 0xe0, 0x1f, 0xf0, 0x1f,
0xf8, 0x1f, 0xd8, 0x1b, 0x98, 0x19, 0x38, 0x1c,
0x78, 0x1e, 0x38, 0x1c, 0x98, 0x19, 0xd8, 0x1b,
0xf8, 0x1f, 0xf8, 0x1f, 0x00, 0x00, 0x00, 0x00,
};
static constexpr Bitmap bitmap_sd_card_error {
{ 16, 16 }, bitmap_sd_card_error_data
};
const Bitmap& bitmap_sd_card(const sd_card::Status status) {
switch(status) {
case sd_card::Status::IOError:
@@ -113,7 +82,7 @@ const Color color_sd_card(const sd_card::Status status) {
SDCardStatusView::SDCardStatusView(
const Rect parent_rect
) : Image { parent_rect, &detail::bitmap_sd_card_unknown, detail::color_sd_card_unknown, Color::black() }
) : Image { parent_rect, &bitmap_sd_card_unknown, detail::color_sd_card_unknown, Color::black() }
{
}
+2 -1
View File
@@ -114,6 +114,7 @@ void FrequencyScale::draw_frequency_ticks(Painter& painter, const Rect r) {
(magnitude_n >= 6) ? "M" :
(magnitude_n >= 3) ? "k" : "";
const std::string label = to_string_dec_uint(tick_offset) + zero_pad + unit;
const auto label_width = style().font.size_of(label).w;
const Coord offset_low = r.left() + x_center - pixel_offset;
const Rect tick_low { offset_low, r.top(), 1, r.height() };
@@ -123,7 +124,7 @@ void FrequencyScale::draw_frequency_ticks(Painter& painter, const Rect r) {
const Coord offset_high = r.left() + x_center + pixel_offset;
const Rect tick_high { offset_high, r.top(), 1, r.height() };
painter.fill_rectangle(tick_high, Color::white());
painter.draw_string({ offset_high + 2, r.top() }, style(), label );
painter.draw_string({ offset_high - 2 - label_width, r.top() }, style(), label );
tick_offset += tick_interval;
}