Illumination module fixes, report as module
This commit is contained in:
parent
225e208eae
commit
5c0d38f3b2
4 changed files with 110 additions and 29 deletions
|
|
@ -137,6 +137,9 @@ void get_modules(String)
|
|||
comPort->print(" soft");
|
||||
#endif
|
||||
comPort->println();
|
||||
#endif
|
||||
#if defined(ILLUMINATION)
|
||||
comPort->println("Illumination:default");
|
||||
#endif
|
||||
comPort->println("--END--");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,23 +8,53 @@
|
|||
#include "dummyEEPROM.h"
|
||||
#endif
|
||||
|
||||
const uint16_t eeprom_offset = 100;
|
||||
|
||||
const uint8_t pwm_led_pins[] = WIRING_PWM_LEDS;
|
||||
const uint16_t cc_value_eeprom = eeprom_offset;
|
||||
const uint16_t pwm_frequency_eeprom = cc_value_eeprom + sizeof(uint8_t);
|
||||
const uint16_t pwm_values_eeprom = pwm_frequency_eeprom + sizeof(uint16_t);
|
||||
|
||||
uint32_t pwm_frequency;
|
||||
uint8_t cc_value;
|
||||
|
||||
uint16_t pwm_values[PWM_NUM];
|
||||
|
||||
|
||||
void illumination_pwm_freq(String command)
|
||||
{
|
||||
char * args[1];
|
||||
parse_arguments(args, command, 1);
|
||||
uint8_t parsed = parse_arguments(args, command, 1);
|
||||
#ifdef MCU_PICO
|
||||
analogWriteFreq(atol(args[0]));//32khz seems sensible
|
||||
analogWriteRange(65535);
|
||||
if (parsed > 0 && !(args[0] == "" || args[0][0] == '?'))
|
||||
{
|
||||
pwm_frequency = atol(args[0]);
|
||||
EEPROM.put(pwm_frequency_eeprom, pwm_frequency);
|
||||
analogWriteFreq(pwm_frequency);
|
||||
analogWriteRange(65535);
|
||||
}
|
||||
|
||||
comPort->print("Frequency set: ");
|
||||
comPort->print(atol(args[0]));
|
||||
comPort->print("PWM Frequency:");
|
||||
comPort->print(pwm_frequency);
|
||||
comPort->println("Hz");
|
||||
#else
|
||||
comPort->println("Feature not supported");
|
||||
#endif
|
||||
|
||||
free(args[0]);
|
||||
if (parsed > 0)
|
||||
free(args[0]);
|
||||
}
|
||||
|
||||
void illumination_channels(String command)
|
||||
{
|
||||
comPort->print("CC:");
|
||||
#ifdef WIRING_CC_LED
|
||||
comPort->print(1);
|
||||
#else
|
||||
comPort->print(0);
|
||||
#endif
|
||||
comPort->print(" PWM:");
|
||||
comPort->println(PWM_NUM);
|
||||
}
|
||||
|
||||
void illumination_pwm(String command)
|
||||
|
|
@ -32,7 +62,26 @@ void illumination_pwm(String command)
|
|||
#ifdef MCU_PICO
|
||||
//PWM frequency is shared between both PWM outputs
|
||||
char * args[2];
|
||||
parse_arguments(args, command, 2);
|
||||
uint8_t parsed = parse_arguments(args, command, 2);
|
||||
if (parsed > 0 && args[0][0] == '?')
|
||||
{
|
||||
comPort->print("PWM:");
|
||||
for(int i=0; i<PWM_NUM; i++)
|
||||
{
|
||||
#ifdef MCU_PICO
|
||||
comPort->print(pwm_values[i]/65535.0);
|
||||
#else
|
||||
comPort->print(pwm_values[i]/255.0);
|
||||
#endif
|
||||
comPort->print(";");
|
||||
}
|
||||
comPort->println("");
|
||||
free(args[0]);
|
||||
if (parsed == 2)
|
||||
free(args[1]);
|
||||
|
||||
return;
|
||||
}
|
||||
uint8_t index = atoi(args[0]);
|
||||
if (index >= PWM_NUM)
|
||||
{
|
||||
|
|
@ -45,26 +94,28 @@ void illumination_pwm(String command)
|
|||
digitalWrite(pwm_led_pins[index], LOW);
|
||||
}
|
||||
#ifdef MCU_PICO
|
||||
uint32_t pwm_val = val * 65535;
|
||||
uint16_t pwm_val = val * 65535;
|
||||
#else
|
||||
uint8_t pwm_val = val*255;
|
||||
uint8_t pwm_val = val * 255;
|
||||
#endif
|
||||
|
||||
analogWrite(pwm_led_pins[index], pwm_val);
|
||||
comPort->print("Illumination set");
|
||||
pwm_values[index] = pwm_val;
|
||||
EEPROM.put(pwm_values_eeprom+index*sizeof(uint16_t), pwm_val);
|
||||
comPort->print("PWM:");
|
||||
comPort->print(index);
|
||||
comPort->print(":");
|
||||
comPort->println(pwm_val);
|
||||
|
||||
free(args[0]);
|
||||
free(args[1]);
|
||||
if (parsed > 0)
|
||||
free(args[0]);
|
||||
if (parsed > 1)
|
||||
free(args[1]);
|
||||
#endif
|
||||
}
|
||||
|
||||
void illumination_setup()
|
||||
{
|
||||
#ifdef MCU_PICO
|
||||
analogWriteRange(65535);
|
||||
analogWriteFreq(32000);//32khz seems sensible
|
||||
#endif
|
||||
for (uint8_t i = 0; i < PWM_NUM; i++)
|
||||
{
|
||||
pinMode(pwm_led_pins[i], OUTPUT);
|
||||
|
|
@ -72,15 +123,31 @@ void illumination_setup()
|
|||
}
|
||||
|
||||
#ifdef WIRING_CC_LED
|
||||
EEPROM.get(cc_value_eeprom, cc_value);
|
||||
pinMode(WIRING_CC_LED, OUTPUT);
|
||||
if (cc_value > 0)
|
||||
cc_set_value(cc_value/32.0);
|
||||
#endif
|
||||
|
||||
#ifdef MCU_PICO
|
||||
EEPROM.get(pwm_frequency_eeprom, pwm_frequency);
|
||||
if (pwm_frequency < 1)
|
||||
pwm_frequency = 64000;
|
||||
analogWriteRange(65535);
|
||||
analogWriteFreq(pwm_frequency);//32khz seems sensible
|
||||
#endif
|
||||
|
||||
for(int i = 0; i < PWM_NUM; i++)
|
||||
{
|
||||
EEPROM.get(pwm_values_eeprom+i*sizeof(uint16_t), pwm_values[i]);
|
||||
analogWrite(pwm_led_pins[i], pwm_values[i]);
|
||||
}
|
||||
|
||||
register_module(illumination_commands, NULL);
|
||||
}
|
||||
|
||||
#ifdef WIRING_CC_LED
|
||||
|
||||
//these functions are useful testing
|
||||
//these functions are useful for testing
|
||||
float multi_read(uint8_t pin, uint16_t reads)
|
||||
{
|
||||
float total = 0;
|
||||
|
|
@ -114,11 +181,17 @@ void cc_test()
|
|||
void cc_set(String command)
|
||||
{
|
||||
char * args[1];
|
||||
parse_arguments(args, command, 1);
|
||||
float val = atof(args[0]);
|
||||
uint8_t parsed = parse_arguments(args, command, 1);
|
||||
if (parsed > 0 && !(args[0] == "" || args[0][0] == '?'))
|
||||
{
|
||||
float val = atof(args[0]);
|
||||
cc_set_value(val);
|
||||
}
|
||||
|
||||
free(args[0]);
|
||||
cc_set_value(val);
|
||||
comPort->print("CC LED:");
|
||||
comPort->println(cc_value/32.0);
|
||||
if (parsed > 0)
|
||||
free(args[0]);
|
||||
}
|
||||
|
||||
void cc_set_value(float val)
|
||||
|
|
@ -130,6 +203,9 @@ void cc_set_value(float val)
|
|||
return;
|
||||
}
|
||||
|
||||
cc_value = 32 * val;
|
||||
EEPROM.put(cc_value_eeprom, cc_value);
|
||||
|
||||
const uint8_t td = 3; // >= 1.5 us
|
||||
const uint8_t tup = 2; // 1-75 us
|
||||
const uint8_t tdown = 180; //180-300us
|
||||
|
|
@ -173,7 +249,8 @@ void cc_set_value(float val)
|
|||
|
||||
extern const Command illumination_commands[] = {
|
||||
{"led_pwm", illumination_pwm},
|
||||
{"led_freq", illumination_pwm_freq},
|
||||
{"led_cc_set", cc_set},
|
||||
{"led_channels", illumination_channels},
|
||||
{"led_frequency", illumination_pwm_freq},
|
||||
{"led_cc", cc_set},
|
||||
END_COMMAND};
|
||||
#endif
|
||||
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
void illumination_pwm(String command);
|
||||
void illumination_pwm_freq(String command);
|
||||
void illumination_channels(String command);
|
||||
|
||||
void cc_set(String command);
|
||||
void cc_set_value(float val);
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ void setup() {
|
|||
Serial.begin(115200);
|
||||
// NOTE!!! Wait for >2 secs
|
||||
// if board doesn't support software reset via comPort->DTR/RTS
|
||||
delay(2000);
|
||||
delay(5000);
|
||||
UNITY_BEGIN(); // IMPORTANT LINE!
|
||||
//bizzare string issues caused this to fail in specific sequences, so we run it multiple times
|
||||
RUN_TEST(test_multiple_argument_parsing);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue