Skip to content

Commit

Permalink
Merge pull request #36 from sssata/a-lot-of-changes
Browse files Browse the repository at this point in the history
remove app images from lfs, others
  • Loading branch information
sssata authored Sep 25, 2023
2 parents 40eb466 + c11c658 commit 8a8cd76
Show file tree
Hide file tree
Showing 11 changed files with 261 additions and 67 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
*.SLDASM filter=lfs diff=lfs merge=lfs -text
*.STEP filter=lfs diff=lfs merge=lfs -text
*.STP filter=lfs diff=lfs merge=lfs -text
APP/images/** -filter=lfs -diff=lfs -merge=lfs -text
232 changes: 208 additions & 24 deletions APP/fluxapp.py

Large diffs are not rendered by default.

45 changes: 37 additions & 8 deletions APP/fluxpad_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ class LightingMode(enum.IntEnum):
Flash = 3


class RGBMode(enum.IntEnum):
Off = 0
Static = 1
Rainbow = 2


class MessageKey:
COMMAND = "cmd"
TOKEN = "tkn"
Expand Down Expand Up @@ -263,7 +269,7 @@ def key_code(self):

@key_code.setter
def key_code(self, key_code: int):
self._assert_uint8(key_code)
self._assert_uint16(key_code)
self.data[MessageKey.KEY_CODE] = key_code

@property
Expand Down Expand Up @@ -457,7 +463,6 @@ def color1(self):

@color1.setter
def color1(self, color: int):
self._assert_uint8(color)
self.data[MessageKey.RGB_C1] = color

# RGB Color 2
Expand All @@ -467,7 +472,6 @@ def color2(self):

@color2.setter
def color2(self, color: int):
self._assert_uint8(color)
self.data[MessageKey.RGB_C2] = color

# RGB Color 3
Expand All @@ -477,7 +481,6 @@ def color3(self):

@color3.setter
def color3(self, color: int):
self._assert_uint8(color)
self.data[MessageKey.RGB_C3] = color

# RGB BRIGHTNESS
Expand Down Expand Up @@ -535,7 +538,7 @@ def height_mm(self, dummy: int):
# """Composite class of all settings types"""
# pass

AnyMessage = TypeVar("AnyMessage", DigitalSettingsMessage, AnalogSettingsMessage, EncoderSettingsMessage, AnalogCalibrationMessage, AnalogReadMessage, Union[DigitalSettingsMessage, AnalogSettingsMessage, EncoderSettingsMessage, AnalogCalibrationMessage, AnalogReadMessage])
AnyMessage = TypeVar("AnyMessage", DigitalSettingsMessage, AnalogSettingsMessage, EncoderSettingsMessage, AnalogCalibrationMessage, AnalogReadMessage, RGBSettingsMessage, Union[DigitalSettingsMessage, AnalogSettingsMessage, EncoderSettingsMessage, AnalogCalibrationMessage, AnalogReadMessage, RGBSettingsMessage])


class Fluxpad:
Expand Down Expand Up @@ -714,6 +717,7 @@ def _worker(self):
class FluxpadSettings:

KEY_SETTINGS_KEY = "key_settings"
RGB_SETTINGS_KEY = "rgb_settings"

def __init__(self) -> None:
self.key_settings_list: List[Union[EncoderSettingsMessage, AnalogSettingsMessage, DigitalSettingsMessage]] = [
Expand All @@ -725,6 +729,7 @@ def __init__(self) -> None:
EncoderSettingsMessage(),
EncoderSettingsMessage(),
]
self.rgb_settings = RGBSettingsMessage()

def _set_key_ids(self):
key_id = 0
Expand Down Expand Up @@ -753,6 +758,18 @@ def load_from_keypad(self, fluxpad: Fluxpad):
else:
key_settings.data = response.data.copy()

try:
# Read RGB Settings
self.rgb_settings.set_zeros()
response = fluxpad.send_read_request(self.rgb_settings)

# Check all requested keys exist
assert set(response.data.keys()) == set(self.rgb_settings.data.keys()), f"Difference: {set(response.data.keys()).symmetric_difference(set(self.rgb_settings.data.keys()))}"
logging.debug("Got RGB settings")
except Exception:
logging.error(f"Failed to get RGB settings {self.rgb_settings.data}", exc_info=True)
else:
self.rgb_settings.data = response.data.copy()

def save_to_fluxpad(self, fluxpad: Fluxpad, include_calibration: bool = False):
"""Save all settings to the given connected fluxpad"""
Expand All @@ -767,6 +784,13 @@ def save_to_fluxpad(self, fluxpad: Fluxpad, include_calibration: bool = False):
logging.debug(f"Wrote settings for Key ID {key_settings.key_id}")
except Exception:
logging.error(f"Failed to write settings for Key ID {key_settings.key_id} with message {key_settings.data}", exc_info=True)

rgb_settings = self.rgb_settings
try:
response = fluxpad.send_write_request(rgb_settings)
logging.debug(f"Wrote rgb settings")
except Exception:
logging.error(f"Failed to write rgb settings with message {rgb_settings.data}", exc_info=True)

def load_from_file(self, path: pathlib.Path):
"""Load all settings from the given file"""
Expand All @@ -781,8 +805,12 @@ def load_from_file(self, path: pathlib.Path):
for json_object in root_json[self.KEY_SETTINGS_KEY]:
self.key_settings_list[json_object[MessageKey.KEY_ID]].data = json_object
except Exception:
logging.error(f"Failed to parse settings from {path}", exc_info=True)

logging.error(f"Failed to parse key settings from {path}", exc_info=True)

try:
self.rgb_settings.data = root_json[self.RGB_SETTINGS_KEY]
except Exception:
logging.error(f"Failed to parse rgb settings from {path}", exc_info=True)

def save_to_file(self, path: pathlib.Path):
"""Save all settings to the given file"""
Expand All @@ -795,7 +823,8 @@ def save_to_file(self, path: pathlib.Path):

# Construct master json to store all settings
root_dict = dict()
root_dict[self.KEY_SETTINGS_KEY] = [key_settings.data for key_settings in self.key_settings_list]\
root_dict[self.KEY_SETTINGS_KEY] = [key_settings.data for key_settings in self.key_settings_list]
root_dict[self.RGB_SETTINGS_KEY] = self.rgb_settings.data

with path.open("w") as f:
json.dump(root_dict, f, indent=4)
Expand Down
Binary file modified APP/images/FluxappIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified APP/images/cal_key1_down.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified APP/images/cal_key1_up.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified APP/images/cal_key2_down.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified APP/images/cal_key2_up.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 10 additions & 10 deletions FW/fluxpad_rp2040_pio/src/AnalogSwitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,27 @@ typedef int64_t q53_10_t;
#define ADC_BITS 12
#define LUT_BITS 4
const q22_10_t adc_to_dist_lut[] = {
FLOAT_TO_Q22_10(0.0f), // 0
FLOAT_TO_Q22_10(0.6f), // 256
FLOAT_TO_Q22_10(1.8f), // 512
FLOAT_TO_Q22_10(0.0f), // 0
FLOAT_TO_Q22_10(0.6f), // 256
FLOAT_TO_Q22_10(1.8f), // 512
FLOAT_TO_Q22_10(2.42f), // 768
FLOAT_TO_Q22_10(2.65f), // 1024
FLOAT_TO_Q22_10(2.65f), // 1024
FLOAT_TO_Q22_10(2.79), // 1280
FLOAT_TO_Q22_10(2.95f), // 1536
FLOAT_TO_Q22_10(3.15f), // 1792
FLOAT_TO_Q22_10(3.4f), // 2048
FLOAT_TO_Q22_10(2.95f), // 1536
FLOAT_TO_Q22_10(3.15f), // 1792
FLOAT_TO_Q22_10(3.4f), // 2048
FLOAT_TO_Q22_10(3.71f), // 2304
FLOAT_TO_Q22_10(4.05f), // 2560
FLOAT_TO_Q22_10(4.55f), // 2816
FLOAT_TO_Q22_10(5.31f), // 3072
FLOAT_TO_Q22_10(6.55f), // 3328
FLOAT_TO_Q22_10(9.0f), // 3584
FLOAT_TO_Q22_10(9.5f), // 3840
FLOAT_TO_Q22_10(9.0f), // 3584
FLOAT_TO_Q22_10(9.5f), // 3840
FLOAT_TO_Q22_10(10.0f), // 4096
};

const q22_10_t adc_clamp_min = INT_TO_Q22_10(0);
const q22_10_t adc_clamp_max = INT_TO_Q22_10(1<<ADC_BITS);
const q22_10_t adc_clamp_max = INT_TO_Q22_10(1 << ADC_BITS);

const q22_10_t reference_up_mm = FLOAT_TO_Q22_10(6.0f);
const q22_10_t reference_down_mm = FLOAT_TO_Q22_10(2.0f);
Expand Down
2 changes: 0 additions & 2 deletions FW/fluxpad_rp2040_pio/src/RBGLed.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class RGBLeds {
}

void new_mode() {
Serial.printf("newmode");
switch (settings.mode) {
case RGBMode::OFF:
turn_off();
Expand All @@ -82,7 +81,6 @@ class RGBLeds {
}

void static_mode() {
Serial.print("static");
leds[0].setColorCode(settings.color_1);
leds[1].setColorCode(settings.color_2);
leds[2].setColorCode(settings.color_3);
Expand Down
28 changes: 5 additions & 23 deletions FW/fluxpad_rp2040_pio/src/flux_arduino.ino
Original file line number Diff line number Diff line change
Expand Up @@ -124,25 +124,13 @@ uint32_t last_datatream_time_ms = 0;

void setup() {

// DISABLE UART RX TX LEDS
// pinMode(PIN_LED2, INPUT_PULLUP);
// pinMode(PIN_LED3, INPUT_PULLUP);

EEPROM.begin(1024);

analogReadResolution(12);

Serial.setTimeout(100);
Serial.begin(115200);
// Keyboard.begin();
// Consumer.begin();
usb_service_setup(VID, PID);
// adc_input.setFrequency(5000);
// adc_input.setBuffers(100, 1zzzzzzz6);
// adc_input.begin();

// encoder.begin(ENC_A_PIN, ENC_B_PIN, EncoderTool::CountMode::quarter, INPUT_PULLUP);
// encoder = RotaryEncoder(ENC_A_PIN, ENC_A_PIN);

pinMode(ENC_A_PIN, INPUT_PULLUP);
pinMode(ENC_B_PIN, INPUT_PULLUP);
Expand All @@ -166,7 +154,6 @@ void setup() {
i++;
}

pinMode(3, OUTPUT_12MA);
rgb_leds.setup();

last_time_us = time_us_64();
Expand All @@ -179,7 +166,6 @@ uint32_t blink_period_us = HZ_TO_PERIOD_US(50);
void loop() {

uint64_t curr_time_us = time_us_64();
curr_time_us += UINT32_MAX;
if (curr_time_us - last_time_us < mainloop_period_us) {
return;
}
Expand Down Expand Up @@ -261,14 +247,10 @@ void loop() {
lighting.lightingTask(curr_time_us);
}

// keyLighting[0].lightingTask(curr_time_us);
// keyLighting[1].lightingTask(curr_time_us);
// keyLighting[2].lightingTask(curr_time_us);
// keyLighting[3].lightingTask(curr_time_us);
// keyLighting[4].lightingTask(curr_time_us);

// Keyboard.send();
usb_service();
if (!debug_mode) {
usb_service();
}
read_serial();

// Send data out in datastream mode
Expand Down Expand Up @@ -664,11 +646,11 @@ void read_serial() {
rgb_leds.new_mode();
}
if (request_msg.containsKey("rgb_c2")) {
storage_vars.rgbSettings.color_1 = request_msg["rgb_c2"].as<unsigned int>();
storage_vars.rgbSettings.color_2 = request_msg["rgb_c2"].as<unsigned int>();
rgb_leds.new_mode();
}
if (request_msg.containsKey("rgb_c3")) {
storage_vars.rgbSettings.color_1 = request_msg["rgb_c3"].as<unsigned int>();
storage_vars.rgbSettings.color_3 = request_msg["rgb_c3"].as<unsigned int>();
rgb_leds.new_mode();
}
if (request_msg.containsKey("rgb_s")) {
Expand Down

0 comments on commit 8a8cd76

Please sign in to comment.