kopia lustrzana https://gitlab.com/sane-project/backends
Merge branch 'genesys-fix-warnings' into 'master'
genesys: Fix warnings See merge request sane-project/backends!211merge-requests/212/merge
commit
6638f00b84
|
@ -45,7 +45,7 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
void Genesys_Buffer::alloc(size_t size)
|
void Genesys_Buffer::alloc(std::size_t size)
|
||||||
{
|
{
|
||||||
buffer_.resize(size);
|
buffer_.resize(size);
|
||||||
avail_ = 0;
|
avail_ = 0;
|
||||||
|
@ -65,7 +65,7 @@ void Genesys_Buffer::reset()
|
||||||
pos_ = 0;
|
pos_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t* Genesys_Buffer::get_write_pos(size_t size)
|
std::uint8_t* Genesys_Buffer::get_write_pos(std::size_t size)
|
||||||
{
|
{
|
||||||
if (avail_ + size > buffer_.size())
|
if (avail_ + size > buffer_.size())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -77,19 +77,19 @@ uint8_t* Genesys_Buffer::get_write_pos(size_t size)
|
||||||
return buffer_.data() + pos_ + avail_;
|
return buffer_.data() + pos_ + avail_;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t* Genesys_Buffer::get_read_pos()
|
std::uint8_t* Genesys_Buffer::get_read_pos()
|
||||||
{
|
{
|
||||||
return buffer_.data() + pos_;
|
return buffer_.data() + pos_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Genesys_Buffer::produce(size_t size)
|
void Genesys_Buffer::produce(std::size_t size)
|
||||||
{
|
{
|
||||||
if (size > buffer_.size() - avail_)
|
if (size > buffer_.size() - avail_)
|
||||||
throw std::runtime_error("buffer size exceeded");
|
throw std::runtime_error("buffer size exceeded");
|
||||||
avail_ += size;
|
avail_ += size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Genesys_Buffer::consume(size_t size)
|
void Genesys_Buffer::consume(std::size_t size)
|
||||||
{
|
{
|
||||||
if (size > avail_)
|
if (size > avail_)
|
||||||
throw std::runtime_error("no more data in buffer");
|
throw std::runtime_error("no more data in buffer");
|
||||||
|
|
|
@ -56,30 +56,30 @@ struct Genesys_Buffer
|
||||||
{
|
{
|
||||||
Genesys_Buffer() = default;
|
Genesys_Buffer() = default;
|
||||||
|
|
||||||
size_t size() const { return buffer_.size(); }
|
std::size_t size() const { return buffer_.size(); }
|
||||||
size_t avail() const { return avail_; }
|
std::size_t avail() const { return avail_; }
|
||||||
size_t pos() const { return pos_; }
|
std::size_t pos() const { return pos_; }
|
||||||
|
|
||||||
// TODO: refactor code that uses this function to no longer use it
|
// TODO: refactor code that uses this function to no longer use it
|
||||||
void set_pos(size_t pos) { pos_ = pos; }
|
void set_pos(std::size_t pos) { pos_ = pos; }
|
||||||
|
|
||||||
void alloc(size_t size);
|
void alloc(std::size_t size);
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
uint8_t* get_write_pos(size_t size);
|
std::uint8_t* get_write_pos(std::size_t size);
|
||||||
uint8_t* get_read_pos(); // TODO: mark as const
|
std::uint8_t* get_read_pos(); // TODO: mark as const
|
||||||
|
|
||||||
void produce(size_t size);
|
void produce(std::size_t size);
|
||||||
void consume(size_t size);
|
void consume(std::size_t size);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<uint8_t> buffer_;
|
std::vector<std::uint8_t> buffer_;
|
||||||
// current position in read buffer
|
// current position in read buffer
|
||||||
size_t pos_ = 0;
|
std::size_t pos_ = 0;
|
||||||
// data bytes currently in buffer
|
// data bytes currently in buffer
|
||||||
size_t avail_ = 0;
|
std::size_t avail_ = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BACKEND_GENESYS_BUFFER_H
|
#endif // BACKEND_GENESYS_BUFFER_H
|
||||||
|
|
|
@ -46,6 +46,7 @@
|
||||||
|
|
||||||
#include "sensor.h"
|
#include "sensor.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
struct Genesys_Calibration_Cache
|
struct Genesys_Calibration_Cache
|
||||||
{
|
{
|
||||||
|
@ -55,7 +56,7 @@ struct Genesys_Calibration_Cache
|
||||||
// used to check if entry is compatible
|
// used to check if entry is compatible
|
||||||
Genesys_Current_Setup used_setup;
|
Genesys_Current_Setup used_setup;
|
||||||
SetupParams params;
|
SetupParams params;
|
||||||
time_t last_calibration = 0;
|
std::time_t last_calibration = 0;
|
||||||
|
|
||||||
Genesys_Frontend frontend;
|
Genesys_Frontend frontend;
|
||||||
Genesys_Sensor sensor;
|
Genesys_Sensor sensor;
|
||||||
|
@ -63,8 +64,8 @@ struct Genesys_Calibration_Cache
|
||||||
size_t calib_pixels = 0;
|
size_t calib_pixels = 0;
|
||||||
size_t calib_channels = 0;
|
size_t calib_channels = 0;
|
||||||
size_t average_size = 0;
|
size_t average_size = 0;
|
||||||
std::vector<uint16_t> white_average_data;
|
std::vector<std::uint16_t> white_average_data;
|
||||||
std::vector<uint16_t> dark_average_data;
|
std::vector<std::uint16_t> dark_average_data;
|
||||||
|
|
||||||
bool operator==(const Genesys_Calibration_Cache& other) const
|
bool operator==(const Genesys_Calibration_Cache& other) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -79,7 +79,7 @@ public:
|
||||||
|
|
||||||
virtual bool test_buffer_empty_bit(std::uint8_t val) const = 0;
|
virtual bool test_buffer_empty_bit(std::uint8_t val) const = 0;
|
||||||
|
|
||||||
virtual void set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t set) const = 0;
|
virtual void set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, std::uint8_t set) const = 0;
|
||||||
virtual void set_powersaving(Genesys_Device* dev, int delay) const = 0;
|
virtual void set_powersaving(Genesys_Device* dev, int delay) const = 0;
|
||||||
virtual void save_power(Genesys_Device* dev, bool enable) const = 0;
|
virtual void save_power(Genesys_Device* dev, bool enable) const = 0;
|
||||||
|
|
||||||
|
@ -107,9 +107,9 @@ public:
|
||||||
|
|
||||||
virtual bool has_rewind() const { return true; }
|
virtual bool has_rewind() const { return true; }
|
||||||
|
|
||||||
virtual void bulk_write_data(Genesys_Device* dev, uint8_t addr, uint8_t* data,
|
virtual void bulk_write_data(Genesys_Device* dev, std::uint8_t addr, std::uint8_t* data,
|
||||||
size_t len) const = 0;
|
size_t len) const = 0;
|
||||||
virtual void bulk_read_data(Genesys_Device * dev, uint8_t addr, uint8_t* data,
|
virtual void bulk_read_data(Genesys_Device * dev, std::uint8_t addr, std::uint8_t* data,
|
||||||
size_t len) const = 0;
|
size_t len) const = 0;
|
||||||
|
|
||||||
// Updates hardware sensor information in Genesys_Scanner.val[].
|
// Updates hardware sensor information in Genesys_Scanner.val[].
|
||||||
|
@ -142,7 +142,7 @@ public:
|
||||||
|
|
||||||
/// write shading data calibration to ASIC
|
/// write shading data calibration to ASIC
|
||||||
virtual void send_shading_data(Genesys_Device* dev, const Genesys_Sensor& sensor,
|
virtual void send_shading_data(Genesys_Device* dev, const Genesys_Sensor& sensor,
|
||||||
uint8_t* data, int size) const = 0;
|
std::uint8_t* data, int size) const = 0;
|
||||||
|
|
||||||
virtual bool has_send_shading_data() const
|
virtual bool has_send_shading_data() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -54,6 +54,7 @@
|
||||||
#include "sensor.h"
|
#include "sensor.h"
|
||||||
#include "register.h"
|
#include "register.h"
|
||||||
#include "sanei.h"
|
#include "sanei.h"
|
||||||
|
#include <cstdio>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
struct Genesys_Gpo
|
struct Genesys_Gpo
|
||||||
|
@ -266,7 +267,7 @@ struct Genesys_Device
|
||||||
|
|
||||||
Genesys_Gpo gpo;
|
Genesys_Gpo gpo;
|
||||||
Genesys_Motor motor;
|
Genesys_Motor motor;
|
||||||
uint8_t control[6] = {};
|
std::uint8_t control[6] = {};
|
||||||
|
|
||||||
size_t average_size = 0;
|
size_t average_size = 0;
|
||||||
// number of pixels used during shading calibration
|
// number of pixels used during shading calibration
|
||||||
|
@ -288,10 +289,10 @@ struct Genesys_Device
|
||||||
|
|
||||||
// gamma overrides. If a respective array is not empty then it means that the gamma for that
|
// gamma overrides. If a respective array is not empty then it means that the gamma for that
|
||||||
// color is overridden.
|
// color is overridden.
|
||||||
std::vector<uint16_t> gamma_override_tables[3];
|
std::vector<std::uint16_t> gamma_override_tables[3];
|
||||||
|
|
||||||
std::vector<uint16_t> white_average_data;
|
std::vector<std::uint16_t> white_average_data;
|
||||||
std::vector<uint16_t> dark_average_data;
|
std::vector<std::uint16_t> dark_average_data;
|
||||||
|
|
||||||
bool already_initialized = false;
|
bool already_initialized = false;
|
||||||
SANE_Int scanhead_position_in_steps = 0;
|
SANE_Int scanhead_position_in_steps = 0;
|
||||||
|
@ -353,10 +354,10 @@ struct Genesys_Device
|
||||||
bool buffer_image = false;
|
bool buffer_image = false;
|
||||||
|
|
||||||
// image buffer where the scanned picture is stored
|
// image buffer where the scanned picture is stored
|
||||||
std::vector<uint8_t> img_buffer;
|
std::vector<std::uint8_t> img_buffer;
|
||||||
|
|
||||||
// binary logger file
|
// binary logger file
|
||||||
FILE *binary = nullptr;
|
std::FILE *binary = nullptr;
|
||||||
|
|
||||||
// A snapshot of the last known physical state of the device registers. This variable is updated
|
// A snapshot of the last known physical state of the device registers. This variable is updated
|
||||||
// whenever a register is written or read to the scanner.
|
// whenever a register is written or read to the scanner.
|
||||||
|
@ -364,12 +365,12 @@ struct Genesys_Device
|
||||||
|
|
||||||
ImagePipelineNodeBytesSource& get_pipeline_source();
|
ImagePipelineNodeBytesSource& get_pipeline_source();
|
||||||
|
|
||||||
uint8_t read_register(uint16_t address);
|
std::uint8_t read_register(std::uint16_t address);
|
||||||
void write_register(uint16_t address, uint8_t value);
|
void write_register(std::uint16_t address, std::uint8_t value);
|
||||||
void write_registers(Genesys_Register_Set& regs);
|
void write_registers(Genesys_Register_Set& regs);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void update_register_state(uint16_t address, uint8_t value);
|
void update_register_state(std::uint16_t address, std::uint8_t value);
|
||||||
};
|
};
|
||||||
|
|
||||||
void apply_reg_settings_to_device(Genesys_Device& dev, const GenesysRegisterSettingSet& regs);
|
void apply_reg_settings_to_device(Genesys_Device& dev, const GenesysRegisterSettingSet& regs);
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
extern "C" void sanei_debug_msg(int level, int max_level, const char *be, const char *fmt,
|
extern "C" void sanei_debug_msg(int level, int max_level, const char *be, const char *fmt,
|
||||||
va_list ap);
|
std::va_list ap);
|
||||||
|
|
||||||
#if (defined(__GNUC__) || defined(__CLANG__)) && (defined(__linux__) || defined(__APPLE__))
|
#if (defined(__GNUC__) || defined(__CLANG__)) && (defined(__linux__) || defined(__APPLE__))
|
||||||
extern "C" char* __cxa_get_globals();
|
extern "C" char* __cxa_get_globals();
|
||||||
|
|
|
@ -52,6 +52,7 @@
|
||||||
#include <cstdarg>
|
#include <cstdarg>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <new>
|
||||||
|
|
||||||
#define DBG_error0 0 /* errors/warnings printed even with devuglevel 0 */
|
#define DBG_error0 0 /* errors/warnings printed even with devuglevel 0 */
|
||||||
#define DBG_error 1 /* fatal errors */
|
#define DBG_error 1 /* fatal errors */
|
||||||
|
@ -137,6 +138,7 @@ SANE_Status wrap_exceptions_to_status_code(const char* func, F&& function)
|
||||||
} catch (const SaneException& exc) {
|
} catch (const SaneException& exc) {
|
||||||
return exc.status();
|
return exc.status();
|
||||||
} catch (const std::bad_alloc& exc) {
|
} catch (const std::bad_alloc& exc) {
|
||||||
|
(void) exc;
|
||||||
return SANE_STATUS_NO_MEM;
|
return SANE_STATUS_NO_MEM;
|
||||||
} catch (const std::exception& exc) {
|
} catch (const std::exception& exc) {
|
||||||
DBG(DBG_error, "%s: got uncaught exception: %s\n", func, exc.what());
|
DBG(DBG_error, "%s: got uncaught exception: %s\n", func, exc.what());
|
||||||
|
|
|
@ -70,6 +70,7 @@
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <iterator>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
@ -3833,7 +3834,6 @@ static void init_options(Genesys_Scanner* s)
|
||||||
s->opt[OPT_BIT_DEPTH].type = SANE_TYPE_INT;
|
s->opt[OPT_BIT_DEPTH].type = SANE_TYPE_INT;
|
||||||
s->opt[OPT_BIT_DEPTH].constraint_type = SANE_CONSTRAINT_WORD_LIST;
|
s->opt[OPT_BIT_DEPTH].constraint_type = SANE_CONSTRAINT_WORD_LIST;
|
||||||
s->opt[OPT_BIT_DEPTH].size = sizeof (SANE_Word);
|
s->opt[OPT_BIT_DEPTH].size = sizeof (SANE_Word);
|
||||||
s->opt[OPT_BIT_DEPTH].constraint.word_list = 0;
|
|
||||||
s->opt[OPT_BIT_DEPTH].constraint.word_list = s->bpp_list;
|
s->opt[OPT_BIT_DEPTH].constraint.word_list = s->bpp_list;
|
||||||
create_bpp_list (s, model->bpp_gray_values);
|
create_bpp_list (s, model->bpp_gray_values);
|
||||||
s->bit_depth = model->bpp_gray_values[0];
|
s->bit_depth = model->bpp_gray_values[0];
|
||||||
|
|
|
@ -1771,7 +1771,7 @@ void CommandSetGl124::send_shading_data(Genesys_Device* dev, const Genesys_Senso
|
||||||
/* binary data logging */
|
/* binary data logging */
|
||||||
if(DBG_LEVEL>=DBG_data)
|
if(DBG_LEVEL>=DBG_data)
|
||||||
{
|
{
|
||||||
dev->binary=fopen("binary.pnm","wb");
|
dev->binary = std::fopen("binary.pnm","wb");
|
||||||
lines = dev->reg.get24(REG_LINCNT);
|
lines = dev->reg.get24(REG_LINCNT);
|
||||||
channels = dev->session.params.channels;
|
channels = dev->session.params.channels;
|
||||||
if (dev->binary != nullptr) {
|
if (dev->binary != nullptr) {
|
||||||
|
|
|
@ -53,6 +53,7 @@
|
||||||
#include "gl646.h"
|
#include "gl646.h"
|
||||||
#include "gl646_registers.h"
|
#include "gl646_registers.h"
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -59,6 +59,14 @@ std::size_t ImagePipelineNodeBytesSource::consume_remaining_bytes(std::size_t by
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ImagePipelineNodeCallableSource::get_next_row_data(std::uint8_t* out_data)
|
||||||
|
{
|
||||||
|
bool got_data = producer_(get_row_bytes(), out_data);
|
||||||
|
if (!got_data)
|
||||||
|
eof_ = true;
|
||||||
|
return got_data;
|
||||||
|
}
|
||||||
|
|
||||||
ImagePipelineNodeBufferedCallableSource::ImagePipelineNodeBufferedCallableSource(
|
ImagePipelineNodeBufferedCallableSource::ImagePipelineNodeBufferedCallableSource(
|
||||||
std::size_t width, std::size_t height, PixelFormat format, std::size_t input_batch_size,
|
std::size_t width, std::size_t height, PixelFormat format, std::size_t input_batch_size,
|
||||||
ProducerCallback producer) :
|
ProducerCallback producer) :
|
||||||
|
|
|
@ -105,13 +105,7 @@ public:
|
||||||
|
|
||||||
bool eof() const override { return eof_; }
|
bool eof() const override { return eof_; }
|
||||||
|
|
||||||
bool get_next_row_data(std::uint8_t* out_data) override
|
bool get_next_row_data(std::uint8_t* out_data) override;
|
||||||
{
|
|
||||||
bool got_data = producer_(get_row_bytes(), out_data);
|
|
||||||
if (!got_data)
|
|
||||||
eof_ = true;
|
|
||||||
return got_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ProducerCallback producer_;
|
ProducerCallback producer_;
|
||||||
|
|
|
@ -47,6 +47,7 @@
|
||||||
#include "low.h"
|
#include "low.h"
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------------ */
|
||||||
|
@ -84,7 +85,7 @@ void sanei_genesys_init_cmd_set(Genesys_Device* dev)
|
||||||
/* General IO and debugging functions */
|
/* General IO and debugging functions */
|
||||||
/* ------------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------------ */
|
||||||
|
|
||||||
void sanei_genesys_write_file(const char* filename, const std::uint8_t* data, size_t length)
|
void sanei_genesys_write_file(const char* filename, const std::uint8_t* data, std::size_t length)
|
||||||
{
|
{
|
||||||
DBG_HELPER(dbg);
|
DBG_HELPER(dbg);
|
||||||
FILE *out;
|
FILE *out;
|
||||||
|
@ -104,10 +105,9 @@ void sanei_genesys_write_pnm_file(const char* filename, const std::uint8_t* data
|
||||||
{
|
{
|
||||||
DBG_HELPER_ARGS(dbg, "depth=%d, channels=%d, ppl=%d, lines=%d", depth, channels,
|
DBG_HELPER_ARGS(dbg, "depth=%d, channels=%d, ppl=%d, lines=%d", depth, channels,
|
||||||
pixels_per_line, lines);
|
pixels_per_line, lines);
|
||||||
FILE *out;
|
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
out = fopen (filename, "w");
|
std::FILE* out = std::fopen(filename, "w");
|
||||||
if (!out)
|
if (!out)
|
||||||
{
|
{
|
||||||
throw SaneException("could not open %s for writing: %s\n", filename, strerror(errno));
|
throw SaneException("could not open %s for writing: %s\n", filename, strerror(errno));
|
||||||
|
@ -157,7 +157,7 @@ void sanei_genesys_write_pnm_file(const char* filename, const std::uint8_t* data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose (out);
|
std::fclose(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sanei_genesys_write_pnm_file16(const char* filename, const uint16_t* data, unsigned channels,
|
void sanei_genesys_write_pnm_file16(const char* filename, const uint16_t* data, unsigned channels,
|
||||||
|
@ -166,7 +166,7 @@ void sanei_genesys_write_pnm_file16(const char* filename, const uint16_t* data,
|
||||||
DBG_HELPER_ARGS(dbg, "channels=%d, ppl=%d, lines=%d", channels,
|
DBG_HELPER_ARGS(dbg, "channels=%d, ppl=%d, lines=%d", channels,
|
||||||
pixels_per_line, lines);
|
pixels_per_line, lines);
|
||||||
|
|
||||||
FILE* out = std::fopen(filename, "w");
|
std::FILE* out = std::fopen(filename, "w");
|
||||||
if (!out) {
|
if (!out) {
|
||||||
throw SaneException("could not open %s for writing: %s\n", filename, strerror(errno));
|
throw SaneException("could not open %s for writing: %s\n", filename, strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
|
@ -404,7 +404,8 @@ extern void sanei_genesys_search_reference_point(Genesys_Device* dev, Genesys_Se
|
||||||
const uint8_t* src_data, int start_pixel, int dpi,
|
const uint8_t* src_data, int start_pixel, int dpi,
|
||||||
int width, int height);
|
int width, int height);
|
||||||
|
|
||||||
extern void sanei_genesys_write_file(const char* filename, const std::uint8_t* data, size_t length);
|
extern void sanei_genesys_write_file(const char* filename, const std::uint8_t* data,
|
||||||
|
std::size_t length);
|
||||||
|
|
||||||
extern void sanei_genesys_write_pnm_file(const char* filename, const std::uint8_t* data, int depth,
|
extern void sanei_genesys_write_pnm_file(const char* filename, const std::uint8_t* data, int depth,
|
||||||
int channels, int pixels_per_line, int lines);
|
int channels, int pixels_per_line, int lines);
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
#define BACKEND_GENESYS_REGISTER_H
|
#define BACKEND_GENESYS_REGISTER_H
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <climits>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
@ -52,8 +53,8 @@
|
||||||
|
|
||||||
struct GenesysRegister
|
struct GenesysRegister
|
||||||
{
|
{
|
||||||
uint16_t address = 0;
|
std::uint16_t address = 0;
|
||||||
uint8_t value = 0;
|
std::uint8_t value = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool operator<(const GenesysRegister& lhs, const GenesysRegister& rhs)
|
inline bool operator<(const GenesysRegister& lhs, const GenesysRegister& rhs)
|
||||||
|
@ -97,7 +98,7 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_reg(uint16_t address, uint8_t default_value)
|
void init_reg(std::uint16_t address, std::uint8_t default_value)
|
||||||
{
|
{
|
||||||
if (find_reg_index(address) >= 0) {
|
if (find_reg_index(address) >= 0) {
|
||||||
set8(address, default_value);
|
set8(address, default_value);
|
||||||
|
@ -111,12 +112,12 @@ public:
|
||||||
std::sort(registers_.begin(), registers_.end());
|
std::sort(registers_.begin(), registers_.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool has_reg(uint16_t address) const
|
bool has_reg(std::uint16_t address) const
|
||||||
{
|
{
|
||||||
return find_reg_index(address) >= 0;
|
return find_reg_index(address) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void remove_reg(uint16_t address)
|
void remove_reg(std::uint16_t address)
|
||||||
{
|
{
|
||||||
int i = find_reg_index(address);
|
int i = find_reg_index(address);
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
|
@ -125,7 +126,7 @@ public:
|
||||||
registers_.erase(registers_.begin() + i);
|
registers_.erase(registers_.begin() + i);
|
||||||
}
|
}
|
||||||
|
|
||||||
GenesysRegister& find_reg(uint16_t address)
|
GenesysRegister& find_reg(std::uint16_t address)
|
||||||
{
|
{
|
||||||
int i = find_reg_index(address);
|
int i = find_reg_index(address);
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
|
@ -134,7 +135,7 @@ public:
|
||||||
return registers_[i];
|
return registers_[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
const GenesysRegister& find_reg(uint16_t address) const
|
const GenesysRegister& find_reg(std::uint16_t address) const
|
||||||
{
|
{
|
||||||
int i = find_reg_index(address);
|
int i = find_reg_index(address);
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
|
@ -143,51 +144,51 @@ public:
|
||||||
return registers_[i];
|
return registers_[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
GenesysRegister* find_reg_address(uint16_t address)
|
GenesysRegister* find_reg_address(std::uint16_t address)
|
||||||
{
|
{
|
||||||
return &find_reg(address);
|
return &find_reg(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
const GenesysRegister* find_reg_address(uint16_t address) const
|
const GenesysRegister* find_reg_address(std::uint16_t address) const
|
||||||
{
|
{
|
||||||
return &find_reg(address);
|
return &find_reg(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set8(uint16_t address, uint8_t value)
|
void set8(std::uint16_t address, std::uint8_t value)
|
||||||
{
|
{
|
||||||
find_reg(address).value = value;
|
find_reg(address).value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set8_mask(uint16_t address, uint8_t value, uint8_t mask)
|
void set8_mask(std::uint16_t address, std::uint8_t value, std::uint8_t mask)
|
||||||
{
|
{
|
||||||
auto& reg = find_reg(address);
|
auto& reg = find_reg(address);
|
||||||
reg.value = (reg.value & ~mask) | value;
|
reg.value = (reg.value & ~mask) | value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set16(uint16_t address, uint16_t value)
|
void set16(std::uint16_t address, std::uint16_t value)
|
||||||
{
|
{
|
||||||
find_reg(address).value = (value >> 8) & 0xff;
|
find_reg(address).value = (value >> 8) & 0xff;
|
||||||
find_reg(address + 1).value = value & 0xff;
|
find_reg(address + 1).value = value & 0xff;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set24(uint16_t address, uint32_t value)
|
void set24(std::uint16_t address, std::uint32_t value)
|
||||||
{
|
{
|
||||||
find_reg(address).value = (value >> 16) & 0xff;
|
find_reg(address).value = (value >> 16) & 0xff;
|
||||||
find_reg(address + 1).value = (value >> 8) & 0xff;
|
find_reg(address + 1).value = (value >> 8) & 0xff;
|
||||||
find_reg(address + 2).value = value & 0xff;
|
find_reg(address + 2).value = value & 0xff;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t get8(uint16_t address) const
|
std::uint8_t get8(std::uint16_t address) const
|
||||||
{
|
{
|
||||||
return find_reg(address).value;
|
return find_reg(address).value;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t get16(uint16_t address) const
|
std::uint16_t get16(std::uint16_t address) const
|
||||||
{
|
{
|
||||||
return (find_reg(address).value << 8) | find_reg(address + 1).value;
|
return (find_reg(address).value << 8) | find_reg(address + 1).value;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t get24(uint16_t address) const
|
std::uint32_t get24(std::uint16_t address) const
|
||||||
{
|
{
|
||||||
return (find_reg(address).value << 16) |
|
return (find_reg(address).value << 16) |
|
||||||
(find_reg(address + 1).value << 8) |
|
(find_reg(address + 1).value << 8) |
|
||||||
|
@ -195,7 +196,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear() { registers_.clear(); }
|
void clear() { registers_.clear(); }
|
||||||
size_t size() const { return registers_.size(); }
|
std::size_t size() const { return registers_.size(); }
|
||||||
|
|
||||||
iterator begin() { return registers_.begin(); }
|
iterator begin() { return registers_.begin(); }
|
||||||
const_iterator begin() const { return registers_.begin(); }
|
const_iterator begin() const { return registers_.begin(); }
|
||||||
|
@ -204,10 +205,10 @@ public:
|
||||||
const_iterator end() const { return registers_.end(); }
|
const_iterator end() const { return registers_.end(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int find_reg_index(uint16_t address) const
|
int find_reg_index(std::uint16_t address) const
|
||||||
{
|
{
|
||||||
if (!sorted_) {
|
if (!sorted_) {
|
||||||
for (size_t i = 0; i < registers_.size(); i++) {
|
for (std::size_t i = 0; i < registers_.size(); i++) {
|
||||||
if (registers_[i].address == address) {
|
if (registers_[i].address == address) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
@ -289,10 +290,10 @@ public:
|
||||||
iterator end() { return registers_.end(); }
|
iterator end() { return registers_.end(); }
|
||||||
const_iterator end() const { return registers_.end(); }
|
const_iterator end() const { return registers_.end(); }
|
||||||
|
|
||||||
SettingType& operator[](size_t i) { return registers_[i]; }
|
SettingType& operator[](std::size_t i) { return registers_[i]; }
|
||||||
const SettingType& operator[](size_t i) const { return registers_[i]; }
|
const SettingType& operator[](std::size_t i) const { return registers_[i]; }
|
||||||
|
|
||||||
size_t size() const { return registers_.size(); }
|
std::size_t size() const { return registers_.size(); }
|
||||||
bool empty() const { return registers_.empty(); }
|
bool empty() const { return registers_.empty(); }
|
||||||
void clear() { registers_.clear(); }
|
void clear() { registers_.clear(); }
|
||||||
|
|
||||||
|
@ -356,7 +357,7 @@ private:
|
||||||
|
|
||||||
int find_reg_index(AddressType address) const
|
int find_reg_index(AddressType address) const
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < registers_.size(); i++) {
|
for (std::size_t i = 0; i < registers_.size(); i++) {
|
||||||
if (registers_[i].address == address) {
|
if (registers_[i].address == address) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
@ -376,7 +377,7 @@ inline void serialize(std::istream& str, RegisterSettingSet<Value>& reg)
|
||||||
using AddressType = typename RegisterSetting<Value>::AddressType;
|
using AddressType = typename RegisterSetting<Value>::AddressType;
|
||||||
|
|
||||||
reg.clear();
|
reg.clear();
|
||||||
const size_t max_register_address = 1 << (sizeof(AddressType) * CHAR_BIT);
|
const std::size_t max_register_address = 1 << (sizeof(AddressType) * CHAR_BIT);
|
||||||
serialize(str, reg.registers_, max_register_address);
|
serialize(str, reg.registers_, max_register_address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -388,9 +389,9 @@ inline void serialize(std::ostream& str, RegisterSettingSet<Value>& reg)
|
||||||
|
|
||||||
template<class F, class Value>
|
template<class F, class Value>
|
||||||
void apply_registers_ordered(const RegisterSettingSet<Value>& set,
|
void apply_registers_ordered(const RegisterSettingSet<Value>& set,
|
||||||
std::initializer_list<uint16_t> order, F f)
|
std::initializer_list<std::uint16_t> order, F f)
|
||||||
{
|
{
|
||||||
for (uint16_t addr : order) {
|
for (std::uint16_t addr : order) {
|
||||||
f(set.find_reg(addr));
|
f(set.find_reg(addr));
|
||||||
}
|
}
|
||||||
for (const auto& reg : set) {
|
for (const auto& reg : set) {
|
||||||
|
|
|
@ -104,21 +104,22 @@ void UsbDevice::get_vendor_product(int& vendor, int& product)
|
||||||
TIE(sanei_usb_get_vendor_product(device_num_, &vendor, &product));
|
TIE(sanei_usb_get_vendor_product(device_num_, &vendor, &product));
|
||||||
}
|
}
|
||||||
|
|
||||||
void UsbDevice::control_msg(int rtype, int reg, int value, int index, int length, uint8_t* data)
|
void UsbDevice::control_msg(int rtype, int reg, int value, int index, int length,
|
||||||
|
std::uint8_t* data)
|
||||||
{
|
{
|
||||||
DBG_HELPER(dbg);
|
DBG_HELPER(dbg);
|
||||||
assert_is_open();
|
assert_is_open();
|
||||||
TIE(sanei_usb_control_msg(device_num_, rtype, reg, value, index, length, data));
|
TIE(sanei_usb_control_msg(device_num_, rtype, reg, value, index, length, data));
|
||||||
}
|
}
|
||||||
|
|
||||||
void UsbDevice::bulk_read(uint8_t* buffer, size_t* size)
|
void UsbDevice::bulk_read(std::uint8_t* buffer, std::size_t* size)
|
||||||
{
|
{
|
||||||
DBG_HELPER(dbg);
|
DBG_HELPER(dbg);
|
||||||
assert_is_open();
|
assert_is_open();
|
||||||
TIE(sanei_usb_read_bulk(device_num_, buffer, size));
|
TIE(sanei_usb_read_bulk(device_num_, buffer, size));
|
||||||
}
|
}
|
||||||
|
|
||||||
void UsbDevice::bulk_write(const uint8_t* buffer, size_t* size)
|
void UsbDevice::bulk_write(const std::uint8_t* buffer, std::size_t* size)
|
||||||
{
|
{
|
||||||
DBG_HELPER(dbg);
|
DBG_HELPER(dbg);
|
||||||
assert_is_open();
|
assert_is_open();
|
||||||
|
|
|
@ -80,9 +80,9 @@ public:
|
||||||
|
|
||||||
void get_vendor_product(int& vendor, int& product);
|
void get_vendor_product(int& vendor, int& product);
|
||||||
|
|
||||||
void control_msg(int rtype, int reg, int value, int index, int length, uint8_t* data);
|
void control_msg(int rtype, int reg, int value, int index, int length, std::uint8_t* data);
|
||||||
void bulk_read(uint8_t* buffer, size_t* size);
|
void bulk_read(std::uint8_t* buffer, std::size_t* size);
|
||||||
void bulk_write(const uint8_t* buffer, size_t* size);
|
void bulk_write(const std::uint8_t* buffer, std::size_t* size);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -75,8 +75,8 @@ enum class FrontendType : unsigned
|
||||||
struct GenesysFrontendLayout
|
struct GenesysFrontendLayout
|
||||||
{
|
{
|
||||||
FrontendType type = FrontendType::UNKNOWN;
|
FrontendType type = FrontendType::UNKNOWN;
|
||||||
std::array<uint16_t, 3> offset_addr = {};
|
std::array<std::uint16_t, 3> offset_addr = {};
|
||||||
std::array<uint16_t, 3> gain_addr = {};
|
std::array<std::uint16_t, 3> gain_addr = {};
|
||||||
|
|
||||||
bool operator==(const GenesysFrontendLayout& other) const
|
bool operator==(const GenesysFrontendLayout& other) const
|
||||||
{
|
{
|
||||||
|
@ -149,9 +149,9 @@ void serialize(Stream& str, Genesys_Frontend& x)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SensorExposure {
|
struct SensorExposure {
|
||||||
uint16_t red = 0;
|
std::uint16_t red = 0;
|
||||||
uint16_t green = 0;
|
std::uint16_t green = 0;
|
||||||
uint16_t blue = 0;
|
std::uint16_t blue = 0;
|
||||||
|
|
||||||
SensorExposure() = default;
|
SensorExposure() = default;
|
||||||
SensorExposure(std::uint16_t r, std::uint16_t g, std::uint16_t b) :
|
SensorExposure(std::uint16_t r, std::uint16_t g, std::uint16_t b) :
|
||||||
|
|
Ładowanie…
Reference in New Issue