From ec4d565a0ecfe9db849478648a8d3fbd4d5cb5d4 Mon Sep 17 00:00:00 2001 From: Edward Emelianov Date: Wed, 16 Mar 2022 22:21:03 +0300 Subject: [PATCH] fixed trouble with sybolic links --- F0:F030,F042,F072/3steppersLB/steppers.bin | Bin .../CANbus_stepper/src/canstepper.bin | Bin F0:F030,F042,F072/Chiller/chiller.bin | Bin F0:F030,F042,F072/F0_testbrd/pl2303.bin | Bin F0:F030,F042,F072/QuadEncoder/encoder.bin | Bin F0:F030,F042,F072/Servo/servo.bin | Bin F0:F030,F042,F072/Socket_fans/sockfans.bin | Bin F0:F030,F042,F072/TM1637/tm1637.bin | Bin F0:F030,F042,F072/USBHID/usbhid.bin | Bin F0:F030,F042,F072/USB_pl2303_snippet/usb.bin | Bin F0:F030,F042,F072/blink/blink.bin | Bin F0:F030,F042,F072/canbus/src/canbus.bin | Bin F0:F030,F042,F072/htu21d_nucleo/usart.bin | Bin F0:F030,F042,F072/inc/F0 | 1 - F0:F030,F042,F072/morze/morze.bin | Bin F0:F030,F042,F072/pl2303/pl2303.bin | Bin F0:F030,F042,F072/tsys01_nucleo/tsys01.bin | Bin F0:F030,F042,F072/uart_blink/uartblink.bin | Bin .../uart_blink_dma/uartblink.bin | Bin F0:F030,F042,F072/uart_nucleo/usart.bin | Bin F0:F030,F042,F072/usbcan/usbcan.bin | Bin F0:F030,F042,F072/usbcan_relay/usbcan.bin | Bin F1:F103/BMP180/BMP180.bin | Bin F1:F103/BMP280/BMP280.bin | Bin F1:F103/CDC_ACM/cdcacm.bin | Bin F1:F103/DHT22_DHT11/DHT22.bin | Bin F1:F103/DS18/DS18.bin | Bin F1:F103/F1_testbrd/pl2303.bin | Bin F1:F103/I2Cscan/I2Cscan.bin | Bin F1:F103/LED_Screen/LEDscreen.bin | Bin F1:F103/LED_Screen/genlist | 0 F1:F103/LED_Screen/scrtest/scrtest | Bin F1:F103/MAX7219_screen/MAX7219.bin | Bin F1:F103/PL2303/pl2303.bin | Bin F1:F103/RGB_LED_Screen/RGBLEDscreen.bin | Bin F1:F103/RGB_LED_Screen/getrand | 0 F1:F103/RGB_LED_Screen/proto.c | 302 +++++++++++++++++- F1:F103/SI7005_HTU21D/si7005.bin | Bin F1:F103/SPI/SPI.bin | Bin F1:F103/SevenCDCs/cdcacmcore.bin | Bin F1:F103/Tetris/TETRIS.bin | Bin F1:F103/Tetris/getrand | 0 F1:F103/Tetris/main.c | 194 ++++++++++- F1:F103/USB_HID/usbhid103.bin | Bin F1:F103/chronometer/chrono.bin | Bin F1:F103/chronometer_v2/chrono.bin | Bin F1:F103/chronometer_v3/chrono.bin | Bin F1:F103/led_blink/blink.bin | Bin F1:F103/pl2303_snippet/pl2303.bin | Bin F1:F103/pl2303_snippet_naked/pl2303.bin | Bin F1:F103/pwmdmatest/pwmtest.bin | Bin F1:F103/pwmtest/pwmtest.bin | Bin F1:F103/uart/uart.bin | Bin F1:F103/ws2815/ws2815.bin | Bin F3:F303/PL2303/pl2303.bin | Bin F3:F303/blink/blink.bin | Bin F3:F303/floatPrintf/usart1.bin | Bin F3:F303/usart1/usart1.bin | Bin F3:F303/usart1fullDMA/usart.bin | Bin F3:F303/usarts/usart.bin | Bin deprecated/F0/blink/blink.bin | Bin deprecated/F0/uart/uart.bin | Bin deprecated/F1/1_wire/onewire.bin | Bin deprecated/F1/2.8TFT/dma_gpio.bin | Bin deprecated/F1/DMA_GPIO/dma_gpio.bin | Bin deprecated/F1/GPIO_TIM/tim_gpio.bin | Bin deprecated/F1/GPS+ultrasonic/timelapse.bin | Bin deprecated/F1/GPS/GPS.bin | Bin .../F1/Jeep_generator/jeep_generator.bin | Bin .../F1/Timelapse_keyboard/timelapse.bin | Bin .../timelapse.bin | Bin .../F1/USBCDC_template/usb_cdc_simple.bin | Bin deprecated/F1/canon_lens/canon_lens.bin | Bin deprecated/F1/distance_meters/ultrasonic.bin | Bin deprecated/F1/hid_mouse_keyboard/usbhid.bin | Bin deprecated/F1/keyboard_snippet/keyboard.bin | Bin deprecated/F1/matrix_keyboard/matrkeyb.bin | Bin deprecated/F1/nokia5110/nokia5110.bin | Bin deprecated/F1/simple_cdc/usb_cdc_simple.bin | Bin .../F1/stepper_motion/usb_cdc_simple.bin | Bin deprecated/F1/ultrasonic/ultrasonic.bin | Bin 81 files changed, 494 insertions(+), 3 deletions(-) mode change 100755 => 100644 F0:F030,F042,F072/3steppersLB/steppers.bin mode change 100644 => 100755 F0:F030,F042,F072/CANbus_stepper/src/canstepper.bin mode change 100644 => 100755 F0:F030,F042,F072/Chiller/chiller.bin mode change 100644 => 100755 F0:F030,F042,F072/F0_testbrd/pl2303.bin mode change 100644 => 100755 F0:F030,F042,F072/QuadEncoder/encoder.bin mode change 100644 => 100755 F0:F030,F042,F072/Servo/servo.bin mode change 100644 => 100755 F0:F030,F042,F072/Socket_fans/sockfans.bin mode change 100644 => 100755 F0:F030,F042,F072/TM1637/tm1637.bin mode change 100644 => 100755 F0:F030,F042,F072/USBHID/usbhid.bin mode change 100644 => 100755 F0:F030,F042,F072/USB_pl2303_snippet/usb.bin mode change 100755 => 100644 F0:F030,F042,F072/blink/blink.bin mode change 100644 => 100755 F0:F030,F042,F072/canbus/src/canbus.bin mode change 100644 => 100755 F0:F030,F042,F072/htu21d_nucleo/usart.bin delete mode 120000 F0:F030,F042,F072/inc/F0 mode change 100644 => 100755 F0:F030,F042,F072/morze/morze.bin mode change 100644 => 100755 F0:F030,F042,F072/pl2303/pl2303.bin mode change 100644 => 100755 F0:F030,F042,F072/tsys01_nucleo/tsys01.bin mode change 100644 => 100755 F0:F030,F042,F072/uart_blink/uartblink.bin mode change 100644 => 100755 F0:F030,F042,F072/uart_blink_dma/uartblink.bin mode change 100644 => 100755 F0:F030,F042,F072/uart_nucleo/usart.bin mode change 100755 => 100644 F0:F030,F042,F072/usbcan/usbcan.bin mode change 100755 => 100644 F0:F030,F042,F072/usbcan_relay/usbcan.bin mode change 100644 => 100755 F1:F103/BMP180/BMP180.bin mode change 100644 => 100755 F1:F103/BMP280/BMP280.bin mode change 100644 => 100755 F1:F103/CDC_ACM/cdcacm.bin mode change 100644 => 100755 F1:F103/DHT22_DHT11/DHT22.bin mode change 100644 => 100755 F1:F103/DS18/DS18.bin mode change 100644 => 100755 F1:F103/F1_testbrd/pl2303.bin mode change 100644 => 100755 F1:F103/I2Cscan/I2Cscan.bin mode change 100644 => 100755 F1:F103/LED_Screen/LEDscreen.bin mode change 100644 => 100755 F1:F103/LED_Screen/genlist mode change 100644 => 100755 F1:F103/LED_Screen/scrtest/scrtest mode change 100644 => 100755 F1:F103/MAX7219_screen/MAX7219.bin mode change 100644 => 100755 F1:F103/PL2303/pl2303.bin mode change 100644 => 100755 F1:F103/RGB_LED_Screen/RGBLEDscreen.bin mode change 100644 => 100755 F1:F103/RGB_LED_Screen/getrand mode change 120000 => 100644 F1:F103/RGB_LED_Screen/proto.c mode change 100644 => 100755 F1:F103/SI7005_HTU21D/si7005.bin mode change 100644 => 100755 F1:F103/SPI/SPI.bin mode change 100644 => 100755 F1:F103/SevenCDCs/cdcacmcore.bin mode change 100644 => 100755 F1:F103/Tetris/TETRIS.bin mode change 100644 => 100755 F1:F103/Tetris/getrand mode change 120000 => 100644 F1:F103/Tetris/main.c mode change 100644 => 100755 F1:F103/USB_HID/usbhid103.bin mode change 100755 => 100644 F1:F103/chronometer/chrono.bin mode change 100644 => 100755 F1:F103/chronometer_v2/chrono.bin mode change 100644 => 100755 F1:F103/chronometer_v3/chrono.bin mode change 100644 => 100755 F1:F103/led_blink/blink.bin mode change 100644 => 100755 F1:F103/pl2303_snippet/pl2303.bin mode change 100644 => 100755 F1:F103/pl2303_snippet_naked/pl2303.bin mode change 100644 => 100755 F1:F103/pwmdmatest/pwmtest.bin mode change 100644 => 100755 F1:F103/pwmtest/pwmtest.bin mode change 100644 => 100755 F1:F103/uart/uart.bin mode change 100644 => 100755 F1:F103/ws2815/ws2815.bin mode change 100644 => 100755 F3:F303/PL2303/pl2303.bin mode change 100644 => 100755 F3:F303/blink/blink.bin mode change 100644 => 100755 F3:F303/floatPrintf/usart1.bin mode change 100644 => 100755 F3:F303/usart1/usart1.bin mode change 100644 => 100755 F3:F303/usart1fullDMA/usart.bin mode change 100644 => 100755 F3:F303/usarts/usart.bin mode change 100644 => 100755 deprecated/F0/blink/blink.bin mode change 100644 => 100755 deprecated/F0/uart/uart.bin mode change 100644 => 100755 deprecated/F1/1_wire/onewire.bin mode change 100644 => 100755 deprecated/F1/2.8TFT/dma_gpio.bin mode change 100644 => 100755 deprecated/F1/DMA_GPIO/dma_gpio.bin mode change 100644 => 100755 deprecated/F1/GPIO_TIM/tim_gpio.bin mode change 100644 => 100755 deprecated/F1/GPS+ultrasonic/timelapse.bin mode change 100644 => 100755 deprecated/F1/GPS/GPS.bin mode change 100644 => 100755 deprecated/F1/Jeep_generator/jeep_generator.bin mode change 100644 => 100755 deprecated/F1/Timelapse_keyboard/timelapse.bin mode change 100644 => 100755 deprecated/F1/Timelapse_keyboard_only_lasers/timelapse.bin mode change 100644 => 100755 deprecated/F1/USBCDC_template/usb_cdc_simple.bin mode change 100644 => 100755 deprecated/F1/canon_lens/canon_lens.bin mode change 100644 => 100755 deprecated/F1/distance_meters/ultrasonic.bin mode change 100644 => 100755 deprecated/F1/hid_mouse_keyboard/usbhid.bin mode change 100644 => 100755 deprecated/F1/keyboard_snippet/keyboard.bin mode change 100644 => 100755 deprecated/F1/matrix_keyboard/matrkeyb.bin mode change 100644 => 100755 deprecated/F1/nokia5110/nokia5110.bin mode change 100644 => 100755 deprecated/F1/simple_cdc/usb_cdc_simple.bin mode change 100644 => 100755 deprecated/F1/stepper_motion/usb_cdc_simple.bin mode change 100644 => 100755 deprecated/F1/ultrasonic/ultrasonic.bin diff --git a/F0:F030,F042,F072/3steppersLB/steppers.bin b/F0:F030,F042,F072/3steppersLB/steppers.bin old mode 100755 new mode 100644 diff --git a/F0:F030,F042,F072/CANbus_stepper/src/canstepper.bin b/F0:F030,F042,F072/CANbus_stepper/src/canstepper.bin old mode 100644 new mode 100755 diff --git a/F0:F030,F042,F072/Chiller/chiller.bin b/F0:F030,F042,F072/Chiller/chiller.bin old mode 100644 new mode 100755 diff --git a/F0:F030,F042,F072/F0_testbrd/pl2303.bin b/F0:F030,F042,F072/F0_testbrd/pl2303.bin old mode 100644 new mode 100755 diff --git a/F0:F030,F042,F072/QuadEncoder/encoder.bin b/F0:F030,F042,F072/QuadEncoder/encoder.bin old mode 100644 new mode 100755 diff --git a/F0:F030,F042,F072/Servo/servo.bin b/F0:F030,F042,F072/Servo/servo.bin old mode 100644 new mode 100755 diff --git a/F0:F030,F042,F072/Socket_fans/sockfans.bin b/F0:F030,F042,F072/Socket_fans/sockfans.bin old mode 100644 new mode 100755 diff --git a/F0:F030,F042,F072/TM1637/tm1637.bin b/F0:F030,F042,F072/TM1637/tm1637.bin old mode 100644 new mode 100755 diff --git a/F0:F030,F042,F072/USBHID/usbhid.bin b/F0:F030,F042,F072/USBHID/usbhid.bin old mode 100644 new mode 100755 diff --git a/F0:F030,F042,F072/USB_pl2303_snippet/usb.bin b/F0:F030,F042,F072/USB_pl2303_snippet/usb.bin old mode 100644 new mode 100755 diff --git a/F0:F030,F042,F072/blink/blink.bin b/F0:F030,F042,F072/blink/blink.bin old mode 100755 new mode 100644 diff --git a/F0:F030,F042,F072/canbus/src/canbus.bin b/F0:F030,F042,F072/canbus/src/canbus.bin old mode 100644 new mode 100755 diff --git a/F0:F030,F042,F072/htu21d_nucleo/usart.bin b/F0:F030,F042,F072/htu21d_nucleo/usart.bin old mode 100644 new mode 100755 diff --git a/F0:F030,F042,F072/inc/F0 b/F0:F030,F042,F072/inc/F0 deleted file mode 120000 index 0be4819..0000000 --- a/F0:F030,F042,F072/inc/F0 +++ /dev/null @@ -1 +0,0 @@ -Fx \ No newline at end of file diff --git a/F0:F030,F042,F072/morze/morze.bin b/F0:F030,F042,F072/morze/morze.bin old mode 100644 new mode 100755 diff --git a/F0:F030,F042,F072/pl2303/pl2303.bin b/F0:F030,F042,F072/pl2303/pl2303.bin old mode 100644 new mode 100755 diff --git a/F0:F030,F042,F072/tsys01_nucleo/tsys01.bin b/F0:F030,F042,F072/tsys01_nucleo/tsys01.bin old mode 100644 new mode 100755 diff --git a/F0:F030,F042,F072/uart_blink/uartblink.bin b/F0:F030,F042,F072/uart_blink/uartblink.bin old mode 100644 new mode 100755 diff --git a/F0:F030,F042,F072/uart_blink_dma/uartblink.bin b/F0:F030,F042,F072/uart_blink_dma/uartblink.bin old mode 100644 new mode 100755 diff --git a/F0:F030,F042,F072/uart_nucleo/usart.bin b/F0:F030,F042,F072/uart_nucleo/usart.bin old mode 100644 new mode 100755 diff --git a/F0:F030,F042,F072/usbcan/usbcan.bin b/F0:F030,F042,F072/usbcan/usbcan.bin old mode 100755 new mode 100644 diff --git a/F0:F030,F042,F072/usbcan_relay/usbcan.bin b/F0:F030,F042,F072/usbcan_relay/usbcan.bin old mode 100755 new mode 100644 diff --git a/F1:F103/BMP180/BMP180.bin b/F1:F103/BMP180/BMP180.bin old mode 100644 new mode 100755 diff --git a/F1:F103/BMP280/BMP280.bin b/F1:F103/BMP280/BMP280.bin old mode 100644 new mode 100755 diff --git a/F1:F103/CDC_ACM/cdcacm.bin b/F1:F103/CDC_ACM/cdcacm.bin old mode 100644 new mode 100755 diff --git a/F1:F103/DHT22_DHT11/DHT22.bin b/F1:F103/DHT22_DHT11/DHT22.bin old mode 100644 new mode 100755 diff --git a/F1:F103/DS18/DS18.bin b/F1:F103/DS18/DS18.bin old mode 100644 new mode 100755 diff --git a/F1:F103/F1_testbrd/pl2303.bin b/F1:F103/F1_testbrd/pl2303.bin old mode 100644 new mode 100755 diff --git a/F1:F103/I2Cscan/I2Cscan.bin b/F1:F103/I2Cscan/I2Cscan.bin old mode 100644 new mode 100755 diff --git a/F1:F103/LED_Screen/LEDscreen.bin b/F1:F103/LED_Screen/LEDscreen.bin old mode 100644 new mode 100755 diff --git a/F1:F103/LED_Screen/genlist b/F1:F103/LED_Screen/genlist old mode 100644 new mode 100755 diff --git a/F1:F103/LED_Screen/scrtest/scrtest b/F1:F103/LED_Screen/scrtest/scrtest old mode 100644 new mode 100755 diff --git a/F1:F103/MAX7219_screen/MAX7219.bin b/F1:F103/MAX7219_screen/MAX7219.bin old mode 100644 new mode 100755 diff --git a/F1:F103/PL2303/pl2303.bin b/F1:F103/PL2303/pl2303.bin old mode 100644 new mode 100755 diff --git a/F1:F103/RGB_LED_Screen/RGBLEDscreen.bin b/F1:F103/RGB_LED_Screen/RGBLEDscreen.bin old mode 100644 new mode 100755 diff --git a/F1:F103/RGB_LED_Screen/getrand b/F1:F103/RGB_LED_Screen/getrand old mode 100644 new mode 100755 diff --git a/F1:F103/RGB_LED_Screen/proto.c b/F1:F103/RGB_LED_Screen/proto.c deleted file mode 120000 index ef1f2e9..0000000 --- a/F1:F103/RGB_LED_Screen/proto.c +++ /dev/null @@ -1 +0,0 @@ -/home/eddy/Yandex.Disk/Projects/mytakepic/.hg/wcache/checklink-target \ No newline at end of file diff --git a/F1:F103/RGB_LED_Screen/proto.c b/F1:F103/RGB_LED_Screen/proto.c new file mode 100644 index 0000000..63ffb0f --- /dev/null +++ b/F1:F103/RGB_LED_Screen/proto.c @@ -0,0 +1,301 @@ +/* + * This file is part of the RGBLEDscreen project. + * Copyright 2020 Edward V. Emelianov . + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "adcrandom.h" +#include "balls.h" +#include "fonts.h" +#include "proto.h" +#include "screen.h" +#include "usb.h" + +extern uint8_t countms, rainbow, balls; +extern uint32_t Tms; + +char *omit_spaces(const char *buf){ + while(*buf){ + if(*buf > ' ') break; + ++buf; + } + return (char*)buf; +} + +// In case of overflow return `buf` and N==0xffffffff +// read decimal number & return pointer to next non-number symbol +static char *getdec(const char *buf, uint32_t *N){ + char *start = (char*)buf; + uint32_t num = 0; + while(*buf){ + char c = *buf; + if(c < '0' || c > '9'){ + break; + } + if(num > 429496729 || (num == 429496729 && c > '5')){ // overflow + *N = 0xffffff; + return start; + } + num *= 10; + num += c - '0'; + ++buf; + } + *N = num; + return (char*)buf; +} +// read hexadecimal number (without 0x prefix!) +static char *gethex(const char *buf, uint32_t *N){ + char *start = (char*)buf; + uint32_t num = 0; + while(*buf){ + char c = *buf; + uint8_t M = 0; + if(c >= '0' && c <= '9'){ + M = '0'; + }else if(c >= 'A' && c <= 'F'){ + M = 'A' - 10; + }else if(c >= 'a' && c <= 'f'){ + M = 'a' - 10; + } + if(M){ + if(num & 0xf0000000){ // overflow + *N = 0xffffff; + return start; + } + num <<= 4; + num += c - M; + }else{ + break; + } + ++buf; + } + *N = num; + return (char*)buf; +} +// read octal number (without 0 prefix!) +static char *getoct(const char *buf, uint32_t *N){ + char *start = (char*)buf; + uint32_t num = 0; + while(*buf){ + char c = *buf; + if(c < '0' || c > '7'){ + break; + } + if(num & 0xe0000000){ // overflow + *N = 0xffffff; + return start; + } + num <<= 3; + num += c - '0'; + ++buf; + } + *N = num; + return (char*)buf; +} +// read binary number (without b prefix!) +static char *getbin(const char *buf, uint32_t *N){ + char *start = (char*)buf; + uint32_t num = 0; + while(*buf){ + char c = *buf; + if(c < '0' || c > '1'){ + break; + } + if(num & 0x80000000){ // overflow + *N = 0xffffff; + return start; + } + num <<= 1; + if(c == '1') num |= 1; + ++buf; + } + *N = num; + return (char*)buf; +} + +/** + * @brief getnum - read uint32_t from string (dec, hex or bin: 127, 0x7f, 0b1111111) + * @param buf - buffer with number and so on + * @param N - the number read + * @return pointer to first non-number symbol in buf + * (if it is == buf, there's no number or if *N==0xffffffff there was overflow) + */ +char *getnum(const char *txt, uint32_t *N){ + char *nxt = NULL; + char *s = omit_spaces(txt); + if(*s == '0'){ // hex, oct or 0 + if(s[1] == 'x' || s[1] == 'X'){ // hex + nxt = gethex(s+2, N); + if(nxt == s+2) nxt = (char*)txt; + }else if(s[1] > '0'-1 && s[1] < '8'){ // oct + nxt = getoct(s+1, N); + if(nxt == s+1) nxt = (char*)txt; + }else{ // 0 + nxt = s+1; + *N = 0; + } + }else if(*s == 'b' || *s == 'B'){ + nxt = getbin(s+1, N); + if(nxt == s+1) nxt = (char*)txt; + }else{ + nxt = getdec(s, N); + if(nxt == s) nxt = (char*)txt; + } + return nxt; +} + +const char* helpmsg = + "'0/1' - screen off/on\n" + "'2,3' - select font\n" + "'A' - get ADC values\n" + "'B' - start/stop rainBow\n" + "'b' - start/stop Balls\n" + "'C' - clear screen with given color\n" + "'F' - set foreground color\n" + "'G' - get 100 random numbers\n" + "'f' - get FPS\n" + "'R' - software reset\n" + "'W' - test watchdog\n" + "'Zz' -start/stop counting ms\n" + "Any text - put text @ screen\n" +; + +const char *parse_cmd(const char *buf){ + uint32_t N; + if(buf[1] == '\n'){ // one symbol commands + switch(*buf){ + case '0': + ScreenOFF(); + return "OFF\n"; + break; + case '1': + ScreenON(); + return "ON\n"; + break; + case '2': + if(choose_font(FONT14)) return "Font14\n"; + return "err\n"; + break; + case '3': + if(choose_font(FONT16)) return "Font16\n"; + return "err\n"; + break; + case 'A': + USB_send("Tsens="); USB_send(u2str(getADCval(0))); + USB_send("\nVref="); USB_send(u2str(getADCval(1))); + USB_send("\nRand="); USB_send(u2str(getRand())); + USB_send("\n"); + return NULL; + break; + case 'B': + if(rainbow){ + rainbow = 0; + return "Stop rainbow\n"; + }else{ + rainbow = 1; + return "Start rainbow\n"; + } + break; + case 'b': + if(balls){ + balls = 0; + return "Stop balls\n"; + }else{ + balls_init(); + balls = 1; + return "Start balls\n"; + } + case 'f': + if(SCREEN_RELAX == getScreenState()) return "Screen is inactive\n"; + USB_send("FPS="); + USB_send(u2str(getFPS())); + USB_send("\n"); + return NULL; + break; + case 'G': + /*USB_send(u2str(Tms)); USB_send("\n"); + for(int i=0; i < 1000; ++i) getRand(); + USB_send(u2str(Tms)); USB_send("\n");*/ + for(int i = 0; i < 100; ++i){ + USB_send(u2str(getRand())); + USB_send("\n"); + } + return NULL; + break; + case 'R': + USB_send("Soft reset\n"); + NVIC_SystemReset(); + break; + case 'W': + USB_send("Wait for reboot\n"); + while(1){nop();}; + break; + case 'Z': + countms = 1; + return "Start\n"; + break; + case 'z': + countms = 0; + return "Stop\n"; + break; + default: + return helpmsg; + } + return NULL; + }else{ + switch(*buf){ + case 'C': + if(getnum(buf+1, &N)){ + ScreenOFF(); + setBGcolor(N); + ClearScreen(); + ScreenON(); + return "Background color\n"; + } + return "Wrong color\n"; + break; + case 'F': + if(getnum(buf+1, &N)){ + setFGcolor(N); + return "Foreground color\n"; + } + return "Wrong color\n"; + break; + default: + ScreenOFF(); + ClearScreen(); + PutStringAt(1, curfont->height + 3, buf); + ScreenON(); + } + return buf; + } + return NULL; +} + +// return string with number `val` +char *u2str(uint32_t val){ + static char strbuf[11]; + char *bufptr = &strbuf[10]; + *bufptr = 0; + if(!val){ + *(--bufptr) = '0'; + }else{ + while(val){ + *(--bufptr) = val % 10 + '0'; + val /= 10; + } + } + return bufptr; +} diff --git a/F1:F103/SI7005_HTU21D/si7005.bin b/F1:F103/SI7005_HTU21D/si7005.bin old mode 100644 new mode 100755 diff --git a/F1:F103/SPI/SPI.bin b/F1:F103/SPI/SPI.bin old mode 100644 new mode 100755 diff --git a/F1:F103/SevenCDCs/cdcacmcore.bin b/F1:F103/SevenCDCs/cdcacmcore.bin old mode 100644 new mode 100755 diff --git a/F1:F103/Tetris/TETRIS.bin b/F1:F103/Tetris/TETRIS.bin old mode 100644 new mode 100755 diff --git a/F1:F103/Tetris/getrand b/F1:F103/Tetris/getrand old mode 100644 new mode 100755 diff --git a/F1:F103/Tetris/main.c b/F1:F103/Tetris/main.c deleted file mode 120000 index ef1f2e9..0000000 --- a/F1:F103/Tetris/main.c +++ /dev/null @@ -1 +0,0 @@ -/home/eddy/Yandex.Disk/Projects/mytakepic/.hg/wcache/checklink-target \ No newline at end of file diff --git a/F1:F103/Tetris/main.c b/F1:F103/Tetris/main.c new file mode 100644 index 0000000..0513d46 --- /dev/null +++ b/F1:F103/Tetris/main.c @@ -0,0 +1,193 @@ +/* + * This file is part of the TETRIS project. + * Copyright 2021 Edward V. Emelianov . + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "adcrandom.h" +#include "arkanoid.h" +#include "balls.h" +#include "buttons.h" +#include "fonts.h" +#include "hardware.h" +#include "menu.h" +#include "proto.h" +#include "screen.h" +#include "snake.h" +#include "tetris.h" +#include "usb.h" +#include "usb_lib.h" + +// timeout for autosleep (30s) +#define AUTOSLEEP_TMOUT (30000) + +volatile uint32_t Tms = 0; +uint8_t balls = 0; + +enum{ + STATE_MENU, + STATE_SNAKE, + STATE_TETRIS, + STATE_ARKANOID, + STATE_SLEEP, + STATE_GAMEOVER +} curstate = STATE_SLEEP; + +/* Called when systick fires */ +void sys_tick_handler(void){ + ++Tms; +} + +#define USBBUFSZ (127) +// usb getline +static char *get_USB(){ + static char tmpbuf[USBBUFSZ+1], *curptr = tmpbuf; + static int rest = USBBUFSZ; + int x = USB_receive(curptr); + curptr[x] = 0; + if(!x) return NULL; + if(curptr[x-1] == '\n'){ + curptr = tmpbuf; + rest = USBBUFSZ; + return tmpbuf; + } + curptr += x; rest -= x; + if(rest <= 0){ // buffer overflow + curptr = tmpbuf; + rest = USBBUFSZ; + USB_send("USB buffer overflow\n"); + } + return NULL; +} + +static void process_menu(){ + switch(menu_activated()){ + case MENU_SLEEP: + USB_send("Select 'Sleep'\n"); + ScreenOFF(); + curstate = STATE_SLEEP; + break; + case MENU_BALLS: + USB_send("Select 'Balls'\n"); + if(balls){ + balls = 0; + }else{ + curstate = STATE_SLEEP; + balls_init(); + balls = 1; + } + break; + case MENU_SNAKE: + USB_send("Select 'Snake'\n"); + snake_init(); + curstate = STATE_SNAKE; + break; + case MENU_TETRIS: + USB_send("Select 'Tetris'\n"); + tetris_init(); + curstate = STATE_TETRIS; + break; + case MENU_ARKANOID: + USB_send("Select 'Arkanoid'\n"); + arkanoid_init(); + curstate = STATE_ARKANOID; + default: + break; + } +} + +static void gotomenu(){ + curstate = STATE_MENU; + clear_events(); + show_menu(); +} + +int main(void){ + uint32_t lastT = 0; + sysreset(); + StartHSE(); + SysTick_Config(72000); + RCC->CSR |= RCC_CSR_RMVF; // remove reset flags + + hw_setup(); + USBPU_OFF(); + adc_setup(); + USB_setup(); + //iwdg_setup(); + USBPU_ON(); + + keyevent evt; + while(1){ + if(Tms - lastT > 499){ + LED_blink(LED0); + lastT = Tms; + } + IWDG->KR = IWDG_REFRESH; + if(balls) process_balls(); + process_keys(); + switch(curstate){ + case STATE_SLEEP: + if(keystate(KEY_M, &evt) && evt == EVT_RELEASE){ + USB_send("Activate menu\n"); + gotomenu(); + } + break; + case STATE_MENU: + process_menu(); + if(Tms - lastUnsleep > AUTOSLEEP_TMOUT){ + USB_send("Autosleep\n"); + ScreenOFF(); + curstate = STATE_SLEEP; + } + break; + case STATE_SNAKE: + if(!snake_proces()){ + show_gameover(); + curstate = STATE_GAMEOVER; + } + break; + case STATE_TETRIS: + if(!tetris_process()){ + show_gameover(); + curstate = STATE_GAMEOVER; + } + break; + case STATE_ARKANOID: + if(!arkanoid_process()){ + show_gameover(); + curstate = STATE_GAMEOVER; + } + break; + case STATE_GAMEOVER: // show gameover screen + if(keystate(KEY_M, &evt) && evt == EVT_RELEASE){ + gotomenu(); + }else if(Tms - lastUnsleep > AUTOSLEEP_TMOUT){ + USB_send("Autosleep\n"); + ScreenOFF(); + curstate = STATE_SLEEP; + } + break; + } + + usb_proc(); + char *txt; const char *ans; + if((txt = get_USB())){ + ans = parse_cmd(txt); + if(ans) USB_send(ans); + } + } + return 0; +} + diff --git a/F1:F103/USB_HID/usbhid103.bin b/F1:F103/USB_HID/usbhid103.bin old mode 100644 new mode 100755 diff --git a/F1:F103/chronometer/chrono.bin b/F1:F103/chronometer/chrono.bin old mode 100755 new mode 100644 diff --git a/F1:F103/chronometer_v2/chrono.bin b/F1:F103/chronometer_v2/chrono.bin old mode 100644 new mode 100755 diff --git a/F1:F103/chronometer_v3/chrono.bin b/F1:F103/chronometer_v3/chrono.bin old mode 100644 new mode 100755 diff --git a/F1:F103/led_blink/blink.bin b/F1:F103/led_blink/blink.bin old mode 100644 new mode 100755 diff --git a/F1:F103/pl2303_snippet/pl2303.bin b/F1:F103/pl2303_snippet/pl2303.bin old mode 100644 new mode 100755 diff --git a/F1:F103/pl2303_snippet_naked/pl2303.bin b/F1:F103/pl2303_snippet_naked/pl2303.bin old mode 100644 new mode 100755 diff --git a/F1:F103/pwmdmatest/pwmtest.bin b/F1:F103/pwmdmatest/pwmtest.bin old mode 100644 new mode 100755 diff --git a/F1:F103/pwmtest/pwmtest.bin b/F1:F103/pwmtest/pwmtest.bin old mode 100644 new mode 100755 diff --git a/F1:F103/uart/uart.bin b/F1:F103/uart/uart.bin old mode 100644 new mode 100755 diff --git a/F1:F103/ws2815/ws2815.bin b/F1:F103/ws2815/ws2815.bin old mode 100644 new mode 100755 diff --git a/F3:F303/PL2303/pl2303.bin b/F3:F303/PL2303/pl2303.bin old mode 100644 new mode 100755 diff --git a/F3:F303/blink/blink.bin b/F3:F303/blink/blink.bin old mode 100644 new mode 100755 diff --git a/F3:F303/floatPrintf/usart1.bin b/F3:F303/floatPrintf/usart1.bin old mode 100644 new mode 100755 diff --git a/F3:F303/usart1/usart1.bin b/F3:F303/usart1/usart1.bin old mode 100644 new mode 100755 diff --git a/F3:F303/usart1fullDMA/usart.bin b/F3:F303/usart1fullDMA/usart.bin old mode 100644 new mode 100755 diff --git a/F3:F303/usarts/usart.bin b/F3:F303/usarts/usart.bin old mode 100644 new mode 100755 diff --git a/deprecated/F0/blink/blink.bin b/deprecated/F0/blink/blink.bin old mode 100644 new mode 100755 diff --git a/deprecated/F0/uart/uart.bin b/deprecated/F0/uart/uart.bin old mode 100644 new mode 100755 diff --git a/deprecated/F1/1_wire/onewire.bin b/deprecated/F1/1_wire/onewire.bin old mode 100644 new mode 100755 diff --git a/deprecated/F1/2.8TFT/dma_gpio.bin b/deprecated/F1/2.8TFT/dma_gpio.bin old mode 100644 new mode 100755 diff --git a/deprecated/F1/DMA_GPIO/dma_gpio.bin b/deprecated/F1/DMA_GPIO/dma_gpio.bin old mode 100644 new mode 100755 diff --git a/deprecated/F1/GPIO_TIM/tim_gpio.bin b/deprecated/F1/GPIO_TIM/tim_gpio.bin old mode 100644 new mode 100755 diff --git a/deprecated/F1/GPS+ultrasonic/timelapse.bin b/deprecated/F1/GPS+ultrasonic/timelapse.bin old mode 100644 new mode 100755 diff --git a/deprecated/F1/GPS/GPS.bin b/deprecated/F1/GPS/GPS.bin old mode 100644 new mode 100755 diff --git a/deprecated/F1/Jeep_generator/jeep_generator.bin b/deprecated/F1/Jeep_generator/jeep_generator.bin old mode 100644 new mode 100755 diff --git a/deprecated/F1/Timelapse_keyboard/timelapse.bin b/deprecated/F1/Timelapse_keyboard/timelapse.bin old mode 100644 new mode 100755 diff --git a/deprecated/F1/Timelapse_keyboard_only_lasers/timelapse.bin b/deprecated/F1/Timelapse_keyboard_only_lasers/timelapse.bin old mode 100644 new mode 100755 diff --git a/deprecated/F1/USBCDC_template/usb_cdc_simple.bin b/deprecated/F1/USBCDC_template/usb_cdc_simple.bin old mode 100644 new mode 100755 diff --git a/deprecated/F1/canon_lens/canon_lens.bin b/deprecated/F1/canon_lens/canon_lens.bin old mode 100644 new mode 100755 diff --git a/deprecated/F1/distance_meters/ultrasonic.bin b/deprecated/F1/distance_meters/ultrasonic.bin old mode 100644 new mode 100755 diff --git a/deprecated/F1/hid_mouse_keyboard/usbhid.bin b/deprecated/F1/hid_mouse_keyboard/usbhid.bin old mode 100644 new mode 100755 diff --git a/deprecated/F1/keyboard_snippet/keyboard.bin b/deprecated/F1/keyboard_snippet/keyboard.bin old mode 100644 new mode 100755 diff --git a/deprecated/F1/matrix_keyboard/matrkeyb.bin b/deprecated/F1/matrix_keyboard/matrkeyb.bin old mode 100644 new mode 100755 diff --git a/deprecated/F1/nokia5110/nokia5110.bin b/deprecated/F1/nokia5110/nokia5110.bin old mode 100644 new mode 100755 diff --git a/deprecated/F1/simple_cdc/usb_cdc_simple.bin b/deprecated/F1/simple_cdc/usb_cdc_simple.bin old mode 100644 new mode 100755 diff --git a/deprecated/F1/stepper_motion/usb_cdc_simple.bin b/deprecated/F1/stepper_motion/usb_cdc_simple.bin old mode 100644 new mode 100755 diff --git a/deprecated/F1/ultrasonic/ultrasonic.bin b/deprecated/F1/ultrasonic/ultrasonic.bin old mode 100644 new mode 100755