src/CadMouseConfig.h
branchv_0
changeset 5 6799cec5c2f8
parent 4 405aa9de65d2
child 6 975f38eb1e12
equal deleted inserted replaced
4:405aa9de65d2 5:6799cec5c2f8
       
     1 #pragma once
       
     2 
       
     3 #include <type_traits>
       
     4 
       
     5 #include "HID.h"
       
     6 
       
     7 enum class Frequency : uint8_t {
       
     8 	Hz_0125 = 8,
       
     9 	Hz_0250 = 4,
       
    10 	Hz_0500 = 2,
       
    11 	Hz_1000 = 1
       
    12 };
       
    13 
       
    14 using FrequencyType = std::underlying_type<Frequency>::type;
       
    15 
       
    16 class CadMouseConfig {
       
    17 private:
       
    18 	bool liftOffDetection = true;
       
    19 	bool smartScrolling = false;
       
    20 	Frequency frequency = Frequency::Hz_1000;
       
    21 public:
       
    22 
       
    23 	void setFrequency(Frequency frequency) {
       
    24 		this->frequency = frequency;
       
    25 	}
       
    26 
       
    27 	void setLiftOffDetection(bool liftOffDetection) {
       
    28 		this->liftOffDetection = liftOffDetection;
       
    29 	}
       
    30 
       
    31 	void setSmartScrolling(bool smartScrolling) {
       
    32 		this->smartScrolling = smartScrolling;
       
    33 	}
       
    34 
       
    35 	Packet serialize() {
       
    36 		Packet data;
       
    37 		data.reserve(32);
       
    38 
       
    39 		data.push_back(0x10); // report ID
       
    40 		data.push_back(0x00); // option
       
    41 
       
    42 		data.push_back(0x1c); // speed
       
    43 
       
    44 		data.push_back(liftOffDetection ? 0x00 : 0x1f);
       
    45 
       
    46 		if (smartScrolling) {
       
    47 			data.push_back(0x00);
       
    48 			data.push_back(0x00);
       
    49 			data.push_back(0x00);
       
    50 			data.push_back(0x01);
       
    51 		} else {
       
    52 			data.push_back(0x01);
       
    53 			data.push_back(0xff);
       
    54 			data.push_back(0x00);
       
    55 			data.push_back(0x00);
       
    56 		}
       
    57 
       
    58 		for (int i = 0; i < 8; i++) data.push_back(0x00); // constant padding or magic
       
    59 
       
    60 		// magic constants or unknown fields
       
    61 		data.push_back(0x00);
       
    62 		data.push_back(0x03);
       
    63 		data.push_back(0x00);
       
    64 		data.push_back(0x0a);
       
    65 		data.push_back(0x0b);
       
    66 		data.push_back(0x0c);
       
    67 		data.push_back(0x0c);
       
    68 		data.push_back(0x0e);
       
    69 		data.push_back(0x0d);
       
    70 		data.push_back(0x2f);
       
    71 		data.push_back(0x00);
       
    72 		data.push_back(0x1e);
       
    73 
       
    74 		data.push_back(0x00);
       
    75 		data.push_back(0x00);
       
    76 		data.push_back(0x00);
       
    77 		data.push_back(static_cast<FrequencyType> (frequency));
       
    78 
       
    79 		return data;
       
    80 	}
       
    81 
       
    82 };