src/CadMouseConfig.h
author František Kučera <franta-hg@frantovo.cz>
Sun, 18 Aug 2019 23:30:01 +0200
branchv_0
changeset 5 6799cec5c2f8
parent 4 src/cadMousePro.cpp@405aa9de65d2
child 6 975f38eb1e12
permissions -rw-r--r--
refactoring: separate into several files

#pragma once

#include <type_traits>

#include "HID.h"

enum class Frequency : uint8_t {
	Hz_0125 = 8,
	Hz_0250 = 4,
	Hz_0500 = 2,
	Hz_1000 = 1
};

using FrequencyType = std::underlying_type<Frequency>::type;

class CadMouseConfig {
private:
	bool liftOffDetection = true;
	bool smartScrolling = false;
	Frequency frequency = Frequency::Hz_1000;
public:

	void setFrequency(Frequency frequency) {
		this->frequency = frequency;
	}

	void setLiftOffDetection(bool liftOffDetection) {
		this->liftOffDetection = liftOffDetection;
	}

	void setSmartScrolling(bool smartScrolling) {
		this->smartScrolling = smartScrolling;
	}

	Packet serialize() {
		Packet data;
		data.reserve(32);

		data.push_back(0x10); // report ID
		data.push_back(0x00); // option

		data.push_back(0x1c); // speed

		data.push_back(liftOffDetection ? 0x00 : 0x1f);

		if (smartScrolling) {
			data.push_back(0x00);
			data.push_back(0x00);
			data.push_back(0x00);
			data.push_back(0x01);
		} else {
			data.push_back(0x01);
			data.push_back(0xff);
			data.push_back(0x00);
			data.push_back(0x00);
		}

		for (int i = 0; i < 8; i++) data.push_back(0x00); // constant padding or magic

		// magic constants or unknown fields
		data.push_back(0x00);
		data.push_back(0x03);
		data.push_back(0x00);
		data.push_back(0x0a);
		data.push_back(0x0b);
		data.push_back(0x0c);
		data.push_back(0x0c);
		data.push_back(0x0e);
		data.push_back(0x0d);
		data.push_back(0x2f);
		data.push_back(0x00);
		data.push_back(0x1e);

		data.push_back(0x00);
		data.push_back(0x00);
		data.push_back(0x00);
		data.push_back(static_cast<FrequencyType> (frequency));

		return data;
	}

};