2020-06-24 02:49:24 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2019-2020 PixlOne
|
|
|
|
*
|
|
|
|
* 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 3 of the License, 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. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-07-17 05:53:51 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <string>
|
|
|
|
#include <cstring>
|
|
|
|
#include <cstdarg>
|
|
|
|
#include <cmath>
|
|
|
|
#include <algorithm>
|
2020-06-16 23:53:38 +00:00
|
|
|
#include <stdexcept>
|
2019-07-17 05:53:51 +00:00
|
|
|
|
|
|
|
#include "util.h"
|
|
|
|
|
2019-10-05 01:56:17 +00:00
|
|
|
using namespace logid;
|
|
|
|
|
|
|
|
void logid::log_printf(LogLevel level, const char* format, ...)
|
2019-07-17 05:53:51 +00:00
|
|
|
{
|
|
|
|
if(global_verbosity > level) return;
|
|
|
|
|
|
|
|
va_list vargs;
|
|
|
|
va_start(vargs, format);
|
|
|
|
|
|
|
|
FILE* stream = stdout;
|
|
|
|
if(level == ERROR || level == WARN) stream = stderr;
|
|
|
|
|
|
|
|
fprintf(stream, "[%s] ", level_prefix(level));
|
|
|
|
vfprintf(stream, format, vargs);
|
|
|
|
fprintf(stream, "\n");
|
|
|
|
}
|
|
|
|
|
2019-10-05 01:56:17 +00:00
|
|
|
const char* logid::level_prefix(LogLevel level)
|
2019-07-17 05:53:51 +00:00
|
|
|
{
|
2020-06-20 07:25:52 +00:00
|
|
|
if(level == RAWREPORT) return "RAWREPORT";
|
2019-07-17 05:53:51 +00:00
|
|
|
if(level == DEBUG) return "DEBUG";
|
|
|
|
if(level == INFO) return "INFO" ;
|
|
|
|
if(level == WARN) return "WARN";
|
|
|
|
if(level == ERROR) return "ERROR";
|
|
|
|
|
|
|
|
return "DEBUG";
|
|
|
|
}
|
|
|
|
|
2020-06-16 23:53:38 +00:00
|
|
|
/*
|
2019-10-06 01:27:17 +00:00
|
|
|
Direction logid::getDirection(int x, int y)
|
2019-07-17 05:53:51 +00:00
|
|
|
{
|
2019-08-08 22:22:54 +00:00
|
|
|
if(x == 0 && y == 0) return Direction::None;
|
2019-07-17 05:53:51 +00:00
|
|
|
|
|
|
|
double angle;
|
|
|
|
|
|
|
|
if(x == 0 && y > 0) angle = 90; // Y+
|
|
|
|
else if(x == 0 && y < 0) angle = 270; // Y-
|
|
|
|
else if(x > 0 && y == 0) angle = 0; // X+
|
|
|
|
else if(x < 0 && y == 0) angle = 180; // X+
|
|
|
|
else
|
|
|
|
{
|
|
|
|
angle = fabs(atan((double)y/(double)x) * 180.0 / M_PI);
|
|
|
|
|
|
|
|
if(x < 0 && y > 0) angle = 180.0 - angle; //Q2
|
|
|
|
else if(x < 0 && y < 0) angle += 180; // Q3
|
|
|
|
else if(x > 0 && y < 0) angle = 360.0 - angle; // Q4
|
|
|
|
}
|
|
|
|
|
|
|
|
if(315 < angle || angle <= 45) return Direction::Right;
|
|
|
|
else if(45 < angle && angle <= 135) return Direction::Down;
|
|
|
|
else if(135 < angle && angle <= 225) return Direction::Left;
|
|
|
|
else if(225 < angle && angle <= 315) return Direction::Up;
|
|
|
|
|
|
|
|
return Direction::None;
|
|
|
|
}
|
|
|
|
|
2019-10-06 01:27:17 +00:00
|
|
|
Direction logid::stringToDirection(std::string s)
|
2019-07-17 05:53:51 +00:00
|
|
|
{
|
|
|
|
const char* original_str = s.c_str();
|
|
|
|
std::transform(s.begin(), s.end(), s.begin(), ::tolower);
|
|
|
|
|
|
|
|
if(s == "none") return Direction::None;
|
|
|
|
if(s == "up") return Direction::Up;
|
|
|
|
if(s == "down") return Direction::Down;
|
|
|
|
if(s == "left") return Direction::Left;
|
|
|
|
if(s == "right") return Direction::Right;
|
|
|
|
|
|
|
|
s = original_str;
|
|
|
|
|
|
|
|
throw std::invalid_argument(s + " is an invalid direction.");
|
|
|
|
}
|
|
|
|
|
2019-10-06 01:27:17 +00:00
|
|
|
GestureMode logid::stringToGestureMode(std::string s)
|
2019-07-17 05:53:51 +00:00
|
|
|
{
|
|
|
|
const char* original_str = s.c_str();
|
|
|
|
std::transform(s.begin(), s.end(), s.begin(), ::tolower);
|
|
|
|
|
|
|
|
if(s == "nopress") return GestureMode::NoPress;
|
|
|
|
if(s == "onrelease") return GestureMode::OnRelease;
|
|
|
|
if(s == "onfewpixels") return GestureMode::OnFewPixels;
|
2019-08-08 22:22:54 +00:00
|
|
|
if(s == "axis") return GestureMode::Axis;
|
2019-07-17 05:53:51 +00:00
|
|
|
|
|
|
|
s = original_str;
|
|
|
|
|
|
|
|
log_printf(INFO, "%s is an invalid gesture mode. Defaulting to OnRelease", original_str);
|
|
|
|
|
2019-08-08 22:22:54 +00:00
|
|
|
|
2019-07-17 05:53:51 +00:00
|
|
|
return GestureMode::OnRelease;
|
|
|
|
}
|
|
|
|
|
2019-10-06 01:27:17 +00:00
|
|
|
Action logid::stringToAction(std::string s)
|
2019-07-17 05:53:51 +00:00
|
|
|
{
|
|
|
|
std::string original_str = s;
|
|
|
|
std::transform(s.begin(), s.end(), s.begin(), ::tolower);
|
|
|
|
|
|
|
|
if(s == "none") return Action::None;
|
|
|
|
if(s == "keypress") return Action::Keypress;
|
|
|
|
if(s == "gestures") return Action::Gestures;
|
|
|
|
if(s == "togglesmartshift") return Action::ToggleSmartshift;
|
|
|
|
if(s == "togglehiresscroll") return Action::ToggleHiresScroll;
|
|
|
|
if(s == "cycledpi") return Action::CycleDPI;
|
|
|
|
if(s == "changedpi") return Action::ChangeDPI;
|
|
|
|
|
|
|
|
throw std::invalid_argument(original_str + " is an invalid action.");
|
2019-08-09 02:13:50 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 23:53:38 +00:00
|
|
|
*/
|
|
|
|
|
2019-10-06 01:27:17 +00:00
|
|
|
LogLevel logid::stringToLogLevel(std::string s)
|
2019-08-09 02:13:50 +00:00
|
|
|
{
|
|
|
|
std::string original_str = s;
|
|
|
|
std::transform(s.begin(), s.end(), s.begin(), ::tolower);
|
|
|
|
|
2020-06-20 07:25:52 +00:00
|
|
|
if(s == "rawreport") return RAWREPORT;
|
2019-08-09 02:13:50 +00:00
|
|
|
if(s == "debug") return DEBUG;
|
|
|
|
if(s == "info") return INFO;
|
|
|
|
if(s == "warn" || s == "warning") return WARN;
|
|
|
|
if(s == "error") return ERROR;
|
|
|
|
|
|
|
|
throw std::invalid_argument(original_str + " is an invalid log level.");
|
2019-07-17 05:53:51 +00:00
|
|
|
}
|