/* * Copyright (C) 2020 Freie Universität Berlin * * This file is subject to the terms and conditions of the GNU Lesser * General Public License v2.1. See the file LICENSE in the top level * directory for more details. */ /** * @ingroup tests * @brief Test application for the PCA9633 I2C PWM controller * @author Hendrik van Essen * @file * */ #include #include #include "xtimer.h" #include "shell.h" #include "pca9633.h" #include "pca9633_params.h" pca9633_t pca9633_dev; int turn_on(int argc, char **argv) { (void) argc; (void) argv; pca9633_turn_on(&pca9633_dev); return 0; } int turn_off(int argc, char **argv) { (void) argc; (void) argv; pca9633_turn_off(&pca9633_dev); return 0; } int wakeup(int argc, char **argv) { (void) argc; (void) argv; pca9633_wakeup(&pca9633_dev); return 0; } int enter_sleep(int argc, char **argv) { (void) argc; (void) argv; pca9633_sleep(&pca9633_dev); return 0; } int pwm(int argc, char **argv) { if (argc != 3) { puts("usage: pwm "); } else { uint8_t pwm = atoi(argv[2]); pca9633_pwm_channel_t pwm_channel; switch (atoi(argv[1])) { case 0: pwm_channel = PCA9633_PWM_CHANNEL_0; break; case 1: pwm_channel = PCA9633_PWM_CHANNEL_1; break; case 2: pwm_channel = PCA9633_PWM_CHANNEL_2; break; case 3: pwm_channel = PCA9633_PWM_CHANNEL_3; break; default: puts("channel needs to be one of [0-3]"); return -1; } pca9633_set_pwm(&pca9633_dev, pwm_channel, pwm); } return 0; } int grp_pwm(int argc, char **argv) { if (argc != 2) { puts("usage: grp_pwm "); } else { uint8_t pwm = atoi(argv[1]); pca9633_set_grp_pwm(&pca9633_dev, pwm); } return 0; } int blinking(int argc, char **argv) { if (argc != 2) { puts("usage: blinking <0 or 1>"); } else { uint8_t enabled = atoi(argv[1]); if (enabled >= 1) { pca9633_set_group_control_mode(&pca9633_dev, PCA9633_GROUP_CONTROL_MODE_BLINKING); pca9633_set_blinking(&pca9633_dev, 1000, PCA9633_BLINKING_RATIO_BALANCED); } else { pca9633_set_group_control_mode(&pca9633_dev, PCA9633_GROUP_CONTROL_MODE_DIMMING); } } return 0; } int rgb(int argc, char **argv) { if (argc != 4) { puts("usage: rgb "); } else { uint8_t r = atoi(argv[1]); uint8_t g = atoi(argv[2]); uint8_t b = atoi(argv[3]); pca9633_set_rgb(&pca9633_dev, r, g, b); } return 0; } int rgba(int argc, char **argv) { if (argc != 5) { puts("usage: rgba "); } else { uint8_t r = atoi(argv[1]); uint8_t g = atoi(argv[2]); uint8_t b = atoi(argv[3]); uint8_t w = atoi(argv[4]); pca9633_set_rgba(&pca9633_dev, r, g, b, w); } return 0; } int ldr_state(int argc, char **argv) { if (argc != 3) { puts("usage: ldr_state pwm "); puts(" state 0: PCA9633_LDR_STATE_OFF"); puts(" state 1: PCA9633_LDR_STATE_ON"); puts(" state 2: PCA9633_LDR_STATE_IND"); puts(" state 3: PCA9633_LDR_STATE_IND_GRP"); puts(" channel 0: PCA9633_PWM_CHANNEL_0"); puts(" channel 1: PCA9633_PWM_CHANNEL_1"); puts(" channel 2: PCA9633_PWM_CHANNEL_2"); puts(" channel 3: PCA9633_PWM_CHANNEL_3"); } else { pca9633_ldr_state_t state; switch (atoi(argv[1])) { case 0: state = PCA9633_LDR_STATE_OFF; break; case 1: state = PCA9633_LDR_STATE_ON; break; case 2: state = PCA9633_LDR_STATE_IND; break; case 3: state = PCA9633_LDR_STATE_IND_GRP; break; default: puts("state needs to be one of [0-3]"); puts(" state 0: PCA9633_LDR_STATE_OFF"); puts(" state 1: PCA9633_LDR_STATE_ON"); puts(" state 2: PCA9633_LDR_STATE_IND"); puts(" state 3: PCA9633_LDR_STATE_IND_GRP"); return -1; } pca9633_pwm_channel_t pwm_channel; switch (atoi(argv[2])) { case 0: pwm_channel = PCA9633_PWM_CHANNEL_0; break; case 1: pwm_channel = PCA9633_PWM_CHANNEL_1; break; case 2: pwm_channel = PCA9633_PWM_CHANNEL_2; break; case 3: pwm_channel = PCA9633_PWM_CHANNEL_3; break; default: puts("channel needs to be one of [0-3]"); puts(" channel 0: PCA9633_PWM_CHANNEL_0"); puts(" channel 1: PCA9633_PWM_CHANNEL_1"); puts(" channel 2: PCA9633_PWM_CHANNEL_2"); puts(" channel 3: PCA9633_PWM_CHANNEL_3"); return -1; } pca9633_set_ldr_state(&pca9633_dev, state, pwm_channel); } return 0; } int ldr_state_all(int argc, char **argv) { if (argc != 2) { puts("usage: ldr_state "); puts(" state 0: PCA9633_LDR_STATE_OFF"); puts(" state 1: PCA9633_LDR_STATE_ON"); puts(" state 2: PCA9633_LDR_STATE_IND"); puts(" state 3: PCA9633_LDR_STATE_IND_GRP"); } else { pca9633_ldr_state_t state; switch (atoi(argv[1])) { case 0: state = PCA9633_LDR_STATE_OFF; break; case 1: state = PCA9633_LDR_STATE_ON; break; case 2: state = PCA9633_LDR_STATE_IND; break; case 3: state = PCA9633_LDR_STATE_IND_GRP; break; default: puts("state needs to be one of [0-3]"); puts(" state 0: PCA9633_LDR_STATE_OFF"); puts(" state 1: PCA9633_LDR_STATE_ON"); puts(" state 2: PCA9633_LDR_STATE_IND"); puts(" state 3: PCA9633_LDR_STATE_IND_GRP"); return -1; } pca9633_set_ldr_state_all(&pca9633_dev, state); } return 0; } int auto_inc(int argc, char **argv) { if (argc != 2) { puts("usage: auto_inc