Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
rampinglight
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
4
Issues
4
List
Boards
Labels
Service Desk
Milestones
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Sven Greiner
rampinglight
Commits
a8a5725f
Commit
a8a5725f
authored
Jul 07, 2019
by
Sven Greiner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Store output non inverted and index levels from 0
This saves 12 bytes of flash.
parent
95a0188d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
21 deletions
+14
-21
rampinglight.c
rampinglight.c
+14
-21
No files found.
rampinglight.c
View file @
a8a5725f
...
@@ -171,22 +171,17 @@ static void set_pwm(const uint8_t pwm) {
...
@@ -171,22 +171,17 @@ static void set_pwm(const uint8_t pwm) {
}
}
/**
/**
* Set output to a level as defined in the ramp table. The table is indexed
* Set output to a level as defined in the ramp table.
* starting from 1 so that level 0 can be used to disable the output.
*
*
* @param level Index in ramp_values or fixed_values depending on fixed_mode
* @param level Index in ramp_values or fixed_values depending on fixed_mode
*/
*/
void
set_level
(
const
uint8_t
level
)
{
void
set_level
(
const
uint8_t
level
)
{
if
(
level
==
0
)
{
if
(
options
.
fixed_mode
)
{
disable_output
(
);
set_pwm
(
fixed_values
[
options
.
start_high
?
FIXED_SIZE
-
level
-
1
:
level
]
);
}
else
{
}
else
{
if
(
options
.
fixed_mode
)
{
set_pwm
(
ramp_values
[
level
]);
set_pwm
(
fixed_values
[
options
.
start_high
?
FIXED_SIZE
-
level
:
level
-
1
]);
}
else
{
set_pwm
(
ramp_values
[
level
-
1
]);
}
enable_output
();
}
}
enable_output
();
}
}
/**
/**
...
@@ -272,9 +267,7 @@ void save_output(void) {
...
@@ -272,9 +267,7 @@ void save_output(void) {
}
while
(
i
);
}
while
(
i
);
}
}
// Store inverted so that an output of 0 (invalid in this code) can be used
eeprom_onlywrite_byte
(
output_eeprom_pos
,
output
);
// to detect unused bytes in the EEPROM (0xFF)
eeprom_onlywrite_byte
(
output_eeprom_pos
,
~
output
);
}
}
/**
/**
...
@@ -287,7 +280,7 @@ void restore_state(void) {
...
@@ -287,7 +280,7 @@ void restore_state(void) {
// From back to front find the first byte that is not uninitialized EEPROM
// From back to front find the first byte that is not uninitialized EEPROM
output_eeprom_pos
=
EEPROM_OUTPUT_WL_BYTES
-
1
;
output_eeprom_pos
=
EEPROM_OUTPUT_WL_BYTES
-
1
;
while
(
output_eeprom_pos
&&
!
(
output_eeprom
=
~
eeprom_read_byte
((
uint8_t
*
)
output_eeprom_pos
))
)
{
while
(
output_eeprom_pos
&&
(
output_eeprom
=
eeprom_read_byte
((
uint8_t
*
)
output_eeprom_pos
))
==
0xFF
)
{
--
output_eeprom_pos
;
--
output_eeprom_pos
;
}
}
if
(
output_eeprom_pos
==
EEPROM_OUTPUT_WL_BYTES
-
1
)
{
if
(
output_eeprom_pos
==
EEPROM_OUTPUT_WL_BYTES
-
1
)
{
...
@@ -407,13 +400,13 @@ int main(void) {
...
@@ -407,13 +400,13 @@ int main(void) {
fast_presses
=
0
;
fast_presses
=
0
;
ramping_up
=
1
;
ramping_up
=
1
;
if
(
options
.
mode_memory
&&
output_eeprom
)
{
if
(
options
.
mode_memory
&&
output_eeprom
!=
0xFF
)
{
output
=
output_eeprom
;
output
=
output_eeprom
;
}
else
{
}
else
{
if
(
!
options
.
fixed_mode
&&
options
.
start_high
)
{
if
(
!
options
.
fixed_mode
&&
options
.
start_high
)
{
output
=
RAMP_SIZE
;
output
=
RAMP_SIZE
-
1
;
}
else
{
}
else
{
output
=
1
;
output
=
0
;
}
}
}
}
}
else
{
// User has tapped the power button
}
else
{
// User has tapped the power button
...
@@ -459,7 +452,7 @@ int main(void) {
...
@@ -459,7 +452,7 @@ int main(void) {
break
;
break
;
case
kFixed
:
case
kFixed
:
output
=
(
output
%
FIXED_SIZE
)
+
1
;
output
=
(
output
+
1
)
%
FIXED_SIZE
;
save_output
();
save_output
();
break
;
break
;
...
@@ -489,13 +482,13 @@ int main(void) {
...
@@ -489,13 +482,13 @@ int main(void) {
case
kRamping
:
case
kRamping
:
ramping_up
=
ramping_up
=
(
ramping_up
&&
output
<
RAMP_SIZE
)
||
(
ramping_up
&&
output
<
RAMP_SIZE
-
1
)
||
(
!
ramping_up
&&
output
==
1
);
(
!
ramping_up
&&
output
==
0
);
output
+=
ramping_up
?
1
:
-
1
;
output
+=
ramping_up
?
1
:
-
1
;
set_level
(
output
);
set_level
(
output
);
if
(
output
==
RAMP_SIZE
)
{
if
(
output
==
RAMP_SIZE
-
1
)
{
if
(
options
.
freeze_on_high
)
{
if
(
options
.
freeze_on_high
)
{
state
=
kFrozen
;
state
=
kFrozen
;
break
;
break
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment