From d1048322cea7cf755bf81f4cc7cb94d7f354a4a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergiusz=20Baza=C5=84ski?= Date: Sun, 11 Nov 2012 23:03:15 +0100 Subject: [PATCH] Last version from HackWAW. See ya next year! --- test.py | 4 ++++ uart_echo.c | 41 ++++++++++++++++++++++++++++++++++------- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/test.py b/test.py index 60617db..e3fe591 100644 --- a/test.py +++ b/test.py @@ -1,8 +1,12 @@ import serial import sys +import time s = serial.Serial("/dev/ttyACM0", 115200, timeout=10) +def fire(): + s.write("c\xFF") +fire() #s.write("r") #print s.read() s.write("a" + chr(int(sys.argv[1]))) diff --git a/uart_echo.c b/uart_echo.c index 4f7d8db..6f12e95 100644 --- a/uart_echo.c +++ b/uart_echo.c @@ -97,6 +97,8 @@ typedef unsigned char u8; typedef char s8; typedef unsigned int u32; +volatile u32 g_FiredTime = 0; + struct { struct { u32 Servo1 : 1, @@ -119,7 +121,8 @@ struct { void CommitState(void) { // F4 = fire - GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_4, g_OutputControl.Digital.A ? GPIO_PIN_4 : 0); + //GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_4, g_OutputControl.Digital.A ? GPIO_PIN_4 : 0); + GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, g_OutputControl.Digital.A ? GPIO_PIN_2 : 0); } void ClearNext(void) @@ -131,10 +134,18 @@ void ClearNext(void) g_OutputControl.NextReceive.Digital.C = 0; } -u32 Timer0Counter = 0; +volatile u32 Timer0Counter = 0; +volatile u32 MiliCounter = 0; +u32 MiliSubCounter = 0; void Timer0Handler(void) { ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT); + MiliSubCounter++; + if (MiliSubCounter >= 100) + { + MiliSubCounter = 0; + MiliCounter++; + } Timer0Counter++; if (Timer0Counter >= 2000) @@ -146,11 +157,20 @@ void Timer0Handler(void) GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_3, GPIO_PIN_3); } - if (Timer0Counter == 100 + g_OutputControl.Servo1) + if (Timer0Counter == 50 + g_OutputControl.Servo1) GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_2, 0); - if (Timer0Counter == 100 + g_OutputControl.Servo2) + if (Timer0Counter == 50 + g_OutputControl.Servo2) GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_3, 0); + + if (g_OutputControl.Digital.A) + { + if (MiliCounter > (g_FiredTime + 200)) + { + g_OutputControl.Digital.A = 0; + CommitState(); + } + } } void @@ -180,17 +200,24 @@ UARTIntHandler(void) u8 Sent = 0; if (g_OutputControl.NextReceive.Digital.A) { - g_OutputControl.Digital.A = Data > 0 ? 1 : 0; + if (Data > 0) + { + UARTSend("start ", 6); + g_FiredTime = MiliCounter; + g_OutputControl.Digital.A = 1; + } Sent = 1; } else if (g_OutputControl.NextReceive.Servo1) { - g_OutputControl.Servo1 = (Data * 100) / 256; + UARTSend("s1 ", 3); + g_OutputControl.Servo1 = (Data * 200) / 256; Sent = 1; } else if (g_OutputControl.NextReceive.Servo2) { - g_OutputControl.Servo2 = (Data * 100) / 256; + UARTSend("s2, ", 4); + g_OutputControl.Servo2 = (Data * 200) / 256; //UARTSend("b", 1); Sent = 1; }