mirror of
https://github.com/skogaby/OpeNITHM.git
synced 2026-09-22 22:58:16 +03:00
Make the controller save all the configurable values to EEPROM and make the OpeNITHMConfig tool load the values from EEPROM and initialize the UI with the current controller values
This commit is contained in:
@@ -135,7 +135,10 @@ AirSensor::AirSensor(int requiredSamples, int skippedSamples) : thresholds{ 1000
|
||||
}
|
||||
}
|
||||
|
||||
analogSensitivity = 40;
|
||||
EEPROM.get(66, analogSensitivity);
|
||||
|
||||
if (analogSensitivity == 0)
|
||||
setAnalogSensitivity(DEFAULT_SENSITIVITY);
|
||||
}
|
||||
|
||||
// Check if all IR sensors are calibrated. If they are, set a flag to not need to re-check it
|
||||
@@ -225,10 +228,12 @@ float AirSensor::getHandPosition()
|
||||
uint8_t AirSensor::getSensorReadings()
|
||||
{
|
||||
uint8_t reading = 0;
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
reading |= ((int)getSensorState(i) << i);
|
||||
}
|
||||
|
||||
return reading;
|
||||
}
|
||||
|
||||
@@ -240,6 +245,12 @@ bool AirSensor::getSensorCalibrated(int i)
|
||||
void AirSensor::setAnalogSensitivity(uint8_t analogSensitivity)
|
||||
{
|
||||
this->analogSensitivity = analogSensitivity;
|
||||
EEPROM.put(66, analogSensitivity);
|
||||
}
|
||||
|
||||
uint8_t AirSensor::getAnalogSensitivity()
|
||||
{
|
||||
return analogSensitivity;
|
||||
}
|
||||
|
||||
void AirSensor::recalibrate()
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#include "PinConfig.h"
|
||||
#include <EEPROM.h>
|
||||
|
||||
#define DEFAULT_SENSITIVITY 40
|
||||
|
||||
class AirSensor
|
||||
{
|
||||
private:
|
||||
@@ -40,6 +42,7 @@ class AirSensor
|
||||
uint8_t getSensorReadings();
|
||||
bool getSensorCalibrated(int i);
|
||||
void setAnalogSensitivity(uint8_t analogSensitivity);
|
||||
uint8_t getAnalogSensitivity();
|
||||
void recalibrate();
|
||||
};
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ void AutoTouchboard::saveConfig()
|
||||
EEPROM.put((i * 2) + 32, double_thresholds[i]);
|
||||
}
|
||||
|
||||
EEPROM.put(64, CALIBRATION_FLAG);
|
||||
EEPROM.put(64, (byte) CALIBRATION_FLAG);
|
||||
}
|
||||
|
||||
void AutoTouchboard::calibrateKeys(bool forceCalibrate = false)
|
||||
@@ -49,7 +49,7 @@ void AutoTouchboard::calibrateKeys(bool forceCalibrate = false)
|
||||
// * the calibration flag is not set in EEPROM
|
||||
bool needsCalibration = forceCalibrate;
|
||||
|
||||
int calibrationFlag;
|
||||
byte calibrationFlag;
|
||||
EEPROM.get(64, calibrationFlag);
|
||||
|
||||
// only check the last 4 keys if we've calibrated at least once
|
||||
@@ -179,6 +179,12 @@ uint16_t AutoTouchboard::getRawValue(int key)
|
||||
void AutoTouchboard::setSensitivity(uint8_t sensitivity)
|
||||
{
|
||||
this->sensitivity = sensitivity;
|
||||
EEPROM.put(65, sensitivity);
|
||||
}
|
||||
|
||||
uint8_t AutoTouchboard::getSensitivity()
|
||||
{
|
||||
return sensitivity;
|
||||
}
|
||||
|
||||
AutoTouchboard::AutoTouchboard()
|
||||
@@ -189,7 +195,11 @@ AutoTouchboard::AutoTouchboard()
|
||||
pinMode(MUX_0, OUTPUT);
|
||||
pinMode(MUX_1, OUTPUT);
|
||||
pinMode(MUX_2, OUTPUT);
|
||||
sensitivity = 76;
|
||||
|
||||
EEPROM.get(65, sensitivity);
|
||||
|
||||
if (sensitivity == 0)
|
||||
setSensitivity(DEFAULT_SENSITIVITY);
|
||||
|
||||
calibrateKeys();
|
||||
}
|
||||
|
||||
@@ -14,7 +14,8 @@
|
||||
|
||||
#define CALIBRATION_SAMPLES 25
|
||||
#define CALIBRATION_DETECTION_THRESHOLD 55
|
||||
#define CALIBRATION_FLAG 0xFFFF
|
||||
#define CALIBRATION_FLAG 0xFF
|
||||
#define DEFAULT_SENSITIVITY 80
|
||||
|
||||
extern CRGB leds[16];
|
||||
|
||||
@@ -38,6 +39,7 @@ class AutoTouchboard
|
||||
uint16_t getRawValue(int key);
|
||||
void calibrateKeys(bool forceCalibrate = false);
|
||||
void setSensitivity(uint8_t sensitivity);
|
||||
uint8_t getSensitivity();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
// *** USER EDITABLE CONFIG OPTIONS ***
|
||||
|
||||
// Select which board you're using (ignore if not using Teensy)
|
||||
#define TEESNY_V1_0 // Version 1.0 (No version number on board)
|
||||
#define TEENSY_V1_0 // Version 1.0 (No version number on board)
|
||||
//#define TEENSY_V1_1 // Version 1.1 (v1.1 on board under logo)
|
||||
|
||||
// Uncomment this line to force the processor to use Serial Output
|
||||
@@ -50,9 +50,9 @@
|
||||
#endif
|
||||
|
||||
// Spit out errors for board definitions
|
||||
#if !defined(TEESNY_V1_0) && !defined(TEENSY_V1_1)
|
||||
#if !defined(TEENSY_V1_0) && !defined(TEENSY_V1_1)
|
||||
#error "For Teensy, EITHER v1.0 OR v1.1 must be defined in Config.h"
|
||||
#elif defined(TEESNY_V1_0) && defined(TEENSY_V1_1)
|
||||
#elif defined(TEENSY_V1_0) && defined(TEENSY_V1_1)
|
||||
#error "For Teensy, cannot define BOTH v1.0 AND v1.1 in Config.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -21,8 +21,8 @@ bool updateLeds = false;
|
||||
bool useSerialLeds = false;
|
||||
int serialLightsCounter;
|
||||
|
||||
CRGB led_on = CRGB::Purple;
|
||||
CRGB led_off = CRGB::Yellow;
|
||||
CRGB led_on;
|
||||
CRGB led_off;
|
||||
|
||||
float lightIntensity[16];
|
||||
bool activated = true;
|
||||
@@ -58,6 +58,21 @@ void setup() {
|
||||
// Initialize the serial LED processor
|
||||
serialLeds = new SerialLeds();
|
||||
|
||||
// Initialize the reactive lighting colors, and if they're not in EEPROM, save them
|
||||
byte lightsFlag;
|
||||
EEPROM.get(67, lightsFlag);
|
||||
|
||||
if (lightsFlag == LIGHTS_FLAG)
|
||||
{
|
||||
serialLeds->loadLights();
|
||||
}
|
||||
else
|
||||
{
|
||||
led_on = CRGB::Purple;
|
||||
led_off = CRGB::Yellow;
|
||||
serialLeds->saveLights();
|
||||
}
|
||||
|
||||
// Initialize air sensor
|
||||
// Digital mode calibrations in the constructor
|
||||
// Analog mode will automatically calibrate as it starts being read
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
// Multiplexer pin settings
|
||||
#ifdef TEENSY // Teensy LC
|
||||
#if defined(TEESNY_V1_0)
|
||||
#if defined(TEENSY_V1_0)
|
||||
#define MUX_0 20
|
||||
#define MUX_1 19
|
||||
#define MUX_2 18
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
// Sensor pin settings
|
||||
#ifdef TEENSY
|
||||
#if defined(TEESNY_V1_0)
|
||||
#if defined(TEENSY_V1_0)
|
||||
#define LED_0 16
|
||||
#define LED_1 21
|
||||
#define LED_2 5
|
||||
@@ -42,7 +42,7 @@
|
||||
#define SENSOR_IN A0
|
||||
#else
|
||||
#ifdef TEENSY
|
||||
#if defined(TEESNY_V1_0)
|
||||
#if defined(TEENSY_V1_0)
|
||||
#define AIR_SENSOR_0_PIN 10
|
||||
#define AIR_SENSOR_1_PIN 11
|
||||
#define AIR_SENSOR_2_PIN 12
|
||||
@@ -73,7 +73,7 @@
|
||||
#define SEND 10
|
||||
|
||||
#ifdef TEENSY // Teensy LC
|
||||
#if defined(TEESNY_V1_0)
|
||||
#if defined(TEENSY_V1_0)
|
||||
#define TOUCH_0 22
|
||||
#define TOUCH_1 23
|
||||
#elif defined(TEENSY_V1_1)
|
||||
@@ -86,7 +86,7 @@
|
||||
#define LED_TYPE WS2812B
|
||||
#define LED_ORDER GRB
|
||||
#ifdef TEENSY // Teensy LC
|
||||
#if defined(TEESNY_V1_0)
|
||||
#if defined(TEENSY_V1_0)
|
||||
#define RGBPIN 4
|
||||
#elif defined(TEENSY_V1_1)
|
||||
#define RGBPIN 11
|
||||
|
||||
@@ -3,6 +3,25 @@
|
||||
SerialLeds::SerialLeds()
|
||||
{ }
|
||||
|
||||
void SerialLeds::saveLights() {
|
||||
EEPROM.put(67, (byte) LIGHTS_FLAG);
|
||||
EEPROM.put(68, led_on.r);
|
||||
EEPROM.put(69, led_on.g);
|
||||
EEPROM.put(70, led_on.b);
|
||||
EEPROM.put(71, led_off.r);
|
||||
EEPROM.put(72, led_off.g);
|
||||
EEPROM.put(73, led_off.b);
|
||||
}
|
||||
|
||||
void SerialLeds::loadLights() {
|
||||
EEPROM.get(68, led_on.r);
|
||||
EEPROM.get(69, led_on.g);
|
||||
EEPROM.get(70, led_on.b);
|
||||
EEPROM.get(71, led_off.r);
|
||||
EEPROM.get(72, led_off.g);
|
||||
EEPROM.get(73, led_off.b);
|
||||
}
|
||||
|
||||
void SerialLeds::processBulk(uint8_t *buf)
|
||||
{
|
||||
if (memcmp(buf + 2, lastBuffer + 2, 98) != 0)
|
||||
|
||||
@@ -7,7 +7,14 @@
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
#include <EEPROM.h>
|
||||
#include <FastLED.h>
|
||||
|
||||
#define LIGHTS_FLAG 0xFF
|
||||
|
||||
extern bool updateLeds;
|
||||
extern CRGB led_on;
|
||||
extern CRGB led_off;
|
||||
|
||||
typedef struct {
|
||||
uint8_t b;
|
||||
@@ -22,6 +29,8 @@ class SerialLeds
|
||||
|
||||
public:
|
||||
SerialLeds();
|
||||
void saveLights();
|
||||
void loadLights();
|
||||
void processBulk(uint8_t *buf);
|
||||
RGBLed getKey(uint8_t key); // Left to Right
|
||||
|
||||
|
||||
@@ -8,32 +8,45 @@ void SerialProcessor::processConfigCommand(uint8_t* buf)
|
||||
// figure out which command we're running
|
||||
switch (buf[2])
|
||||
{
|
||||
case CMD_CHANGE_LIGHT_MODE:
|
||||
if (buf[3] == LIGHT_MODE_SERIAL)
|
||||
{
|
||||
useSerialLeds = true;
|
||||
// print the controller info
|
||||
case CMD_PRINT_INFO:
|
||||
byte bytes[100];
|
||||
|
||||
// whether the air sensor is analog or not
|
||||
#ifdef IR_SENSOR_ANALOG
|
||||
bytes[0] = 0x11;
|
||||
#else
|
||||
bytes[0] = 0x00;
|
||||
#endif
|
||||
// slider on color
|
||||
bytes[1] = led_on.r;
|
||||
bytes[2] = led_on.g;
|
||||
bytes[3] = led_on.b;
|
||||
|
||||
// slider off color
|
||||
bytes[4] = led_off.r;
|
||||
bytes[5] = led_off.g;
|
||||
bytes[6] = led_off.b;
|
||||
|
||||
// slider sensitivity
|
||||
bytes[7] = touchboard->getSensitivity();
|
||||
|
||||
// air sensitivity
|
||||
bytes[8] = sensor->getAnalogSensitivity();
|
||||
|
||||
// Set LEDs blue for "ready"
|
||||
for (CRGB& led : leds)
|
||||
led = CRGB::Blue;
|
||||
|
||||
FastLED.show();
|
||||
}
|
||||
else if (buf[3] == LIGHT_MODE_REACTIVE)
|
||||
{
|
||||
useSerialLeds = false;
|
||||
}
|
||||
|
||||
Serial.write(bytes, 100);
|
||||
break;
|
||||
case CMD_CHANGE_ON_COLOR:
|
||||
led_on.r = buf[3];
|
||||
led_on.g = buf[4];
|
||||
led_on.b = buf[5];
|
||||
serialLeds->saveLights();
|
||||
break;
|
||||
case CMD_CHANGE_OFF_COLOR:
|
||||
led_off.r = buf[3];
|
||||
led_off.g = buf[4];
|
||||
led_off.b = buf[5];
|
||||
serialLeds->saveLights();
|
||||
break;
|
||||
case CMD_CALIBRATE_SLIDER:
|
||||
touchboard->setSensitivity(buf[3]);
|
||||
|
||||
@@ -15,16 +15,12 @@
|
||||
#define CONFIG_FLAG 0xBB
|
||||
|
||||
// config command opcodes
|
||||
#define CMD_CHANGE_LIGHT_MODE 0x11
|
||||
#define CMD_PRINT_INFO 0x11
|
||||
#define CMD_CHANGE_ON_COLOR 0x22
|
||||
#define CMD_CHANGE_OFF_COLOR 0x33
|
||||
#define CMD_CALIBRATE_SLIDER 0x44
|
||||
#define CMD_CALIBRATE_AIR_SENSORS 0x55
|
||||
|
||||
// light modes for the change light mode command
|
||||
#define LIGHT_MODE_SERIAL 0x00
|
||||
#define LIGHT_MODE_REACTIVE 0x01
|
||||
|
||||
extern AirSensor *sensor;
|
||||
extern AutoTouchboard *touchboard;
|
||||
extern SerialLeds *serialLeds;
|
||||
|
||||
+28
-18
@@ -33,7 +33,8 @@
|
||||
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.mnuComPort = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
|
||||
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
|
||||
this.mnuFactoryReset = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
|
||||
this.mnuExit = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.mnuAbout = new System.Windows.Forms.ToolStripMenuItem();
|
||||
@@ -50,7 +51,8 @@
|
||||
this.btnCalibrateAir = new System.Windows.Forms.Button();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.trkAirSensitivity = new System.Windows.Forms.TrackBar();
|
||||
this.colorDialog = new System.Windows.Forms.ColorDialog();
|
||||
this.colorDialogOn = new System.Windows.Forms.ColorDialog();
|
||||
this.colorDialogOff = new System.Windows.Forms.ColorDialog();
|
||||
this.menuStrip1.SuspendLayout();
|
||||
this.grpSliderConfig.SuspendLayout();
|
||||
this.grpSliderCalibration.SuspendLayout();
|
||||
@@ -75,7 +77,8 @@
|
||||
//
|
||||
this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.mnuComPort,
|
||||
this.toolStripSeparator1,
|
||||
this.mnuFactoryReset,
|
||||
this.toolStripSeparator2,
|
||||
this.mnuExit});
|
||||
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
|
||||
this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
|
||||
@@ -85,24 +88,31 @@
|
||||
//
|
||||
this.mnuComPort.DropDown = this.contextMenuStrip1;
|
||||
this.mnuComPort.Name = "mnuComPort";
|
||||
this.mnuComPort.Size = new System.Drawing.Size(161, 22);
|
||||
this.mnuComPort.Size = new System.Drawing.Size(195, 22);
|
||||
this.mnuComPort.Text = "Select COM port";
|
||||
//
|
||||
// contextMenuStrip1
|
||||
//
|
||||
this.contextMenuStrip1.Name = "contextMenuStrip1";
|
||||
this.contextMenuStrip1.OwnerItem = this.mnuComPort;
|
||||
this.contextMenuStrip1.Size = new System.Drawing.Size(61, 4);
|
||||
//
|
||||
// toolStripSeparator1
|
||||
// mnuFactoryReset
|
||||
//
|
||||
this.toolStripSeparator1.Name = "toolStripSeparator1";
|
||||
this.toolStripSeparator1.Size = new System.Drawing.Size(158, 6);
|
||||
this.mnuFactoryReset.Enabled = false;
|
||||
this.mnuFactoryReset.Name = "mnuFactoryReset";
|
||||
this.mnuFactoryReset.Size = new System.Drawing.Size(195, 22);
|
||||
this.mnuFactoryReset.Text = "Factory reset controller";
|
||||
this.mnuFactoryReset.Click += new System.EventHandler(this.factoryResetControllerToolStripMenuItem_Click);
|
||||
//
|
||||
// toolStripSeparator2
|
||||
//
|
||||
this.toolStripSeparator2.Name = "toolStripSeparator2";
|
||||
this.toolStripSeparator2.Size = new System.Drawing.Size(192, 6);
|
||||
//
|
||||
// mnuExit
|
||||
//
|
||||
this.mnuExit.Name = "mnuExit";
|
||||
this.mnuExit.Size = new System.Drawing.Size(161, 22);
|
||||
this.mnuExit.Size = new System.Drawing.Size(195, 22);
|
||||
this.mnuExit.Text = "Exit";
|
||||
//
|
||||
// helpToolStripMenuItem
|
||||
@@ -173,11 +183,10 @@
|
||||
// trkSliderSensitivity
|
||||
//
|
||||
this.trkSliderSensitivity.Location = new System.Drawing.Point(6, 38);
|
||||
this.trkSliderSensitivity.Maximum = 100;
|
||||
this.trkSliderSensitivity.Maximum = 25;
|
||||
this.trkSliderSensitivity.Name = "trkSliderSensitivity";
|
||||
this.trkSliderSensitivity.Size = new System.Drawing.Size(271, 45);
|
||||
this.trkSliderSensitivity.TabIndex = 6;
|
||||
this.trkSliderSensitivity.TickFrequency = 5;
|
||||
//
|
||||
// grpReactiveLightsConfig
|
||||
//
|
||||
@@ -193,7 +202,7 @@
|
||||
//
|
||||
// btnSliderOnColor
|
||||
//
|
||||
this.btnSliderOnColor.Location = new System.Drawing.Point(6, 23);
|
||||
this.btnSliderOnColor.Location = new System.Drawing.Point(6, 66);
|
||||
this.btnSliderOnColor.Name = "btnSliderOnColor";
|
||||
this.btnSliderOnColor.Size = new System.Drawing.Size(271, 35);
|
||||
this.btnSliderOnColor.TabIndex = 3;
|
||||
@@ -203,7 +212,7 @@
|
||||
//
|
||||
// btnSliderOffColor
|
||||
//
|
||||
this.btnSliderOffColor.Location = new System.Drawing.Point(6, 64);
|
||||
this.btnSliderOffColor.Location = new System.Drawing.Point(6, 23);
|
||||
this.btnSliderOffColor.Name = "btnSliderOffColor";
|
||||
this.btnSliderOffColor.Size = new System.Drawing.Size(271, 35);
|
||||
this.btnSliderOffColor.TabIndex = 4;
|
||||
@@ -222,7 +231,7 @@
|
||||
this.grpAirConfig.Size = new System.Drawing.Size(294, 127);
|
||||
this.grpAirConfig.TabIndex = 3;
|
||||
this.grpAirConfig.TabStop = false;
|
||||
this.grpAirConfig.Text = "Air sensor configuration (analog controllers only)";
|
||||
this.grpAirConfig.Text = "Air sensor configuration (analog air sensors only)";
|
||||
//
|
||||
// btnCalibrateAir
|
||||
//
|
||||
@@ -246,11 +255,10 @@
|
||||
// trkAirSensitivity
|
||||
//
|
||||
this.trkAirSensitivity.Location = new System.Drawing.Point(12, 44);
|
||||
this.trkAirSensitivity.Maximum = 100;
|
||||
this.trkAirSensitivity.Maximum = 25;
|
||||
this.trkAirSensitivity.Name = "trkAirSensitivity";
|
||||
this.trkAirSensitivity.Size = new System.Drawing.Size(271, 45);
|
||||
this.trkAirSensitivity.TabIndex = 6;
|
||||
this.trkAirSensitivity.TickFrequency = 5;
|
||||
//
|
||||
// MainForm
|
||||
//
|
||||
@@ -285,7 +293,6 @@
|
||||
private System.Windows.Forms.MenuStrip menuStrip1;
|
||||
private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem mnuComPort;
|
||||
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
|
||||
private System.Windows.Forms.ToolStripMenuItem mnuExit;
|
||||
private System.Windows.Forms.ToolStripMenuItem helpToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem mnuAbout;
|
||||
@@ -303,7 +310,10 @@
|
||||
private System.Windows.Forms.Button btnCalibrateAir;
|
||||
private System.Windows.Forms.Label label2;
|
||||
private System.Windows.Forms.TrackBar trkAirSensitivity;
|
||||
private System.Windows.Forms.ColorDialog colorDialog;
|
||||
private System.Windows.Forms.ColorDialog colorDialogOn;
|
||||
private System.Windows.Forms.ToolStripMenuItem mnuFactoryReset;
|
||||
private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
|
||||
private System.Windows.Forms.ColorDialog colorDialogOff;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.IO.Ports;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace OpeNITHMConfig
|
||||
@@ -11,15 +13,22 @@ namespace OpeNITHMConfig
|
||||
private const byte CONFIG_FLAG = 0xBB;
|
||||
|
||||
// config command opcodes
|
||||
private const byte CMD_CHANGE_LIGHT_MODE = 0x11;
|
||||
private const byte CMD_PRINT_INFO = 0x11;
|
||||
private const byte CMD_CHANGE_ON_COLOR = 0x22;
|
||||
private const byte CMD_CHANGE_OFF_COLOR = 0x33;
|
||||
private const byte CMD_CALIBRATE_SLIDER = 0x44;
|
||||
private const byte CMD_CALIBRATE_AIR_SENSORS = 0x55;
|
||||
private const byte CMD_FACTORY_RESET = 0x66;
|
||||
|
||||
// light modes for the change light mode command
|
||||
private const byte LIGHT_MODE_SERIAL = 0x00;
|
||||
private const byte LIGHT_MODE_REACTIVE = 0x01;
|
||||
// the "maximum" sensitivity values, that we subtract the value of the sensitivity slider from
|
||||
// to send to the controller. lower values sent to the controller result in higher sensitivity
|
||||
// so we do the subtraction
|
||||
private const int MAX_SLIDER_SENSITIVITY = 95;
|
||||
private const int MAX_AIR_SENSITIVITY = 55;
|
||||
|
||||
// default values for the sensitivity sliders
|
||||
private const int DEFAULT_TOUCH_SENSITIVITY = 15;
|
||||
private const int DEFAULT_AIR_SENSITIVITY = 15;
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not the controller is connected
|
||||
@@ -55,7 +64,13 @@ namespace OpeNITHMConfig
|
||||
{
|
||||
grpSliderConfig.Enabled = true;
|
||||
grpReactiveLightsConfig.Enabled = true;
|
||||
grpAirConfig.Enabled = analogAirSensors;
|
||||
mnuFactoryReset.Enabled = true;
|
||||
|
||||
if (analogAirSensors)
|
||||
{
|
||||
grpAirConfig.Enabled = true;
|
||||
grpAirConfig.Text = "Air sensor configuration";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -65,18 +80,9 @@ namespace OpeNITHMConfig
|
||||
{
|
||||
grpSliderConfig.Enabled = false;
|
||||
grpReactiveLightsConfig.Enabled = false;
|
||||
mnuFactoryReset.Enabled = false;
|
||||
grpAirConfig.Enabled = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Connects to a new controller and initializes our values
|
||||
/// </summary>
|
||||
/// <param name="port"></param>
|
||||
private void ConnectToController(string port)
|
||||
{
|
||||
serialPort.PortName = port;
|
||||
isConnected = true;
|
||||
enableControls(true);
|
||||
grpAirConfig.Text = "Air sensor configuration (analog air sensors only)";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -84,7 +90,8 @@ namespace OpeNITHMConfig
|
||||
/// </summary>
|
||||
/// <param name="command"></param>
|
||||
/// <param name="args"></param>
|
||||
private void sendCommand(byte command, byte[] args)
|
||||
/// <param name="close"></param>
|
||||
private void sendCommand(byte command, byte[] args, bool close = true)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -105,7 +112,9 @@ namespace OpeNITHMConfig
|
||||
// send the data
|
||||
serialPort.Open();
|
||||
serialPort.Write(data, 0, 100);
|
||||
serialPort.Close();
|
||||
|
||||
if (close)
|
||||
serialPort.Close();
|
||||
}
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
@@ -116,6 +125,45 @@ namespace OpeNITHMConfig
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Connects to a new controller and initializaes our values
|
||||
/// </summary>
|
||||
/// <param name="port"></param>
|
||||
/// <param name="sender"></param>
|
||||
private void ConnectToController(string port, ToolStripMenuItem sender)
|
||||
{
|
||||
serialPort.PortName = port;
|
||||
|
||||
// get the current info from the controller
|
||||
isConnected = true;
|
||||
//enableControls(false);
|
||||
sendCommand(CMD_PRINT_INFO, new byte[]{}, false);
|
||||
Thread.Sleep(500);
|
||||
|
||||
byte[] info = new byte[100];
|
||||
|
||||
try
|
||||
{
|
||||
serialPort.Read(info, 0, 100);
|
||||
serialPort.Close();
|
||||
|
||||
bool isAnalogAir = (info[0] == 0x11);
|
||||
colorDialogOn.Color = Color.FromArgb(info[1], info[2], info[3]);
|
||||
colorDialogOff.Color = Color.FromArgb(info[4], info[5], info[6]);
|
||||
trkSliderSensitivity.Value = MAX_SLIDER_SENSITIVITY - info[7];
|
||||
trkAirSensitivity.Value = MAX_AIR_SENSITIVITY - info[8];
|
||||
|
||||
enableControls(isAnalogAir);
|
||||
}
|
||||
catch (TimeoutException ex)
|
||||
{
|
||||
// serial timeout, don't enable anything
|
||||
isConnected = false;
|
||||
sender.Enabled = false;
|
||||
disableControls();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Show the "About" dialog
|
||||
/// </summary>
|
||||
@@ -135,12 +183,12 @@ namespace OpeNITHMConfig
|
||||
/// <param name="e"></param>
|
||||
private void btnSliderOnColor_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (colorDialog.ShowDialog() == DialogResult.OK)
|
||||
if (colorDialogOn.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
sendCommand(CMD_CHANGE_ON_COLOR, new byte[] {
|
||||
colorDialog.Color.R,
|
||||
colorDialog.Color.G,
|
||||
colorDialog.Color.B
|
||||
colorDialogOn.Color.R,
|
||||
colorDialogOn.Color.G,
|
||||
colorDialogOn.Color.B
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -152,12 +200,12 @@ namespace OpeNITHMConfig
|
||||
/// <param name="e"></param>
|
||||
private void btnSliderOffColor_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (colorDialog.ShowDialog() == DialogResult.OK)
|
||||
if (colorDialogOff.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
sendCommand(CMD_CHANGE_OFF_COLOR, new byte[] {
|
||||
colorDialog.Color.R,
|
||||
colorDialog.Color.G,
|
||||
colorDialog.Color.B
|
||||
colorDialogOff.Color.R,
|
||||
colorDialogOff.Color.G,
|
||||
colorDialogOff.Color.B
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -169,7 +217,7 @@ namespace OpeNITHMConfig
|
||||
/// <param name="e"></param>
|
||||
private void btnCalibrateSlider_Click(object sender, EventArgs e)
|
||||
{
|
||||
sendCommand(CMD_CALIBRATE_SLIDER, new byte[] { (byte) trkSliderSensitivity.Value });
|
||||
sendCommand(CMD_CALIBRATE_SLIDER, new byte[] { (byte) (MAX_SLIDER_SENSITIVITY - trkSliderSensitivity.Value) });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -179,7 +227,7 @@ namespace OpeNITHMConfig
|
||||
/// <param name="e"></param>
|
||||
private void btnCalibrateAir_Click(object sender, EventArgs e)
|
||||
{
|
||||
sendCommand(CMD_CALIBRATE_AIR_SENSORS, new byte[] { (byte) trkAirSensitivity.Value });
|
||||
sendCommand(CMD_CALIBRATE_AIR_SENSORS, new byte[] { (byte) (MAX_AIR_SENSITIVITY - trkAirSensitivity.Value) });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -204,8 +252,8 @@ namespace OpeNITHMConfig
|
||||
// set the click handler for the menu items
|
||||
ToolStripItem item = new ToolStripMenuItem(port, null, new EventHandler(delegate (Object o, EventArgs a)
|
||||
{
|
||||
ConnectToController(((ToolStripItem)o).Text);
|
||||
((ToolStripMenuItem)o).Checked = true;
|
||||
ConnectToController(((ToolStripItem) o).Text, (ToolStripMenuItem) o);
|
||||
((ToolStripMenuItem) o).Checked = true;
|
||||
}));
|
||||
|
||||
mnuComPort.DropDownItems.Add(item);
|
||||
@@ -220,5 +268,15 @@ namespace OpeNITHMConfig
|
||||
disableControls();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears the controller's EEPROM and re-initializes the default settings / goes through calibration again
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void factoryResetControllerToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,7 +126,10 @@
|
||||
<metadata name="tmrComPorts.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>132, 17</value>
|
||||
</metadata>
|
||||
<metadata name="colorDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<metadata name="colorDialogOn.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>411, 17</value>
|
||||
</metadata>
|
||||
<metadata name="colorDialogOff.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>542, 17</value>
|
||||
</metadata>
|
||||
</root>
|
||||
Reference in New Issue
Block a user