#include <string.h>
static void rc_init(void);
+static bool rc_send(char key);
static void clock_init(void)
{
systick_interrupt_enable();
}
+#if 0
static void delay_ms(uint ms)
{
u32 start_ticks = ms_ticks;
while (ms_ticks - start_ticks < ms)
;
}
+#endif
static void usart_init(void)
{
static byte bypass_active;
static byte fan_pwm;
-// FIXME
static void show_temperature(void)
{
debug_putc('#');
// 50% PWM for the IR LED
timer_set_oc_mode(TIM4, TIM_OC2, TIM_OCM_FORCE_HIGH); // will be TIM_OCM_PWM1 when transmitting
- // timer_set_oc_mode(TIM4, TIM_OC2, TIM_OCM_PWM1); // FIXME
timer_set_oc_value(TIM4, TIM_OC2, T4_CYCLE / 2);
timer_set_oc_polarity_high(TIM4, TIM_OC2);
timer_enable_oc_output(TIM4, TIM_OC2);
pwm_init();
rc_init();
- debug_puts("Hello, world!\n");
+ debug_puts("Hello, world! This is Aircon Controller speaking.\n");
ds_init();
modbus_init();
- byte cycles = 0;
+ u32 last_show_temp = 0;
+ u32 last_ds_step = 0;
+
for (;;) {
- debug_led_toggle();
- delay_ms(100);
- ds_step();
+ if (ms_ticks - last_ds_step >= 100) {
+ debug_led_toggle();
+ ds_step();
+ last_ds_step = ms_ticks;
+ }
+
modbus_loop();
+
if (usart_get_flag(USART1, USART_SR_RXNE)) {
uint ch = usart_recv(USART1);
if (ch == 'B') {
* % = pwm*4.389 - 12.723
*/
timer_set_oc_value(TIM4, TIM_OC1, T4_CYCLE * fan_pwm / 256);
+ } else {
+ rc_send(ch);
}
}
- if (cycles++ >= 50) {
- cycles = 0;
+
+ if (ms_ticks - last_show_temp >= 5000) {
show_temperature();
+ last_show_temp = ms_ticks;
}
+
+ wait_for_interrupt();
}
return 0;
return false;
rc_pending = key;
rc_pattern_pos = rc_patterns[s - rc_keys];
+ debug_printf("RC sending: %c", key);
gpio_clear(GPIOC, GPIO13);