Skip to content

Commit 66b7f7d

Browse files
committed
Add documentation of setb command to readme; make indentation consistent.
1 parent 77933a4 commit 66b7f7d

File tree

2 files changed

+107
-106
lines changed

2 files changed

+107
-106
lines changed

prawnblaster/prawnblaster.cpp

Lines changed: 106 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,112 +1169,112 @@ void loop()
11691169
{
11701170
fast_serial_printf("invalid address or too many instructions\r\n");
11711171
}
1172-
// It takes 8 bytes to describe an instruction: 4 bytes for reps, 4 bytes for half period
1173-
uint32_t inst_per_buffer = SERIAL_BUFFER_SIZE / 8;
1174-
unsigned int addr = start_addr;
1175-
while(inst_count > inst_per_buffer){
1176-
fast_serial_read(readstring, 8*inst_per_buffer);
1177-
for (int i = 0; i < inst_per_buffer; i++)
1178-
{
1179-
uint32_t reps = ((readstring[8*i + 7] << 24)
1180-
| (readstring[8*i + 6] << 16)
1181-
| (readstring[8*i + 5] << 8)
1182-
| (readstring[8*i + 4]));
1183-
uint32_t half_period = ((readstring[8*i + 3] << 24)
1184-
| (readstring[8*i + 2] << 16)
1185-
| (readstring[8*i + 1] << 8)
1186-
| (readstring[8*i + 0]));
1187-
1188-
if (reps == 0)
1189-
{
1190-
// This indicates either a stop or a wait instruction
1191-
instructions[address_offset + addr * 2] = 0;
1192-
if (half_period == 0)
1193-
{
1194-
// It's a stop instruction
1195-
instructions[address_offset + addr * 2 + 1] = 0;
1196-
addr++;
1197-
}
1198-
else if (half_period >= 6)
1199-
{
1200-
// It's a wait instruction. See "set" command for why we do this.
1201-
instructions[address_offset + addr * 2 + 1] = (half_period - 4) / 2;
1202-
addr++;
1203-
}
1204-
else
1205-
{
1206-
fast_serial_printf("invalid request\r\n");
1207-
}
1208-
}
1209-
else if (half_period < (non_loop_path_length))
1210-
{
1211-
fast_serial_printf("half-period too short\r\n");
1212-
}
1213-
else if (reps < 1)
1214-
{
1215-
fast_serial_printf("reps must be at least one\r\n");
1216-
}
1217-
else
1218-
{
1219-
instructions[address_offset + addr * 2] = reps;
1220-
instructions[address_offset + addr * 2 + 1] = half_period - non_loop_path_length;
1221-
addr++;
1222-
}
1223-
}
1224-
inst_count -= inst_per_buffer;
1225-
}
1226-
// In this if statement, we read a final serial buffer and load it into instructions.
1227-
if(inst_count > 0){
1228-
fast_serial_read(readstring, 8*inst_count);
1229-
for(int i = 0; i < inst_count; i++){
1230-
uint32_t reps = ((readstring[8*i + 7] << 24)
1231-
| (readstring[8*i + 6] << 16)
1232-
| (readstring[8*i + 5] << 8)
1233-
| (readstring[8*i + 4]));
1234-
uint32_t half_period = ((readstring[8*i + 3] << 24)
1235-
| (readstring[8*i + 2] << 16)
1236-
| (readstring[8*i + 1] << 8)
1237-
| (readstring[8*i + 0]));
1238-
1239-
if (reps == 0)
1240-
{
1241-
// This indicates either a stop or a wait instruction
1242-
instructions[address_offset + addr * 2] = 0;
1243-
if (half_period == 0)
1244-
{
1245-
// It's a stop instruction
1246-
instructions[address_offset + addr * 2 + 1] = 0;
1247-
addr++;
1248-
}
1249-
else if (half_period >= 6)
1250-
{
1251-
// It's a wait instruction. See "set" command for why we do this.
1252-
instructions[address_offset + addr * 2 + 1] = (half_period - 4) / 2;
1253-
addr++;
1254-
}
1255-
else
1256-
{
1257-
fast_serial_printf("invalid request\r\n");
1258-
}
1259-
}
1260-
else if (half_period < (non_loop_path_length))
1261-
{
1262-
fast_serial_printf("half-period too short\r\n");
1263-
}
1264-
else if (reps < 1)
1265-
{
1266-
fast_serial_printf("reps must be at least one\r\n");
1267-
}
1268-
else
1269-
{
1270-
instructions[address_offset + addr * 2] = reps;
1271-
instructions[address_offset + addr * 2 + 1] = half_period - non_loop_path_length;
1272-
addr++;
1273-
}
1274-
}
1275-
}
1276-
fast_serial_printf("ok\r\n");
1277-
}
1172+
// It takes 8 bytes to describe an instruction: 4 bytes for reps, 4 bytes for half period
1173+
uint32_t inst_per_buffer = SERIAL_BUFFER_SIZE / 8;
1174+
unsigned int addr = start_addr;
1175+
while(inst_count > inst_per_buffer){
1176+
fast_serial_read(readstring, 8*inst_per_buffer);
1177+
for (int i = 0; i < inst_per_buffer; i++)
1178+
{
1179+
uint32_t reps = ((readstring[8*i + 7] << 24)
1180+
| (readstring[8*i + 6] << 16)
1181+
| (readstring[8*i + 5] << 8)
1182+
| (readstring[8*i + 4]));
1183+
uint32_t half_period = ((readstring[8*i + 3] << 24)
1184+
| (readstring[8*i + 2] << 16)
1185+
| (readstring[8*i + 1] << 8)
1186+
| (readstring[8*i + 0]));
1187+
1188+
if (reps == 0)
1189+
{
1190+
// This indicates either a stop or a wait instruction
1191+
instructions[address_offset + addr * 2] = 0;
1192+
if (half_period == 0)
1193+
{
1194+
// It's a stop instruction
1195+
instructions[address_offset + addr * 2 + 1] = 0;
1196+
addr++;
1197+
}
1198+
else if (half_period >= 6)
1199+
{
1200+
// It's a wait instruction. See "set" command for why we do this.
1201+
instructions[address_offset + addr * 2 + 1] = (half_period - 4) / 2;
1202+
addr++;
1203+
}
1204+
else
1205+
{
1206+
fast_serial_printf("invalid request\r\n");
1207+
}
1208+
}
1209+
else if (half_period < (non_loop_path_length))
1210+
{
1211+
fast_serial_printf("half-period too short\r\n");
1212+
}
1213+
else if (reps < 1)
1214+
{
1215+
fast_serial_printf("reps must be at least one\r\n");
1216+
}
1217+
else
1218+
{
1219+
instructions[address_offset + addr * 2] = reps;
1220+
instructions[address_offset + addr * 2 + 1] = half_period - non_loop_path_length;
1221+
addr++;
1222+
}
1223+
}
1224+
inst_count -= inst_per_buffer;
1225+
}
1226+
// In this if statement, we read a final serial buffer and load it into instructions.
1227+
if(inst_count > 0){
1228+
fast_serial_read(readstring, 8*inst_count);
1229+
for(int i = 0; i < inst_count; i++){
1230+
uint32_t reps = ((readstring[8*i + 7] << 24)
1231+
| (readstring[8*i + 6] << 16)
1232+
| (readstring[8*i + 5] << 8)
1233+
| (readstring[8*i + 4]));
1234+
uint32_t half_period = ((readstring[8*i + 3] << 24)
1235+
| (readstring[8*i + 2] << 16)
1236+
| (readstring[8*i + 1] << 8)
1237+
| (readstring[8*i + 0]));
1238+
1239+
if (reps == 0)
1240+
{
1241+
// This indicates either a stop or a wait instruction
1242+
instructions[address_offset + addr * 2] = 0;
1243+
if (half_period == 0)
1244+
{
1245+
// It's a stop instruction
1246+
instructions[address_offset + addr * 2 + 1] = 0;
1247+
addr++;
1248+
}
1249+
else if (half_period >= 6)
1250+
{
1251+
// It's a wait instruction. See "set" command for why we do this.
1252+
instructions[address_offset + addr * 2 + 1] = (half_period - 4) / 2;
1253+
addr++;
1254+
}
1255+
else
1256+
{
1257+
fast_serial_printf("invalid request\r\n");
1258+
}
1259+
}
1260+
else if (half_period < (non_loop_path_length))
1261+
{
1262+
fast_serial_printf("half-period too short\r\n");
1263+
}
1264+
else if (reps < 1)
1265+
{
1266+
fast_serial_printf("reps must be at least one\r\n");
1267+
}
1268+
else
1269+
{
1270+
instructions[address_offset + addr * 2] = reps;
1271+
instructions[address_offset + addr * 2 + 1] = half_period - non_loop_path_length;
1272+
addr++;
1273+
}
1274+
}
1275+
}
1276+
fast_serial_printf("ok\r\n");
1277+
}
12781278
else if (strncmp(readstring, "go high", 7) == 0)
12791279
{
12801280
unsigned int pseudoclock;

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ Note: the commands are only read if terminated with `\r\n`.
7575
* `hwstart`: Triggers the execution of the instruction set(s), but only after first detecting logical high on the trigger input(s).
7676
* `set <pseudoclock:int> <addr:int> <half-period:int> <reps:int>`: Sets the values of instruction number `addr` for the pseudoclock `pseudoclock` (pseudoclock is zero indexed). `addr` starts at `0`. `half-period` is specified in clock cycles and must be at least `5` (and less than 2^32) for a normal instruction. `reps` should be `1` or more (and less than 2^32) for a normal instruction and indicates how many times the pulse should repeat. Special instructions can be specified with `reps=0`. A stop (end execution) instruction is specified by setting both `reps` and `half-period` to `0`. A wait instruction is specified by `reps=0` and `half-period=<wait timeout in clock cycles>` where the wait-timeout/half-period must be at least 6 clock cycles. Two waits in a row (sequential PrawnBlaster instructions) will trigger an indefinite wait should the first timeout expire (the second wait timeout is ignored and the length of this wait is not logged). See below (FAQ) for details on the requirements for trigger pulse lengths.
7777
* `get <pseudoclock:int> <addr:int>`: Gets the half-period and reps of the instruction at `addr` for the pseudoclock `pseudoclock` (pseudoclock is zero indexed). Return values are integers, separated by a space, in the same format as `set`.
78+
* `setb <pseudoclock:int> <start addr:int> <instruction count:int>`: Sets the values of instructions number `start addr` through `start addr + instruction count` for the pseudoclock `pseudoclock` (pseudoclock is zero indexed). `addr` starts at `0`. After this command is sent, PrawnBlaster reads `instruction count` 8 byte packets and decodes them into instruction values. The first 4 bytes of each packet are `reps` and the second 4 bytes are `half period`, each encoded as an unsigned little-Endian 32 bit integer. Instructions are then processed the same way as `set` (including stop instructions and wait instructions).
7879
* `go high <pseudoclock:int>`: Forces the GPIO output high for the pseudoclock `pseudoclock` (pseudoclock is zero indexed). This is useful for debugging.
7980
* `go low <pseudoclock:int>`: Forces the GPIO output low for the pseudoclock `pseudoclock` (pseudoclock is zero indexed). This is useful for debugging.
8081
* `setinpin <pseudoclock:int> <pin:int>`: Configures which GPIO to use for the pseudoclock `pseudoclock` trigger input (pseudoclock is zero indexed). Defaults to GPIO 0, 2, 4, and 6 for pseudoclocks 0, 1, 2 and 3 respectively. Should be between 0 and 19 inclusive. Trigger inputs can be shared between pseudoclocks (e.g. `setinpin 0 10` followed by `setinpin 1 10` is valid). Note that different defaults may be used if you explicitly assign the default for another use via `setinpin` or `setoutpin`. See FAQ below for more details.

0 commit comments

Comments
 (0)