mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-10-01 01:26:06 -04:00
Touch: Migrate touch calibration to persistent memory.
This commit is contained in:
parent
aa1b8f63fc
commit
c424bf08f3
@ -21,6 +21,9 @@
|
||||
|
||||
#include "touch.hpp"
|
||||
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
using namespace portapack;
|
||||
|
||||
#include "utility.hpp"
|
||||
|
||||
namespace touch {
|
||||
@ -76,25 +79,13 @@ ui::Point Calibration::translate(const DigitizerPoint& p) const {
|
||||
};
|
||||
}
|
||||
|
||||
static const Calibration _default_calibration {
|
||||
const Calibration default_calibration() {
|
||||
/* Values derived from one PortaPack H1 unit. */
|
||||
return {
|
||||
{ { { 256, 731 }, { 880, 432 }, { 568, 146 } } },
|
||||
{ { { 32, 48 }, { 208, 168 }, { 120, 288 } } }
|
||||
};
|
||||
|
||||
static Calibration _calibration = _default_calibration;
|
||||
|
||||
void set_calibration(const Calibration& value) {
|
||||
_calibration = value;
|
||||
}
|
||||
|
||||
const Calibration& calibration() {
|
||||
return _calibration;
|
||||
}
|
||||
|
||||
const Calibration& default_calibration() {
|
||||
return _default_calibration;
|
||||
}
|
||||
};
|
||||
|
||||
void Manager::feed(const Frame& frame) {
|
||||
// touch_debounce.feed(touch_raw);
|
||||
@ -145,7 +136,7 @@ void Manager::feed(const Frame& frame) {
|
||||
}
|
||||
|
||||
ui::Point Manager::filtered_point() const {
|
||||
return calibration().translate({ filter_x.value(), filter_y.value() });
|
||||
return persistent_memory::touch_calibration().translate({ filter_x.value(), filter_y.value() });
|
||||
}
|
||||
|
||||
} /* namespace touch */
|
||||
|
@ -149,9 +149,7 @@ private:
|
||||
int32_t f;
|
||||
};
|
||||
|
||||
void set_calibration(const Calibration& calibration);
|
||||
const Calibration& calibration();
|
||||
const Calibration& default_calibration();
|
||||
const Calibration default_calibration();
|
||||
|
||||
template<size_t N>
|
||||
class Filter {
|
||||
|
@ -23,6 +23,9 @@
|
||||
|
||||
#include "irq_controls.hpp"
|
||||
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
using namespace portapack;
|
||||
|
||||
namespace ui {
|
||||
|
||||
TouchCalibrationView::TouchCalibrationView(
|
||||
@ -151,7 +154,7 @@ void TouchCalibrationView::touch_complete() {
|
||||
|
||||
void TouchCalibrationView::on_ok() {
|
||||
if( phase == Phase::Success ) {
|
||||
touch::set_calibration(calibration);
|
||||
persistent_memory::set_touch_calibration(calibration);
|
||||
nav.pop();
|
||||
}
|
||||
if( phase == Phase::Failure ) {
|
||||
|
@ -46,6 +46,8 @@ constexpr ppb_t ppb_reset_value { 0 };
|
||||
struct data_t {
|
||||
int64_t tuned_frequency;
|
||||
int32_t correction_ppb;
|
||||
uint32_t touch_calibration_magic;
|
||||
touch::Calibration touch_calibration;
|
||||
};
|
||||
|
||||
static_assert(sizeof(data_t) <= backup_ram.size(), "Persistent memory structure too large for VBAT-maintained region");
|
||||
@ -72,5 +74,19 @@ void set_correction_ppb(const ppb_t new_value) {
|
||||
portapack::clock_manager.set_reference_ppb(clipped_value);
|
||||
}
|
||||
|
||||
static constexpr uint32_t touch_calibration_magic = 0x074af82f;
|
||||
|
||||
void set_touch_calibration(const touch::Calibration& new_value) {
|
||||
data->touch_calibration = new_value;
|
||||
data->touch_calibration_magic = touch_calibration_magic;
|
||||
}
|
||||
|
||||
const touch::Calibration& touch_calibration() {
|
||||
if( data->touch_calibration_magic != touch_calibration_magic ) {
|
||||
set_touch_calibration(touch::default_calibration());
|
||||
}
|
||||
return data->touch_calibration;
|
||||
}
|
||||
|
||||
} /* namespace persistent_memory */
|
||||
} /* namespace portapack */
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include <cstdint>
|
||||
|
||||
#include "rf_path.hpp"
|
||||
#include "touch.hpp"
|
||||
|
||||
namespace portapack {
|
||||
namespace persistent_memory {
|
||||
@ -37,6 +38,9 @@ void set_tuned_frequency(const rf::Frequency new_value);
|
||||
ppb_t correction_ppb();
|
||||
void set_correction_ppb(const ppb_t new_value);
|
||||
|
||||
void set_touch_calibration(const touch::Calibration& new_value);
|
||||
const touch::Calibration& touch_calibration();
|
||||
|
||||
} /* namespace persistent_memory */
|
||||
} /* namespace portapack */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user