Use more conventional C code formatting

This commit is contained in:
Reinout Meliesie 2026-02-17 14:00:13 +01:00
commit a8b283d1c3
Signed by: zedfrigg
GPG key ID: 3AFCC06481308BC6

View file

@ -1,10 +1,10 @@
#include "Arduino.h"
void set_up_fooler () {
void set_up_fooler() {
// 122Hz @ 50% on pin 3 using T/C0
pinMode ( 3 , OUTPUT ) ; // 0C0B is connected to pin 3
pinMode(3, OUTPUT); // 0C0B is connected to pin 3
TCCR0A =
0 << COM0A1 |
@ -12,23 +12,23 @@ void set_up_fooler () {
1 << COM0B1 |
0 << COM0B0 |
1 << WGM01 |
1 << WGM00 ;
1 << WGM00;
TCCR0B =
1 << WGM02 |
1 << CS02 |
0 << CS01 |
1 << CS00 ;
1 << CS00;
OCR0A = 127 ;
OCR0B = 63 ;
OCR0A = 127;
OCR0B = 63;
}
void set_up_cooler () {
void set_up_cooler() {
// 25kHz @ variable duty cycle (initially 50%) on pins 9 and 10 using T/C1
pinMode ( 9 , OUTPUT ) ; // 0C1A is connected to pin 9
pinMode ( 10 , OUTPUT ) ; // 0C1B is connected to pin 10
pinMode(9, OUTPUT); // 0C1A is connected to pin 9
pinMode(10, OUTPUT); // 0C1B is connected to pin 10
TCCR1A =
1 << COM1A1 |
@ -38,41 +38,41 @@ void set_up_cooler () {
0 << COM1C1 |
0 << COM1C0 |
1 << WGM11 |
0 << WGM10 ;
0 << WGM10;
TCCR1B =
1 << WGM13 |
1 << WGM12 |
0 << CS12 |
1 << CS11 |
0 << CS10 ;
0 << CS10;
ICR1H = 0 ;
ICR1L = 79 ;
ICR1H = 0;
ICR1L = 79;
OCR1AH = 0 ;
OCR1AL = 39 ;
OCR1BH = 0 ;
OCR1BL = 39 ;
OCR1AH = 0;
OCR1AL = 39;
OCR1BH = 0;
OCR1BL = 39;
}
void set_cooler_duty_cycle ( int duty_cycle ) {
OCR1AL = duty_cycle ;
OCR1BL = duty_cycle ;
void set_cooler_duty_cycle(int duty_cycle) {
OCR1AL = duty_cycle;
OCR1BL = duty_cycle;
}
int main () {
init () ;
USBDevice . attach () ;
int main() {
init();
USBDevice.attach();
Serial . begin (9600) ;
set_up_fooler () ;
set_up_cooler () ;
Serial.begin(9600);
set_up_fooler();
set_up_cooler();
int seqPos = 0 ;
int seqPos = 0;
while (true) {
if ( Serial . available () ) {
int input = Serial . read () ;
if (Serial.available()) {
int input = Serial.read();
// In order to avoid serial writes by software other than kulifuli-host messing things up,
// we check for a specific sequence of 8 bytes before the byte that contains the new duty cycle
@ -87,16 +87,16 @@ int main () {
seqPos == 7 && input == 139
) {
// Advance in the sequence
seqPos ++ ;
} else if ( seqPos == 8 ) {
seqPos++;
} else if (seqPos == 8) {
// Sequence completed, `input` is the new duty cycle
set_cooler_duty_cycle (input) ;
set_cooler_duty_cycle(input);
// Write back the value as confirmation
Serial . write (input) ;
seqPos = 0 ;
Serial.write(input);
seqPos = 0;
} else {
// Reset sequence progress
seqPos = 0 ;
seqPos = 0;
}
}
}