6 ledseq_header = open(
"led_seq.h" ,
"w")
7 ledseq_source = open(
"led_seq.c" ,
"w")
12 * @file led_seq.h Header to access the PWM values for the 13 * one or more color LED(s) for the different sequences 15 * Automagically created on: """ 16 date = datetime.datetime.now().strftime(
'%d-%m-%Y at %H:%M')
19 * @file led_seq.c Contains the PWM values for the one or more color LED(s) 20 * for the different sequences 22 * Automagically created on: """ 32 const uint32_t led_pin_num[LED_COLOR_MAX] = {LED_RED, LED_GREEN}; 34 const uint32_t * const led_seq_get_pin_ptr(void) 39 uint32_t led_seq_get_pin_num(led_sequences seq) 41 return led_num_len[seq]; 44 uint32_t led_seq_get_seg_len(led_sequences seq) 46 return led_seq_len[seq]; 49 uint16_t * led_seq_get_seq_color_ptr(led_sequences seq, led_seq_color color) 51 return ((uint16_t *)(led_seq_ptr[seq] + color*led_seq_len[seq])); 54 uint16_t * led_seq_get_seq_duration_ptr(led_sequences seq) 56 return (uint16_t *) led_seq_duration_ptr[seq]; 61 header2 =
"\n */\n\n#ifndef _LED_SEQ_H_\n#define _LED_SEQ_H_\n\n#include <stdint.h>\n" 62 rgb_strut =
"""#define LED_STRUCT1(name, count) const struct { \\ 63 uint16_t red[count]; \\ 64 } __attribute__((packed)) name 66 #define LED_STRUCT2(name, count) const struct { \\ 67 uint16_t red[count]; \\ 68 uint16_t green[count]; \\ 69 } __attribute__((packed)) name 73 /** Specify the different LED patterns possible */ 76 enum_end =
""" LED_SEQ_NULL = 255, 79 /** @brief The different color LEDs present in this instance */ 83 /// To specify the number of LEDs presents 88 * @brief Gets the pointer to the array containing LED pin numbers 89 * with a length of @ref LED_COLOR_MAX 90 * @return Constant pointer to a const array for reason mention in brief 92 const uint32_t * const led_seq_get_pin_ptr(void); 95 * @brief Gets the number of LEDs used in the sequence 96 * @param seq The sequence to query the number of LEDs 97 * @return Returns the number of LEDs in the sequence 99 uint32_t led_seq_get_pin_num(led_sequences seq); 102 * @brief Get the number of segments in the sequence 103 * @param seq The sequence whose number of segments is required 104 * @return The number of segments in the parameter's sequence 106 uint32_t led_seq_get_seg_len(led_sequences seq); 109 * @brief Gets the pointer to the start of values for a color for a sequence 110 * @param seq The sequence whose pointer is required 111 * @param color The color in question 112 * @return Pointer to the start of a color in a sequence 114 uint16_t * led_seq_get_seq_color_ptr(led_sequences seq, led_seq_color color); 117 * @brief Gets the pointer to the start of segment duration array for a sequence 118 * @param seq The sequence whose pointer is required 119 * @return Pointer to the start of duration in a sequence 121 uint16_t * led_seq_get_seq_duration_ptr(led_sequences seq); 123 #endif /* _LED_SEQ_H_ */ 131 ledseq_header.write(header1 + date + header2)
133 ledseq_source.write(source1 + date + source2 + rgb_strut)
135 ledseq_header.write(enum_def)
138 for file
in glob.glob(
"*.txt"):
139 curr_seq = file.split(
".")[0]
140 ledseq_header.write(
" LED_SEQ_" + curr_seq.upper() +
" = " + str(i) +
",\n" )
143 ledseq_header.write(enum_end)
150 for file
in glob.glob(
"*.txt"):
151 ip0_file = open(file,
"r")
152 ip0_txt = ip0_file.read().replace(
"\r",
"\n")
153 ip0 = ip0_txt.split(
"\n")
156 curr_seq = file.split(
".")[0]
157 len_list.append(len(ip0))
158 seq_list.append(
"(uint16_t *) &" + str(curr_seq) +
"_seq")
159 duration_list.append(str(curr_seq) +
"_duration")
168 line = line.replace(
";",
"")
169 num_elements = len(line.split())
170 if num_elements == 3 :
171 R, G, ms = line.split()
172 R = round((int(R) * pwm_max_value/inp_res),0)
173 G = round((int(G) * pwm_max_value/inp_res),0)
174 ms = round((int(ms)/unit_time_ms),0)
175 R_list.append(int(R))
176 G_list.append(int(G))
177 ms_list.append(int(ms))
178 elif num_elements == 2 :
180 R = round((int(R) * pwm_max_value/inp_res),0)
181 ms = round((int(ms)/unit_time_ms),0)
182 R_list.append(int(R))
183 ms_list.append(int(ms))
185 sys.exit(
"Error: "+ file +
"has number of elements that's not 2 or 3")
187 if num_elements == 3 :
188 ledseq_source.write(
"\nLED_STRUCT2(" + curr_seq +
"_seq, " + str(len(ip0)) +
") = {\n")
189 ledseq_source.write(
" {" + str(R_list).strip(
'[]') +
"},\n")
190 ledseq_source.write(
" {" + str(G_list).strip(
'[]') +
"}\n};\n")
192 if num_elements == 2 :
193 ledseq_source.write(
"\nLED_STRUCT1(" + curr_seq +
"_seq, " + str(len(ip0)) +
") = {\n")
194 ledseq_source.write(
" {" + str(R_list).strip(
'[]') +
"}\n};\n")
196 total_duration = sum(ms_list) - ms_list[0]
197 ms_list.append(total_duration)
198 led_num_list.append(num_elements-1)
200 ledseq_source.write(
"const uint16_t " + curr_seq +
"_duration[] = { " + str(ms_list).strip(
'[]') +
" };\n")
202 ledseq_source.write(
"\nconst uint32_t led_num_len[] = {" + str(led_num_list).strip(
'[]') +
"};\n")
203 ledseq_source.write(
"const uint32_t led_seq_len[] = {" + str(len_list).strip(
'[]') +
"};\n")
204 ledseq_source.write(
"const uint16_t * const led_seq_ptr[] = {" +
', '.join(seq_list) +
" };\n")
205 ledseq_source.write(
"const uint16_t * const led_seq_duration_ptr[] = { " +
', '.join(duration_list) +
" };\n")
208 ledseq_source.write(source3)
210 ledseq_header.close()
211 ledseq_source.close()