Skip to content

Commit

Permalink
Few clean ups
Browse files Browse the repository at this point in the history
  • Loading branch information
disq committed Nov 15, 2022
1 parent 6c3b90d commit 8b2a888
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 19 deletions.
28 changes: 18 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,32 @@ project(${NAME} C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

if (PICO_SDK_VERSION_STRING VERSION_LESS "1.4.0")
message(FATAL_ERROR "Raspberry Pi Pico SDK version 1.4.0 (or later) required. Your version is ${PICO_SDK_VERSION_STRING}")
endif()

set(PICO_CXX_ENABLE_EXCEPTIONS 1)
set(PICO_CXX_ENABLE_RTTI 1)

# Initialize the SDK
pico_sdk_init()

add_compile_options(-Wall
-Wno-format # int != int32_t as far as the compiler is concerned because gcc has int32_t as long int
-Wno-unused-function
-Wno-maybe-uninitialized
)

# Add your source files
add_executable(${NAME}
main.cpp ledcontrol.cpp ledcontrol.h util.h config.h encoder.cpp encoder.h
)

# Include required libraries
# This assumes `pimoroni-pico` is stored alongside your project
include(../pimoroni-pico/common/pimoroni_i2c)
include(../pimoroni-pico/drivers/ioexpander/ioexpander)
include(../pimoroni-pico/libraries/breakout_encoder/breakout_encoder)
include(../pimoroni-pico/drivers/button/button)
include(PicoLED/PicoLed.cmake)

# Don't forget to link the libraries you need!
target_link_libraries(${NAME}
pico_stdlib
button
Expand All @@ -43,24 +49,26 @@ target_link_libraries(${NAME}
pico_bootsel_via_double_reset
)

if (PICO_CYW43_SUPPORTED)
if (PICO_CYW43_SUPPORTED) # set by BOARD=pico-w
if (TARGET pico_cyw43_arch)
target_link_libraries(${NAME}
pico_cyw43_arch_none # we need Wifi to access the GPIO, but we don't need anything else
)
endif()
endif()

pico_enable_stdio_usb(${NAME} 1)
pico_enable_stdio_uart(${NAME} 0)

# create map/bin/hex file etc.
pico_add_extra_outputs(${NAME})
pico_enable_stdio_usb(${NAME} ENABLED)

# Set up files for the release packages
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${NAME}.uf2
${CMAKE_CURRENT_LIST_DIR}/README.md
DESTINATION .
)
${CMAKE_CURRENT_BINARY_DIR}/${NAME}.uf2
${CMAKE_CURRENT_LIST_DIR}/README.md
DESTINATION .
)

set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF)
set(CPACK_GENERATOR "ZIP" "TGZ")
Expand Down
4 changes: 2 additions & 2 deletions encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ uint32_t pwm_set_freq_duty(uint slice_num, uint chan, uint32_t f, int d) {
Encoder::Encoder() {
}

void Encoder::init(int p_pin_led_r, int p_pin_led_g, int p_pin_led_b,
int p_pin_enc_a, int p_pin_enc_b, int p_pin_enc_sw, bool p_leds_active_low) {
void Encoder::init(uint p_pin_led_r, uint p_pin_led_g, uint p_pin_led_b,
uint p_pin_enc_a, uint p_pin_enc_b, uint p_pin_enc_sw, bool p_leds_active_low) {
pin_enc_a = p_pin_enc_a;
pin_enc_b = p_pin_enc_b;
pin_enc_sw = p_pin_enc_sw;
Expand Down
6 changes: 3 additions & 3 deletions encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

class Encoder {
private:
int pin_enc_a, pin_enc_b, pin_enc_sw; // connect encoder pin C to ground
int led_pins[3], in_pins[3];
uint pin_enc_a, pin_enc_b, pin_enc_sw; // connect encoder pin C to ground
uint led_pins[3], in_pins[3];
uint8_t led_vals[3];
bool leds_active_low;
float led_brightness;
Expand All @@ -21,7 +21,7 @@ class Encoder {

public:
Encoder();
void init(int p_pin_led_r, int p_pin_led_g, int p_pin_led_b, int p_pin_enc_a, int p_pin_enc_b, int p_pin_enc_sw, bool p_leds_active_low = true);
void init(uint p_pin_led_r, uint p_pin_led_g, uint p_pin_led_b, uint p_pin_enc_a, uint p_pin_enc_b, uint p_pin_enc_sw, bool p_leds_active_low = true);
void set_leds(uint8_t r, uint8_t g, uint8_t b);
void set_brightness(float brightness);

Expand Down
1 change: 1 addition & 0 deletions ledcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ LEDControl::LEDControl():
state(DEFAULT_STATE),
encoder_last_blink(0),
encoder_blink_state(false),
start_time(0),
stop_time(0),
led_strip(PicoLed::addLeds<PicoLed::WS2812B>(pio0, 0, LED_DATA_PIN, NUM_LEDS, PicoLed::FORMAT_WRGB)),
button_b(pimoroni::Button(BUTTON_B_PIN, pimoroni::Polarity::ACTIVE_LOW, 0))
Expand Down
8 changes: 4 additions & 4 deletions ledcontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ namespace ledcontrol {
void _enc_rotate_cb(signed int counter);

private:
state_t state;
uint32_t encoder_last_blink;
bool encoder_blink_state;
uint32_t start_time, stop_time;
PicoLed::PicoLedController led_strip;
pimoroni::Button button_b;
Encoder *enc = nullptr;

state_t state;
enum MENU_MODE menu_mode;
bool cycle{};
uint32_t encoder_last_blink;
bool encoder_blink_state;
uint32_t start_time{}, stop_time;

const char flash_save_magic[8] = "LEDCTRL";
typedef struct {
Expand Down

0 comments on commit 8b2a888

Please sign in to comment.