diff options
-rw-r--r-- | avr-attiny25-ampli-wakeup-delay/Makefile | 41 | ||||
-rw-r--r-- | avr-attiny25-ampli-wakeup-delay/main.c | 23 | ||||
-rw-r--r-- | two_hosts_auto_powerswitch/readme.rst | 41 | ||||
-rw-r--r-- | two_hosts_auto_powerswitch/readme_flowchart.asciio | bin | 0 -> 26794 bytes | |||
-rw-r--r-- | two_hosts_auto_powerswitch/readme_flowchart.txt | 33 |
5 files changed, 138 insertions, 0 deletions
diff --git a/avr-attiny25-ampli-wakeup-delay/Makefile b/avr-attiny25-ampli-wakeup-delay/Makefile new file mode 100644 index 0000000..14bc95e --- /dev/null +++ b/avr-attiny25-ampli-wakeup-delay/Makefile @@ -0,0 +1,41 @@ +# settings for arduino uno +DEVICE = attiny25 +CLOCK = 1000000 + +# buspirate programmer +PORT=/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A400XJSH-if00-port0 +AVRDUDE=avrdude -p $(DEVICE) -c buspirate -P $(PORT) + +DEFS = -DF_CPU=$(CLOCK)UL +LIBS = -Wl,--relax,--gc-sections,--print-gc-sections,--entry=main +LIBS = -Wl,--entry=main,--gc-sections,--rela +CFLAGS = -Wall -Werror -pedantic +#-std=c99 // default should be gnu99 nowaday, no need to specify c99 +CFLAGS += -Os -funsigned-bitfields -fpack-struct -fshort-enums +CFLAGS += -mmcu=$(DEVICE) $(DEFS) +#LDFLAGS = $(LIBS) + +all: main.hex size + +main.hex: main.c + avr-gcc -o main.elf $? $(CFLAGS) $(LDFLAGS) + avr-objcopy -j .text -j .data -O ihex main.elf main.hex + +f: flash +flash: all + $(AVRDUDE) -U flash:w:main.hex:i + +dumpfuses: + $(AVRDUDE) -U lfuse:r:lfuse.txt:h + $(AVRDUDE) -U hfuse:r:hfuse.txt:h + $(AVRDUDE) -U efuse:r:efuse.txt:h + +clean: + rm -f *.o *.elf *.hex + +size: + avr-size --mcu=$(DEVICE) -t -A main.elf + avr-size --mcu=$(DEVICE) -C main.elf + avr-nm --size-sort main.elf + + diff --git a/avr-attiny25-ampli-wakeup-delay/main.c b/avr-attiny25-ampli-wakeup-delay/main.c new file mode 100644 index 0000000..6fb530e --- /dev/null +++ b/avr-attiny25-ampli-wakeup-delay/main.c @@ -0,0 +1,23 @@ +#include <avr/io.h> +#include <util/delay.h> + +int main(void) +{ + /* PB4 output */ + DDRB |= _BV(4); + PORTB &= ~_BV(4); + + //for (;;) + //{ + // _delay_ms(1000); + // PORTB ^= _BV(4); + //} + + // wait for 45s and enable the amplifier + for (uint8_t i = 0; i < 32; ++i) { + _delay_ms(1000); + } + PORTB |= _BV(4); + + return 0; +} diff --git a/two_hosts_auto_powerswitch/readme.rst b/two_hosts_auto_powerswitch/readme.rst index 7eac7fe..2a4617d 100644 --- a/two_hosts_auto_powerswitch/readme.rst +++ b/two_hosts_auto_powerswitch/readme.rst @@ -122,3 +122,44 @@ in another location, one does not need the associated devices to be on). In my case, the wake-on-lan was an exception to the normal usage of my computer, so I made the skip choice to be in the workflow. + +State machines +============== + +- debouncing buttons state tables:: + + #0 button released [pin change interrupt] -> debounce start [timeout] + -> timeout [button pressed] -> #1 + event button_down + -> timeout [button released] -> #0 + + #1 button pressed [timeout] -> first up [timeout] -> debounce [timeout] + -> timeout [button pressed] -> #1 + -> timeout [button released] -> #0 + event button_up + +Ex of a transition table: +State Event Next state Transition function +stopped play_event playing do_play +playing stop_event stopped do_stop +playing pause_event paused do_pause +paused play_event playing do_resume +paused stop_event stopped do_stop + +ex of fsm implem for another language: +https://github.com/hyperandroid/Automata + +ex of fsm implem in c: +https://github.com/gitrealname/ofsm + +formal description in yaml ? + +fsm0: + initialstate: state0 + state0: + enter: action_enter + exit: action_exit + events: + - event: ok + nextstate: state1 + - event: ... + state1: + ... diff --git a/two_hosts_auto_powerswitch/readme_flowchart.asciio b/two_hosts_auto_powerswitch/readme_flowchart.asciio Binary files differnew file mode 100644 index 0000000..91aa2cc --- /dev/null +++ b/two_hosts_auto_powerswitch/readme_flowchart.asciio diff --git a/two_hosts_auto_powerswitch/readme_flowchart.txt b/two_hosts_auto_powerswitch/readme_flowchart.txt new file mode 100644 index 0000000..6a7ef42 --- /dev/null +++ b/two_hosts_auto_powerswitch/readme_flowchart.txt @@ -0,0 +1,33 @@ +.------------------. .-----------------------. +| Host state | | Serial | .---. +| change detection | | computer state toggle | | A | +'------------------' .---------------. '-----------------------' '---' + | | Computer | | + | | Button toggle |-----------------| + | '---------------' | ^ + v v ----' + .------------. .----------------------. + | Lookup | | Update | + | skip table |-------------------------------->| computer state table | + '------------' '----------------------' + .-------------. .------------. | + | Serial | | Update | | + | skip update |---->| skip table |<----------|-----' + '-------------' '------------' | .---------------. + | | Outlet | + | | Button toggle | + v '---------------' + .---------------. .--------------. | + | Serial | | Update | | + | outlet toggle |---->| Outlet table |<-' + '---------------' '--------------' + | + v + .---------------------. + | Start on/off timers | + '---------------------' + | + v + .--------------. + | Switch relay | + '--------------' |